Exemple #1
0
    /**
     * @magentoDataFixture Magento/Catalog/_files/indexer_catalog_category.php
     * @magentoDbIsolation enabled
     */
    public function testReindexAll()
    {
        $categories = $this->getCategories(4);
        $products = $this->getProducts(2);

        /** @var Category $categoryFourth */
        $categoryFourth = end($categories);
        foreach ($products as $product) {
            /** @var \Magento\Catalog\Model\Product $product */
            $product->setCategoryIds([$categoryFourth->getId()]);
            $product->save();
        }

        /** @var Category $categoryThird */
        $categoryThird = $categories[2];
        $categoryThird->setIsAnchor(true);
        $categoryThird->save();

        $this->clearIndex();
        $categories = [self::DEFAULT_ROOT_CATEGORY, $categoryThird->getId(), $categoryFourth->getId()];

        $this->indexer->reindexAll();

        foreach ($products as $product) {
            /** @var \Magento\Catalog\Model\Product $product */
            foreach ($categories as $categoryId) {
                $this->assertTrue((bool)$this->productResource->canBeShowInCategory($product, $categoryId));
            }

            $this->assertTrue(
                (bool)$this->productResource->canBeShowInCategory($product, $categoryThird->getParentId())
            );
        }
    }
 /**
  * @magentoDataFixture Magento/Bundle/_files/product.php
  * @covers \Magento\Indexer\Model\Indexer::reindexAll
  * @covers \Magento\Bundle\Model\Product\Type::getSearchableData
  */
 public function testPrepareProductIndexForBundleProduct()
 {
     $this->indexer->reindexAll();
     $select = $this->connectionMock->select()->from($this->resource->getTableName('catalogsearch_fulltext_scope1'))->where('`data_index` LIKE ?', '%' . 'Bundle Product Items' . '%');
     $result = $this->connectionMock->fetchAll($select);
     $this->assertCount(1, $result);
 }
 public function testAfterDeleteScheduled()
 {
     $this->indexerMock->expects($this->once())->method('isScheduled')->will($this->returnValue(true));
     $this->indexerMock->expects($this->never())->method('reindexRow');
     $this->prepareIndexer();
     $this->subjectMock->expects($this->once())->method('getId')->will($this->returnValue(1));
     $this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock));
 }
 /**
  * @param array $data
  * @dataProvider beforeSaveDataProvider
  */
 public function testBeforeSave(array $data)
 {
     $subjectMock = $this->getMock('Magento\\Store\\Model\\ResourceModel\\Group', [], [], '', false);
     $objectMock = $this->getMock('Magento\\Framework\\Model\\AbstractModel', ['getId', 'dataHasChangedFor', '__wakeup'], [], '', false);
     $objectMock->expects($this->once())->method('getId')->will($this->returnValue($data['object_id']));
     $objectMock->expects($this->any())->method('dataHasChangedFor')->with('website_id')->will($this->returnValue($data['has_website_id_changed']));
     $this->_indexerMock->expects($this->once())->method('markIndexerAsInvalid');
     $this->_model->beforeSave($subjectMock, $objectMock);
 }
 public function testAroundSave()
 {
     $this->stateMock->expects($this->once())->method('isFlatEnabled')->will($this->returnValue(true));
     $this->indexerMock->expects($this->once())->method('invalidate');
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnValue($this->indexerMock));
     $this->groupMock->expects($this->once())->method('dataHasChangedFor')->with('root_category_id')->will($this->returnValue(true));
     $this->groupMock->expects($this->once())->method('isObjectNew')->will($this->returnValue(false));
     $this->assertFalse($this->model->aroundSave($this->subjectMock, $this->closureMock, $this->groupMock));
 }
 /**
  * @param $isAvailable
  * @param $isFlatEnabled
  * @param $isValid
  * @param $result
  * @dataProvider isAvailableDataProvider
  */
 public function testIsAvailable($isAvailable, $isFlatEnabled, $isValid, $result)
 {
     $this->flatIndexerMock->expects($this->any())->method('load')->with('catalog_category_flat');
     $this->flatIndexerMock->expects($this->any())->method('isValid')->will($this->returnValue($isValid));
     $this->indexerRegistryMock->expects($this->any())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Flat\State::INDEXER_ID)->will($this->returnValue($this->flatIndexerMock));
     $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->with('catalog/frontend/flat_catalog_category')->will($this->returnValue($isFlatEnabled));
     $this->model = new \Magento\Catalog\Model\Indexer\Category\Flat\State($this->scopeConfigMock, $this->indexerRegistryMock, $isAvailable);
     $this->assertEquals($result, $this->model->isAvailable());
 }
 public function testExecuteWithIndexerNotWorking()
 {
     $ids = [1, 2, 3];
     $this->indexerMock->expects($this->once())->method('isWorking')->will($this->returnValue(false));
     $this->prepareIndexer();
     $rowMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Category\\Product\\Action\\Rows', ['execute'], [], '', false);
     $rowMock->expects($this->once())->method('execute')->with($ids, false)->will($this->returnSelf());
     $this->rowsMock->expects($this->once())->method('create')->will($this->returnValue($rowMock));
     $this->model->execute($ids);
 }
 public function testDelete()
 {
     $this->designConfig->expects($this->exactly(2))->method('getExtensionAttributes')->willReturn($this->designExtension);
     $this->designExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->configStorage->expects($this->once())->method('delete')->with($this->designConfig);
     $this->reinitableConfig->expects($this->once())->method('reinit');
     $this->indexerRegistry->expects($this->once())->method('get')->with(Config::DESIGN_CONFIG_GRID_INDEXER_ID)->willReturn($this->indexer);
     $this->indexer->expects($this->once())->method('reindexAll');
     $this->assertSame($this->designConfig, $this->repository->delete($this->designConfig));
 }
