Inject bulk action controller using DI
[MAILPOET-1689]
This commit is contained in:
@ -3,29 +3,33 @@ namespace MailPoet\Test\API\JSON\v1;
|
||||
|
||||
use MailPoet\API\JSON\v1\Segments;
|
||||
use MailPoet\API\JSON\Response as APIResponse;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
|
||||
class SegmentsTest extends \MailPoetTest {
|
||||
|
||||
/** @var Segments */
|
||||
private $endpoint;
|
||||
|
||||
function _before() {
|
||||
$this->endpoint = ContainerWrapper::getInstance()->get(Segments::class);
|
||||
$this->segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1', 'type' => 'default'));
|
||||
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2', 'type' => 'default'));
|
||||
$this->segment_3 = Segment::createOrUpdate(array('name' => 'Segment 3', 'type' => 'default'));
|
||||
}
|
||||
|
||||
function testItCanGetASegment() {
|
||||
$router = new Segments();
|
||||
|
||||
$response = $router->get(/* missing id */);
|
||||
$response = $this->endpoint->get(/* missing id */);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->equals('This list does not exist.');
|
||||
|
||||
$response = $router->get(array('id' => 'not_an_id'));
|
||||
$response = $this->endpoint->get(array('id' => 'not_an_id'));
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->equals('This list does not exist.');
|
||||
|
||||
$response = $router->get(array('id' => $this->segment_1->id));
|
||||
$response = $this->endpoint->get(array('id' => $this->segment_1->id));
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
Segment::findOne($this->segment_1->id)->asArray()
|
||||
@ -33,8 +37,7 @@ class SegmentsTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanGetListingData() {
|
||||
$router = new Segments();
|
||||
$response = $router->listing();
|
||||
$response = $this->endpoint->listing();
|
||||
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
|
||||
@ -53,12 +56,11 @@ class SegmentsTest extends \MailPoetTest {
|
||||
'name' => 'New Segment'
|
||||
);
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->save(/* missing data */);
|
||||
$response = $this->endpoint->save(/* missing data */);
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals('Please specify a name.');
|
||||
|
||||
$response = $router->save($segment_data);
|
||||
$response = $this->endpoint->save($segment_data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
Segment::where('name', 'New Segment')->findOne()->asArray()
|
||||
@ -70,8 +72,7 @@ class SegmentsTest extends \MailPoetTest {
|
||||
'name' => 'Segment 1'
|
||||
);
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->save($duplicate_entry);
|
||||
$response = $this->endpoint->save($duplicate_entry);
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals(
|
||||
'Another record already exists. Please specify a different "name".'
|
||||
@ -84,8 +85,7 @@ class SegmentsTest extends \MailPoetTest {
|
||||
$trashed_segment = Segment::findOne($this->segment_1->id);
|
||||
expect($trashed_segment->deleted_at)->notNull();
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->restore(array('id' => $this->segment_1->id));
|
||||
$response = $this->endpoint->restore(array('id' => $this->segment_1->id));
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
Segment::findOne($this->segment_1->id)->asArray()
|
||||
@ -95,8 +95,7 @@ class SegmentsTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanTrashASegment() {
|
||||
$router = new Segments();
|
||||
$response = $router->trash(array('id' => $this->segment_2->id));
|
||||
$response = $this->endpoint->trash(array('id' => $this->segment_2->id));
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
Segment::findOne($this->segment_2->id)->asArray()
|
||||
@ -106,16 +105,14 @@ class SegmentsTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanDeleteASegment() {
|
||||
$router = new Segments();
|
||||
$response = $router->delete(array('id' => $this->segment_3->id));
|
||||
$response = $this->endpoint->delete(array('id' => $this->segment_3->id));
|
||||
expect($response->data)->isEmpty();
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->meta['count'])->equals(1);
|
||||
}
|
||||
|
||||
function testItCanDuplicateASegment() {
|
||||
$router = new Segments();
|
||||
$response = $router->duplicate(array('id' => $this->segment_1->id));
|
||||
$response = $this->endpoint->duplicate(array('id' => $this->segment_1->id));
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
Segment::where('name', 'Copy of Segment 1')->findOne()->asArray()
|
||||
@ -130,16 +127,14 @@ class SegmentsTest extends \MailPoetTest {
|
||||
'status' => Subscriber::STATUS_SUBSCRIBED
|
||||
));
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->bulkAction(array(
|
||||
$response = $this->endpoint->bulkAction(array(
|
||||
'action' => 'trash',
|
||||
'listing' => array('group' => 'all')
|
||||
));
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->meta['count'])->equals(3);
|
||||
|
||||
$router = new Segments();
|
||||
$response = $router->bulkAction(array(
|
||||
$response = $this->endpoint->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
@ -147,7 +142,7 @@ class SegmentsTest extends \MailPoetTest {
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->meta['count'])->equals(3);
|
||||
|
||||
$response = $router->bulkAction(array(
|
||||
$response = $this->endpoint->bulkAction(array(
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
|
Reference in New Issue
Block a user