Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCatalogPriceRuleForm.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\CatalogRule\Test\Fixture\CatalogRule;
10 use Magento\CatalogRule\Test\Page\Adminhtml\CatalogRuleIndex;
11 use Magento\CatalogRule\Test\Page\Adminhtml\CatalogRuleNew;
12 use Magento\Mtf\Constraint\AbstractConstraint;
13 
17 class AssertCatalogPriceRuleForm extends AbstractConstraint
18 {
28  public function processAssert(
29  CatalogRule $catalogPriceRule,
30  CatalogRuleIndex $pageCatalogRuleIndex,
31  CatalogRuleNew $pageCatalogRuleNew,
32  CatalogRule $catalogPriceRuleOriginal = null
33  ) {
34  $data = ($catalogPriceRuleOriginal === null)
35  ? $catalogPriceRule->getData()
36  : array_merge($catalogPriceRuleOriginal->getData(), $catalogPriceRule->getData());
37  $filter['name'] = $data['name'];
38 
39  $pageCatalogRuleIndex->open();
40  $pageCatalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
41  $formData = $pageCatalogRuleNew->getEditForm()->getData($catalogPriceRule);
42  $fixtureData = $catalogPriceRule->getData();
43  //convert discount_amount to float to compare
44  if (isset($formData['discount_amount'])) {
45  $formData['discount_amount'] = floatval($formData['discount_amount']);
46  }
47  if (isset($fixtureData['discount_amount'])) {
48  $fixtureData['discount_amount'] = floatval($fixtureData['discount_amount']);
49  }
50  $diff = $this->verifyData($formData, $fixtureData);
51  \PHPUnit\Framework\Assert::assertTrue(
52  empty($diff),
53  implode(' ', $diff)
54  );
55  }
56 
64  protected function verifyData(array $formData, array $fixtureData)
65  {
66  $errorMessage = [];
67  foreach ($fixtureData as $key => $value) {
68  if ($key == 'conditions') {
69  continue;
70  }
71  if (is_array($value)) {
72  $diff = array_diff($value, $formData[$key]);
73  $diff = array_merge($diff, array_diff($formData[$key], $value));
74  if (!empty($diff)) {
75  $errorMessage[] = "Data in " . $key . " field not equal."
76  . "\nExpected: " . implode(", ", $value)
77  . "\nActual: " . implode(", ", $formData[$key]);
78  }
79  } else {
80  if ($value !== $formData[$key]) {
81  $errorMessage[] = "Data in " . $key . " field not equal."
82  . "\nExpected: " . $value
83  . "\nActual: " . $formData[$key];
84  }
85  }
86  }
87  return $errorMessage;
88  }
89 
95  public function toString()
96  {
97  return 'Displayed catalog price rule data on edit page(backend) equals to passed from fixture.';
98  }
99 }
processAssert(CatalogRule $catalogPriceRule, CatalogRuleIndex $pageCatalogRuleIndex, CatalogRuleNew $pageCatalogRuleNew, CatalogRule $catalogPriceRuleOriginal=null)
$value
Definition: gender.phtml:16