Exemple #9
0
 public function testExecuteWithIndexerNotWorking()
 {
     $ids = [1, 2, 3];
     $this->indexerMock->expects($this->once())->method('isInvalid')->will($this->returnValue(false));
     $this->indexerMock->expects($this->once())->method('isWorking')->will($this->returnValue(false));
     $this->prepareIndexer();
     $rowMock = $this->getMock('Magento\\Catalog\\Model\\Indexer\\Category\\Flat\\Action\\Rows', ['reindex'], [], '', false);
     $rowMock->expects($this->once())->method('reindex')->with($ids, false)->will($this->returnSelf());
     $this->rowsMock->expects($this->once())->method('create')->will($this->returnValue($rowMock));
     $this->cacheContextMock->expects($this->once())->method('registerEntities')->with(\Magento\Catalog\Model\Category::CACHE_TAG, $ids);
     $this->model->execute($ids);
 }
 public function testAroundUpdateWebsitesScheduled()
 {
     $this->indexerMock->expects($this->once())->method('isScheduled')->will($this->returnValue(true));
     $this->indexerMock->expects($this->never())->method('reindexList');
     $this->prepareIndexer();
     $closureMock = function ($productIds, $websiteIds, $type) {
         $this->assertEquals([1, 2, 3], $productIds);
         $this->assertEquals([4, 5, 6], $websiteIds);
         $this->assertEquals('type', $type);
         return $this->subjectMock;
     };
     $this->model->aroundUpdateWebsites($this->subjectMock, $closureMock, [1, 2, 3], [4, 5, 6], 'type');
 }
 /**
  * @param bool $isObjectNew
  * @param bool $isSearchable
  * @param int $invalidateCounter
  * @return void
  * @dataProvider aroundDeleteDataProvider
  */
 public function testAroundDelete($isObjectNew, $isSearchable, $invalidateCounter)
 {
     $attributeMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', ['getIsSearchable', 'isObjectNew', '__wakeup'], [], '', false);
     $attributeMock->expects($this->any())->method('getIsSearchable')->will($this->returnValue($isSearchable));
     $attributeMock->expects($this->once())->method('isObjectNew')->will($this->returnValue($isObjectNew));
     $closureMock = function (\Magento\Catalog\Model\ResourceModel\Eav\Attribute $object) use($attributeMock) {
         $this->assertEquals($object, $attributeMock);
         return $this->subjectMock;
     };
     $this->indexerMock->expects($this->exactly($invalidateCounter))->method('invalidate');
     $this->prepareIndexer($invalidateCounter);
     $this->assertEquals($this->subjectMock, $this->model->aroundDelete($this->subjectMock, $closureMock, $attributeMock));
 }
