Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
anvasiliev authored and eduard13 committed Jul 19, 2018
1 parent 924567f commit ceb7a41
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Newsletter\Test\Unit\Model;

use Magento\Newsletter\Model\Subscriber;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
Expand Down Expand Up @@ -116,7 +118,7 @@ public function testSubscribe()
$email = 'subscriber_email@magento.com';
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(
[
'subscriber_status' => 3,
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED,
'subscriber_email' => $email,
'name' => 'subscriber_name'
]
Expand All @@ -133,15 +135,15 @@ public function testSubscribe()
$this->sendEmailCheck();
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();

$this->assertEquals(1, $this->subscriber->subscribe($email));
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email));
}

public function testSubscribeNotLoggedIn()
{
$email = 'subscriber_email@magento.com';
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(
[
'subscriber_status' => 3,
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED,
'subscriber_email' => $email,
'name' => 'subscriber_name'
]
Expand All @@ -158,7 +160,7 @@ public function testSubscribeNotLoggedIn()
$this->sendEmailCheck();
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();

$this->assertEquals(2, $this->subscriber->subscribe($email));
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email));
}

public function testUpdateSubscription()
Expand All @@ -175,7 +177,7 @@ public function testUpdateSubscription()
->willReturn(
[
'subscriber_id' => 1,
'subscriber_status' => 1
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED
]
);
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
Expand Down Expand Up @@ -210,7 +212,7 @@ public function testUnsubscribeCustomerById()
->willReturn(
[
'subscriber_id' => 1,
'subscriber_status' => 1
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED
]
);
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
Expand All @@ -236,7 +238,7 @@ public function testSubscribeCustomerById()
->willReturn(
[
'subscriber_id' => 1,
'subscriber_status' => 3
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED
]
);
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
Expand All @@ -262,7 +264,7 @@ public function testSubscribeCustomerById1()
->willReturn(
[
'subscriber_id' => 1,
'subscriber_status' => 3
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED
]
);
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
Expand All @@ -276,7 +278,7 @@ public function testSubscribeCustomerById1()
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);

$this->subscriber->subscribeCustomerById($customerId);
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
}

public function testSubscribeCustomerByIdAfterConfirmation()
Expand All @@ -293,7 +295,7 @@ public function testSubscribeCustomerByIdAfterConfirmation()
->willReturn(
[
'subscriber_id' => 1,
'subscriber_status' => 4
'subscriber_status' => Subscriber::STATUS_UNCONFIRMED
]
);
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
Expand All @@ -305,7 +307,7 @@ public function testSubscribeCustomerByIdAfterConfirmation()
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);

$this->subscriber->updateSubscription($customerId);
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
}

public function testUnsubscribe()
Expand Down

0 comments on commit ceb7a41

Please sign in to comment.