Skip to content

Commit cd457aa

Browse files
committed
MAGETWO-38011: [Nord] Unit test Coverage - Sprint 22
1 parent d07b84d commit cd457aa

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Newsletter\Test\Unit\Model\Plugin;
7+
8+
class CustomerPluginTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Newsletter\Model\Plugin\CustomerPlugin
12+
*/
13+
protected $plugin;
14+
15+
/**
16+
* @var \Magento\Newsletter\Model\SubscriberFactory|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
private $subscriberFactory;
19+
20+
/**
21+
* @var \Magento\Newsletter\Model\Subscriber|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $subscriber;
24+
25+
/**
26+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
27+
*/
28+
protected $objectManager;
29+
30+
public function setUp()
31+
{
32+
$this->subscriberFactory = $this->getMockBuilder('\Magento\Newsletter\Model\SubscriberFactory')
33+
->disableOriginalConstructor()
34+
->setMethods(['create'])
35+
->getMock();
36+
$this->subscriber = $this->getMockBuilder('\Magento\Newsletter\Model\Subscriber')
37+
->setMethods(['loadByEmail', 'getId', 'delete', 'updateSubscription'])
38+
->disableOriginalConstructor()
39+
->getMock();
40+
$this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber);
41+
42+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
43+
44+
$this->plugin = $this->objectManager->getObject(
45+
'Magento\Newsletter\Model\Plugin\CustomerPlugin',
46+
[
47+
'subscriberFactory' => $this->subscriberFactory
48+
]
49+
);
50+
}
51+
52+
public function testAfterSave()
53+
{
54+
$customerId = 1;
55+
$subject = $this->getMock('\Magento\Customer\Api\CustomerRepositoryInterface');
56+
$customer = $this->getMock('Magento\Customer\Api\Data\CustomerInterface');
57+
$customer->expects($this->once())->method('getId')->willReturn($customerId);
58+
$this->subscriber->expects($this->once())->method('updateSubscription')->with($customerId)->willReturnSelf();
59+
60+
$this->assertEquals($customer, $this->plugin->afterSave($subject, $customer));
61+
}
62+
63+
public function testAroundDelete()
64+
{
65+
$deleteCustomer = function () {
66+
return true;
67+
};
68+
$subject = $this->getMock('\Magento\Customer\Api\CustomerRepositoryInterface');
69+
$customer = $this->getMock('Magento\Customer\Api\Data\CustomerInterface');
70+
$customer->expects($this->once())->method('getEmail')->willReturn('test@test.com');
71+
$this->subscriber->expects($this->once())->method('loadByEmail')->with('test@test.com')->willReturnSelf();
72+
$this->subscriber->expects($this->once())->method('getId')->willReturn(1);
73+
$this->subscriber->expects($this->once())->method('delete')->willReturnSelf();
74+
75+
$this->assertEquals(true, $this->plugin->aroundDelete($subject, $deleteCustomer, $customer));
76+
}
77+
78+
public function testAroundDeleteById()
79+
{
80+
$customerId = 1;
81+
$deleteCustomerById = function () {
82+
return true;
83+
};
84+
$subject = $this->getMock('\Magento\Customer\Api\CustomerRepositoryInterface');
85+
$customer = $this->getMock('Magento\Customer\Api\Data\CustomerInterface');
86+
$subject->expects($this->once())->method('getById')->willReturn($customer);
87+
$customer->expects($this->once())->method('getEmail')->willReturn('test@test.com');
88+
$this->subscriber->expects($this->once())->method('loadByEmail')->with('test@test.com')->willReturnSelf();
89+
$this->subscriber->expects($this->once())->method('getId')->willReturn(1);
90+
$this->subscriber->expects($this->once())->method('delete')->willReturnSelf();
91+
92+
$this->assertEquals(true, $this->plugin->aroundDeleteById($subject, $deleteCustomerById, $customerId));
93+
}
94+
}

0 commit comments

Comments
 (0)