Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductDuplicateForm.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
10 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
11 use Magento\Mtf\Fixture\FixtureInterface;
12 
17 {
18  /* tags */
19  const SEVERITY = 'low';
20  /* end tags */
21 
27  protected $formattingOptions = [
28  'price' => [
29  'decimals' => 2,
30  'dec_point' => '.',
31  'thousands_sep' => '',
32  ],
33  'qty' => [
34  'decimals' => 4,
35  'dec_point' => '.',
36  'thousands_sep' => '',
37  ],
38  'weight' => [
39  'decimals' => 4,
40  'dec_point' => '.',
41  'thousands_sep' => '',
42  ],
43  ];
44 
53  public function processAssert(
54  FixtureInterface $product,
55  CatalogProductIndex $productGrid,
56  CatalogProductEdit $productPage
57  ) {
58  $filter = ['sku' => $product->getSku() . '-1'];
59  $productGrid->open()->getProductGrid()->searchAndOpen($filter);
60 
61  $formData = $productPage->getProductForm()->getData($product);
62  $fixtureData = $this->prepareFixtureData($product->getData());
63 
64  $errors = $this->verifyData($fixtureData, $formData);
65  \PHPUnit\Framework\Assert::assertEmpty($errors, $errors);
66  }
67 
75  protected function prepareFixtureData(array $data, array $sortFields = [])
76  {
77  $compareData = array_filter($data);
78 
79  array_walk_recursive(
80  $compareData,
81  function (&$item, $key, $formattingOptions) {
82  if (isset($formattingOptions[$key])) {
83  $item = number_format(
84  $item,
85  $formattingOptions[$key]['decimals'],
86  $formattingOptions[$key]['dec_point'],
87  $formattingOptions[$key]['thousands_sep']
88  );
89  }
90  },
92  );
93 
94  if (isset($compareData['status'])) {
95  $compareData['status'] = 'No';
96  }
97  if (isset($compareData['quantity_and_stock_status']['qty'])) {
98  $compareData['quantity_and_stock_status']['qty'] = '';
99  $compareData['quantity_and_stock_status']['is_in_stock'] = 'Out of Stock';
100  }
101  if (isset($compareData['special_price'])) {
102  $compareData['special_price'] = ['special_price' => $compareData['special_price']];
103  }
104  $compareData['sku'] .= '-1';
105  $compareData['url_key'] = $this->prepareUrlKey($compareData['url_key']);
106 
107  return parent::prepareFixtureData($compareData, $sortFields);
108  }
109 
116  protected function prepareUrlKey($urlKey)
117  {
118  preg_match("~\d+$~", $urlKey, $matches);
119  $key = intval($matches[0]) + 1;
120  return str_replace($matches[0], $key, $urlKey);
121  }
122 
128  public function toString()
129  {
130  return 'Form data equals to fixture data of duplicated product.';
131  }
132 }
verifyData(array $fixtureData, array $formData, $isStrict=false, $isPrepareError=true)
processAssert(FixtureInterface $product, CatalogProductIndex $productGrid, CatalogProductEdit $productPage)
$errors
Definition: overview.phtml:9