Skip to content

Commit 4966873

Browse files
committed
Merge branch 'develop' into FearlessKiwis-MAGETWO-55867-New-Incorrect-Time
2 parents ef98593 + 67c29c6 commit 4966873

File tree

10 files changed

+63
-23
lines changed

10 files changed

+63
-23
lines changed

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testToHtml()
5353
->disableOriginalConstructor()
5454
->setMethods(['dispatch'])
5555
->getMock();
56-
$eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true));
56+
$eventManager->expects($this->exactly(2))->method('dispatch')->will($this->returnValue(true));
5757

5858
$scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class)
5959
->setMethods(['getValue'])

app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function testGetProductsCount()
186186

187187
protected function generalGetProductCollection()
188188
{
189-
$this->eventManager->expects($this->once())->method('dispatch')
189+
$this->eventManager->expects($this->exactly(2))->method('dispatch')
190190
->will($this->returnValue(true));
191191
$this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()
192192
->willReturn(false);

app/code/Magento/Email/Model/AbstractTemplate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,13 @@ public function getTemplateFilter()
663663
* Save current design config and replace with design config from specified store
664664
* Event is not dispatched.
665665
*
666-
* @param int|string $storeId
666+
* @param null|bool|int|string $storeId
667667
* @param string $area
668668
* @return void
669669
*/
670670
public function emulateDesign($storeId, $area = self::DEFAULT_DESIGN_AREA)
671671
{
672-
if ($storeId) {
672+
if ($storeId !== null && $storeId !== false) {
673673
// save current design settings
674674
$this->emulatedDesignConfig = clone $this->getDesignConfig();
675675
if (

app/code/Magento/Email/Test/Unit/Model/AbstractTemplateTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,24 @@ public function testEmulateDesignAndRevertDesign()
331331
{
332332
$model = $this->getModelMock();
333333
$originalConfig = ['area' => 'some_area', 'store' => 1];
334-
$expectedConfig = ['area' => 'frontend', 'store' => 2];
335334
$model->setDesignConfig($originalConfig);
336335

337-
$model->emulateDesign(2);
338-
// assert config data has been emulated
339-
$this->assertEquals($expectedConfig, $model->getDesignConfig()->getData());
340-
341-
$model->revertDesign();
342-
// assert config data has been reverted to the original state
343-
$this->assertEquals($originalConfig, $model->getDesignConfig()->getData());
336+
$expectedConfigs = [
337+
['in' => ['area' => 'frontend', 'store' => null], 'out' => $originalConfig],
338+
['in' => ['area' => 'frontend', 'store' => false], 'out' => $originalConfig],
339+
['in' => ['area' => 'frontend', 'store' => 0], 'out' => ['area' => 'frontend', 'store' => 0]],
340+
['in' => ['area' => 'frontend', 'store' => 1], 'out' => ['area' => 'frontend', 'store' => 1]],
341+
['in' => ['area' => 'frontend', 'store' => 2], 'out' => ['area' => 'frontend', 'store' => 2]],
342+
];
343+
foreach ($expectedConfigs as $set) {
344+
$model->emulateDesign($set['in']['store'], $set['in']['area']);
345+
// assert config data has been emulated
346+
$this->assertEquals($set['out'], $model->getDesignConfig()->getData());
347+
348+
$model->revertDesign();
349+
// assert config data has been reverted to the original state
350+
$this->assertEquals($originalConfig, $model->getDesignConfig()->getData());
351+
}
344352
}
345353

346354
public function testGetDesignConfig()

app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,14 @@ public function testGetWizardPaymentMethodOptions()
235235
public function testToHtml()
236236
{
237237
$this->eventManager
238-
->expects($this->once())
238+
->expects($this->at(0))
239239
->method('dispatch')
240240
->with('view_block_abstract_to_html_before', ['block' => $this->block]);
241+
$transport = new \Magento\Framework\DataObject(['html' => '']);
242+
$this->eventManager
243+
->expects($this->at(1))
244+
->method('dispatch')
245+
->with('view_block_abstract_to_html_after', ['block' => $this->block, 'transport' => $transport]);
241246
$this->scopeConfig
242247
->expects($this->once())
243248
->method('getValue')

app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ public function testToHtml($customerId)
261261
$this->additional->setData('cache_lifetime', 789);
262262
$this->additional->setData('cache_key', 'cache-key');
263263

264-
$this->eventManagerMock->expects($this->once())
264+
$this->eventManagerMock->expects($this->at(0))
265265
->method('dispatch')
266266
->with('view_block_abstract_to_html_before', ['block' => $this->additional]);
267+
$this->eventManagerMock->expects($this->at(1))
268+
->method('dispatch')
269+
->with('view_block_abstract_to_html_after');
267270
$this->scopeConfigMock->expects($this->once())
268271
->method('getValue')
269272
->with(

app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testToHtmlCatalogProductsListGroupedProduct()
6666
. 'Main Content Area</option><option value="content.bottom" >Main Content Bottom</option>'
6767
. '<option value="content.top" >Main Content Top</option></select>';
6868

69-
$this->eventManagerMock->expects($this->once())->method('dispatch')->willReturn(true);
69+
$this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true);
7070
$this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false);
7171

7272
$this->themeCollectionFactoryMock->expects($this->once())
@@ -153,7 +153,7 @@ public function testToHtmlCatalogCategoryLinkSimpleProduct()
153153
. '<option value="sidebar.additional" >Sidebar Additional</option>'
154154
. '<option value="sidebar.main" >Sidebar Main</option></select>';
155155

156-
$this->eventManagerMock->expects($this->once())->method('dispatch')->willReturn(true);
156+
$this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true);
157157
$this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false);
158158

159159
$this->themeCollectionFactoryMock->expects($this->once())
@@ -284,7 +284,7 @@ public function testToHtmlCmsStaticBlockAllProductTypes()
284284
. '<option value="sidebar.additional" >Sidebar Additional</option>'
285285
. '<option value="sidebar.main" >Sidebar Main</option></select>';
286286

287-
$this->eventManagerMock->expects($this->once())->method('dispatch')->willReturn(true);
287+
$this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true);
288288
$this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false);
289289

290290
$this->themeCollectionFactoryMock->expects($this->once())
@@ -402,7 +402,7 @@ public function testToHtmlOrderBySkuAllPages()
402402
. '<option value="sidebar.additional" >Sidebar Additional</option><option value="sidebar.main" >'
403403
. 'Sidebar Main</option></select>';
404404

405-
$this->eventManagerMock->expects($this->once())->method('dispatch')->willReturn(true);
405+
$this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true);
406406
$this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false);
407407

