Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertUrlRewriteUpdatedProductInGrid.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\UrlRewrite\Test\Page\Adminhtml\UrlRewriteIndex;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 
17 class AssertUrlRewriteUpdatedProductInGrid extends AbstractConstraint
18 {
27  public function processAssert(
28  CatalogProductSimple $product,
29  CatalogProductSimple $initialProduct,
30  UrlRewriteIndex $urlRewriteIndex
31  ) {
32  $urlRewriteIndex->open();
33  $category = $product->getDataFieldConfig('category_ids')['source']->getCategories()[0];
34  $targetPath = "catalog/product/view/id/{$initialProduct->getId()}/category/{$category->getId()}";
35  $url = strtolower($product->getCategoryIds()[0] . '/' . $product->getUrlKey());
36  $filter = [
37  'request_path' => $url,
38  'target_path' => $targetPath,
39  ];
40  \PHPUnit\Framework\Assert::assertTrue(
41  $urlRewriteIndex->getUrlRedirectGrid()->isRowVisible($filter, true, false),
42  "URL Rewrite with request path '$url' is absent in grid."
43  );
44 
45  $categoryInitial = $initialProduct->getDataFieldConfig('category_ids')['source']->getCategories()[0];
46  $targetPath = "catalog/product/view/id/{$initialProduct->getId()}/category/{$categoryInitial->getId()}";
47 
48  \PHPUnit\Framework\Assert::assertFalse(
49  $urlRewriteIndex->getUrlRedirectGrid()->isRowVisible(['target_path' => $targetPath], true, false),
50  "URL Rewrite with target path '$targetPath' is present in grid."
51  );
52  }
53 
59  public function toString()
60  {
61  return 'URL Rewrite for product was changed after assign category.';
62  }
63 }
processAssert(CatalogProductSimple $product, CatalogProductSimple $initialProduct, UrlRewriteIndex $urlRewriteIndex)