Skip to content

Commit

Permalink
Adapt integration tests to use locale indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Dec 16, 2024
1 parent e37f6c7 commit 9808ef6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 60 deletions.
14 changes: 7 additions & 7 deletions tests/Integration/ApiPlatform/CustomerGroupApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testAddCustomerGroup(): int
'auth_bearer' => $bearerToken,
'json' => [
'localizedNames' => [
1 => 'test1',
'en-US' => 'test1',
],
'reductionPercent' => 10.3,
'displayPriceTaxExcluded' => true,
Expand All @@ -92,7 +92,7 @@ public function testAddCustomerGroup(): int
[
'customerGroupId' => $customerGroupId,
'localizedNames' => [
1 => 'test1',
'en-US' => 'test1',
],
'reductionPercent' => 10.3,
'displayPriceTaxExcluded' => true,
Expand All @@ -114,7 +114,7 @@ public function testAddCustomerGroupWithoutShopIds(): int
'auth_bearer' => $bearerToken,
'json' => [
'localizedNames' => [
1 => 'test1',
'en-US' => 'test1',
],
'reductionPercent' => 10.3,
'displayPriceTaxExcluded' => true,
Expand All @@ -132,7 +132,7 @@ public function testAddCustomerGroupWithoutShopIds(): int
[
'customerGroupId' => $customerGroupId,
'localizedNames' => [
1 => 'test1',
'en-US' => 'test1',
],
'reductionPercent' => 10.3,
'displayPriceTaxExcluded' => true,
Expand Down Expand Up @@ -162,7 +162,7 @@ public function testUpdateCustomerGroup(int $customerGroupId): int
'auth_bearer' => $bearerToken,
'json' => [
'localizedNames' => [
1 => 'new_test1',
'en-US' => 'new_test1',
],
'displayPriceTaxExcluded' => false,
'shopIds' => [1],
Expand All @@ -179,7 +179,7 @@ public function testUpdateCustomerGroup(int $customerGroupId): int
[
'customerGroupId' => $customerGroupId,
'localizedNames' => [
1 => 'new_test1',
'en-US' => 'new_test1',
],
'reductionPercent' => 10.3,
'displayPriceTaxExcluded' => false,
Expand Down Expand Up @@ -214,7 +214,7 @@ public function testGetCustomerGroup(int $customerGroupId): int
[
'customerGroupId' => $customerGroupId,
'localizedNames' => [
1 => 'new_test1',
'en-US' => 'new_test1',
],
'reductionPercent' => 10.3,
'displayPriceTaxExcluded' => false,
Expand Down
79 changes: 38 additions & 41 deletions tests/Integration/ApiPlatform/ProductEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@

class ProductEndpointTest extends ApiTestCase
{
protected const EN_LANG_ID = 1;
protected static int $frenchLangId;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
(new ResourceResetter())->backupTestModules();
ProductResetter::resetProducts();
LanguageResetter::resetLanguages();
self::$frenchLangId = self::addLanguageByLocale('fr-FR');
self::addLanguageByLocale('fr-FR');
self::createApiClient(['product_write', 'product_read']);
}

Expand Down Expand Up @@ -110,8 +107,8 @@ public function testAddProduct(): int
'json' => [
'type' => ProductType::TYPE_STANDARD,
'names' => [
self::EN_LANG_ID => 'product name',
self::$frenchLangId => 'nom produit',
'en-US' => 'product name',
'fr-FR' => 'nom produit',
],
],
]);
Expand All @@ -128,12 +125,12 @@ public function testAddProduct(): int
'type' => ProductType::TYPE_STANDARD,
'productId' => $productId,
'names' => [
self::EN_LANG_ID => 'product name',
self::$frenchLangId => 'nom produit',
'en-US' => 'product name',
'fr-FR' => 'nom produit',
],
'descriptions' => [
self::EN_LANG_ID => '',
self::$frenchLangId => '',
'en-US' => '',
'fr-FR' => '',
],
'active' => false,
],
Expand Down Expand Up @@ -163,10 +160,10 @@ public function testPartialUpdateProduct(int $productId): int
],
'json' => [
'names' => [
self::$frenchLangId => 'nouveau nom',
'fr-FR' => 'nouveau nom',
],
'descriptions' => [
self::EN_LANG_ID => 'new description',
'en-US' => 'new description',
],
'active' => true,
],
Expand All @@ -183,12 +180,12 @@ public function testPartialUpdateProduct(int $productId): int
'type' => ProductType::TYPE_STANDARD,
'productId' => $productId,
'names' => [
self::EN_LANG_ID => 'product name',
self::$frenchLangId => 'nouveau nom',
'en-US' => 'product name',
'fr-FR' => 'nouveau nom',
],
'descriptions' => [
self::EN_LANG_ID => 'new description',
self::$frenchLangId => '',
'en-US' => 'new description',
'fr-FR' => '',
],
'active' => true,
],
Expand All @@ -203,7 +200,7 @@ public function testPartialUpdateProduct(int $productId): int
],
'json' => [
'names' => [
self::EN_LANG_ID => 'new product name',
'en-US' => 'new product name',
],
],
]);
Expand All @@ -216,12 +213,12 @@ public function testPartialUpdateProduct(int $productId): int
'type' => ProductType::TYPE_STANDARD,
'productId' => $productId,
'names' => [
self::EN_LANG_ID => 'new product name',
self::$frenchLangId => 'nouveau nom',
'en-US' => 'new product name',
'fr-FR' => 'nouveau nom',
],
'descriptions' => [
self::EN_LANG_ID => 'new description',
self::$frenchLangId => '',
'en-US' => 'new description',
'fr-FR' => '',
],
'active' => true,
],
Expand Down Expand Up @@ -252,12 +249,12 @@ public function testGetProduct(int $productId): int
'type' => ProductType::TYPE_STANDARD,
'productId' => $productId,
'names' => [
self::EN_LANG_ID => 'new product name',
self::$frenchLangId => 'nouveau nom',
'en-US' => 'new product name',
'fr-FR' => 'nouveau nom',
],
'descriptions' => [
self::EN_LANG_ID => 'new description',
self::$frenchLangId => '',
'en-US' => 'new description',
'fr-FR' => '',
],
'active' => true,
],
Expand Down Expand Up @@ -302,8 +299,8 @@ public function testAddImage(int $productId): int
$this->assertMatchesRegularExpression('@/img/p[/0-9]+/' . $imageId . '-small_default\.jpg@', $decodedResponse['thumbnailUrl']);
$this->assertArrayHasKey('legends', $decodedResponse);
$this->assertEquals([
self::EN_LANG_ID => '',
self::$frenchLangId => '',
'en-US' => '',
'fr-FR' => '',
], $decodedResponse['legends']);
$this->assertArrayHasKey('cover', $decodedResponse);
$this->assertIsBool($decodedResponse['cover']);
Expand Down Expand Up @@ -337,8 +334,8 @@ public function testGetImage(int $imageId): string
$this->assertMatchesRegularExpression('@/img/p[/0-9]+/' . $imageId . '-small_default\.jpg@', $decodedResponse['thumbnailUrl']);
$this->assertArrayHasKey('legends', $decodedResponse);
$this->assertEquals([
self::EN_LANG_ID => '',
self::$frenchLangId => '',
'en-US' => '',
'fr-FR' => '',
], $decodedResponse['legends']);
$this->assertArrayHasKey('cover', $decodedResponse);
$this->assertIsBool($decodedResponse['cover']);
Expand Down Expand Up @@ -369,8 +366,8 @@ public function testUpdateImage(int $imageId, string $imageMD5): int
'extra' => [
'parameters' => [
'legends' => [
self::EN_LANG_ID => 'legend en',
self::$frenchLangId => 'legend fr',
'en-US' => 'legend en',
'fr-FR' => 'legend fr',
],
],
'files' => [
Expand All @@ -392,8 +389,8 @@ public function testUpdateImage(int $imageId, string $imageMD5): int
$this->assertMatchesRegularExpression('@/img/p[/0-9]+/' . $imageId . '-small_default\.jpg@', $decodedResponse['thumbnailUrl']);
$this->assertArrayHasKey('legends', $decodedResponse);
$this->assertEquals([
self::EN_LANG_ID => 'legend en',
self::$frenchLangId => 'legend fr',
'en-US' => 'legend en',
'fr-FR' => 'legend fr',
], $decodedResponse['legends']);
$this->assertArrayHasKey('cover', $decodedResponse);
$this->assertIsBool($decodedResponse['cover']);
Expand Down Expand Up @@ -443,8 +440,8 @@ public function testListImages(int $productId, int $imageId): void
'imageUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($imageId, false),
'thumbnailUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($imageId, true),
'legends' => [
self::EN_LANG_ID => 'legend en',
self::$frenchLangId => 'legend fr',
'en-US' => 'legend en',
'fr-FR' => 'legend fr',
],
'cover' => true,
'position' => 1,
Expand All @@ -457,8 +454,8 @@ public function testListImages(int $productId, int $imageId): void
'imageUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($newImageId, false),
'thumbnailUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($newImageId, true),
'legends' => [
self::EN_LANG_ID => '',
self::$frenchLangId => '',
'en-US' => '',
'fr-FR' => '',
],
'cover' => false,
'position' => 2,
Expand Down Expand Up @@ -496,8 +493,8 @@ public function testListImages(int $productId, int $imageId): void
'imageUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($newImageId, false),
'thumbnailUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($newImageId, true),
'legends' => [
self::EN_LANG_ID => '',
self::$frenchLangId => '',
'en-US' => '',
'fr-FR' => '',
],
'cover' => true,
'position' => 1,
Expand All @@ -510,8 +507,8 @@ public function testListImages(int $productId, int $imageId): void
'imageUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($imageId, false),
'thumbnailUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($imageId, true),
'legends' => [
self::EN_LANG_ID => 'legend en',
self::$frenchLangId => 'legend fr',
'en-US' => 'legend en',
'fr-FR' => 'legend fr',
],
'cover' => false,
'position' => 2,
Expand Down
21 changes: 9 additions & 12 deletions tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@

class ProductMultiShopEndpointTest extends ApiTestCase
{
protected const EN_LANG_ID = 1;
protected static int $frenchLangId;

protected const DEFAULT_SHOP_GROUP_ID = 1;
protected static int $secondShopGroupId;

Expand All @@ -58,7 +55,7 @@ public static function setUpBeforeClass(): void
ShopResetter::resetShops();
ConfigurationResetter::resetConfiguration();

self::$frenchLangId = self::addLanguageByLocale('fr-FR');
self::addLanguageByLocale('fr-FR');

self::updateConfiguration(MultistoreConfig::FEATURE_STATUS, 1);
// Disable secure protection for the tests (the configuration reset forced the default config back)
Expand All @@ -72,12 +69,12 @@ public static function setUpBeforeClass(): void
self::$defaultProductData = [
'type' => ProductType::TYPE_STANDARD,
'names' => [
self::EN_LANG_ID => 'product name',
self::$frenchLangId => 'nom produit',
'en-US' => 'product name',
'fr-FR' => 'nom produit',
],
'descriptions' => [
self::EN_LANG_ID => '',
self::$frenchLangId => '',
'en-US' => '',
'fr-FR' => '',
],
'active' => false,
];
Expand Down Expand Up @@ -114,8 +111,8 @@ public function testShopContextIsRequired(): void
'json' => [
'type' => ProductType::TYPE_STANDARD,
'names' => [
self::EN_LANG_ID => 'product name',
self::$frenchLangId => 'nom produit',
'en-US' => 'product name',
'fr-FR' => 'nom produit',
],
],
]);
Expand All @@ -132,8 +129,8 @@ public function testCreateProductForFirstShop(): int
'json' => [
'type' => ProductType::TYPE_STANDARD,
'names' => [
self::EN_LANG_ID => 'product name',
self::$frenchLangId => 'nom produit',
'en-US' => 'product name',
'fr-FR' => 'nom produit',
],
],
'extra' => [
Expand Down

0 comments on commit 9808ef6

Please sign in to comment.