예제 #1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @return void
  */
 protected function setUp()
 {
     $this->select = $this->getMockBuilder('\\Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'joinLeft', 'where', 'joinInner'])->getMock();
     $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->setMethods(['select', 'quoteInto'])->getMockForAbstractClass();
     $this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select));
     $this->resource = $this->getMockBuilder('\\Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->setMethods(['getConnection', 'getTableName'])->getMock();
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->setMethods(['getIndex', 'getDimensions', 'getQuery'])->getMockForAbstractClass();
     $this->config = $this->getMockBuilder('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface')->disableOriginalConstructor()->setMethods(['isSetFlag'])->getMockForAbstractClass();
     $this->storeManager = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->getMock();
     $this->scopeResolver = $this->getMockBuilder('\\Magento\\Framework\\Indexer\\ScopeResolver\\IndexScopeResolver')->disableOriginalConstructor()->getMock();
     $this->conditionManager = $this->getMockBuilder('\\Magento\\Framework\\Search\\Adapter\\Mysql\\ConditionManager')->setMethods(['combineQueries', 'wrapBrackets', 'generateCondition'])->disableOriginalConstructor()->getMock();
     $this->conditionManager->expects($this->any())->method('combineQueries')->willReturnCallback(function (array $queries, $expression) {
         return implode(' ' . $expression . ' ', $queries);
     });
     $this->conditionManager->expects($this->any())->method('wrapBrackets')->willReturnCallback(function ($expression) {
         return '(' . $expression . ')';
     });
     $this->conditionManager->expects($this->any())->method('generateCondition')->willReturnCallback(function ($left, $operator, $right) {
         return $left . $operator . $right;
     });
     $this->tableMapper = $this->getMockBuilder('\\Magento\\CatalogSearch\\Model\\Search\\TableMapper')->disableOriginalConstructor()->getMock();
     $this->tableMapper->expects($this->once())->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);
     $this->stockConfiguration = $this->getMockBuilder('\\Magento\\CatalogInventory\\Api\\StockConfigurationInterface')->getMock();
     $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->target = $objectManagerHelper->getObject('Magento\\CatalogSearch\\Model\\Search\\IndexBuilder', ['resource' => $this->resource, 'config' => $this->config, 'storeManager' => $this->storeManager, 'conditionManager' => $this->conditionManager, 'scopeResolver' => $this->scopeResolver, 'tableMapper' => $this->tableMapper, 'dimensionScopeResolver' => $this->dimensionScopeResolver]);
     // Todo: \Magento\Framework\TestFramework\Unit\Helper\ObjectManager to do this automatically (MAGETWO-49793)
     $reflection = new \ReflectionClass(get_class($this->target));
     $reflectionProperty = $reflection->getProperty('stockConfiguration');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->target, $this->stockConfiguration);
 }
 /**
  * @dataProvider testTermFilterDataProvider
  */
 public function testProcessTermFilter($frontendInput, $fieldValue, $isNegation, $expected)
 {
     $this->config->expects($this->exactly(1))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'termField')->will($this->returnValue($this->attribute));
     $this->attribute->expects($this->once())->method('isStatic')->will($this->returnValue(false));
     $this->filter->expects($this->once())->method('getType')->willReturn(FilterInterface::TYPE_TERM);
     $this->attribute->expects($this->once())->method('getFrontendInput')->willReturn($frontendInput);
     $this->tableMapper->expects($this->once())->method('getMappingAlias')->willReturn('termAttrAlias');
     $this->filter->expects($this->exactly(3))->method('getField')->willReturn('termField');
     $this->filter->expects($this->exactly(2))->method('getValue')->willReturn($fieldValue);
     $actualResult = $this->target->process($this->filter, $isNegation, 'This filter is not depends on used query');
     $this->assertSame($expected, $this->removeWhitespaces($actualResult));
 }