Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateProductWithSeveralWebsitesUrlRewriteTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
11 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductNew;
12 use Magento\Mtf\Fixture\FixtureFactory;
13 use Magento\Mtf\TestCase\Injectable;
14 
27 {
28  /* tags */
29  const MVP = 'yes';
30  /* end tags */
31 
42  public function testCreate(
43  CatalogProductSimple $product,
44  CatalogProductIndex $productGrid,
45  CatalogProductNew $newProductPage,
46  FixtureFactory $fixtureFactory,
47  array $websiteCategories
48  ) {
49  $categoryParent = [];
50  $categoryList = [];
51  $storeList = [];
52 
53  // Preconditions
54  foreach ($websiteCategories as $websiteCategory) {
55  list($storeGroup, $store, $category) = explode('::', $websiteCategory);
56  if (!isset($categoryParent[$category])) {
57  $categoryListItem = $fixtureFactory->createByCode('category', ['dataset' => $category]);
58  $categoryListItem->persist();
59  $categoryParent[$category] = $categoryListItem->getDataFieldConfig('parent_id')['source']
60  ->getParentCategory();
61  $categoryList[] = $categoryListItem;
62  }
63  $storeGroup = $fixtureFactory->createByCode('storeGroup', [
64  'dataset' => $storeGroup,
65  'data' => [
66  'root_category_id' => [
67  'category' => $categoryParent[$category]
68  ]
69  ]
70  ]);
71  $storeGroup->persist();
72  $store = $fixtureFactory->createByCode('store', [
73  'dataset' => $store,
74  'data' => [
75  'group_id' => [
76  'storeGroup' => $storeGroup
77  ]
78  ]
79  ]);
80  $store->persist();
81  $storeList[] = $store;
82  }
83 
84  $productData = $product->getData();
85  $productData['website_ids'] = $storeList;
86  $productData['category_ids'] = $categoryList;
87 
88  $product = $fixtureFactory->createByCode(
89  'catalogProductSimple',
90  [
91  'dataset' => 'default',
92  'data' => $productData,
93  ]
94  );
95 
96  // Steps
97  $productGrid->open();
98  $productGrid->getGridPageActionBlock()->addProduct('simple');
99  $newProductPage->getProductForm()->fill($product);
100  $newProductPage->getFormPageActions()->save();
101 
102  return ['product' => $product];
103  }
104 }
testCreate(CatalogProductSimple $product, CatalogProductIndex $productGrid, CatalogProductNew $newProductPage, FixtureFactory $fixtureFactory, array $websiteCategories)
$productData