408408
$this->themeCollectionFactoryMock->expects($this->once())

lib/internal/Magento/Framework/View/Element/AbstractBlock.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,18 @@ public function toHtml()
670670
}
671671
$html = $this->_afterToHtml($html);
672672

673+
/** @var \Magento\Framework\DataObject */
674+
$transportObject = new \Magento\Framework\DataObject(
675+
[
676+
'html' => $html,
677+
]
678+
);
679+
$this->_eventManager->dispatch('view_block_abstract_to_html_after', [
680+
'block' => $this,
681+
'transport' => $transportObject
682+
]);
683+
$html = $transportObject->getHtml();
684+
673685
return $html;
674686
}
675687

lib/internal/Magento/Framework/View/Layout/Generator/Block.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ protected function getBlockInstance($block, array $arguments = [])
261261
}
262262
if (!$block instanceof \Magento\Framework\View\Element\AbstractBlock) {
263263
throw new \Magento\Framework\Exception\LocalizedException(
264-
new \Magento\Framework\Phrase('Invalid block type: %1', [$block]),
264+
new \Magento\Framework\Phrase(
265+
'Invalid block type: %1',
266+
[is_object($block) ? get_class($block) : (string) $block]
267+
),
265268
$e
266269
);
267270
}

lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
use Magento\Framework\Session\SidResolverInterface;
2020
use Magento\Framework\Session\SessionManagerInterface;
2121

