@@ -16,11 +16,8 @@ class CustomerNotificationTest extends \PHPUnit_Framework_TestCase
16
16
/** @var \Magento\Customer\Model\Customer\NotificationStorage|\PHPUnit_Framework_MockObject_MockObject */
17
17
protected $ notificationStorage ;
18
18
19
- /** @var \Magento\Framework\Stdlib\CookieManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
20
- protected $ cookieManager ;
21
-
22
- /** @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */
23
- protected $ cookieMetadataFactory ;
19
+ /** @var \Magento\Customer\Api\CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
20
+ protected $ customerRepository ;
24
21
25
22
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject */
26
23
protected $ appState ;
@@ -42,63 +39,46 @@ protected function setUp()
42
39
$ this ->notificationStorage = $ this ->getMockBuilder ('Magento\Customer\Model\Customer\NotificationStorage ' )
43
40
->disableOriginalConstructor ()
44
41
->getMock ();
45
- $ this ->cookieManager = $ this ->getMockBuilder ('Magento\Framework\Stdlib\CookieManagerInterface ' )
42
+ $ this ->customerRepository = $ this ->getMockBuilder ('Magento\Customer\Api\CustomerRepositoryInterface ' )
46
43
->getMockForAbstractClass ();
47
- $ this ->cookieMetadataFactory = $ this ->getMockBuilder ('Magento\Framework\Stdlib\Cookie\CookieMetadataFactory ' )
48
- ->disableOriginalConstructor ()
49
- ->getMock ();
50
44
$ this ->abstractAction = $ this ->getMockBuilder ('Magento\Backend\App\AbstractAction ' )
51
45
->disableOriginalConstructor ()
52
46
->getMockForAbstractClass ();
53
- $ this ->request = $ this ->getMockBuilder ('Magento\Framework\App\RequestInterface ' )->getMockForAbstractClass ();
47
+ $ this ->request = $ this ->getMockBuilder ('Magento\Framework\App\RequestInterface ' )
48
+ ->setMethods (['isPost ' ])
49
+ ->getMockForAbstractClass ();
54
50
$ this ->appState = $ this ->getMockBuilder ('Magento\Framework\App\State ' )->disableOriginalConstructor ()->getMock ();
55
51
$ this ->plugin = new CustomerNotification (
56
52
$ this ->session ,
57
53
$ this ->notificationStorage ,
58
- $ this ->cookieManager ,
59
- $ this ->cookieMetadataFactory ,
60
- $ this ->appState
54
+ $ this ->appState ,
55
+ $ this ->customerRepository
61
56
);
62
57
}
63
58
64
59
public function testBeforeDispatch ()
65
60
{
66
61
$ customerId = 1 ;
62
+ $ customerGroupId =1 ;
67
63
$ this ->appState ->expects ($ this ->any ())
68
64
->method ('getAreaCode ' )
69
65
->willReturn (\Magento \Framework \App \Area::AREA_FRONTEND );
66
+ $ this ->request ->expects ($ this ->any ())->method ('isPost ' )->willReturn (true );
67
+ $ customerMock = $ this ->getMockBuilder ('Magento\Customer\Api\Data\CustomerInterface ' )->getMockForAbstractClass ();
68
+ $ customerMock ->expects ($ this ->any ())->method ('getGroupId ' )->willReturn ($ customerGroupId );
69
+ $ this ->customerRepository ->expects ($ this ->any ())
70
+ ->method ('getById ' )
71
+ ->with ($ customerId )
72
+ ->willReturn ($ customerMock );
70
73
$ this ->session ->expects ($ this ->any ())->method ('getCustomerId ' )->willReturn ($ customerId );
74
+ $ this ->session ->expects ($ this ->any ())->method ('setCustomerData ' )->with ($ customerMock );
75
+ $ this ->session ->expects ($ this ->any ())->method ('setCustomerGroupId ' )->with ($ customerGroupId );
76
+ $ this ->session ->expects ($ this ->once ())->method ('regenerateId ' );
71
77
$ this ->notificationStorage ->expects ($ this ->any ())
72
78
->method ('isExists ' )
73
79
->with (NotificationStorage::UPDATE_CUSTOMER_SESSION , $ customerId )
74
80
->willReturn (true );
75
81
76
- $ publicCookieMetadata = $ this ->getMockBuilder ('Magento\Framework\Stdlib\Cookie\PublicCookieMetadata ' )
77
- ->disableOriginalConstructor ()
78
- ->getMock ();
79
- $ publicCookieMetadata ->expects ($ this ->once ())->method ('setPath ' )->with ('/ ' );
80
- $ publicCookieMetadata ->expects ($ this ->once ())->method ('setDurationOneYear ' );
81
- $ publicCookieMetadata ->expects ($ this ->once ())->method ('setHttpOnly ' )->with (false );
82
-
83
- $ sensitiveCookieMetadata = $ this ->getMockBuilder ('Magento\Framework\Stdlib\Cookie\SensitiveCookieMetadata ' )
84
- ->disableOriginalConstructor ()
85
- ->getMock ();
86
- $ sensitiveCookieMetadata ->expects ($ this ->once ())->method ('setPath ' )->with ('/ ' )->willReturnSelf ();
87
-
88
- $ this ->cookieMetadataFactory ->expects ($ this ->any ())
89
- ->method ('createPublicCookieMetadata ' )
90
- ->willReturn ($ publicCookieMetadata );
91
- $ this ->cookieMetadataFactory ->expects ($ this ->any ())
92
- ->method ('createSensitiveCookieMetadata ' )
93
- ->willReturn ($ sensitiveCookieMetadata );
94
-
95
- $ this ->cookieManager ->expects ($ this ->once ())
96
- ->method ('setPublicCookie ' )
97
- ->with (NotificationStorage::UPDATE_CUSTOMER_SESSION , $ customerId , $ publicCookieMetadata );
98
- $ this ->cookieManager ->expects ($ this ->once ())
99
- ->method ('deleteCookie ' )
100
- ->with (\Magento \Framework \App \Response \Http::COOKIE_VARY_STRING , $ sensitiveCookieMetadata );
101
-
102
82
$ this ->plugin ->beforeDispatch ($ this ->abstractAction , $ this ->request );
103
83
}
104
84
}
0 commit comments