public function testFindOneByDataIfFound()
 {
     $data = [['field1' => 'value1']];
     $row = ['row1'];
     $urlRewrite = ['urlRewrite1'];
     $this->storage->expects($this->once())->method('doFindOneByData')->with($data)->will($this->returnValue($row));
     $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($urlRewrite, $row, '\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->will($this->returnSelf());
     $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($urlRewrite));
     $this->assertEquals($urlRewrite, $this->storage->findOneByData($data));
 }
Example #2
0
 public function testFindOneByData()
 {
     $data = ['col1' => 'val1', 'col2' => 'val2'];
     $this->select->expects($this->at(1))->method('where')->with('col1 IN (?)', 'val1');
     $this->select->expects($this->at(2))->method('where')->with('col2 IN (?)', 'val2');
     $this->adapter->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->adapter->expects($this->once())->method('fetchRow')->with($this->select)->will($this->returnValue(['row1']));
     $this->dataObjectHelper->expects($this->at(0))->method('populateWithArray')->with(['urlRewrite1'], ['row1'], '\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->will($this->returnSelf());
     $this->urlRewriteFactory->expects($this->at(0))->method('create')->will($this->returnValue(['urlRewrite1']));
     $this->assertEquals(['urlRewrite1'], $this->storage->findOneByData($data));
 }
 public function testGenerate()
 {
     $requestPath = 'category.html';
     $targetPath = 'target-path';
     $storeId = 'store_id';
     $categoryId = 'category_id';
     $this->category->expects($this->any())->method('getId')->will($this->returnValue($categoryId));
     $this->categoryUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($requestPath));
     $this->categoryUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($targetPath));
     $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityId')->with($categoryId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityType')->with(CategoryUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf());
     $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite));
     $this->assertEquals(['category.html_store_id' => $this->urlRewrite], $this->canonicalUrlRewriteGenerator->generate($storeId, $this->category));
 }
 public function testGenerate()
 {
     $requestPath = 'simple-product.html';
     $storeId = 10;
     $productId = 'product_id';
     $targetPath = 'catalog/product/view/id/' . $productId;
     $this->product->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($requestPath));
     $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($targetPath));
     $this->categoryRegistry->expects($this->any())->method('getList')->will($this->returnValue([]));
     $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityId')->with($productId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityType')->with(ProductUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf());
     $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite));
     $this->assertEquals([$this->urlRewrite], $this->canonicalUrlRewriteGenerator->generate($storeId, $this->product));
 }
 /**
  * @param mixed $storeId
  * @param mixed $categoryId
  * @param mixed $requestPath
  * @param mixed $targetPath
  * @param mixed $redirectType
  */
 protected function prepareUrlRewriteMock($storeId, $categoryId, $requestPath, $targetPath, $redirectType)
 {
     $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityId')->with($categoryId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityType')->with(CategoryUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setIsAutogenerated')->with(0)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setRedirectType')->with($redirectType)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setMetadata')->with([])->will($this->returnSelf());
     $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite));
 }
 public function testGenerateCategories()
 {
     $urlPathWithCategory = 'category/simple-product.html';
     $storeId = 10;
     $productId = 'product_id';
     $canonicalUrlPathWithCategory = 'canonical-path-with-category';
     $categoryId = 'category_id';
     $this->product->expects($this->any())->method('getId')->will($this->returnValue($productId));
     $this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->will($this->returnValue($urlPathWithCategory));
     $this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->will($this->returnValue($canonicalUrlPathWithCategory));
     $category = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false);
     $category->expects($this->any())->method('getId')->will($this->returnValue($categoryId));
     $this->categoryRegistry->expects($this->any())->method('getList')->will($this->returnValue([$category]));
     $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityId')->with($productId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityType')->with(ProductUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($urlPathWithCategory)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($canonicalUrlPathWithCategory)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setMetadata')->with(['category_id' => $categoryId])->will($this->returnSelf());
     $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite));
     $this->assertEquals([$this->urlRewrite], $this->categoriesUrlRewriteGenerator->generate($storeId, $this->product, $this->categoryRegistry));
 }
 /**
  * @param mixed $storeId
  * @param mixed $productId
  * @param mixed $requestPath
  * @param mixed $targetPath
  * @param mixed $redirectType
  * @param mixed $metadata
  * @param mixed $description
  */
 protected function prepareUrlRewriteMock($storeId, $productId, $requestPath, $targetPath, $redirectType, $metadata, $description)
 {
     $this->urlRewrite->expects($this->any())->method('setStoreId')->with($storeId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityId')->with($productId)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setEntityType')->with(ProductUrlRewriteGenerator::ENTITY_TYPE)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setRequestPath')->with($requestPath)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setTargetPath')->with($targetPath)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setIsAutogenerated')->with(0)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setRedirectType')->with($redirectType)->will($this->returnSelf());
     $this->urlRewrite->expects($this->any())->method('setMetadata')->with($metadata)->will($this->returnSelf());
     $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($this->urlRewrite));
     $this->urlRewrite->expects($this->once())->method('setDescription')->with($description)->will($this->returnSelf());
 }