From 718db32c761750a6282320a7fd325e4c5e3453f0 Mon Sep 17 00:00:00 2001 From: Dragos Protung Date: Wed, 11 Nov 2026 20:20:10 +0100 Subject: [PATCH] Allow EasyAdmin 5.10 --- composer.json | 5 +- .../Controller/AdminControllerWebTestCase.php | 19 ++++++ src/Test/Controller/DetailActionTestCase.php | 5 +- src/Test/Controller/IndexActionTestCase.php | 5 +- .../Test/Controller/CountryExtractionTest.php | 68 +++++++++++++++++++ 5 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 tests/Test/Controller/CountryExtractionTest.php diff --git a/composer.json b/composer.json index fd92739..205ff45 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "require": { "php": "~8.4.0 || ~8.5.0", "doctrine/orm": "^2.20.9 || ^3.5.0", - "easycorp/easyadmin-bundle": "~4.29.16 || ~5.6.1 || ~5.7.0 || ~5.8.0 || ~5.9.0", + "easycorp/easyadmin-bundle": "~4.29.16 || ~5.6.1 || ~5.7.0 || ~5.8.0 || ~5.9.0 || ~5.10.0", "php-standard-library/php-standard-library": "^3.3.0 || ^4.0.0 || ^5.0.0 || ^6.0.0", "symfony/config": "^6.4 || ^7.4 || ^8.0", "symfony/dependency-injection": "^6.4 || ^7.4 || ^8.0", @@ -93,7 +93,8 @@ "policy": { "abandoned": { "ignore": { - "doctrine/cache": "Required by doctrine/orm 2, which is still supported" + "doctrine/cache": "Required by doctrine/orm 2, which is still supported", + "doctrine/common": "Required by doctrine/orm 2, which is still supported" } } }, diff --git a/src/Test/Controller/AdminControllerWebTestCase.php b/src/Test/Controller/AdminControllerWebTestCase.php index e91e339..31ff19e 100644 --- a/src/Test/Controller/AdminControllerWebTestCase.php +++ b/src/Test/Controller/AdminControllerWebTestCase.php @@ -234,6 +234,25 @@ protected function mapFieldsErrors(Crawler $crawler, FormField|array $fields): a ); } + /** + * Extracts the name and the flag of the first country in the value of a country field. + * + * @return array{name: string, flag: string} + */ + protected function extractCountry(Crawler $countryValue): array + { + // Since EasyAdmin 5.10, the name next to the flag has an element of its own. + $name = $countryValue->filter('.country-flag-name'); + if ($name->count() === 0) { + $name = $countryValue->filter('span'); + } + + return [ + 'name' => $name->innerText(), + 'flag' => $countryValue->filter('span svg.country-flag title')->innerText(), + ]; + } + /** * @return array> */ diff --git a/src/Test/Controller/DetailActionTestCase.php b/src/Test/Controller/DetailActionTestCase.php index b25846a..a53fb19 100644 --- a/src/Test/Controller/DetailActionTestCase.php +++ b/src/Test/Controller/DetailActionTestCase.php @@ -194,10 +194,7 @@ protected function extractField(Crawler $field): array protected function extractFieldValue(Crawler $field): string|array { if ($field->matches('.field-country')) { - return [ - 'name' => $field->filter('div.field-value span')->innerText(), - 'flag' => $field->filter('div.field-value span svg.country-flag title')->innerText(), - ]; + return $this->extractCountry($field->filter('div.field-value')); } return $field->filter('div.field-value')->text(normalizeWhitespace: true); diff --git a/src/Test/Controller/IndexActionTestCase.php b/src/Test/Controller/IndexActionTestCase.php index 742db3f..60962ed 100644 --- a/src/Test/Controller/IndexActionTestCase.php +++ b/src/Test/Controller/IndexActionTestCase.php @@ -143,10 +143,7 @@ protected function extractDataFromCell(Crawler $cell): array|string|bool } if ($cell->matches('.field-country')) { - return [ - 'name' => $cell->filter('span')->innerText(), - 'flag' => $cell->filter('span svg.country-flag title')->innerText(), - ]; + return $this->extractCountry($cell); } return $this->extractDataFromElement($cell); diff --git a/tests/Test/Controller/CountryExtractionTest.php b/tests/Test/Controller/CountryExtractionTest.php new file mode 100644 index 0000000..6014c57 --- /dev/null +++ b/tests/Test/Controller/CountryExtractionTest.php @@ -0,0 +1,68 @@ + + */ +#[CoversClass(AdminControllerWebTestCase::class)] +final class CountryExtractionTest extends CustomActionTestCase +{ + private const string FLAG = 'Japan'; + + #[Override] + protected function controllerUnderTest(): string + { + return ReportCrudController::class; + } + + #[Override] + protected function actionName(): string + { + return 'download'; + } + + #[Override] + protected function entityIdUnderTest(): int + { + return 1; + } + + /** + * @return Generator + */ + public static function dataProviderTestExtractCountry(): Generator + { + yield 'before-easyadmin-5.10' => [ + '' . self::FLAG . 'Japan', + ]; + + yield 'since-easyadmin-5.10' => [ + '' . self::FLAG + . 'Japan', + ]; + } + + #[DataProvider('dataProviderTestExtractCountry')] + public function testExtractCountry(string $flagHtml): void + { + $countryValue = new Crawler('
' . $flagHtml . '
'); + + self::assertSame( + ['name' => 'Japan', 'flag' => 'Japan'], + $this->extractCountry($countryValue->filter('div.field-value')), + ); + } +}