Skip to content

Commit 2bcd7f3

Browse files
author
Kopylova,Olga(okopylova)
committed
Merge pull request #206 from magento-ogre/PR_Branch_ES
[Phoenix Media - Ogres] Accept Phoenix Media Sprint 2 code for Elastic Search Adapter
2 parents a76952f + e974fee commit 2bcd7f3

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Model;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
10+
class EngineResolver
11+
{
12+
/**
13+
* MySQL search engine
14+
*/
15+
const CATALOG_SEARCH_MYSQL_ENGINE = 'mysql';
16+
17+
/**
18+
* @var ScopeConfigInterface
19+
*/
20+
protected $scopeConfig;
21+
22+
/**
23+
* Path to catalog search engine
24+
* @var string
25+
*/
26+
protected $path;
27+
28+
/**
29+
* Scope type
30+
* @var string
31+
*/
32+
protected $scopeType;
33+
34+
/**
35+
* Scope code
36+
* @var null|string
37+
*/
38+
protected $scopeCode;
39+
40+
/**
41+
* @param ScopeConfigInterface $scopeConfig
42+
* @param string $path
43+
* @param string $scopeType
44+
* @param string $scopeCode
45+
*/
46+
public function __construct(
47+
ScopeConfigInterface $scopeConfig,
48+
$path,
49+
$scopeType,
50+
$scopeCode = null
51+
) {
52+
$this->scopeConfig = $scopeConfig;
53+
$this->path = $path;
54+
$this->scopeType = $scopeType;
55+
$this->scopeCode = $scopeCode;
56+
}
57+
58+
/**
59+
* Current Search Engine
60+
* @return string
61+
*/
62+
public function getCurrentSearchEngine()
63+
{
64+
return $this->scopeConfig->getValue(
65+
$this->path,
66+
$this->scopeType,
67+
$this->scopeCode
68+
);
69+
}
70+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Test\Unit\Model;
7+
8+
use Magento\Search\Model\EngineResolver;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
11+
class EngineResolverTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Search\Model\EngineResolver
15+
*/
16+
private $model;
17+
18+
/**
19+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $scopeConfig;
22+
23+
/**
24+
* @var string|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $path;
27+
28+
/**
29+
* @var string|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $scopeType;
32+
33+
/**
34+
* @var null|string|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $scopeCode;
37+
38+
/**
39+
* Setup
40+
*
41+
* @return void
42+
*/
43+
protected function setUp()
44+
{
45+
$this->scopeConfig = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
46+
->disableOriginalConstructor()
47+
->getMock();
48+
49+
$this->path = 'catalog/search/engine';
50+
$this->scopeType = 'default';
51+
$this->scopeCode = null;
52+
53+
$this->model = new EngineResolver(
54+
$this->scopeConfig,
55+
$this->path,
56+
$this->scopeType,
57+
$this->scopeCode
58+
);
59+
}
60+
61+
/**
62+
* Test getCurrentSearchEngine
63+
*/
64+
public function testGetCurrentSearchEngine()
65+
{
66+
$engine = 'mysql';
67+
68+
$this->scopeConfig->expects($this->any())
69+
->method('getValue')
70+
->willReturn($engine);
71+
72+
$this->assertEquals($engine, $this->model->getCurrentSearchEngine());
73+
}
74+
}

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

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
</argument>
3232
</arguments>
3333
</type>
34+
<type name="Magento\Search\Model\EngineResolver">
35+
<arguments>
36+
<argument name="path" xsi:type="string">catalog/search/engine</argument>
37+
<argument name="scopeType" xsi:type="string">default</argument>
38+
</arguments>
39+
</type>
3440
<preference for="Magento\Search\Model\AutocompleteInterface" type="Magento\Search\Model\Autocomplete" />
3541
<preference for="Magento\Search\Model\Autocomplete\ItemInterface" type="Magento\Search\Model\Autocomplete\Item" />
3642
<preference for="Magento\Framework\Search\SearchEngineInterface" type="Magento\Search\Model\SearchEngine"/>

0 commit comments

Comments
 (0)