10 use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit;
11 use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryIndex;
12 use Magento\Mtf\Fixture\FixtureFactory;
13 use Magento\Mtf\TestCase\Injectable;
44 private $catalogCategoryIndex;
51 private $catalogCategoryEdit;
58 private $fixtureFactory;
69 CatalogCategoryIndex $catalogCategoryIndex,
70 CatalogCategoryEdit $catalogCategoryEdit,
71 FixtureFactory $fixtureFactory
73 $this->catalogCategoryIndex = $catalogCategoryIndex;
74 $this->catalogCategoryEdit = $catalogCategoryEdit;
75 $this->fixtureFactory = $fixtureFactory;
87 Category $childCategory,
88 Category $parentCategory,
92 $parentCategory->persist();
93 $childCategory->persist();
94 $resultCategory = $childCategory;
96 if (!empty($moveLevel)) {
97 for ($nestingIterator = 1; $nestingIterator < $moveLevel; $nestingIterator++) {
98 $childCategory = $childCategory->getDataFieldConfig(
'parent_id')[
'source']->getParentCategory();
100 $resultCategory = $this->
getMovedCategoryTree($resultCategory, $parentCategory, $childCategory);
104 $this->catalogCategoryIndex->open();
105 $this->catalogCategoryIndex->getTreeCategories()->expandAllCategories();
106 $this->catalogCategoryIndex->getTreeCategories()->selectCategory($childCategory);
107 $this->catalogCategoryIndex->getTreeCategories()->assignCategory(
108 $parentCategory->getName(),
109 $childCategory->getName()
111 $this->catalogCategoryEdit->getModalBlock()->dismissWarning();
113 $this->catalogCategoryIndex->getTreeCategories()->assignCategory(
114 $parentCategory->getName(),
115 $childCategory->getName()
117 $this->catalogCategoryEdit->getModalBlock()->acceptWarning();
118 $this->catalogCategoryEdit->getFormPageActions()->save();
121 'category' => $resultCategory,
122 'parentCategory' => $parentCategory,
123 'childCategory' => $childCategory,
135 public function getMovedCategoryTree(Category $movedCategory, Category $parentCategory, Category $childCategory)
137 $bottomChildCategory = [];
138 while ($movedCategory->getName() != $childCategory->getName()) {
139 $bottomChildCategory[] = $movedCategory->getData();
140 $movedCategory = $movedCategory->getDataFieldConfig(
'parent_id')[
'source']->getParentCategory();
142 $bottomChildCategory[] = $movedCategory->getData();
145 for (
$i = count($bottomChildCategory) - 1;
$i >= 0;
$i--) {
146 unset($bottomChildCategory[
$i][
'parent_id']);
150 [
'data' => $bottomChildCategory[
$i]]
__inject(CatalogCategoryIndex $catalogCategoryIndex, CatalogCategoryEdit $catalogCategoryEdit, FixtureFactory $fixtureFactory)
getMovedCategoryTree(Category $movedCategory, Category $parentCategory, Category $childCategory)
test(Category $childCategory, Category $parentCategory, $moveLevel=null)