public function testBuildDimensionWithDefaultScope() { $name = 'scope'; $value = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT; $scopeId = -123456; $this->dimension->expects($this->once())->method('getName')->will($this->returnValue($name)); $this->dimension->expects($this->once())->method('getValue')->will($this->returnValue($value)); $this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId)); $this->scopeResolver->expects($this->once())->method('getScope')->with($value)->will($this->returnValue($this->scope)); $query = $this->builder->build($this->dimension); $this->assertEquals(sprintf('`%s` = `%s`', \Magento\Framework\Search\Adapter\Mysql\Dimensions::STORE_FIELD_NAME, $scopeId), $query); }
/** * Check is possible to get all categories for all store starting from top level root category */ public function testGetTreeForAllScope() { $rootCategoryId = null; $depth = null; $category = null; $categoriesMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection', [], [], '', false); $categoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Category', [], [], 'categoryMock', false); $categoriesMock->expects($this->once())->method('getFirstItem')->willReturn($categoryMock); $categoriesMock->expects($this->once())->method('addFilter')->with('level', ['eq' => 0])->willReturnSelf(); $this->categoriesFactoryMock->expects($this->once())->method('create')->willReturn($categoriesMock); $nodeMock = $this->getMock('\\Magento\\Framework\\Data\\Tree\\Node', [], [], '', false); $this->categoryTreeMock->expects($this->once())->method('getTree')->with($nodeMock, $depth); $this->categoryRepositoryMock->expects($this->never())->method('get'); $this->categoryTreeMock->expects($this->once())->method('getRootNode')->with($categoryMock)->willReturn($nodeMock); $this->scopeResolverMock->expects($this->once())->method('getScope')->willReturn($this->scopeMock); $this->scopeMock->expects($this->once())->method('getCode')->willReturn(\Magento\Store\Model\Store::ADMIN_CODE); $this->model->getTree(); }
public function testBuildWithoutOutOfStock() { $scopeId = '113'; $tableSuffix = 'scope113_someNamesomeValue'; $index = 'test_index_name'; $dimensions = [$this->createDimension('scope', $scopeId), $this->createDimension('someName', 'someValue')]; $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); $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn(1); $this->config->expects($this->once())->method('isSetFlag')->with('cataloginventory/options/show_out_of_stock')->will($this->returnValue(false)); $this->connection->expects($this->once())->method('quoteInto')->with(' AND stock_index.website_id = ?', 1)->willReturn(' AND stock_index.website_id = 1'); $this->select->expects($this->at(2))->method('where')->with('(someName=someValue)')->willReturnSelf(); $this->select->expects($this->at(3))->method('joinLeft')->with(['stock_index' => 'cataloginventory_stock_status'], 'search_index.entity_id = stock_index.product_id' . ' AND stock_index.website_id = 1', [])->willReturnSelf(); $this->select->expects($this->at(4))->method('where')->with('stock_index.stock_status = ?', 1)->will($this->returnSelf()); $result = $this->target->build($this->request); $this->assertSame($this->select, $result); }
public function testProcessNotStaticAttribute() { $expectedResult = 'search_index.entity_id IN (select entity_id from (TEST QUERY PART) as filter)'; $scopeId = 0; $isNegation = false; $query = 'SELECT field FROM table'; $attributeId = 1234567; $this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId)); $this->filter->expects($this->exactly(4))->method('getField')->will($this->returnValue('not_static_attribute')); $this->config->expects($this->exactly(1))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'not_static_attribute')->will($this->returnValue($this->attribute)); $this->attribute->expects($this->once())->method('isStatic')->will($this->returnValue(false)); $this->attribute->expects($this->once())->method('getBackendTable')->will($this->returnValue('backend_table')); $this->attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue($attributeId)); $this->connection->expects($this->once())->method('getIfNullSql')->with('current_store.value', 'main_table.value')->will($this->returnValue('IF NULL SQL')); $this->select->expects($this->once())->method('from')->with(['main_table' => 'backend_table'], 'entity_id')->will($this->returnSelf()); $this->select->expects($this->once())->method('joinLeft')->with(['current_store' => 'backend_table'])->will($this->returnSelf()); $this->select->expects($this->once())->method('columns')->with(['not_static_attribute' => 'IF NULL SQL'])->will($this->returnSelf()); $this->select->expects($this->exactly(2))->method('where')->will($this->returnSelf()); $this->select->expects($this->once())->method('__toString')->will($this->returnValue('TEST QUERY PART')); $actualResult = $this->target->process($this->filter, $isNegation, $query); $this->assertSame($expectedResult, $this->removeWhitespaces($actualResult)); }