Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
},
Expand Down
19 changes: 19 additions & 0 deletions src/Test/Controller/AdminControllerWebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, array<mixed>>
*/
Expand Down
5 changes: 1 addition & 4 deletions src/Test/Controller/DetailActionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/Test/Controller/IndexActionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
68 changes: 68 additions & 0 deletions tests/Test/Controller/CountryExtractionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Protung\EasyAdminPlusBundle\Tests\Test\Controller;

use Generator;
use Override;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Protung\EasyAdminPlusBundle\Test\Controller\AdminControllerWebTestCase;
use Protung\EasyAdminPlusBundle\Test\Controller\CustomActionTestCase;
use Protung\EasyAdminPlusBundle\Tests\Test\TestApplication\Controller\ReportCrudController;
use Protung\EasyAdminPlusBundle\Tests\Test\TestApplication\Entity\Report;
use Symfony\Component\DomCrawler\Crawler;

/**
* @template-extends CustomActionTestCase<Report, ReportCrudController>
*/
#[CoversClass(AdminControllerWebTestCase::class)]
final class CountryExtractionTest extends CustomActionTestCase
{
private const string FLAG = '<svg xmlns="http://www.w3.org/2000/svg" class="country-flag" height="17" viewBox="0 0 25 17"><title>Japan</title></svg>';

#[Override]
protected function controllerUnderTest(): string
{
return ReportCrudController::class;
}

#[Override]
protected function actionName(): string
{
return 'download';
}

#[Override]
protected function entityIdUnderTest(): int
{
return 1;
}

/**
* @return Generator<string, array{string}>
*/
public static function dataProviderTestExtractCountry(): Generator
{
yield 'before-easyadmin-5.10' => [
'<span class="country-flag-wrapper country-flag-with-name">' . self::FLAG . 'Japan</span>',
];

yield 'since-easyadmin-5.10' => [
'<span class="country-flag-wrapper country-flag-with-name">' . self::FLAG
. '<span class="country-flag-name" style="margin-inline-start: var(--flag-name-gap, 0.375em)">Japan</span></span>',
];
}

#[DataProvider('dataProviderTestExtractCountry')]
public function testExtractCountry(string $flagHtml): void
{
$countryValue = new Crawler('<div class="field-value">' . $flagHtml . '</div>');

self::assertSame(
['name' => 'Japan', 'flag' => 'Japan'],
$this->extractCountry($countryValue->filter('div.field-value')),
);
}
}
Loading