Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductUrlDuplicateErrorMessage.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
10 use Magento\Mtf\Constraint\AbstractConstraint;
13 
17 class AssertProductUrlDuplicateErrorMessage extends AbstractConstraint
18 {
22  const ERROR_MESSAGE_TITLE = 'The value specified in the URL Key field would generate a URL that already exists.';
23 
32  public function processAssert(
33  CatalogProductEdit $productPage,
34  CatalogProductSimple $product,
35  Category $category
36  ) {
37  $actualMessage = $productPage->getMessagesBlock()->getErrorMessage();
38  \PHPUnit\Framework\Assert::assertContains(
39  self::ERROR_MESSAGE_TITLE,
40  $actualMessage,
41  'Wrong error message is displayed.'
42  . "\nExpected: " . self::ERROR_MESSAGE_TITLE
43  . "\nActual:\n" . $actualMessage
44  );
45 
46  \PHPUnit\Framework\Assert::assertContains(
47  $product->getUrlKey(),
48  $actualMessage,
49  'Product url is not present on error message.'
50  . "\nExpected: " . self::ERROR_MESSAGE_TITLE
51  . "\nActual:\n" . $actualMessage
52  );
53 
54  \PHPUnit\Framework\Assert::assertContains(
55  $category->getUrlKey() . '/' . $product->getUrlKey(),
56  $actualMessage,
57  'Category url is not present on error message.'
58  . "\nExpected: " . self::ERROR_MESSAGE_TITLE
59  . "\nActual:\n" . $actualMessage
60  );
61  }
62 
68  public function toString()
69  {
70  return 'Product url duplication error on save message is present.';
71  }
72 }
processAssert(CatalogProductEdit $productPage, CatalogProductSimple $product, Category $category)