10 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Mtf\Fixture\FixtureInterface;
12 use Magento\Catalog\Test\Page\Product\CatalogProductView;
13 use Magento\Mtf\TestStep\TestStepFactory;
26 TestStepFactory $stepFactory,
27 CatalogProductView $catalogProductView,
30 $stepFactory->create(OpenProductOnFrontendStep::class, [
'product' =>
$product])
33 $actualData = $catalogProductView->getProductViewWithSwatchesBlock()
34 ->getSwatchAttributesData();
35 $expectedData =
$product->getConfigurableAttributesData()[
'attributes_data'];
37 foreach ($expectedData as $expectedAttributeData) {
38 \PHPUnit\Framework\Assert::assertArrayHasKey(
39 $expectedAttributeData[
'attribute_code'],
41 'Attribute with code ' . $expectedAttributeData[
'attribute_code'] .
' is absent on Product page' 43 $actualAttributeData = $actualData[$expectedAttributeData[
'attribute_code']];
44 $this->verifyAttribute($expectedAttributeData, $actualAttributeData);
45 $this->verifyAttributeOptions($expectedAttributeData, $actualAttributeData);
55 private function verifyAttribute(array $expectedAttributeData, array $actualAttributeData)
57 \PHPUnit\Framework\Assert::assertEquals(
58 $expectedAttributeData[
'attribute_code'],
59 $actualAttributeData[
'attribute_code'],
61 'Attribute code "%s" is not equal to expected "%s"',
62 $actualAttributeData[
'attribute_code'],
63 $expectedAttributeData[
'attribute_code']
66 \PHPUnit\Framework\Assert::assertEquals(
67 $expectedAttributeData[
'attribute_id'],
68 $actualAttributeData[
'attribute_id'],
70 'Attribute id "%s" is not equal to expected "%s"',
71 $actualAttributeData[
'attribute_id'],
72 $expectedAttributeData[
'attribute_id']
75 \PHPUnit\Framework\Assert::assertEquals(
76 $expectedAttributeData[
'label'],
77 $actualAttributeData[
'label'],
79 'Attribute label "%s" is not equal to expected "%s"',
80 $actualAttributeData[
'label'],
81 $expectedAttributeData[
'label']
92 private function verifyAttributeOptions(array $expectedAttributeData, array $actualAttributeData)
94 if (isset($expectedAttributeData[
'options'])) {
95 \PHPUnit\Framework\Assert::assertArrayHasKey(
98 'Swatch attribute options are missed on Product page' 101 $expectedOptionsCount = count($expectedAttributeData[
'options']);
102 $actualOptionsCount = count($actualAttributeData[
'options']);
103 \PHPUnit\Framework\Assert::assertEquals(
104 $expectedOptionsCount,
107 'Attribute options count "%d" is not equal to expected "%d"',
109 $expectedOptionsCount
113 \PHPUnit\Framework\Assert::assertArrayNotHasKey(
115 $actualAttributeData,
116 'Product page must be without swatch attribute options' 128 return 'Swatch attributes are displayed on product page';
processAssert(TestStepFactory $stepFactory, CatalogProductView $catalogProductView, FixtureInterface $product)