Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertBundleItemsSummaryOnProductPage.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Catalog\Test\Page\Product\CatalogProductView;
10 use Magento\Mtf\Client\BrowserInterface;
12 
17 {
26  public function processAssert(
27  CatalogProductView $catalogProductView,
28  BundleProduct $product,
29  BrowserInterface $browser
30  ) {
31  $expectedResult = [];
32  $actualResult = [];
33 
34  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
35  $bundleOptions = $product->getData()['bundle_selections']['bundle_options'];
36  $bundleViewBlock = $catalogProductView->getBundleViewBlock();
37  $configuredPriceBlock = $bundleViewBlock->getBundleSummaryBlock()->getConfiguredPriceBlock();
38  foreach ($bundleOptions as $bundleOption) {
39  foreach ($bundleOption['assigned_products'] as $assignedProduct) {
40  $bundleViewBlock->fillOptionsWithCustomData([
41  [
42  'title' => $bundleOption['title'],
43  'type' => $bundleOption['type'],
44  'frontend_type' => $bundleOption['type'],
45  'value' => [
46  'name' => $assignedProduct['search_data']['name']
47  ]
48  ]
49  ]);
50  $assignedProductPrice = (double)$assignedProduct['data']['selection_price_value'];
51  $assignedProductQty = (double)$assignedProduct['data']['selection_qty'];
52 
53  foreach ($bundleViewBlock->getBundleSummaryBlock()->getSummaryItems() as $bundleSummaryItem) {
54  $bundleSummaryItemText = $bundleSummaryItem->getText();
55  if (strpos($bundleSummaryItemText, $assignedProduct['search_data']['name']) !== false) {
56  $optionData = $this->getBundleOptionData($bundleSummaryItemText);
57  $optionData['price'] = (double)$configuredPriceBlock->getPrice();
58  $actualResult[] = $optionData;
59  }
60  }
61 
62  $expectedResult[] = [
63  'qty' => $assignedProduct['data']['selection_qty'],
64  'name' => $assignedProduct['search_data']['name'],
65  'price' => $assignedProductQty * $assignedProductPrice + (double)$product->getPrice()
66  ];
67  }
68  }
69 
70  \PHPUnit\Framework\Assert::assertEquals(
71  $expectedResult,
72  $actualResult,
73  'Bundle Summary Section does not contain correct bundle options data.'
74  );
75  }
76 
83  private function getBundleOptionData($rowItem)
84  {
85  // Row item must be displayed like "1 x Simple Product".
86  $rowItem = explode(' x ', $rowItem);
87  return [
88  'qty' => $rowItem[0],
89  'name' => $rowItem[1]
90  ];
91  }
92 
98  public function toString()
99  {
100  return 'Bundle options are displayed correctly in the summary section.';
101  }
102 }
$optionData
processAssert(CatalogProductView $catalogProductView, BundleProduct $product, BrowserInterface $browser)