49 $this->sessionMock = $this->createMock(\
Magento\Persistent\Helper\Session::class);
50 $this->customerSessionMock = $this->createMock(\
Magento\Customer\Model\Session::class);
51 $this->persistentHelperMock = $this->createMock(\
Magento\Persistent\Helper\Data::class);
52 $this->observerMock = $this->createMock(\
Magento\Framework\Event\Observer::class);
53 $this->persistentConfigMock = $this->createMock(\
Magento\Persistent\Model\Persistent\Config::class);
55 $this->createPartialMock(\
Magento\Persistent\Model\Persistent\ConfigFactory::class, [
'create']);
56 $this->model = new \Magento\Persistent\Observer\ApplyPersistentDataObserver(
58 $this->persistentHelperMock,
59 $this->customerSessionMock,
66 $this->persistentHelperMock
67 ->expects($this->once())
68 ->method(
'canProcess')
69 ->with($this->observerMock)
70 ->will($this->returnValue(
false));
71 $this->configMock->expects($this->never())->method(
'create');
72 $this->model->execute($this->observerMock);
77 $this->persistentHelperMock
78 ->expects($this->once())
79 ->method(
'canProcess')
80 ->with($this->observerMock)
81 ->will($this->returnValue(
true));
82 $this->sessionMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
false));
83 $this->configMock->expects($this->never())->method(
'create');
84 $this->model->execute($this->observerMock);
89 $this->persistentHelperMock
90 ->expects($this->once())
91 ->method(
'canProcess')
92 ->with($this->observerMock)
93 ->will($this->returnValue(
true));
94 $this->sessionMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
95 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->will($this->returnValue(
true));
96 $this->configMock->expects($this->never())->method(
'create');
97 $this->model->execute($this->observerMock);
102 $this->persistentHelperMock
103 ->expects($this->once())
104 ->method(
'canProcess')
105 ->with($this->observerMock)
106 ->will($this->returnValue(
true));
107 $this->sessionMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
108 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->will($this->returnValue(
false));
110 ->expects($this->once())
112 ->will($this->returnValue($this->persistentConfigMock));
113 $this->persistentHelperMock
114 ->expects($this->once())
115 ->method(
'getPersistentConfigFilePath')
116 ->will($this->returnValue(
'path/path1'));
117 $this->persistentConfigMock
118 ->expects($this->once())
119 ->method(
'setConfigFilePath')
121 ->will($this->returnSelf());
122 $this->persistentConfigMock->expects($this->once())->method(
'fire');
123 $this->model->execute($this->observerMock);
testExecuteWhenCustomerIsNotPersistent()
testExecuteWhenCustomerIsLoggedIn()
testExecuteWhenCanNotApplyPersistentData()