Refactor URL helper to DI and move its test to unit [MAILPOET-2009]
This commit is contained in:
@@ -11,8 +11,12 @@ class Form {
|
||||
/** @var API */
|
||||
private $api;
|
||||
|
||||
function __construct(API $api) {
|
||||
/** @var UrlHelper */
|
||||
private $url_helper;
|
||||
|
||||
function __construct(API $api, UrlHelper $url_helper) {
|
||||
$this->api = $api;
|
||||
$this->url_helper = $url_helper;
|
||||
}
|
||||
|
||||
function onSubmit($request_data = false) {
|
||||
@@ -21,7 +25,7 @@ class Form {
|
||||
$form_id = (!empty($request_data['data']['form_id'])) ? (int)$request_data['data']['form_id'] : false;
|
||||
$response = $this->api->processRoute();
|
||||
if ($response->status !== APIResponse::STATUS_OK) {
|
||||
return UrlHelper::redirectBack(
|
||||
return $this->url_helper->redirectBack(
|
||||
array(
|
||||
'mailpoet_error' => ($form_id) ? $form_id : true,
|
||||
'mailpoet_success' => null
|
||||
@@ -29,8 +33,8 @@ class Form {
|
||||
);
|
||||
} else {
|
||||
return (isset($response->meta['redirect_url'])) ?
|
||||
UrlHelper::redirectTo($response->meta['redirect_url']) :
|
||||
UrlHelper::redirectBack(
|
||||
$this->url_helper->redirectTo($response->meta['redirect_url']) :
|
||||
$this->url_helper->redirectBack(
|
||||
array(
|
||||
'mailpoet_success' => $form_id,
|
||||
'mailpoet_error' => null
|
||||
|
Reference in New Issue
Block a user