10 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Mtf\Fixture\FixtureInterface;
13 use Magento\UrlRewrite\Test\Page\Adminhtml\UrlRewriteIndex;
25 private $parentCategoryIndex;
39 private $targetPathTemplate =
'catalog/product/view/id/%s/category/%s';
51 UrlRewriteIndex $urlRewriteIndex,
56 $this->webApi = $webApi;
57 $urlRewriteIndex->open();
59 $rootCategoryArray = [];
61 $parentName =
$category->getDataFieldConfig(
'parent_id')[
'source']->getParentCategory()->getName();
62 $rootCategoryArray[$parentName][
'name'] = !empty(
$category->getUrlKey())
65 $rootCategoryArray[$parentName][
'index'] =
$index;
68 $stores =
$product->getDataFieldConfig(
'website_ids')[
'source']->getStores();
70 $rootCategoryName =
$store->getDataFieldConfig(
'group_id')[
'source']
72 ->getDataFieldConfig(
'root_category_id')[
'source']
76 $this->parentCategoryIndex = $rootCategoryArray[$rootCategoryName][
'index'];
81 'request_path' =>
$product->getUrlKey() .
'.html',
85 'request_path' => $rootCategoryArray[$rootCategoryName][
'name'] .
'.html',
90 $rootCategoryArray[$rootCategoryName][
'name'] .
'/' .
$product->getUrlKey() .
'.html',
96 \PHPUnit\Framework\Assert::assertTrue(
97 $urlRewriteIndex->getUrlRedirectGrid()->isRowVisible($filter,
true,
false),
98 'URL Rewrite with request path \'' . $filter[
'request_path'] .
'\' is absent in grid.
' 111 private function getTargetPath(FixtureInterface $product, FixtureInterface $category = null) 113 $productId = $product->getId() 115 : $this->retrieveProductBySku($product->getSku())['id
']; 116 $categoryId = $product->hasData('category_ids
') 117 ? $this->getCategoryId($product) 118 : ($category ? $category->getId() : ''); 119 return sprintf($this->targetPathTemplate, $productId, $categoryId); 128 private function getCategoryId(FixtureInterface $product) 130 $productSku = $product->getSku(); 131 $categoryId = $product->getDataFieldConfig('category_ids
')['source
'] 132 ->getCategories()[$this->parentCategoryIndex]->getId(); 133 $categoryId = $categoryId 135 : $this->retrieveProductBySku($productSku) 136 ['extension_attributes
']['category_links
'][$this->parentCategoryIndex]['category_id
']; 146 public function retrieveProductBySku($sku) 148 $url = $_ENV['app_frontend_url
'] . 'rest/all/V1/products/
' . $sku; 149 $this->webApi->write($url, [], WebapiDecorator::GET); 150 $response = json_decode($this->webApi->read(), true); 151 $this->webApi->close(); 160 public function toString() 162 return 'URL Rewrite is present in grid.
';
processAssert(UrlRewriteIndex $urlRewriteIndex, WebapiDecorator $webApi, FixtureInterface $product, Category $category=null)