Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateCategoryEntityTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit;
11 use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryIndex;
12 use Magento\Mtf\TestCase\Injectable;
13 use Magento\Mtf\Fixture\FixtureFactory;
14 
33 class UpdateCategoryEntityTest extends Injectable
34 {
35  /* tags */
36  const MVP = 'yes';
37  /* end tags */
38 
45 
52 
58  protected $fixtureFactory;
59 
68  public function __inject(
69  CatalogCategoryIndex $catalogCategoryIndex,
70  CatalogCategoryEdit $catalogCategoryEdit,
71  FixtureFactory $fixtureFactory
72  ) {
73  $this->fixtureFactory = $fixtureFactory;
74  $this->catalogCategoryIndex = $catalogCategoryIndex;
75  $this->catalogCategoryEdit = $catalogCategoryEdit;
76  }
77 
85  public function test(Category $category, Category $initialCategory)
86  {
87  $initialCategory->persist();
88  $this->catalogCategoryIndex->open();
89  $this->catalogCategoryIndex->getTreeCategories()->selectCategory($initialCategory);
90  $this->catalogCategoryEdit->getEditForm()->fill($category);
91  $this->catalogCategoryEdit->getFormPageActions()->save();
92  return ['category' => $this->prepareCategory($category, $initialCategory)];
93  }
94 
102  protected function prepareCategory(Category $category, Category $initialCategory)
103  {
104  $parentCategory = $category->hasData('parent_id')
105  ? $category->getDataFieldConfig('parent_id')['source']->getParentCategory()
106  : $initialCategory->getDataFieldConfig('parent_id')['source']->getParentCategory();
107 
108  $rewriteData = ['parent_id' => ['source' => $parentCategory]];
109  if ($category->hasData('store_id')) {
110  $rewriteData['store_id'] = ['source' => $category->getDataFieldConfig('store_id')['source']->getStore()];
111  }
112 
113  $data = [
114  'data' => array_merge(
115  $initialCategory->getData(),
116  $category->getData(),
117  $rewriteData
118  )
119  ];
120 
121  return $this->fixtureFactory->createByCode('category', $data);
122  }
123 }
__inject(CatalogCategoryIndex $catalogCategoryIndex, CatalogCategoryEdit $catalogCategoryEdit, FixtureFactory $fixtureFactory)
prepareCategory(Category $category, Category $initialCategory)