Skip to content

Commit

Permalink
Merge pull request #504 from magento-ogre/PR_Branch
Browse files Browse the repository at this point in the history
[Ogres] Bug fixes
  • Loading branch information
mazhalai committed Apr 2, 2016
2 parents d447fa6 + b2c8564 commit 1f7a63d
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getDataSet(
array $dimensions,
Table $entityIdsTable
) {
$currentScope = $dimensions['scope']->getValue();
$currentScope = $this->scopeResolver->getScope($dimensions['scope']->getValue())->getId();

$attribute = $this->eavConfig->getAttribute(Product::ENTITY, $bucket->getField());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public function aroundGetDataSet(
Table $entityIdsTable
) {
if ($bucket->getField() == 'category_ids') {
$currentScope = $dimensions['scope']->getValue();
$currentScopeId = $this->scopeResolver->getScope($currentScope)->getId();
$currentScopeId = $this->scopeResolver->getScope($dimensions['scope']->getValue())->getId();
$currentCategory = $this->layer->getCurrentCategory();

$derivedTable = $this->resource->getConnection()->select();
Expand Down
13 changes: 11 additions & 2 deletions app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\ScopeResolverInterface;

/**
* Build base Query for Index
Expand Down Expand Up @@ -57,28 +58,36 @@ class IndexBuilder implements IndexBuilderInterface
*/
private $tableMapper;

/**
* @var ScopeResolverInterface
*/
private $dimensionScopeResolver;

/**
* @param \Magento\Framework\App\ResourceConnection $resource
* @param ScopeConfigInterface $config
* @param StoreManagerInterface $storeManager
* @param ConditionManager $conditionManager
* @param IndexScopeResolver $scopeResolver
* @param TableMapper $tableMapper
* @param ScopeResolverInterface $dimensionScopeResolver
*/
public function __construct(
ResourceConnection $resource,
ScopeConfigInterface $config,
StoreManagerInterface $storeManager,
ConditionManager $conditionManager,
IndexScopeResolver $scopeResolver,
TableMapper $tableMapper
TableMapper $tableMapper,
ScopeResolverInterface $dimensionScopeResolver
) {
$this->resource = $resource;
$this->config = $config;
$this->storeManager = $storeManager;
$this->conditionManager = $conditionManager;
$this->scopeResolver = $scopeResolver;
$this->tableMapper = $tableMapper;
$this->dimensionScopeResolver = $dimensionScopeResolver;
}

/**
Expand Down Expand Up @@ -158,7 +167,7 @@ private function prepareDimensions(array $dimensions)
$preparedDimensions[] = $this->conditionManager->generateCondition(
$dimension->getName(),
'=',
$dimension->getValue()
$this->dimensionScopeResolver->getScope($dimension->getValue())->getId()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,55 @@

namespace Magento\CatalogSearch\Test\Unit\Model\Search;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Test for \Magento\CatalogSearch\Model\Search\IndexBuilder
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexBuilderTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\CatalogSearch\Model\Search\TableMapper|MockObject */
/** @var \Magento\CatalogSearch\Model\Search\TableMapper|\PHPUnit_Framework_MockObject_MockObject */
private $tableMapper;

/** @var \Magento\Framework\Search\Adapter\Mysql\ConditionManager|MockObject */
/** @var \Magento\Framework\Search\Adapter\Mysql\ConditionManager|\PHPUnit_Framework_MockObject_MockObject */
private $conditionManager;

/** @var \Magento\Search\Model\IndexScopeResolver|MockObject */
/** @var \Magento\Search\Model\IndexScopeResolver|\PHPUnit_Framework_MockObject_MockObject */
private $scopeResolver;

/** @var \Magento\Framework\DB\Adapter\AdapterInterface|MockObject */
/** @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */
private $connection;

/** @var \Magento\Framework\DB\Select|MockObject */
/** @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject */
private $select;

/** @var \Magento\Framework\App\Config\ScopeConfigInterface|MockObject */
/** @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
private $config;

/** @var \Magento\Store\Model\StoreManagerInterface|MockObject */
/** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
private $storeManager;

/** @var \Magento\Framework\Search\RequestInterface|MockObject */
/** @var \Magento\Framework\Search\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
private $request;

/** @var \Magento\Search\Model\IndexScopeResolver|MockObject */
/** @var \Magento\Search\Model\IndexScopeResolver|\PHPUnit_Framework_MockObject_MockObject */
private $resource;

/**
* @var \Magento\CatalogSearch\Model\Search\IndexBuilder
*/
private $target;

/**
* @var \Magento\Framework\App\ScopeResolverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $dimensionScopeResolver;

/**
* @var \Magento\Framework\App\ScopeInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $scopeInterface;

protected function setUp()
{
$this->select = $this->getMockBuilder('\Magento\Framework\DB\Select')
Expand Down Expand Up @@ -118,8 +127,20 @@ function ($left, $operator, $right) {
->method('addTables')
->with($this->select, $this->request)
->willReturnArgument(0);
$this->dimensionScopeResolver = $this->getMockForAbstractClass(
'\Magento\Framework\App\ScopeResolverInterface',
[],
'',
false
);
$this->scopeInterface = $this->getMockForAbstractClass(
'\Magento\Framework\App\ScopeInterface',
[],
'',
false
);

$objectManagerHelper = new ObjectManagerHelper($this);
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->target = $objectManagerHelper->getObject(
'Magento\CatalogSearch\Model\Search\IndexBuilder',
[
Expand All @@ -129,6 +150,7 @@ function ($left, $operator, $right) {
'conditionManager' => $this->conditionManager,
'scopeResolver' => $this->scopeResolver,
'tableMapper' => $this->tableMapper,
'dimensionScopeResolver' => $this->dimensionScopeResolver
]
);
}
Expand Down Expand Up @@ -167,6 +189,12 @@ public function testBuildWithoutOutOfStock()
$this->request->expects($this->exactly(2))
->method('getDimensions')
->willReturn($dimensions);
$this->dimensionScopeResolver->expects($this->once())
->method('getScope')
->willReturn($this->scopeInterface);
$this->scopeInterface->expects($this->once())
->method('getId')
->willReturn('someValue');

$this->mockBuild($index, $tableSuffix, false);

Expand Down Expand Up @@ -270,7 +298,7 @@ function ($index, $dimensions) {
/**
* @param $name
* @param $value
* @return MockObject
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createDimension($name, $value)
{
Expand Down
12 changes: 0 additions & 12 deletions app/code/Magento/CatalogUrlRewrite/etc/setup/events.xml

This file was deleted.

12 changes: 0 additions & 12 deletions app/code/Magento/CmsUrlRewrite/etc/setup/events.xml

This file was deleted.

56 changes: 56 additions & 0 deletions lib/internal/Magento/Framework/Filesystem/Filter/ExcludeFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\Filesystem\Filter;

/**
* Filters Iterator to exclude specified files
*/
class ExcludeFilter extends \FilterIterator
{
/**
* Array that is used for filtering
*
* @var array
*/
protected $_filters;

/**
* Constructor
*
* @param \Iterator $iterator
* @param array $filters list of files to skip
*/
public function __construct(\Iterator $iterator, array $filters)
{
parent::__construct($iterator);
$this->_filters = $filters;
}

/**
* Check whether the current element of the iterator is acceptable
*
* @return bool
*/
public function accept()
{
$current = str_replace('\\', '/', $this->current()->__toString());
$currentFilename = str_replace('\\', '/', $this->current()->getFilename());

if ($currentFilename == '.' || $currentFilename == '..') {
return false;
}

foreach ($this->_filters as $filter) {
$filter = str_replace('\\', '/', $filter);
if (false !== strpos($current, $filter)) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\Filesystem\Test\Unit\File;

use \Magento\Framework\Filesystem\Filter\ExcludeFilter;

/**
* Class ExcludeFilterTest
*/
class ExcludeFilterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Iterator
*/
protected $iterator;

protected function setUp()
{
$this->iterator = $this->getFilesIterator();
}

public function testExclusion()
{
$iterator = new ExcludeFilter(
$this->iterator,
[
BP . '/var/session/'
]
);

foreach ($iterator as $i) {
$result[] = $i;
}

$this->assertTrue(!in_array(BP . '/var/session/', $result), 'Filtered path should not be in array');
}

private function getFilesIterator ()
{
$files = [
BP . '/var/',
BP . '/var/session/',
BP . '/var/cache/'
];

foreach ($files as $file) {
$item = $this->getMockBuilder('SplFileInfoClass')->setMethods(['__toString', 'getFilename'])->getMock();
$item->expects($this->any())->method('__toString')->willReturn($file);
$item->expects($this->any())->method('getFilename')->willReturn('notDots');
yield $item;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function __construct(ModuleList $list, ModuleList\Loader $loader, Package
$this->enabledModuleList = $list->getNames();
$this->fullModuleList = $loader->load();
$this->packageInfo = $packageInfoFactory->create();
$this->graph = $this->createGraph();
}

/**
Expand Down Expand Up @@ -93,6 +92,7 @@ public function checkDependenciesWhenEnableModules($toBeEnabledModules, $current
*/
private function checkDependencyGraph($isEnable, $moduleNames, $enabledModules)
{
$this->graph = $this->createGraph();
$dependenciesMissingAll = [];
$graphMode = $isEnable ? Graph::DIRECTIONAL : Graph::INVERSE;
foreach ($moduleNames as $moduleName) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Search/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function search(SearchCriteriaInterface $searchCriteria)
{
$this->requestBuilder->setRequestName($searchCriteria->getRequestName());

$scope = $this->scopeResolver->getScope();
$scope = $this->scopeResolver->getScope()->getId();
$this->requestBuilder->bindDimension('scope', $scope);

foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
Expand Down
12 changes: 10 additions & 2 deletions lib/internal/Magento/Framework/Search/Test/Unit/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ protected function setUp()
public function testSearch()
{
$requestName = 'requestName';
$scope = 333;
$scopeId = 333;
$filterField = 'filterField';
$filterValue = 'filterValue';

$scope = $this->getMockBuilder('Magento\Framework\App\ScopeInterface')
->disableOriginalConstructor()
->getMockForAbstractClass();

$filter = $this->getMockBuilder('Magento\Framework\Api\Filter')
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -113,7 +117,7 @@ public function testSearch()
->with($requestName);
$this->requestBuilder->expects($this->once())
->method('bindDimension')
->with('scope', $scope);
->with('scope', $scopeId);
$this->requestBuilder->expects($this->any())
->method('bind');
$this->requestBuilder->expects($this->once())
Expand All @@ -134,6 +138,10 @@ public function testSearch()
->method('getScope')
->willReturn($scope);

$scope->expects($this->once())
->method('getId')
->willReturn($scopeId);

$searchResult = $this->model->search($searchCriteria);

$this->assertInstanceOf('Magento\Framework\Api\Search\SearchResultInterface', $searchResult);
Expand Down
Loading

0 comments on commit 1f7a63d

Please sign in to comment.