Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertBundleOptionsDeleted.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
12 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
13 use Magento\Mtf\Fixture\FixtureInterface;
14 
18 class AssertBundleOptionsDeleted extends AbstractConstraint
19 {
28  public function processAssert(
29  BundleProduct $product,
30  BundleProduct $originalProduct,
31  CatalogProductIndex $productGrid,
32  CatalogProductEdit $productPage
33  ) {
34  $filter = ['sku' => $product->getSku()];
35  $productGrid->open();
36  $productGrid->getProductGrid()->searchAndOpen($filter);
37 
38  $productData = $product->getData()['bundle_selections']['bundle_options'];
39  $originalProductData = $originalProduct->getData()['bundle_selections']['bundle_options'];
40  $formData = $productPage->getProductForm()->getData($product)['bundle_selections'];
41 
42  $productDataLength = count($productData);
43  $formDataLength = count($productData);
44  \PHPUnit\Framework\Assert::assertEquals($productDataLength, $formDataLength);
45 
46  foreach ($productData as $index => $option) {
47  $productAssociatedDataLength = count($option['assigned_products']);
48  $formAssociatedDataLength = count($formData[$index]['assigned_products']);
49  \PHPUnit\Framework\Assert::assertEquals($productAssociatedDataLength, $formAssociatedDataLength);
50 
51  foreach ($option['assigned_products'] as $productIndex => $associatedProduct) {
52  $associatedProduct['data']['getProductName'] =
53  $originalProductData[$index+1]['assigned_products'][$productIndex]['search_data']['name'];
54  $associatedProduct = $associatedProduct['data'];
55  $errorAssociatedProducts = array_diff(
56  $associatedProduct,
57  $formData[$index]['assigned_products'][$productIndex]
58  );
59  \PHPUnit\Framework\Assert::assertCount(0, $errorAssociatedProducts);
60  }
61 
62  unset($option['assigned_products']);
63  unset($formData[$index]['assigned_products']);
64  $errorFields = array_diff($option, $formData[$index]);
65  \PHPUnit\Framework\Assert::assertCount(0, $errorFields);
66  }
67  }
68 
74  public function toString()
75  {
76  return 'Bundle options were not deleted correctly. There is difference with expected options';
77  }
78 }
$productData
$index
Definition: list.phtml:44
processAssert(BundleProduct $product, BundleProduct $originalProduct, CatalogProductIndex $productGrid, CatalogProductEdit $productPage)