Skip to content

Commit 4afef63

Browse files
committed
Add view_block_abstract_to_html_after event to toHtml() method
1 parent 8fd3e8a commit 4afef63

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
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
@@ -50,7 +50,7 @@ public function testToHtml()
5050
->disableOriginalConstructor()
5151
->setMethods(['dispatch'])
5252
->getMock();
53-
$eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true));
53+
$eventManager->expects($this->exactly(2))->method('dispatch')->will($this->returnValue(true));
5454

5555
$scopeConfig = $this->getMockBuilder('\Magento\Framework\App\Config')
5656
->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
@@ -170,7 +170,7 @@ public function testGetProductsCount()
170170

171171
protected function generalGetProductCollection()
172172
{
173-
$this->eventManager->expects($this->once())->method('dispatch')
173+
$this->eventManager->expects($this->exactly(2))->method('dispatch')
174174
->will($this->returnValue(true));
175175
$this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()
176176
->willReturn(false);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,14 @@ public function testGetWizardPaymentMethodOptions()
227227
public function testToHtml()
228228
{
229229
$this->eventManager
230-
->expects($this->once())
230+
->expects($this->at(0))
231231
->method('dispatch')
232232
->with('view_block_abstract_to_html_before', ['block' => $this->block]);
233+
$transport = new \Magento\Framework\DataObject(['html' => '']);
234+
$this->eventManager
235+
->expects($this->at(1))
236+
->method('dispatch')
237+
->with('view_block_abstract_to_html_after', ['block' => $this->block, 'transport' => $transport]);
233238
$this->scopeConfig
234239
->expects($this->once())
235240
->method('getValue')

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,13 @@ 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+
$transport = new \Magento\Framework\DataObject(['html' => '']);
268+
$this->eventManagerMock->expects($this->at(1))
269+
->method('dispatch')
270+
->with('view_block_abstract_to_html_after');
267271
$this->scopeConfigMock->expects($this->once())
268272
->method('getValue')
269273
->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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,15 @@ public function toHtml()
665665
}
666666
$html = $this->_afterToHtml($html);
667667

668+
/** @var \Magento\Framework\DataObject */
669+
$transportObject = new \Magento\Framework\DataObject(
670+
[
671+
'html' => $html,
672+
]
673+
);
674+
$this->_eventManager->dispatch('view_block_abstract_to_html_after', ['block' => $this, 'transport' => $transportObject]);
675+
$html = $transportObject->getHtml();
676+
668677
return $html;
669678
}
670679

0 commit comments

Comments
 (0)