|
5 | 5 | */
|
6 | 6 | namespace Magento\Catalog\Api;
|
7 | 7 |
|
| 8 | +use Magento\Eav\Api\Data\AttributeSetInterface; |
8 | 9 | use Magento\TestFramework\TestCase\WebapiAbstract;
|
9 | 10 |
|
10 | 11 | class AttributeSetRepositoryTest extends WebapiAbstract
|
@@ -71,38 +72,39 @@ public function testSave()
|
71 | 72 | {
|
72 | 73 | $attributeSetName = 'empty_attribute_set';
|
73 | 74 | $attributeSet = $this->getAttributeSetByName($attributeSetName);
|
74 |
| - $serviceInfo = [ |
75 |
| - 'rest' => [ |
76 |
| - 'resourcePath' => '/V1/products/attribute-sets/' . $attributeSet->getId(), |
77 |
| - 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, |
78 |
| - ], |
79 |
| - 'soap' => [ |
80 |
| - 'service' => 'catalogAttributeSetRepositoryV1', |
81 |
| - 'serviceVersion' => 'V1', |
82 |
| - 'operation' => 'catalogAttributeSetRepositoryV1Save', |
| 75 | + $updatedSortOrder = $attributeSet->getSortOrder() + 200; |
| 76 | + $arguments = [ |
| 77 | + 'attributeSet' => [ |
| 78 | + 'attribute_set_id' => $attributeSet->getId(), |
| 79 | + // name is the same, because it is used by fixture rollback script |
| 80 | + 'attribute_set_name' => $attributeSet->getAttributeSetName(), |
| 81 | + 'entity_type_id' => $attributeSet->getEntityTypeId(), |
| 82 | + 'sort_order' => $updatedSortOrder, |
83 | 83 | ],
|
84 | 84 | ];
|
| 85 | + $result = $this->save($attributeSet, $arguments); |
| 86 | + $this->assertAttributeSetData($result, $attributeSetName, $updatedSortOrder); |
| 87 | + } |
85 | 88 |
|
| 89 | + /** |
| 90 | + * Test update attribute set without specified optional "entity_type_id" param. |
| 91 | + * |
| 92 | + * @magentoApiDataFixture Magento/Eav/_files/empty_attribute_set.php |
| 93 | + */ |
| 94 | + public function testUpdateWithoutEntityType() |
| 95 | + { |
| 96 | + $attributeSetName = 'empty_attribute_set'; |
| 97 | + $attributeSet = $this->getAttributeSetByName('empty_attribute_set'); |
86 | 98 | $updatedSortOrder = $attributeSet->getSortOrder() + 200;
|
87 |
| - |
88 | 99 | $arguments = [
|
89 | 100 | 'attributeSet' => [
|
90 | 101 | 'attribute_set_id' => $attributeSet->getId(),
|
91 |
| - // name is the same, because it is used by fixture rollback script |
92 | 102 | 'attribute_set_name' => $attributeSet->getAttributeSetName(),
|
93 |
| - 'entity_type_id' => $attributeSet->getEntityTypeId(), |
94 | 103 | 'sort_order' => $updatedSortOrder,
|
95 | 104 | ],
|
96 | 105 | ];
|
97 |
| - $result = $this->_webApiCall($serviceInfo, $arguments); |
98 |
| - $this->assertNotNull($result); |
99 |
| - // Reload attribute set data |
100 |
| - $attributeSet = $this->getAttributeSetByName($attributeSetName); |
101 |
| - $this->assertEquals($attributeSet->getAttributeSetId(), $result['attribute_set_id']); |
102 |
| - $this->assertEquals($attributeSet->getAttributeSetName(), $result['attribute_set_name']); |
103 |
| - $this->assertEquals($attributeSet->getEntityTypeId(), $result['entity_type_id']); |
104 |
| - $this->assertEquals($updatedSortOrder, $result['sort_order']); |
105 |
| - $this->assertEquals($attributeSet->getSortOrder(), $result['sort_order']); |
| 106 | + $result = $this->save($attributeSet, $arguments); |
| 107 | + $this->assertAttributeSetData($result, $attributeSetName, $updatedSortOrder); |
106 | 108 | }
|
107 | 109 |
|
108 | 110 | /**
|
@@ -215,4 +217,50 @@ protected function getAttributeSetByName($attributeSetName)
|
215 | 217 | }
|
216 | 218 | return $attributeSet;
|
217 | 219 | }
|
| 220 | + |
| 221 | + /** |
| 222 | + * Save given attribute set with specified arguments. |
| 223 | + * |
| 224 | + * @param AttributeSetInterface $attributeSet |
| 225 | + * @param array $arguments |
| 226 | + * @return array |
| 227 | + */ |
| 228 | + private function save(AttributeSetInterface $attributeSet, array $arguments) |
| 229 | + { |
| 230 | + $serviceInfo = [ |
| 231 | + 'rest' => [ |
| 232 | + 'resourcePath' => '/V1/products/attribute-sets/' . $attributeSet->getAttributeSetId(), |
| 233 | + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, |
| 234 | + ], |
| 235 | + 'soap' => [ |
| 236 | + 'service' => 'catalogAttributeSetRepositoryV1', |
| 237 | + 'serviceVersion' => 'V1', |
| 238 | + 'operation' => 'catalogAttributeSetRepositoryV1Save', |
| 239 | + ], |
| 240 | + ]; |
| 241 | + |
| 242 | + return $this->_webApiCall($serviceInfo, $arguments); |
| 243 | + } |
| 244 | + |
| 245 | + /** |
| 246 | + * Check attribute set data. |
| 247 | + * |
| 248 | + * @param string $attributeSetName |
| 249 | + * @param array $result |
| 250 | + * @param int $updatedSortOrder |
| 251 | + */ |
| 252 | + private function assertAttributeSetData( |
| 253 | + array $result, |
| 254 | + string $attributeSetName, |
| 255 | + int $updatedSortOrder |
| 256 | + ) { |
| 257 | + $this->assertNotNull($result); |
| 258 | + // Reload attribute set data |
| 259 | + $attributeSet = $this->getAttributeSetByName($attributeSetName); |
| 260 | + $this->assertEquals($attributeSet->getAttributeSetId(), $result['attribute_set_id']); |
| 261 | + $this->assertEquals($attributeSet->getAttributeSetName(), $result['attribute_set_name']); |
| 262 | + $this->assertEquals($attributeSet->getEntityTypeId(), $result['entity_type_id']); |
| 263 | + $this->assertEquals($updatedSortOrder, $result['sort_order']); |
| 264 | + $this->assertEquals($attributeSet->getSortOrder(), $result['sort_order']); |
| 265 | + } |
218 | 266 | }
|
0 commit comments