Exemple #12
0
 public function testFilter()
 {
     $attributeCode = 'attribute-code';
     $attributeCodeTwo = 'attribute-code2';
     $tableName = 'customer_grid_flat';
     $attributes = [$attributeCode => [AttributeMetadataInterface::ATTRIBUTE_CODE => $attributeCode, AttributeMetadataInterface::FRONTEND_INPUT => 'input', AttributeMetadataInterface::FRONTEND_LABEL => 'Frontend label', AttributeMetadataInterface::BACKEND_TYPE => 'static', AttributeMetadataInterface::OPTIONS => [], AttributeMetadataInterface::IS_USED_IN_GRID => true, AttributeMetadataInterface::IS_VISIBLE_IN_GRID => true, AttributeMetadataInterface::IS_FILTERABLE_IN_GRID => true, AttributeMetadataInterface::IS_SEARCHABLE_IN_GRID => true], $attributeCodeTwo => [AttributeMetadataInterface::ATTRIBUTE_CODE => $attributeCodeTwo, AttributeMetadataInterface::FRONTEND_INPUT => 'input', AttributeMetadataInterface::FRONTEND_LABEL => 'Frontend label two', AttributeMetadataInterface::BACKEND_TYPE => 'static', AttributeMetadataInterface::OPTIONS => [], AttributeMetadataInterface::IS_USED_IN_GRID => false, AttributeMetadataInterface::IS_VISIBLE_IN_GRID => false, AttributeMetadataInterface::IS_FILTERABLE_IN_GRID => false, AttributeMetadataInterface::IS_SEARCHABLE_IN_GRID => false]];
     $this->indexerRegistry->expects($this->once())->method('get')->with(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID)->willReturn($this->indexer);
     $this->indexer->expects($this->once())->method('getState')->willReturn($this->indexerState);
     $this->indexerState->expects($this->once())->method('getStatus')->willReturn(\Magento\Framework\Indexer\StateInterface::STATUS_INVALID);
     $this->flatScopeResolver->expects($this->once())->method('resolve')->with(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID, [])->willReturn($tableName);
     $this->resource->expects($this->once())->method('getConnection')->willReturn($this->connection);
     $this->connection->expects($this->once())->method('describeTable')->with($tableName)->willReturn(['attribute-code' => ['Attribute data']]);
     $this->assertArrayNotHasKey($attributeCodeTwo, $this->model->filter($attributes));
 }
 /**
  * @magentoAppArea adminhtml
  */
 public function testReindexRowAfterDelete()
 {
     $this->indexer->reindexAll();
     $this->productBanana->delete();
     $products = $this->search('Simple Product');
     $this->assertCount(4, $products);
 }
