Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NavigateUpSellProductsTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\InjectableFixture;
10 
23 {
24  /* tags */
25  const TEST_TYPE = 'acceptance_test, extended_acceptance_test';
26  const MVP = 'yes';
27  /* end tags */
28 
38  public function test(
39  $products,
40  $promotedProducts,
41  $navigateProductsOrder,
42  $productsToVerify
43  ) {
44  // Preconditions
45  $this->createProducts($products);
46  $this->assignPromotedProducts($promotedProducts, 'up_sell_products');
47 
48  // Initialization
49  $navigateProductsOrder = $this->parseNavigateProductsOrder($navigateProductsOrder);
50  $productsToVerify = $this->parseProductsToVerify($productsToVerify);
51  $initialProductName = array_shift($navigateProductsOrder);
52  $initialProduct = $this->products[$initialProductName];
53  $initialProductsToVerify = $productsToVerify[$initialProductName];
54 
55  // Steps
56  $this->browser->open($_ENV['app_frontend_url'] . $initialProduct->getUrlKey() . '.html');
57  $this->assertUpSellSection($initialProductsToVerify);
58  foreach ($navigateProductsOrder as $productName) {
59  $product = $this->products[$productName];
60  $productAssert = $productsToVerify[$productName];
61 
62  $this->catalogProductView->getUpsellBlock()->getProductItem($product)->open();
63  if (empty($productAssert)) {
65  } else {
66  $this->assertUpSellSection($productAssert);
67  }
68  }
69  }
70 
76  protected function assertAbsentUpSellSection()
77  {
78  \PHPUnit\Framework\Assert::assertFalse(
79  $this->catalogProductView->getUpsellBlock()->isVisible(),
80  "Up-sell section is present."
81  );
82  }
83 
90  protected function assertUpSellSection(array $promotedProductNames)
91  {
92  $productNames = [];
93  $pageProductNames = [];
94 
95  foreach ($promotedProductNames as $promotedProductName) {
96  $productNames[] = $this->products[$promotedProductName]->getName();
97  }
98  foreach ($this->catalogProductView->getUpsellBlock()->getProducts() as $productItem) {
99  $pageProductNames[] = $productItem->getProductName();
100  }
101 
102  sort($productNames);
103  sort($pageProductNames);
104  \PHPUnit\Framework\Assert::assertEquals(
105  $productNames,
106  $pageProductNames,
107  'Wrong products are displayed in up-sell section.'
108  );
109  }
110 }
test( $products, $promotedProducts, $navigateProductsOrder, $productsToVerify)