Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertTaxRuleForm.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Tax\Test\Page\Adminhtml\TaxRuleIndex;
11 use Magento\Tax\Test\Page\Adminhtml\TaxRuleNew;
12 use Magento\Mtf\Constraint\AbstractConstraint;
13 
17 class AssertTaxRuleForm extends AbstractConstraint
18 {
27  public function processAssert(
28  TaxRuleNew $taxRuleNew,
29  TaxRuleIndex $taxRuleIndex,
30  TaxRule $taxRule,
31  TaxRule $initialTaxRule = null
32  ) {
33  $data = $taxRule->getData();
34  if ($initialTaxRule !== null) {
35  $taxRuleCode = ($taxRule->hasData('code')) ? $taxRule->getCode() : $initialTaxRule->getCode();
36  } else {
37  $taxRuleCode = $taxRule->getCode();
38  }
39  $filter = [
40  'code' => $taxRuleCode,
41  ];
42  $taxRuleIndex->open();
43  $taxRuleIndex->getTaxRuleGrid()->searchAndOpen($filter);
44  $taxRuleNew->getTaxRuleForm()->openAdditionalSettings();
45  $formData = $taxRuleNew->getTaxRuleForm()->getData($taxRule);
46  $dataDiff = $this->verifyForm($formData, $data);
47  \PHPUnit\Framework\Assert::assertTrue(
48  empty($dataDiff),
49  'Tax Rule form was filled not right.'
50  . "\nLog:\n" . implode(";\n", $dataDiff)
51  );
52  }
53 
61  protected function verifyForm(array $formData, array $fixtureData)
62  {
63  $errorMessage = [];
64 
65  foreach ($fixtureData as $key => $value) {
66  if (is_array($value)) {
67  $diff = array_diff($value, $formData[$key]);
68  $diff = array_merge($diff, array_diff($formData[$key], $value));
69  if (!empty($diff)) {
70  $errorMessage[] = "Data in " . $key . " field not equal."
71  . "\nExpected: " . implode(", ", $value)
72  . "\nActual: " . implode(", ", $formData[$key]);
73  }
74  } else {
75  if ($value !== $formData[$key]) {
76  $errorMessage[] = "Data in " . $key . " field not equal."
77  . "\nExpected: " . $value
78  . "\nActual: " . $formData[$key];
79  }
80  }
81  }
82 
83  return $errorMessage;
84  }
85 
91  public function toString()
92  {
93  return 'Tax Rule form has been filled right.';
94  }
95 }
verifyForm(array $formData, array $fixtureData)
processAssert(TaxRuleNew $taxRuleNew, TaxRuleIndex $taxRuleIndex, TaxRule $taxRule, TaxRule $initialTaxRule=null)
$taxRule
Definition: tax_rule.php:35
$value
Definition: gender.phtml:16