Skip to content

Commit f54366a

Browse files
author
Andrii Kasian
committed
Merge remote-tracking branch 'origin/MAGETWO-24366' into S67
2 parents 71c046f + f443d43 commit f54366a

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

app/code/Magento/CatalogSearch/Model/Resource/Fulltext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function _construct()
4949
public function resetSearchResults()
5050
{
5151
$adapter = $this->_getWriteAdapter();
52-
$adapter->update($this->getTable('search_query'), ['is_processed' => 0]);
52+
$adapter->update($this->getTable('search_query'), ['is_processed' => 0], ['is_processed != 0']);
5353
$this->_eventManager->dispatch('catalogsearch_reset_search_result');
5454
return $this;
5555
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogSearch\Test\Unit\Model\Resource;
8+
9+
10+
use Magento\CatalogSearch\Model\Resource\Fulltext;
11+
use Magento\Framework\App\Resource;
12+
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Framework\Model\Resource\Db\Context;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
16+
class FulltextTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $adapter;
22+
/**
23+
* @var Resource|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $resource;
26+
/**
27+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $context;
30+
/**
31+
* @var Fulltext
32+
*/
33+
private $target;
34+
35+
protected function setUp()
36+
{
37+
$this->context = $this->getMockBuilder('\Magento\Framework\Model\Resource\Db\Context')
38+
->disableOriginalConstructor()
39+
->getMock();
40+
$this->resource = $this->getMockBuilder('\Magento\Framework\App\Resource')
41+
->disableOriginalConstructor()
42+
->getMock();
43+
$this->context->expects($this->once())
44+
->method('getResources')
45+
->willReturn($this->resource);
46+
$this->adapter = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface')
47+
->disableOriginalConstructor()
48+
->getMockForAbstractClass();
49+
$this->resource->expects($this->once())
50+
->method('getConnection')
51+
->with('core_write')
52+
->willReturn($this->adapter);
53+
54+
$objectManager = new ObjectManager($this);
55+
$this->target = $objectManager->getObject(
56+
'\Magento\CatalogSearch\Model\Resource\Fulltext',
57+
[
58+
'context' => $this->context,
59+
]
60+
);
61+
}
62+
63+
public function testResetSearchResult()
64+
{
65+
$this->resource->expects($this->once())
66+
->method('getTableName')
67+
->with('search_query', 'core_read')
68+
->willReturn('table_name_search_query');
69+
$this->adapter->expects($this->once())
70+
->method('update')
71+
->with('table_name_search_query', ['is_processed' => 0], ['is_processed != 0'])
72+
->willReturn(10);
73+
$result = $this->target->resetSearchResults();
74+
$this->assertEquals($this->target, $result);
75+
}
76+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Search\Setup;
8+
9+
10+
use Magento\Framework\Module\ModuleListInterface;
11+
use Magento\Framework\Setup\ModuleContextInterface;
12+
use Magento\Framework\Setup\SchemaSetupInterface;
13+
use Magento\Framework\Setup\UpgradeSchemaInterface;
14+
15+
class UpgradeSchema implements UpgradeSchemaInterface
16+
{
17+
18+
/**
19+
* @var ModuleListInterface
20+
*/
21+
private $moduleList;
22+
23+
/**
24+
* @param ModuleListInterface $moduleList
25+
*/
26+
public function __construct(ModuleListInterface $moduleList)
27+
{
28+
$this->moduleList = $moduleList;
29+
}
30+
31+
/**
32+
* Upgrades DB schema for a module
33+
*
34+
* @param SchemaSetupInterface $setup
35+
* @param ModuleContextInterface $context
36+
* @return void
37+
*/
38+
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
39+
{
40+
if (version_compare($context->getVersion(), '2.0.0.1') < 0) {
41+
$setup->startSetup();
42+
$connection = $setup->getConnection();
43+
$tableName = $setup->getTable('search_query');
44+
$idxName = $setup->getIdxName('search_query', ['is_processed']);
45+
$connection->addIndex($tableName, $idxName, ['is_processed']);
46+
$setup->endSetup();
47+
}
48+
}
49+
}

app/code/Magento/Search/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
10-
<module name="Magento_Search" setup_version="2.0.0">
10+
<module name="Magento_Search" setup_version="2.0.0.1">
1111
<sequence>
1212
<module name="Magento_Backend" />
1313
</sequence>

0 commit comments

Comments
 (0)