Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#10734: Magento 2 is not showing Popular Search Terms [backport]
- Loading branch information
1 parent
321278b
commit 1f77aaa
Showing
6 changed files
with
207 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
dev/tests/integration/testsuite/Magento/Search/Block/TermTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Search\Block; | ||
|
||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Framework\View\LayoutInterface; | ||
|
||
/** | ||
* Tests Magento\Search\Block\Term. | ||
* | ||
* @magentoAppIsolation enabled | ||
* @magentoDbIsolation enabled | ||
*/ | ||
class TermTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var Term | ||
*/ | ||
private $term; | ||
|
||
/** | ||
* Tests Magento\Search\Block\Term::GetTerms. | ||
* | ||
* @magentoDataFixture Magento/Search/_files/query.php | ||
* @dataProvider getTermsDataProvider | ||
* @param array $expected | ||
*/ | ||
public function testGetTerms(array $expected) | ||
{ | ||
$result = $this->term->getTerms(); | ||
$actual = array_map(function ($object) { | ||
return $object->setUpdatedAt(null)->getData(); | ||
}, | ||
$result); | ||
|
||
self::assertEquals( | ||
$expected, | ||
$actual | ||
); | ||
} | ||
|
||
/** | ||
* Data provider for testGetTerms. | ||
* | ||
* @return array | ||
*/ | ||
public function getTermsDataProvider() | ||
{ | ||
return [ | ||
[ | ||
[ | ||
'1st query' => | ||
[ | ||
'query_id' => '1', | ||
'query_text' => '1st query', | ||
'num_results' => '1', | ||
'popularity' => '5', | ||
'redirect' => null, | ||
'store_id' => '1', | ||
'display_in_terms' => '1', | ||
'is_active' => '1', | ||
'is_processed' => '1', | ||
'updated_at' => null, | ||
'ratio' => 0.44444444444444, | ||
], | ||
'2nd query' => | ||
[ | ||
'query_id' => '2', | ||
'query_text' => '2nd query', | ||
'num_results' => '1', | ||
'popularity' => '10', | ||
'redirect' => null, | ||
'store_id' => '1', | ||
'display_in_terms' => '1', | ||
'is_active' => '1', | ||
'is_processed' => '1', | ||
'updated_at' => null, | ||
'ratio' => 1, | ||
], | ||
'3rd query' => | ||
[ | ||
'query_id' => '3', | ||
'query_text' => '3rd query', | ||
'num_results' => '1', | ||
'popularity' => '1', | ||
'redirect' => null, | ||
'store_id' => '1', | ||
'display_in_terms' => '1', | ||
'is_active' => '1', | ||
'is_processed' => '1', | ||
'updated_at' => null, | ||
'ratio' => 0, | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
$this->term = $this->objectManager->get( | ||
LayoutInterface::class | ||
)->createBlock( | ||
Term::class | ||
); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
dev/tests/integration/testsuite/Magento/Search/_files/query.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
|
||
$queries = [ | ||
[ | ||
'text' => '1st query', | ||
'results' => 1, | ||
'popularity' => 5, | ||
'display' => 1, | ||
'active' => 1, | ||
'processed' => 1 | ||
], | ||
[ | ||
'text' => '2nd query', | ||
'results' => 1, | ||
'popularity' => 10, | ||
'display' => 1, | ||
'active' => 1, | ||
'processed' => 1 | ||
], | ||
[ | ||
'text' => '3rd query', | ||
'results' => 1, | ||
'popularity' => 1, | ||
'display' => 1, | ||
'active' => 1, | ||
'processed' => 1 | ||
], | ||
[ | ||
'text' => '4th query', | ||
'results' => 0, | ||
'popularity' => 1, | ||
'display' => 1, | ||
'active' => 1, | ||
'processed' => 1 | ||
], | ||
]; | ||
|
||
foreach ($queries as $queryData) { | ||
/** @var $queryData \Magento\Search\Model\Query */ | ||
$query = $objectManager->create(\Magento\Search\Model\Query::class); | ||
$query->setStoreId(1); | ||
$query->setQueryText( | ||
$queryData['text'] | ||
)->setNumResults( | ||
$queryData['results'] | ||
)->setPopularity( | ||
$queryData['popularity'] | ||
)->setDisplayInTerms( | ||
$queryData['display'] | ||
)->setIsActive( | ||
$queryData['active'] | ||
)->setIsProcessed( | ||
$queryData['processed'] | ||
); | ||
$query->save(); | ||
} |
24 changes: 24 additions & 0 deletions
24
dev/tests/integration/testsuite/Magento/Search/_files/query_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
|
||
/** @var $query \Magento\Search\Model\Query */ | ||
$query = $objectManager->get(\Magento\Search\Model\Query::class); | ||
|
||
$queries = [ | ||
'1st query', | ||
'2nd query', | ||
'3rd query', | ||
'4th query', | ||
]; | ||
|
||
foreach ($queries as $queryText) { | ||
try { | ||
$query->loadByQueryText($queryText); | ||
$query->delete(); | ||
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) { | ||
} | ||
} |