Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertSelectedSwatchOptionsOnProductPage.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Mtf\Fixture\FixtureInterface;
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
11 use Magento\Mtf\Client\BrowserInterface;
12 
17 {
21  public function processAssert(
22  BrowserInterface $browser,
23  CatalogProductView $catalogProductView,
24  FixtureInterface $product
25  ) {
26  $this->product = $product;
27  $this->productView = $catalogProductView->getProductViewWithSwatchesBlock();
28 
29  $this->productView->getSelectedSwatchOptions($this->product);
30  $errors = $this->verify();
31  \PHPUnit\Framework\Assert::assertEmpty(
32  $errors,
33  "\nFound the following errors:\n" . implode(" \n", $errors)
34  );
35  }
36 
42  protected function verify()
43  {
44  $errors = parent::verify();
45  $errors[] = $this->verifySwatches();
46 
47  return array_filter($errors);
48  }
49 
55  protected function verifySwatches()
56  {
57  $actualData = $this->productView->getSelectedSwatchOptions($this->product);
58  $expectedData = $this->convertCheckoutData($this->product);
59  $this->verifyData($expectedData, $actualData);
60  }
61 
68  public function convertCheckoutData(FixtureInterface $product)
69  {
70  $out = [];
71  $checkoutData = $product->getCheckoutData();
72  $availableAttributes = $product->getConfigurableAttributesData();
73  $attributesData = $availableAttributes['attributes_data'];
74  foreach ($checkoutData['options']['configurable_options'] as $item) {
75  $out[$item['title']] = $attributesData[$item['title']]['options'][$item['value']]['label'];
76  }
77 
78  return $out;
79  }
80 
86  public function toString()
87  {
88  return 'Swatch attributes displayed as expected on product page';
89  }
90 }
processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product)
verifyData(array $fixtureData, array $formData, $isStrict=false, $isPrepareError=true)
$attributesData
$errors
Definition: overview.phtml:9