Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductComparePage.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Product\CatalogProductCompare;
10 use Magento\Cms\Test\Page\CmsIndex;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 
17 class AssertProductComparePage extends AbstractConstraint
18 {
24  private $priceFormat = 2;
25 
31  protected $attributeProduct = [
32  'name',
33  'price',
34  'sku' => 'SKU',
35  'description' => 'Description',
36  'short_description' => 'Short Description',
37  ];
38 
54  public function processAssert(
55  array $products,
56  CatalogProductCompare $comparePage,
57  CmsIndex $cmsIndex
58  ) {
59  $cmsIndex->open();
60  $cmsIndex->getLinksBlock()->openLink("Compare Products");
61  foreach ($products as $key => $product) {
62  foreach ($this->attributeProduct as $attributeKey => $attribute) {
64  $attribute = is_numeric($attributeKey) ? $attribute : $attributeKey;
65 
66  $expectedAttributeValue = $attribute != 'price'
67  ? ($product->hasData($attribute)
68  ? $product->getData($attribute)
69  : 'N/A')
70  : ($product->getDataFieldConfig('price')['source']->getPriceData() !== null
71  ? $product->getDataFieldConfig('price')['source']->getPriceData()['compare_price']
72  : number_format($product->getPrice(), $this->priceFormat));
73 
74  $attribute = is_numeric($attributeKey) ? 'info' : 'attribute';
75  $attribute = ucfirst($attribute);
76  $actualAttributeValue =
77  $comparePage->getCompareProductsBlock()->{'getProduct' . $attribute}($key + 1, $value);
78 
79  \PHPUnit\Framework\Assert::assertEquals(
80  $expectedAttributeValue,
81  $actualAttributeValue,
82  'Product "' . $product->getName() . '" has "' . $attribute . '" value different from fixture one.'
83  );
84  }
85  }
86  }
87 
93  public function toString()
94  {
95  return '"Compare Product" page has valid data for all products.';
96  }
97 }
$value
Definition: gender.phtml:16
processAssert(array $products, CatalogProductCompare $comparePage, CmsIndex $cmsIndex)