Refactor URL helper to DI and move its test to unit [MAILPOET-2009]

This commit is contained in:
wxa
2019-04-24 16:50:10 +03:00
committed by M. Shull
parent 388814d226
commit f2e0dc7d2f
11 changed files with 111 additions and 63 deletions

View File

@@ -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