Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MviewStateTest.php
Go to the documentation of this file.
1 <?php
7 
8 class MviewStateTest extends \PHPUnit\Framework\TestCase
9 {
14  {
15  return [['suspended', 'idle'], ['suspended', 'working']];
16  }
17 
23  public function testAfterSetStatusSuspend($stateStatus, $relatedStatus)
24  {
27  $relatedVersion = 'related_version';
28 
29  $state = $this->getMockBuilder(
30  \Magento\Framework\Mview\View\StateInterface::class
31  )->disableOriginalConstructor()->getMockForAbstractClass();
32 
33  $state->expects($this->exactly(2))->method('getViewId')->will($this->returnValue($stateViewId));
34 
35  $state->expects($this->any())->method('getStatus')->will($this->returnValue($stateStatus));
36 
37  $relatedViewState = $this->getMockBuilder(
38  \Magento\Framework\Mview\View\StateInterface::class
39  )->disableOriginalConstructor()->getMock();
40 
41  $relatedViewState->expects(
42  $this->once()
43  )->method(
44  'loadByView'
45  )->with(
46  $this->equalTo($relatedViewId)
47  )->will(
48  $this->returnSelf()
49  );
50 
51  $relatedViewState->expects($this->once())->method('getMode')->will($this->returnValue('enabled'));
52 
53  $relatedViewState->expects($this->once())->method('getStatus')->will($this->returnValue($relatedStatus));
54 
55  $relatedViewState->expects($this->once())->method('save')->will($this->returnSelf());
56 
57  $relatedViewState->expects(
58  $this->once()
59  )->method(
60  'setVersionId'
61  )->with(
62  $this->equalTo($relatedVersion)
63  )->will(
64  $this->returnSelf()
65  );
66 
67  $relatedViewState->expects(
68  $this->once()
69  )->method(
70  'setStatus'
71  )->with(
72  $this->equalTo($stateStatus)
73  )->will(
74  $this->returnSelf()
75  );
76 
77  $relatedViewChangelog = $this->getMockBuilder(
78  \Magento\Framework\Mview\View\ChangelogInterface::class
79  )->disableOriginalConstructor()->getMock();
80 
81  $relatedViewChangelog->expects(
82  $this->once()
83  )->method(
84  'setViewId'
85  )->with(
86  $this->equalTo($relatedViewId)
87  )->will(
88  $this->returnSelf()
89  );
90 
91  $relatedViewChangelog->expects($this->once())->method('getVersion')->will($this->returnValue($relatedVersion));
92 
93  $model = new \Magento\Catalog\Model\Indexer\Category\Product\Plugin\MviewState(
94  $relatedViewState,
95  $relatedViewChangelog
96  );
97  $this->assertInstanceOf(\Magento\Framework\Mview\View\StateInterface::class, $model->afterSetStatus($state));
98  }
99 
104  {
105  return [['idle', 'suspended'], ['working', 'suspended']];
106  }
107 
113  public function testAfterSetStatusResume($stateStatus, $relatedStatus)
114  {
117 
118  $state = $this->getMockBuilder(
119  \Magento\Framework\Mview\View\StateInterface::class
120  )->disableOriginalConstructor()->getMockForAbstractClass();
121 
122  $state->expects($this->exactly(2))->method('getViewId')->will($this->returnValue($stateViewId));
123 
124  $state->expects($this->any())->method('getStatus')->will($this->returnValue($stateStatus));
125 
126  $relatedViewState = $this->getMockBuilder(
127  \Magento\Framework\Mview\View\StateInterface::class
128  )->disableOriginalConstructor()->getMock();
129 
130  $relatedViewState->expects(
131  $this->once()
132  )->method(
133  'loadByView'
134  )->with(
135  $this->equalTo($relatedViewId)
136  )->will(
137  $this->returnSelf()
138  );
139 
140  $relatedViewState->expects($this->once())->method('getMode')->will($this->returnValue('enabled'));
141 
142  $relatedViewState->expects($this->any())->method('getStatus')->will($this->returnValue($relatedStatus));
143 
144  $relatedViewState->expects($this->once())->method('save')->will($this->returnSelf());
145 
146  $relatedViewState->expects($this->never())->method('setVersionId');
147 
148  $relatedViewState->expects(
149  $this->once()
150  )->method(
151  'setStatus'
152  )->with(
153  $this->equalTo('idle')
154  )->will(
155  $this->returnSelf()
156  );
157 
158  $relatedViewChangelog = $this->getMockBuilder(
159  \Magento\Framework\Mview\View\ChangelogInterface::class
160  )->disableOriginalConstructor()->getMock();
161 
162  $model = new \Magento\Catalog\Model\Indexer\Category\Product\Plugin\MviewState(
163  $relatedViewState,
164  $relatedViewChangelog
165  );
166  $this->assertInstanceOf(\Magento\Framework\Mview\View\StateInterface::class, $model->afterSetStatus($state));
167  }
168 
173  {
174  return [
175  ['idle', 'idle'],
176  ['working', 'working'],
177  ['suspended', 'suspended'],
178  ['idle', 'working'],
179  ['working', 'idle']
180  ];
181  }
182 
188  public function testAfterSetStatusSkip($stateStatus, $relatedStatus)
189  {
192 
193  $state = $this->getMockBuilder(
194  \Magento\Framework\Mview\View\StateInterface::class
195  )->disableOriginalConstructor()->getMockForAbstractClass();
196 
197  $state->expects($this->exactly(2))->method('getViewId')->will($this->returnValue($stateViewId));
198 
199  $state->expects($this->any())->method('getStatus')->will($this->returnValue($stateStatus));
200 
201  $relatedViewState = $this->getMockBuilder(
202  \Magento\Framework\Mview\View\StateInterface::class
203  )->disableOriginalConstructor()->getMock();
204 
205  $relatedViewState->expects(
206  $this->once()
207  )->method(
208  'loadByView'
209  )->with(
210  $this->equalTo($relatedViewId)
211  )->will(
212  $this->returnSelf()
213  );
214 
215  $relatedViewState->expects($this->once())->method('getMode')->will($this->returnValue('enabled'));
216 
217  $relatedViewState->expects($this->any())->method('getStatus')->will($this->returnValue($relatedStatus));
218 
219  $relatedViewState->expects($this->never())->method('save');
220 
221  $relatedViewState->expects($this->never())->method('setVersionId');
222 
223  $relatedViewState->expects($this->never())->method('setStatus');
224 
225  $relatedViewChangelog = $this->getMockBuilder(
226  \Magento\Framework\Mview\View\ChangelogInterface::class
227  )->disableOriginalConstructor()->getMock();
228 
229  $model = new \Magento\Catalog\Model\Indexer\Category\Product\Plugin\MviewState(
230  $relatedViewState,
231  $relatedViewChangelog
232  );
233  $this->assertInstanceOf(\Magento\Framework\Mview\View\StateInterface::class, $model->afterSetStatus($state));
234  }
235 
240  {
241  return [['idle'], ['working'], ['suspended']];
242  }
243 
248  public function testAfterSetStatusDisabled($stateStatus)
249  {
252 
253  $state = $this->getMockBuilder(
254  \Magento\Framework\Mview\View\StateInterface::class
255  )->disableOriginalConstructor()->getMockForAbstractClass();
256 
257  $state->expects($this->exactly(2))->method('getViewId')->will($this->returnValue($stateViewId));
258 
259  $state->expects($this->any())->method('getStatus')->will($this->returnValue($stateStatus));
260 
261  $relatedViewState = $this->getMockBuilder(
262  \Magento\Framework\Mview\View\StateInterface::class
263  )->disableOriginalConstructor()->getMock();
264 
265  $relatedViewState->expects(
266  $this->once()
267  )->method(
268  'loadByView'
269  )->with(
270  $this->equalTo($relatedViewId)
271  )->will(
272  $this->returnSelf()
273  );
274 
275  $relatedViewState->expects($this->once())->method('getMode')->will($this->returnValue('disabled'));
276 
277  $relatedViewState->expects($this->never())->method('getStatus');
278 
279  $relatedViewState->expects($this->never())->method('save');
280 
281  $relatedViewState->expects($this->never())->method('setVersionId');
282 
283  $relatedViewState->expects($this->never())->method('setStatus');
284 
285  $relatedViewChangelog = $this->getMockBuilder(
286  \Magento\Framework\Mview\View\ChangelogInterface::class
287  )->disableOriginalConstructor()->getMock();
288 
289  $model = new \Magento\Catalog\Model\Indexer\Category\Product\Plugin\MviewState(
290  $relatedViewState,
291  $relatedViewChangelog
292  );
293  $this->assertInstanceOf(\Magento\Framework\Mview\View\StateInterface::class, $model->afterSetStatus($state));
294  }
295 }