59 $eventMethods = [
'getConfigFilePath',
'getBlock',
'__wakeUp'];
60 $this->sessionMock = $this->createMock(\
Magento\Persistent\Helper\Session::class);
61 $this->customerSessionMock = $this->createMock(\
Magento\Customer\Model\Session::class);
62 $this->persistentHelperMock = $this->createMock(\
Magento\Persistent\Helper\Data::class);
64 $this->createPartialMock(\
Magento\Persistent\Model\Persistent\ConfigFactory::class, [
'create']);
65 $this->observerMock = $this->createMock(\
Magento\Framework\Event\Observer::class);
66 $this->eventMock = $this->createPartialMock(\
Magento\Framework\Event::class, $eventMethods);
67 $this->blockMock = $this->createMock(\
Magento\Framework\View\Element\AbstractBlock::class);
68 $this->persistentConfigMock = $this->createMock(\
Magento\Persistent\Model\Persistent\Config::class);
69 $this->model = new \Magento\Persistent\Observer\ApplyBlockPersistentDataObserver(
71 $this->persistentHelperMock,
72 $this->customerSessionMock,
79 $this->sessionMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
false));
80 $this->observerMock->expects($this->never())->method(
'getEvent');
81 $this->model->execute($this->observerMock);
86 $this->sessionMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
87 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->will($this->returnValue(
true));
88 $this->observerMock->expects($this->never())->method(
'getEvent');
89 $this->model->execute($this->observerMock);
94 $this->sessionMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
95 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->will($this->returnValue(
false));
96 $this->observerMock->expects($this->once())->method(
'getEvent')->will($this->returnValue($this->eventMock));
97 $this->eventMock->expects($this->once())->method(
'getBlock')->will($this->returnValue(
null));
98 $this->eventMock->expects($this->never())->method(
'getConfigFilePath');
99 $this->model->execute($this->observerMock);
104 $this->sessionMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
105 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->will($this->returnValue(
false));
107 ->expects($this->any())
109 ->will($this->returnValue($this->eventMock));
110 $this->eventMock->expects($this->once())->method(
'getBlock')->will($this->returnValue($this->blockMock));
111 $this->eventMock->expects($this->once())->method(
'getConfigFilePath')->will($this->returnValue(
false));
112 $this->persistentHelperMock
113 ->expects($this->once())
114 ->method(
'getPersistentConfigFilePath')
115 ->will($this->returnValue(
'path1/path2'));
117 ->expects($this->once())
119 ->will($this->returnValue($this->persistentConfigMock));
120 $this->persistentConfigMock->expects($this->once())->method(
'setConfigFilePath')->with(
'path1/path2');
121 $this->persistentConfigMock
122 ->expects($this->once())
123 ->method(
'getBlockConfigInfo')
124 ->with(get_class($this->blockMock))
125 ->will($this->returnValue([
'persistentConfigInfo']));
126 $this->persistentConfigMock
127 ->expects($this->once())
129 ->with(
'persistentConfigInfo', $this->blockMock);
130 $this->model->execute($this->observerMock);
135 $this->sessionMock->expects($this->once())->method(
'isPersistent')->will($this->returnValue(
true));
136 $this->customerSessionMock->expects($this->once())->method(
'isLoggedIn')->will($this->returnValue(
false));
138 ->expects($this->any())
140 ->will($this->returnValue($this->eventMock));
141 $this->eventMock->expects($this->once())->method(
'getBlock')->will($this->returnValue($this->blockMock));
142 $this->eventMock->expects($this->once())->method(
'getConfigFilePath')->will($this->returnValue(
'path1/path2'));
143 $this->persistentHelperMock
144 ->expects($this->never())
145 ->method(
'getPersistentConfigFilePath');
147 ->expects($this->once())
149 ->will($this->returnValue($this->persistentConfigMock));
150 $this->persistentConfigMock->expects($this->once())->method(
'setConfigFilePath')->with(
'path1/path2');
151 $this->persistentConfigMock
152 ->expects($this->once())
153 ->method(
'getBlockConfigInfo')
154 ->with(get_class($this->blockMock))
155 ->will($this->returnValue([
'persistentConfigInfo']));
156 $this->persistentConfigMock
157 ->expects($this->once())
159 ->with(
'persistentConfigInfo', $this->blockMock);
160 $this->model->execute($this->observerMock);
testExecuteForLoggedInAndPersistentCustomer()
testExecuteWhenBlockDoesNotExist()
testExecuteWhenConfigFilePathDoesNotExist()
testExecuteWhenSessionNotPersistent()