Skip to content

Commit

Permalink
ENGCOM-7112: FIX #14080 Added improvements to Category repository (sa…
Browse files Browse the repository at this point in the history
…ve method) #27304
  • Loading branch information
slavvka authored Mar 20, 2020
2 parents dda8385 + 92a4477 commit 4b9960c
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/Model/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
$parentCategory = $this->get($parentId, $storeId);
$existingData['path'] = $parentCategory->getPath();
$existingData['parent_id'] = $parentId;
$existingData['level'] = null;
}
$category->addData($existingData);
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminAssertParentChildCategoryTreeElementsActionGroup">
<annotations>
<description>Checks category tree, parent category has child category element.</description>
</annotations>
<arguments>
<argument name="parentCategoryName" type="string" defaultValue="parent"/>
<argument name="childCategoryName" type="string" defaultValue="child"/>
</arguments>

<seeElement selector="{{AdminCategorySidebarTreeSection.childCategoryUnderParent(parentCategoryName, childCategoryName)}}" stepKey="seeSubcategoryIsUnderParent"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminExpandCategoryTreeActionGroup">
<annotations>
<description>Expands category tree.</description>
</annotations>

<click selector="{{AdminCategorySidebarTreeSection.expandAll}}" stepKey="clickOnExpandTree"/>
<waitForPageLoad stepKey="waitForCategoryToLoad"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminOpenCategoryPageActionGroup">
<annotations>
<description>Navigates to category page.</description>
</annotations>

<amOnPage url="{{AdminCategoryPage.url}}" stepKey="openAdminCategoryIndexPage"/>
<waitForPageLoad stepKey="waitForCategoryPageToLoad"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AssertAdminCategoryLevelByParentCategoryLevelActionGroup">
<annotations>
<description>Checks category level by parent category level.</description>
</annotations>
<arguments>
<argument name="parentCategoryLevel" type="string" defaultValue="2"/>
<argument name="categoryLevel" type="string" defaultValue="3"/>
</arguments>

<assertEquals expected="{{parentCategoryLevel}} + 1" actual="{{categoryLevel}}" message="wrongCategoryLevel" stepKey="compareCategoryLevel"/>
</actionGroup>
</actionGroups>
6 changes: 6 additions & 0 deletions app/code/Magento/Catalog/Test/Mftf/Data/CategoryData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,10 @@
<data key="include_in_menu">true</data>
<var key="parent_id" entityType="category" entityKey="id"/>
</entity>
<entity name="ApiSubCategoryWithLevelZero" type="category">
<data key="name" unique="suffix">cat with level 1</data>
<data key="is_active">true</data>
<data key="level">0</data>
<var key="parent_id" entityType="category" entityKey="id"/>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<element name="categoryTreeRoot" type="text" selector="div.x-tree-root-node>li.x-tree-node:first-of-type>div.x-tree-node-el:first-of-type" timeout="30"/>
<element name="categoryInTree" type="text" selector="//a/span[contains(text(), '{{name}}')]" parameterized="true" timeout="30"/>
<element name="categoryInTreeUnderRoot" type="text" selector="//li/ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{name}}')]" parameterized="true"/>
<element name="childCategoryUnderParent" type="text" selector="//li/ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{parentCategoryName}}')]/../../../ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{childCategoryName}}')]" parameterized="true"/>
<element name="lastCreatedCategory" type="block" selector=".x-tree-root-ct li li:last-child" />
<element name="treeContainer" type="block" selector=".tree-holder" />
<element name="expandRootCategory" type="text" selector="img.x-tree-elbow-end-plus"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCheckNewCategoryLevelAddedViaApiTest">
<annotations>
<stories value="Add parent and child categories via API"/>
<title value="Add parent and child categories via API"/>
<description value="Login as admin, create parent and child categories via API.
Check category level for child category entity based on parent level.
Check category tree: parent element has child element. "/>
<group value="catalog"/>
</annotations>
<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminPanel"/>
<createData entity="ApiCategoryWithChildren" stepKey="createCategoryWithChildrenBlank"/>
<createData entity="ApiSubCategoryWithLevelZero" stepKey="createSubCategoryWithLevelZero">
<requiredEntity createDataKey="createCategoryWithChildrenBlank"/>
</createData>
</before>
<after>
<deleteData createDataKey="createCategoryWithChildrenBlank" stepKey="deleteCategoryWithChildrenBlank"/>
<actionGroup ref="logout" stepKey="logout"/>
</after>

<actionGroup ref="AssertAdminCategoryLevelByParentCategoryLevelActionGroup" stepKey="assertCategoryLevelByParentCategory">
<argument name="parentCategoryLevel" value="$createCategoryWithChildrenBlank.level$"/>
<argument name="categoryLevel" value="$createSubCategoryWithLevelZero.level$"/>
</actionGroup>

<actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="openCategoryPage"/>
<actionGroup ref="AdminExpandCategoryTreeActionGroup" stepKey="expandCategoryTree"/>
<actionGroup ref="AdminAssertParentChildCategoryTreeElementsActionGroup" stepKey="assertParentChildCategoryTreeElements">
<argument name="parentCategoryName" value="$createCategoryWithChildrenBlank.name$"/>
<argument name="childCategoryName" value="$createSubCategoryWithLevelZero.name$"/>
</actionGroup>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function testCreateNewCategory()
$parentCategoryId = 15;
$newCategoryId = 25;
$categoryData = ['level' => '1', 'path' => '1/2', 'parent_id' => 1, 'name' => 'category'];
$dataForSave = ['store_id' => 1, 'name' => 'category', 'path' => 'path', 'parent_id' => 15];
$dataForSave = ['store_id' => 1, 'name' => 'category', 'path' => 'path', 'parent_id' => 15, 'level' => null];
$this->extensibleDataObjectConverterMock
->expects($this->once())
->method('toNestedArray')
Expand Down

0 comments on commit 4b9960c

Please sign in to comment.