Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateBundleProductEntityTest.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
12 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
13 use Magento\Mtf\TestCase\Injectable;
14 use Magento\Mtf\Fixture\FixtureFactory;
15 
34 class UpdateBundleProductEntityTest extends Injectable
35 {
36  /* tags */
37  const MVP = 'yes';
38  /* end tags */
39 
46 
53 
59  private $fixtureFactory;
60 
69  public function __inject(
70  CatalogProductIndex $catalogProductIndexNewPage,
71  CatalogProductEdit $catalogProductEditPage,
72  FixtureFactory $fixtureFactory
73  ) {
74  $this->catalogProductIndex = $catalogProductIndexNewPage;
75  $this->catalogProductEdit = $catalogProductEditPage;
76  $this->fixtureFactory = $fixtureFactory;
77  }
78 
87  public function test(
88  BundleProduct $product,
89  BundleProduct $originalProduct,
90  Store $store = null
91  ) {
92  // Preconditions
93  $originalProduct->persist();
94  $category = $this->getCategories($originalProduct, $product);
95 
96  if ($store) {
97  $store->persist();
98  $optionTitle[$store->getStoreId()] = $product->getBundleSelections()['bundle_options'][0]['title'];
99  }
100 
101  // Steps
102  $filter = ['sku' => $originalProduct->getSku()];
103 
104  $this->catalogProductIndex->open();
105  $this->catalogProductIndex->getProductGrid()->searchAndOpen($filter);
106  if ($store) {
107  $this->catalogProductEdit->getFormPageActions()->changeStoreViewScope($store);
108  }
109  $this->catalogProductEdit->getProductForm()->fill($product);
110  $this->catalogProductEdit->getFormPageActions()->save();
111 
112  return [
113  'category' => $category,
114  'stores' => isset($store) ? [$store] : [],
115  'optionTitles' => isset($optionTitle) ? $optionTitle : []
116  ];
117  }
118 
126  protected function getCategories(BundleProduct $originalProduct, BundleProduct $product)
127  {
128  $originalCategory = $originalProduct->hasData('category_ids')
129  ? $originalProduct->getDataFieldConfig('category_ids')['source']->getCategories()
130  : null;
131  return $product->hasData('category_ids')
132  ? $product->getDataFieldConfig('category_ids')['source']->getCategories()
133  : $originalCategory;
134  }
135 }
getCategories(BundleProduct $originalProduct, BundleProduct $product)
test(BundleProduct $product, BundleProduct $originalProduct, Store $store=null)
__inject(CatalogProductIndex $catalogProductIndexNewPage, CatalogProductEdit $catalogProductEditPage, FixtureFactory $fixtureFactory)