/** * Rebuild all index data * * @return void * @throws \Exception */ public function reindexAll() { $this->_catalogResourceUrl->beginTransaction(); try { $this->_catalogUrl->refreshRewrites(); $this->_catalogResourceUrl->commit(); } catch (\Exception $e) { $this->_catalogResourceUrl->rollBack(); throw $e; } }
public function testRefreshRewrites() { $rewrite = array('category/1' => $this->_rewriteModel); $validatedPath = 'validated_path.html'; $this->_urlFactory->expects($this->any())->method('formatUrlKey')->will($this->returnValue('url_formatted')); $this->_urlFactory->expects($this->any())->method('getUrlPath')->will($this->returnValue($validatedPath)); $this->_resourceModel->expects($this->any())->method('prepareRewrites')->will($this->returnValue($rewrite)); $this->_resourceModel->expects($this->at(0))->method('getStores')->will($this->returnValue(array($this->_storeModel))); $this->_resourceModel->expects($this->any())->method('getStores')->will($this->returnValue($this->_storeModel)); $this->_resourceModel->expects($this->once())->method('clearStoreInvalidRewrites')->will($this->returnSelf()); $this->_resourceModel->expects($this->at(14))->method('getProductsByStore')->will($this->returnValue(null)); $this->_resourceModel->expects($this->any())->method('getProductsByStore')->will($this->returnValue(array($this->_productModel))); $this->_resourceModel->expects($this->any())->method('getCategories')->will($this->returnValue(array($this->_categoryModel))); $this->_resourceModel->expects($this->once())->method('checkRequestPaths')->will($this->returnValue($validatedPath)); $this->_resourceModel->expects($this->once())->method('clearCategoryProduct')->will($this->returnSelf()); $this->_productModel->expects($this->any())->method('getCategoryIds')->will($this->returnValue(array(1))); $this->_productModel->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->_productModel->expects($this->any())->method('getResource')->will($this->returnValue($this->_resourceModel)); $this->_productModel->expects($this->once())->method('getUrlPath')->will($this->returnValue($validatedPath)); $this->_storeModel->expects($this->any())->method('getRootCategoryId')->will($this->returnValue(1)); $this->_model->refreshRewrites(); }
/** * @magentoDataFixture Magento/Catalog/_files/url_rewrites_invalid.php */ public function testRefreshRewrites() { $this->assertNotEmpty($this->_loadRewrite('product/1/4')->getId()); $this->assertInstanceOf('Magento\\Catalog\\Model\\Url', $this->_model->refreshRewrites()); $this->assertEmpty($this->_loadRewrite('product/1/4')->getId()); }