Exemple #14
0
 public function testSyncCustomerGrid()
 {
     $gridTable = 'customer_grid_flat';
     $customerLogTable = 'customer_log';
     $this->indexerRegistry->expects($this->once())->method('get')->with(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID)->willReturn($this->indexer);
     $this->resource->expects($this->once())->method('getConnection')->willReturn($this->connection);
     $this->flatScopeResolver->expects($this->once())->method('resolve')->with(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID, [])->willReturn($gridTable);
     $this->resource->expects($this->exactly(2))->method('getTableName')->willReturnMap([[$gridTable], [$customerLogTable]]);
     $this->connection->expects($this->exactly(2))->method('select')->willReturn($this->select);
     $this->select->expects($this->exactly(2))->method('from')->willReturnSelf();
     $this->select->expects($this->once())->method('order')->with('last_visit_at DESC')->willReturnSelf();
     $this->select->expects($this->once())->method('limit')->with(1)->willReturnSelf();
     $this->connection->expects($this->atLeastOnce())->method('query')->with($this->select)->willReturn($this->queryResult);
     $this->queryResult->expects($this->once())->method('fetchColumn')->willReturn('2015-08-13 10:36:44');
     $this->select->expects($this->once())->method('where')->with('last_login_at > ?', '2015-08-13 10:36:44')->willReturnSelf();
     $this->queryResult->expects($this->once())->method('fetchAll')->willReturn([['customer_id' => 23], ['customer_id' => 65]]);
     $this->indexer->expects($this->once())->method('reindexList')->with(['23', '65']);
     $this->observer->syncCustomerGrid();
 }
 /**
  * @param string $oldValue
  * @param string $value
  * @dataProvider dataProviderProcessValueOff
  */
 public function testProcessValueOff($oldValue, $value)
 {
     $this->configMock->expects($this->once())->method('getValue')->with(null, 'default')->will($this->returnValue($oldValue));
     $this->model->setValue($value);
     $this->indexerStateMock->expects($this->never())->method('loadByIndexer');
     $this->indexerStateMock->expects($this->never())->method('setStatus');
     $this->indexerStateMock->expects($this->never())->method('save');
     $this->indexerRegistry->expects($this->once())->method('get')->with('catalog_category_flat')->willReturn($this->flatIndexer);
     $this->flatIndexer->expects($this->once())->method('setScheduled')->with(false);
     $this->model->processValue();
 }
 /**
  * @param $productChanged
  * @param $isScheduled
  * @param $productFlatCount
  * @param $categoryIndexerCount
  *
  * @dataProvider getProductReindexProvider
  */
 public function testReindex($productChanged, $isScheduled, $productFlatCount, $categoryIndexerCount)
 {
     $this->model->setData('entity_id', 1);
     $this->_catalogProduct->expects($this->once())->method('isDataForProductCategoryIndexerWasChanged')->willReturn($productChanged);
     if ($productChanged) {
         $this->indexerRegistryMock->expects($this->exactly($productFlatCount))->method('get')->with(\Magento\Catalog\Model\Indexer\Product\Category::INDEXER_ID)->will($this->returnValue($this->categoryIndexerMock));
         $this->categoryIndexerMock->expects($this->any())->method('isScheduled')->will($this->returnValue($isScheduled));
         $this->categoryIndexerMock->expects($this->exactly($categoryIndexerCount))->method('reindexRow');
     }
     $this->productFlatProcessor->expects($this->exactly($productFlatCount))->method('reindexRow');
     $this->model->reindex();
 }
 /**
  * @param $productScheduled
  * @param $expectedProductReindexCall
  *
  * @dataProvider reindexFlatDisabledTestDataProvider
  */
 public function testReindexFlatDisabled($productScheduled, $expectedProductReindexCall)
 {
     $affectedProductIds = ["1", "2"];
     $this->category->setAffectedProductIds($affectedProductIds);
     $pathIds = ['path/1/2', 'path/2/3'];
     $this->category->setData('path_ids', $pathIds);
     $this->category->setId('123');
     $this->flatState->expects($this->any())->method('isFlatEnabled')->will($this->returnValue(false));
     $this->productIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($productScheduled));
     $this->productIndexer->expects($this->exactly($expectedProductReindexCall))->method('reindexList')->with($pathIds);
     $this->indexerRegistry->expects($this->at(0))->method('get')->with(Indexer\Category\Product::INDEXER_ID)->will($this->returnValue($this->productIndexer));
     $this->category->reindex();
 }
 protected function mockIndexerMethods()
 {
     $this->indexerMock->expects($this->once())->method('invalidate');
     $this->indexerRegistryMock->expects($this->once())->method('get')->with(\Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID)->will($this->returnValue($this->indexerMock));
 }
 /**
  * @return void
  */
 public function testAfterDelete()
 {
     $this->indexerMock->expects($this->once())->method('invalidate');
     $this->prepareIndexer(1);
     $this->assertEquals($this->subjectMock, $this->model->afterDelete($this->subjectMock, $this->subjectMock));
 }
 /**
  * Validate that indexer is not locked
  *
  * @param \Magento\Framework\Indexer\IndexerInterface $indexer
  * @return void
  * @throws LocalizedException
  */
 private function validateIndexerStatus(\Magento\Framework\Indexer\IndexerInterface $indexer)
 {
     if ($indexer->getStatus() == \Magento\Framework\Indexer\StateInterface::STATUS_WORKING) {
         throw new LocalizedException(__('%1 index is locked by another reindex process. Skipping.', $indexer->getTitle()));
     }
 }