Refactor authorized emails validation from Bridge to Controller

[MAILPOET-2022]
This commit is contained in:
Rostislav Wolny
2019-05-23 17:52:45 +02:00
committed by M. Shull
parent f3d8ac4c7d
commit f86c0c9612
18 changed files with 246 additions and 139 deletions

View File

@ -2,12 +2,15 @@
namespace MailPoet\Test\API\JSON\v1;
use Carbon\Carbon;
use Codeception\Stub\Expected;
use MailPoet\API\JSON\Response as APIResponse;
use MailPoet\API\JSON\Error as APIError;
use MailPoet\API\JSON\v1\Settings;
use MailPoet\Cron\Workers\InactiveSubscribers;
use MailPoet\Models\ScheduledTask;
use MailPoet\Models\Setting;
use MailPoet\Services\AuthorizedEmailsController;
use MailPoet\Services\Bridge;
use MailPoet\Settings\SettingsController;
class SettingsTest extends \MailPoetTest {
@ -23,7 +26,11 @@ class SettingsTest extends \MailPoetTest {
\ORM::raw_execute('TRUNCATE ' . ScheduledTask::$_table);
$this->settings = new SettingsController();
$this->settings->set('some.setting.key', true);
$this->endpoint = new Settings($this->settings);
$this->endpoint = new Settings(
$this->settings,
new Bridge,
$this->make(AuthorizedEmailsController::class, ['onSettingsSave' => true ])
);
}
function testItCanGetSettings() {
@ -50,6 +57,12 @@ class SettingsTest extends \MailPoetTest {
],
];
$this->endpoint = new Settings(
$this->settings,
$this->make(Bridge::class, ['onSettingsSave' => Expected::once()]),
$this->make(AuthorizedEmailsController::class, ['onSettingsSave' => Expected::once()])
);
$response = $this->endpoint->set(/* missing data */);
expect($response->errors[0]['error'])->equals(APIError::BAD_REQUEST);
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);