Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions tests/Integration/ApiPlatform/AttributeGroupEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@

class AttributeGroupEndpointTest extends ApiTestCase
{
/**
* 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
*
* @return array<string, int>
*/
private function expectedPosition(int $position): array
{
return self::isVersionAtLeast('9.3.0') ? ['position' => $position] : [];
}

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
Expand Down Expand Up @@ -113,7 +126,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
);

Expand Down Expand Up @@ -145,7 +158,7 @@ public function testGetAttributeGroup(int $attributeGroupId): int
],
'type' => 'select',
'shopIds' => [1],
], $attributeGroup);
] + $this->expectedPosition(4), $attributeGroup);

return $attributeGroupId;
}
Expand Down Expand Up @@ -173,11 +186,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 = [
Expand All @@ -200,7 +213,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);

Expand Down