From e3f35aa7251729746083a03c655297c39fab7fc1 Mon Sep 17 00:00:00 2001 From: Audrius Date: Fri, 26 Jun 2026 10:09:24 +0200 Subject: [PATCH 1/2] Expect the position field in AttributeGroup endpoint responses The GET/POST/PATCH AttributeGroup responses now include the group position (PrestaShop/PrestaShop#39729, fixed core-side in PrestaShop/PrestaShop#41844). Update the endpoint test expectations accordingly. --- .../AttributeGroupEndpointTest.php | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php b/tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php index 6357ebb1f..79dfb57c5 100644 --- a/tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php +++ b/tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php @@ -20,11 +20,27 @@ namespace PsApiResourcesTest\Integration\ApiPlatform; +use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\QueryResult\EditableAttributeGroup; use Symfony\Component\HttpFoundation\Response; use Tests\Resources\DatabaseDump; class AttributeGroupEndpointTest extends ApiTestCase { + /** + * The single-item endpoints only carry the group position once the core CQRS result exposes it + * (PrestaShop/PrestaShop#41844). Cores without it answer the same payload minus that key, so the + * expectation adapts rather than pinning these tests to one core version. The list endpoints are + * unaffected: they read the position from the grid query. + * + * @param int $position + * + * @return array + */ + private function expectedPosition(int $position): array + { + return method_exists(EditableAttributeGroup::class, 'getPosition') ? ['position' => $position] : []; + } + public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -113,7 +129,7 @@ public function testAddAttributeGroup(): int // We assert the returned data matches what was posted (plus the ID) $this->assertEquals( - ['attributeGroupId' => $attributeGroupId] + $postData, + ['attributeGroupId' => $attributeGroupId] + $this->expectedPosition($itemsCount) + $postData, $attributeGroup ); @@ -145,7 +161,7 @@ public function testGetAttributeGroup(int $attributeGroupId): int ], 'type' => 'select', 'shopIds' => [1], - ], $attributeGroup); + ] + $this->expectedPosition(4), $attributeGroup); return $attributeGroupId; } @@ -173,11 +189,11 @@ public function testPartialUpdateAttributeGroup(int $attributeGroupId): int ]; $updatedAttributeGroup = $this->partialUpdateItem('/attributes/groups/' . $attributeGroupId, $patchData, ['attribute_group_write']); - $this->assertEquals(['attributeGroupId' => $attributeGroupId] + $patchData, $updatedAttributeGroup); + $this->assertEquals(['attributeGroupId' => $attributeGroupId] + $this->expectedPosition(4) + $patchData, $updatedAttributeGroup); // We check that when we GET the item it is updated as expected $attributeGroup = $this->getItem('/attributes/groups/' . $attributeGroupId, ['attribute_group_read']); - $this->assertEquals(['attributeGroupId' => $attributeGroupId] + $patchData, $attributeGroup); + $this->assertEquals(['attributeGroupId' => $attributeGroupId] + $this->expectedPosition(4) + $patchData, $attributeGroup); // Test partial update $partialUpdateData = [ @@ -200,7 +216,7 @@ public function testPartialUpdateAttributeGroup(int $attributeGroupId): int ], 'type' => 'radio', 'shopIds' => [1], - ]; + ] + $this->expectedPosition(4); $updatedAttributeGroup = $this->partialUpdateItem('/attributes/groups/' . $attributeGroupId, $partialUpdateData, ['attribute_group_write']); $this->assertEquals($expectedUpdatedData, $updatedAttributeGroup); From 786779badb3a4e0f0fbb51162dfc4cf4efed730e Mon Sep 17 00:00:00 2001 From: boo-code Date: Thu, 29 Oct 2026 19:08:35 +0100 Subject: [PATCH 2/2] Gate the position expectation on the core version instead of the class shape --- .../ApiPlatform/AttributeGroupEndpointTest.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php b/tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php index 79dfb57c5..216af5a76 100644 --- a/tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php +++ b/tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php @@ -20,17 +20,14 @@ namespace PsApiResourcesTest\Integration\ApiPlatform; -use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\QueryResult\EditableAttributeGroup; use Symfony\Component\HttpFoundation\Response; use Tests\Resources\DatabaseDump; class AttributeGroupEndpointTest extends ApiTestCase { /** - * The single-item endpoints only carry the group position once the core CQRS result exposes it - * (PrestaShop/PrestaShop#41844). Cores without it answer the same payload minus that key, so the - * expectation adapts rather than pinning these tests to one core version. The list endpoints are - * unaffected: they read the position from the grid query. + * The single-item endpoints carry the group position from PrestaShop 9.3.0, whose CQRS result exposes + * it (PrestaShop/PrestaShop#41844). The list endpoints are unaffected: they read it from the grid query. * * @param int $position * @@ -38,7 +35,7 @@ class AttributeGroupEndpointTest extends ApiTestCase */ private function expectedPosition(int $position): array { - return method_exists(EditableAttributeGroup::class, 'getPosition') ? ['position' => $position] : []; + return self::isVersionAtLeast('9.3.0') ? ['position' => $position] : []; } public static function setUpBeforeClass(): void