Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertAttributeOptionsOnProductForm.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\InjectableFixture;
10 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
12 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
13 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
14 
18 class AssertAttributeOptionsOnProductForm extends AbstractConstraint
19 {
29  public function processAssert(
30  InjectableFixture $product,
31  CatalogProductIndex $productGrid,
32  CatalogProductAttribute $attribute,
33  CatalogProductEdit $productEdit
34  ) {
35  $productGrid->open();
36  $productGrid->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
37 
38  $attributeOptions = $attribute->getOptions();
39  $options[] = $attribute->getFrontendLabel();
40  foreach ($attributeOptions as $option) {
41  $options[] = $option['admin'];
42  }
43  $productAttributeOptions = $productEdit->getProductForm()->getAttributeElement($attribute)->getText();
44  $productOptions = explode("\n", $productAttributeOptions);
45  $diff = array_diff($options, $productOptions);
46 
47  \PHPUnit\Framework\Assert::assertTrue(
48  empty($diff),
49  "Products attribute options are absent on product form: " . implode(', ', $diff)
50  );
51  }
52 
58  public function toString()
59  {
60  return 'All product attribute options are visible on product creation form.';
61  }
62 }
processAssert(InjectableFixture $product, CatalogProductIndex $productGrid, CatalogProductAttribute $attribute, CatalogProductEdit $productEdit)