Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertExportProduct.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Mtf\Fixture\InjectableFixture;
12 
16 class AssertExportProduct extends AbstractConstraint
17 {
26  public function processAssert(
27  ExportInterface $export,
28  array $exportedFields,
29  array $products
30  ) {
31  $exportData = $export->getLatest();
32 
33  foreach ($products as $product) {
34  \PHPUnit\Framework\Assert::assertTrue(
35  $this->isProductDataInFile(
36  $exportedFields,
37  $product,
38  $exportData
39  ),
40  'Product data was not found in exported file.'
41  );
42  }
43  }
44 
50  public function toString()
51  {
52  return 'Product data exists in exported file.';
53  }
54 
63  private function isProductDataInFile(
64  array $fields,
65  InjectableFixture $product,
66  Data $exportData
67  ) {
68  $regexp = '/';
69  foreach ($fields as $field) {
70  if ($field == 'additional_images' && $product->hasData('media_gallery')) {
71  $regexp .= '.*(\/?.*(jpg|jpeg|png))';
72  } elseif ($field == 'special_price_from_date' && $product->getData('special_price_from_date')) {
73  $regexp .= $this->prepareSpecialPriceDateRegexp($product, 'special_price_from_date');
74  } elseif ($field == 'special_price_to_date' && $product->getData('special_price_to_date')) {
75  $regexp .= $this->prepareSpecialPriceDateRegexp($product, 'special_price_to_date');
76  } else {
77  $regexp .= '.*(' . $product->getData($field) . ')';
78  }
79  }
80  $regexp .= '/U';
81 
82  return (bool) preg_match($regexp, $exportData->getContent());
83  }
84 
93  private function prepareSpecialPriceDateRegexp(InjectableFixture $product, $field, $dateFormat = 'n/j/y')
94  {
95  return '.*' . str_replace('/', '\/', date($dateFormat, strtotime($product->getData($field))));
96  }
97 }
processAssert(ExportInterface $export, array $exportedFields, array $products)
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$fields
Definition: details.phtml:14