Skip to content

Commit

Permalink
Fix no results handle layout update
Browse files Browse the repository at this point in the history
  • Loading branch information
progreg committed Oct 6, 2018
1 parent 158a0fd commit d2c2c00
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function execute()

$handles = null;
if ($size == 0) {
$handles = [static::DEFAULT_NO_RESULT_HANDLE];
$this->_view->getPage()->initLayout();
$handles = $this->_view->getLayout()->getUpdate()->getHandles();
$handles[] = static::DEFAULT_NO_RESULT_HANDLE;
}

$this->_view->loadLayout($handles);
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/CatalogSearch/Controller/Result/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public function execute()

$handles = null;
if ($query->getNumResults() == 0) {
$handles = [static::DEFAULT_NO_RESULT_HANDLE];
$this->_view->getPage()->initLayout();
$handles = $this->_view->getLayout()->getUpdate()->getHandles();
$handles[] = static::DEFAULT_NO_RESULT_HANDLE;
}

if (empty($getAdditionalRequestParameters) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ public function testUrlSetOnException()
/** @var \Magento\CatalogSearch\Controller\Advanced\Result $instance */
$instance = $objectManager->getObject(
\Magento\CatalogSearch\Controller\Advanced\Result::class,
['context' => $contextMock,
'catalogSearchAdvanced' => $catalogSearchAdvanced,
'urlFactory' => $urlFactoryMock
[
'context' => $contextMock,
'catalogSearchAdvanced' => $catalogSearchAdvanced,
'urlFactory' => $urlFactoryMock
]
);
$this->assertEquals($redirectResultMock, $instance->execute());
Expand All @@ -151,10 +152,25 @@ public function testNoResultsHandle()
{
$expectedQuery = 'notExistTerm';

$view = $this->createPartialMock(\Magento\Framework\App\View::class, ['loadLayout', 'renderLayout']);
$update = $this->createPartialMock(\Magento\Framework\View\Model\Layout\Merge::class, ['getHandles']);
$update->expects($this->once())->method('getHandles')->will($this->returnValue([]));

$layout = $this->createPartialMock(\Magento\Framework\View\Result\Layout::class, ['getUpdate']);
$layout->expects($this->once())->method('getUpdate')->will($this->returnValue($update));

$page = $this->createPartialMock(\Magento\Framework\View\Result\Page::class, ['initLayout']);

$view = $this->createPartialMock(
\Magento\Framework\App\View::class,
['loadLayout', 'renderLayout', 'getPage', 'getLayout']
);

$view->expects($this->once())->method('loadLayout')
->with([\Magento\CatalogSearch\Controller\Advanced\Result::DEFAULT_NO_RESULT_HANDLE]);

$view->expects($this->once())->method('getPage')->will($this->returnValue($page));
$view->expects($this->once())->method('getLayout')->will($this->returnValue($layout));

$request = $this->createPartialMock(\Magento\Framework\App\Console\Request::class, ['getQueryValue']);
$request->expects($this->once())->method('getQueryValue')->will($this->returnValue($expectedQuery));

Expand Down

0 comments on commit d2c2c00

Please sign in to comment.