Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertExportAdvancedPricing.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Mtf\Constraint\AbstractConstraint;
9 use Magento\Mtf\Fixture\InjectableFixture;
11 
15 class AssertExportAdvancedPricing extends AbstractConstraint
16 {
22  private $exportData;
23 
32  public function processAssert(
33  ExportInterface $export,
34  array $products,
35  array $exportedFields
36  ) {
37  $this->exportData = $export->getLatest();
38  foreach ($products as $product) {
39  $regexps = $this->prepareRegexpsForCheck($exportedFields, $product);
40  \PHPUnit\Framework\Assert::assertTrue(
41  $this->isProductDataExists($regexps),
42  'A product with name ' . $product->getName() . ' was not found in exported file.'
43  );
44  }
45  }
46 
52  public function toString()
53  {
54  return 'A product(s) with correct data was found in exported file.';
55  }
56 
64  private function prepareRegexpsForCheck(
65  array $fields,
66  InjectableFixture $product
67  ) {
68  $regexpsForCheck = [];
69  $tierPrices = count($product->getData()['tier_price']);
70  for ($i = 0; $i < $tierPrices; $i++) {
71  $regexp = '/';
72  foreach ($fields as $field) {
73  if (strpos($field, 'tier_price') !== false) {
74  $replace = ($field == 'tier_price' || $field == 'tier_price_qty') ? 'tier_' : 'tier_price_';
75  $regexp .= preg_replace(
76  '/[\[\]]/',
77  '.*',
78  '.*(' . $product->getData()['tier_price'][$i][str_replace($replace, '', $field)] . ')'
79  );
80  } else {
81  $regexp .= '.*(' . $product->getData($field) . ').*';
82  }
83  }
84  $regexp .= '/U';
85 
86  $regexpsForCheck[] = $regexp;
87  }
88 
89  return $regexpsForCheck;
90  }
91 
98  private function isProductDataExists(array $data)
99  {
100  foreach ($data as $regexp) {
101  preg_match($regexp, $this->exportData->getContent(), $matches);
102  if (empty($matches)) {
103  return false;
104  }
105  }
106 
107  return true;
108  }
109 }
$fields
Definition: details.phtml:14
processAssert(ExportInterface $export, array $products, array $exportedFields)
$i
Definition: gallery.phtml:31