22+
/**
23+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24+
*/
2225
class AbstractBlockTest extends \PHPUnit_Framework_TestCase
2326
{
2427
/**
@@ -204,7 +207,7 @@ public function testToHtmlWhenModuleIsDisabled()
204207
$moduleName = 'Test';
205208
$this->block->setData('module_name', $moduleName);
206209

207-
$this->eventManagerMock->expects($this->once())
210+
$this->eventManagerMock->expects($this->any())
208211
->method('dispatch')
209212
->with('view_block_abstract_to_html_before', ['block' => $this->block]);
210213
$this->scopeConfigMock->expects($this->once())
@@ -219,6 +222,7 @@ public function testToHtmlWhenModuleIsDisabled()
219222
* @param string|bool $cacheLifetime
220223
* @param string|bool $dataFromCache
221224
* @param string $dataForSaveCache
225+
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsDispatchEvent
222226
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsCacheLoad
223227
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $expectsCacheSave
224228
* @param string $expectedResult
@@ -229,6 +233,7 @@ public function testGetCacheLifetimeViaToHtml(
229233
$cacheLifetime,
230234
$dataFromCache,
231235
$dataForSaveCache,
236+
$expectsDispatchEvent,
232237
$expectsCacheLoad,
233238
$expectsCacheSave,
234239
$expectedResult
@@ -239,9 +244,8 @@ public function testGetCacheLifetimeViaToHtml(
239244
$this->block->setData('module_name', $moduleName);
240245
$this->block->setData('cache_lifetime', $cacheLifetime);
241246

242-
$this->eventManagerMock->expects($this->once())
243-
->method('dispatch')
244-
->with('view_block_abstract_to_html_before', ['block' => $this->block]);
247+
$this->eventManagerMock->expects($expectsDispatchEvent)
248+
->method('dispatch');
245249
$this->scopeConfigMock->expects($this->once())
246250
->method('getValue')
247251
->with('advanced/modules_disable_output/' . $moduleName, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
@@ -278,6 +282,7 @@ public function getCacheLifetimeDataProvider()
278282
'cacheLifetime' => null,
279283
'dataFromCache' => 'dataFromCache',
280284
'dataForSaveCache' => '',
285+
'expectsDispatchEvent' => $this->exactly(2),
281286
'expectsCacheLoad' => $this->never(),
282287
'expectsCacheSave' => $this->never(),
283288
'expectedResult' => '',
@@ -286,6 +291,7 @@ public function getCacheLifetimeDataProvider()
286291
'cacheLifetime' => false,
287292
'dataFromCache' => 'dataFromCache',
288293
'dataForSaveCache' => '',
294+
'expectsDispatchEvent' => $this->exactly(2),
289295
'expectsCacheLoad' => $this->once(),
290296
'expectsCacheSave' => $this->never(),
291297
'expectedResult' => 'dataFromCache',
@@ -294,6 +300,7 @@ public function getCacheLifetimeDataProvider()
294300
'cacheLifetime' => 120,
295301
'dataFromCache' => 'dataFromCache',
296302
'dataForSaveCache' => '',
303+
'expectsDispatchEvent' => $this->exactly(2),
297304
'expectsCacheLoad' => $this->once(),
298305
'expectsCacheSave' => $this->never(),
299306
'expectedResult' => 'dataFromCache',
@@ -302,6 +309,7 @@ public function getCacheLifetimeDataProvider()
302309
'cacheLifetime' => '120string',
303310
'dataFromCache' => 'dataFromCache',
304311
'dataForSaveCache' => '',
312+
'expectsDispatchEvent' => $this->exactly(2),
305313
'expectsCacheLoad' => $this->once(),
306314
'expectsCacheSave' => $this->never(),
307315
'expectedResult' => 'dataFromCache',
@@ -310,6 +318,7 @@ public function getCacheLifetimeDataProvider()
310318
'cacheLifetime' => 120,
311319
'dataFromCache' => false,
312320
'dataForSaveCache' => '',
321+
'expectsDispatchEvent' => $this->exactly(2),
313322
'expectsCacheLoad' => $this->once(),
314323
'expectsCacheSave' => $this->once(),
315324
'expectedResult' => '',

0 commit comments

Comments
 (0)