Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCustomVariableForm.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Variable\Test\Fixture\SystemVariable;
10 use Magento\Variable\Test\Page\Adminhtml\SystemVariableIndex;
11 use Magento\Variable\Test\Page\Adminhtml\SystemVariableNew;
14 
19 {
25  protected $skippedFields = ['use_default_value', 'variable_id'];
26 
39  public function processAssert(
40  SystemVariable $customVariable,
41  SystemVariableIndex $systemVariableIndex,
42  SystemVariableNew $systemVariableNew,
43  Store $storeOrigin = null,
44  SystemVariable $customVariableOrigin = null
45  ) {
46  // Prepare data
47  $data = ($customVariableOrigin === null)
48  ? $customVariable->getData()
49  : array_merge($customVariableOrigin->getData(), $customVariable->getData());
50  if ($customVariableOrigin !== null) {
51  $dataOrigin = $this->arrayCopy($data);
52  $dataOrigin['html_value'] = $customVariableOrigin->getHtmlValue();
53  $dataOrigin['plain_value'] = $customVariableOrigin->getPlainValue();
54  } else {
55  $dataOrigin = $this->arrayCopy($data);
56  }
57  if ($data['html_value'] == '') {
58  $data['html_value'] = $customVariableOrigin->getHtmlValue();
59  $data['use_default_value'] = 'Yes';
60  }
61  $data['plain_value'] = ($data['plain_value'] == '')
62  ? $customVariableOrigin->getPlainValue()
63  : $data['plain_value'];
64  // Perform assert
65  $systemVariableIndex->open();
66  $systemVariableIndex->getSystemVariableGrid()->searchAndOpen(['code' => $data['code']]);
67 
68  $formData = $systemVariableNew->getSystemVariableForm()->getData();
69  $errors = $this->verifyData($dataOrigin, $formData);
70  \PHPUnit\Framework\Assert::assertEmpty($errors, $errors);
71 
72  if ($storeOrigin !== null) {
73  $systemVariableNew->getFormPageActions()->selectStoreView($storeOrigin->getName());
74  $formData = $systemVariableNew->getSystemVariableForm()->getData();
75  $errors = $this->verifyData($data, $formData);
76  \PHPUnit\Framework\Assert::assertEmpty($errors, $errors);
77  }
78  }
79 
85  public function toString()
86  {
87  return 'Displayed Custom Variable data on edit page(backend) equals to passed from fixture.';
88  }
89 
97  private function arrayCopy($sourceArray)
98  {
99  $copyArray = [];
100  foreach ($sourceArray as $key => $value) {
101  $copyArray[$key] = $value;
102  }
103  return $copyArray;
104  }
105 }
processAssert(SystemVariable $customVariable, SystemVariableIndex $systemVariableIndex, SystemVariableNew $systemVariableNew, Store $storeOrigin=null, SystemVariable $customVariableOrigin=null)
verifyData(array $fixtureData, array $formData, $isStrict=false, $isPrepareError=true)
$value
Definition: gender.phtml:16
$errors
Definition: overview.phtml:9