From 78ea6372c8ecafbdf22b7b65cf3c89cd3d57791f Mon Sep 17 00:00:00 2001 From: Jean Valverde <28034-mogtofu33@users.noreply.drupalcode.org> Date: Sun, 9 Feb 2025 13:32:25 +0000 Subject: [PATCH 1/7] Issue #3504272 by mogtofu33, goz: IconFinder does not generate proper url with base_path() --- core/lib/Drupal/Core/Theme/Icon/IconFinder.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Theme/Icon/IconFinder.php b/core/lib/Drupal/Core/Theme/Icon/IconFinder.php index 045e31a67cb2..fe8bd95fb5b1 100644 --- a/core/lib/Drupal/Core/Theme/Icon/IconFinder.php +++ b/core/lib/Drupal/Core/Theme/Icon/IconFinder.php @@ -305,10 +305,14 @@ private function processFoundFiles(Finder $finder, string $source, string $path_ $icon_id = self::extractIconIdFromFilename($icon_id, $path_info_filename); } + // Ensure source is relative to the installation for url generation and + // replace base_path() used in generateString() method. + $source = $this->fileUrlGenerator->generateString(str_replace(sprintf('%s/', $this->appRoot), '', $file_absolute_path)); + // Icon ID is used as index to avoid duplicates. $result[$icon_id] = [ 'icon_id' => $icon_id, - 'source' => $this->fileUrlGenerator->generateString(str_replace($this->appRoot, '', $file_absolute_path)), + 'source' => $source, 'absolute_path' => $file_absolute_path, 'group' => self::extractGroupFromPath($file->getPath(), $group_position), ]; -- GitLab From 14287c8c302774ae61bbed6a13f108536a50bdba Mon Sep 17 00:00:00 2001 From: Jean Valverde <moimog33@gmail.com> Date: Mon, 10 Feb 2025 14:03:01 +0000 Subject: [PATCH 2/7] Issue #3504272 by mogtofu33, goz: IconFinder does not generate proper url with base_path() --- .../lib/Drupal/Core/Theme/Icon/IconFinder.php | 10 +- .../modules/icon_test/icon_test.icons.yml | 8 + .../Core/Theme/Icon/IconFinderKernelTest.php | 144 ++++++++++++++++++ .../Theme/Icon/IconPackManagerKernelTest.php | 4 +- .../Tests/Core/Theme/Icon/IconFinderTest.php | 26 +++- 5 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php diff --git a/core/lib/Drupal/Core/Theme/Icon/IconFinder.php b/core/lib/Drupal/Core/Theme/Icon/IconFinder.php index fe8bd95fb5b1..868be469ccf4 100644 --- a/core/lib/Drupal/Core/Theme/Icon/IconFinder.php +++ b/core/lib/Drupal/Core/Theme/Icon/IconFinder.php @@ -297,7 +297,9 @@ private function processFoundFiles(Finder $finder, string $source, string $path_ $has_icon_pattern = \str_contains($path_info_filename, self::ICON_ID_PATTERN); foreach ($finder as $file) { + /** @var SplFileInfo $file */ $file_absolute_path = $file->getPathName(); + /** @var \Symfony\Component\Finder\SplFileInfo $file */ $icon_id = $file->getFilenameWithoutExtension(); // If an {icon_id} pattern is used, extract it to be used. @@ -305,9 +307,11 @@ private function processFoundFiles(Finder $finder, string $source, string $path_ $icon_id = self::extractIconIdFromFilename($icon_id, $path_info_filename); } - // Ensure source is relative to the installation for url generation and - // replace base_path() used in generateString() method. - $source = $this->fileUrlGenerator->generateString(str_replace(sprintf('%s/', $this->appRoot), '', $file_absolute_path)); + // Url generation with `generateString` method rely on `base_path()` which + // will add a prefix based on $GLOBALS['base_path'], default `/`. + // @todo adapt when https://www.drupal.org/project/drupal/issues/2487055 + $source = str_replace(sprintf('%s%s', $this->appRoot, base_path()), '', $file_absolute_path); + $source = $this->fileUrlGenerator->generateString($source); // Icon ID is used as index to avoid duplicates. $result[$icon_id] = [ diff --git a/core/modules/system/tests/modules/icon_test/icon_test.icons.yml b/core/modules/system/tests/modules/icon_test/icon_test.icons.yml index 8896eb500e39..0e82b63b9927 100644 --- a/core/modules/system/tests/modules/icon_test/icon_test.icons.yml +++ b/core/modules/system/tests/modules/icon_test/icon_test.icons.yml @@ -48,6 +48,14 @@ test_path: title="{{ title }}" > +test_path_relative_root: + extractor: path + config: + sources: + - /core/misc/druplicon.png + template: >- + {{ icon_id }}: <img src="{{ source }}" width="32" height="32"> + test_svg: enabled: true label: Test svg diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php new file mode 100644 index 000000000000..4ca609b36cf7 --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php @@ -0,0 +1,144 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\KernelTests\Core\Theme\Icon; + +use Drupal\Core\Theme\Icon\IconFinder; +use Drupal\Core\Theme\Icon\IconFinderInterface; +use Drupal\KernelTests\KernelTestBase; +use Psr\Log\LoggerInterface; + +/** + * Test icon sources path generated urls. + * + * @group icon + * + * @coversDefaultClass \Drupal\Core\Theme\Icon\IconFinder + */ +class IconFinderKernelTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'system', + ]; + + /** + * The IconFinder instance. + * + * @var \Drupal\Core\Theme\Icon\IconFinderInterface + */ + private IconFinderInterface $iconFinder; + + /** + * The App root instance. + * + * @var string + */ + private string $appRoot; + + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + $fileUrlGenerator = $this->container->get('file_url_generator'); + $this->appRoot = $this->container->getParameter('app.root'); + + $this->iconFinder = new IconFinder( + $fileUrlGenerator, + $this->createMock(LoggerInterface::class), + $this->appRoot, + ); + } + + /** + * Test the IconFinder::_construct method. + */ + public function testConstructor(): void { + $this->assertInstanceOf(IconFinder::class, $this->iconFinder); + } + + /** + * Data provider for ::testGetFilesFromSourcesPath(). + * + * @return \Generator + * The test cases, to minimize test data, result expected is an array with: + * - icon_id: the expected id + * - path: expected path found relative to TEST_ICONS_PATH + * - group: The group name if any + */ + public static function providerGetFilesFromSourcesPath(): iterable { + yield 'path relative to app root' => [ + [ + '/core/misc/druplicon.png', + '/core/misc/feed.svg', + ], + [ + 'druplicon' => [ + 'icon_id' => 'druplicon', + 'source' => '/core/misc/druplicon.png', + 'absolute_path' => '{appRoot}/core/misc/druplicon.png', + 'group' => NULL, + ], + 'feed' => [ + 'icon_id' => 'feed', + 'source' => '/core/misc/feed.svg', + 'absolute_path' => '{appRoot}/core/misc/feed.svg', + 'group' => NULL, + ], + ], + ]; + + yield 'path relative to icon definition' => [ + [ + 'icons/flat/foo.png', + 'icons/flat/bar.svg', + ], + [ + 'foo' => [ + 'icon_id' => 'foo', + 'source' => '/core/modules/system/tests/modules/icon_test/icons/flat/foo.png', + 'absolute_path' => '{appRoot}/core/modules/system/tests/modules/icon_test/icons/flat/foo.png', + 'group' => NULL, + ], + 'bar' => [ + 'icon_id' => 'bar', + 'source' => '/core/modules/system/tests/modules/icon_test/icons/flat/bar.svg', + 'absolute_path' => '{appRoot}/core/modules/system/tests/modules/icon_test/icons/flat/bar.svg', + 'group' => NULL, + ], + ], + 'core/modules/system/tests/modules/icon_test', + ]; + } + + /** + * Test the IconFinder::getFilesFromSources method with paths. + * + * @param array<string> $sources + * The list of remote. + * @param array<string, string> $expected + * The expected result. + * @param string $relative_path + * The relative path to simulate an icon in the module/theme definition. + * + * @dataProvider providerGetFilesFromSourcesPath + */ + public function testGetFilesFromSourcesPath(array $sources, array $expected, string $relativePath = ''): void { + $result = $this->iconFinder->getFilesFromSources( + $sources, + $relativePath, + ); + + foreach ($expected as $key => $value) { + $expected[$key]['absolute_path'] = str_replace('{appRoot}', $this->appRoot, $expected[$key]['absolute_path']); + } + + $this->assertEquals($result, $expected); + } + +} diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconPackManagerKernelTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconPackManagerKernelTest.php index 07c6508cb908..c50e06628061 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconPackManagerKernelTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconPackManagerKernelTest.php @@ -28,7 +28,7 @@ class IconPackManagerKernelTest extends KernelTestBase { */ private const TEST_ICON_FULL_ID = 'test_minimal:foo'; - private const EXPECTED_TOTAL_TEST_ICONS = 30; + private const EXPECTED_TOTAL_TEST_ICONS = 31; /** * {@inheritdoc} @@ -128,6 +128,7 @@ public function testListIconPackOptions(): void { 'test_no_settings' => 'test_no_settings (1)', 'test_settings' => 'Test settings (1)', 'test_url_path' => 'Test url path (2)', + 'test_path_relative_root' => 'test_path_relative_root (1)' ]; $this->assertEquals($expected, $actual); @@ -140,6 +141,7 @@ public function testListIconPackOptions(): void { 'test_no_settings' => 'test_no_settings (1)', 'test_settings' => 'Test settings (1)', 'test_url_path' => 'Test url path (2)', + 'test_path_relative_root' => 'test_path_relative_root (1)' ]; $this->assertEquals($expected, $actual); } diff --git a/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php b/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php index 02139701a812..291e723a2fa5 100644 --- a/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php @@ -18,7 +18,6 @@ class IconFinderTest extends UnitTestCase { private const TEST_ICONS_PATH = 'core/modules/system/tests/modules/icon_test'; - private const TEST_RELATIVE_URL = 'foo/bar'; /** * The file url generator instance. @@ -614,7 +613,7 @@ public function testGetFilesFromSourcesPath(array $sources, array $expected = [] ->expects($this->any()) ->method('generateString') ->willReturnCallback(function ($uri) { - return self::TEST_RELATIVE_URL . $uri; + return base_path() . $uri; }); $result = $this->iconFinder->getFilesFromSources( @@ -630,7 +629,7 @@ public function testGetFilesFromSourcesPath(array $sources, array $expected = [] $group = $expected[$key][2] ?? NULL; $expected_result[$icon_id] = [ 'icon_id' => $icon_id, - 'source' => self::TEST_RELATIVE_URL . '/' . self::TEST_ICONS_PATH . '/' . $filename, + 'source' => base_path() . self::TEST_ICONS_PATH . '/' . $filename, 'absolute_path' => DRUPAL_ROOT . '/' . self::TEST_ICONS_PATH . '/' . $filename, 'group' => $group, ]; @@ -852,3 +851,24 @@ public function testGetFileContents(string $uri, bool $expected): void { } } + +// @todo Remove as part of https://www.example.com/node/2529170. +namespace Drupal\Core\Theme\Icon; + +if (!function_exists('base_path')) { + + function base_path() { + return '/'; + } + +} + +namespace Drupal\Tests\Core\Theme\Icon; + +if (!function_exists('base_path')) { + + function base_path() { + return '/'; + } + +} \ No newline at end of file -- GitLab From e09d093cc4cf257a1e4a89e25da59068b80fb269 Mon Sep 17 00:00:00 2001 From: Jean Valverde <moimog33@gmail.com> Date: Mon, 10 Feb 2025 14:15:43 +0000 Subject: [PATCH 3/7] style: fix some missing comma and return type --- .../KernelTests/Core/Theme/Icon/IconFinderKernelTest.php | 2 +- .../Core/Theme/Icon/IconPackManagerKernelTest.php | 4 ++-- core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php index 4ca609b36cf7..d3be3fd8fbfb 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php @@ -123,7 +123,7 @@ public static function providerGetFilesFromSourcesPath(): iterable { * The list of remote. * @param array<string, string> $expected * The expected result. - * @param string $relative_path + * @param string $relativePath * The relative path to simulate an icon in the module/theme definition. * * @dataProvider providerGetFilesFromSourcesPath diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconPackManagerKernelTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconPackManagerKernelTest.php index c50e06628061..82073b59411b 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconPackManagerKernelTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconPackManagerKernelTest.php @@ -128,7 +128,7 @@ public function testListIconPackOptions(): void { 'test_no_settings' => 'test_no_settings (1)', 'test_settings' => 'Test settings (1)', 'test_url_path' => 'Test url path (2)', - 'test_path_relative_root' => 'test_path_relative_root (1)' + 'test_path_relative_root' => 'test_path_relative_root (1)', ]; $this->assertEquals($expected, $actual); @@ -141,7 +141,7 @@ public function testListIconPackOptions(): void { 'test_no_settings' => 'test_no_settings (1)', 'test_settings' => 'Test settings (1)', 'test_url_path' => 'Test url path (2)', - 'test_path_relative_root' => 'test_path_relative_root (1)' + 'test_path_relative_root' => 'test_path_relative_root (1)', ]; $this->assertEquals($expected, $actual); } diff --git a/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php b/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php index 291e723a2fa5..23d29e7664e0 100644 --- a/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php @@ -857,7 +857,7 @@ public function testGetFileContents(string $uri, bool $expected): void { if (!function_exists('base_path')) { - function base_path() { + function base_path(): string { return '/'; } @@ -867,8 +867,8 @@ function base_path() { if (!function_exists('base_path')) { - function base_path() { + function base_path(): string { return '/'; } -} \ No newline at end of file +} -- GitLab From b735d9d993b0aecc7929ef5e163436b3aba43141 Mon Sep 17 00:00:00 2001 From: Jean Valverde <moimog33@gmail.com> Date: Tue, 11 Feb 2025 10:46:15 +0000 Subject: [PATCH 4/7] fix: back to simple remove starting slash, update test --- .../lib/Drupal/Core/Theme/Icon/IconFinder.php | 11 ++- .../Core/Theme/Icon/IconFinderKernelTest.php | 98 +++++++++---------- 2 files changed, 52 insertions(+), 57 deletions(-) diff --git a/core/lib/Drupal/Core/Theme/Icon/IconFinder.php b/core/lib/Drupal/Core/Theme/Icon/IconFinder.php index 868be469ccf4..28a2d6984378 100644 --- a/core/lib/Drupal/Core/Theme/Icon/IconFinder.php +++ b/core/lib/Drupal/Core/Theme/Icon/IconFinder.php @@ -307,11 +307,14 @@ private function processFoundFiles(Finder $finder, string $source, string $path_ $icon_id = self::extractIconIdFromFilename($icon_id, $path_info_filename); } - // Url generation with `generateString` method rely on `base_path()` which + // Source is the url to access the image, based on the absolute path to + // handle icons relative to definition or Drupal root. + $source = str_replace($this->appRoot, '', $file_absolute_path); + // Url generation with `generateString` method rely on `base_path()` that // will add a prefix based on $GLOBALS['base_path'], default `/`. - // @todo adapt when https://www.drupal.org/project/drupal/issues/2487055 - $source = str_replace(sprintf('%s%s', $this->appRoot, base_path()), '', $file_absolute_path); - $source = $this->fileUrlGenerator->generateString($source); + // Remove any left slash to allow to url generation with a custom + // base_path. + $source = $this->fileUrlGenerator->generateString(ltrim($source, '/')); // Icon ID is used as index to avoid duplicates. $result[$icon_id] = [ diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php index d3be3fd8fbfb..6d4cca5031b1 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php @@ -12,6 +12,10 @@ /** * Test icon sources path generated urls. * + * Test using the service fileUrlGenerator for a real generateString(). + * It rely on base_path() that we override here to allow tests with custom + * values. + * * @group icon * * @coversDefaultClass \Drupal\Core\Theme\Icon\IconFinder @@ -45,6 +49,7 @@ class IconFinderKernelTest extends KernelTestBase { protected function setUp(): void { parent::setUp(); + /** @var \Drupal\Core\File\FileUrlGeneratorInterface $fileUrlGenerator */ $fileUrlGenerator = $this->container->get('file_url_generator'); $this->appRoot = $this->container->getParameter('app.root'); @@ -65,54 +70,27 @@ public function testConstructor(): void { /** * Data provider for ::testGetFilesFromSourcesPath(). * - * @return \Generator + * @return array * The test cases, to minimize test data, result expected is an array with: * - icon_id: the expected id - * - path: expected path found relative to TEST_ICONS_PATH - * - group: The group name if any + * - source: the expected source value, without left base path, + * processed through generateString(). */ - public static function providerGetFilesFromSourcesPath(): iterable { - yield 'path relative to app root' => [ - [ - '/core/misc/druplicon.png', - '/core/misc/feed.svg', - ], - [ - 'druplicon' => [ - 'icon_id' => 'druplicon', - 'source' => '/core/misc/druplicon.png', - 'absolute_path' => '{appRoot}/core/misc/druplicon.png', - 'group' => NULL, - ], - 'feed' => [ - 'icon_id' => 'feed', - 'source' => '/core/misc/feed.svg', - 'absolute_path' => '{appRoot}/core/misc/feed.svg', - 'group' => NULL, - ], - ], - ]; - - yield 'path relative to icon definition' => [ - [ - 'icons/flat/foo.png', - 'icons/flat/bar.svg', - ], + public static function providerGetFilesFromSourcesPath(): array { + return [ [ - 'foo' => [ - 'icon_id' => 'foo', - 'source' => '/core/modules/system/tests/modules/icon_test/icons/flat/foo.png', - 'absolute_path' => '{appRoot}/core/modules/system/tests/modules/icon_test/icons/flat/foo.png', - 'group' => NULL, + [ + // Use real icons for better test, but `/core` are not managed by + // icon_test so they could change and make this test fail. + '/core/misc/druplicon.png', + 'icons/flat/foo.png', ], - 'bar' => [ - 'icon_id' => 'bar', - 'source' => '/core/modules/system/tests/modules/icon_test/icons/flat/bar.svg', - 'absolute_path' => '{appRoot}/core/modules/system/tests/modules/icon_test/icons/flat/bar.svg', - 'group' => NULL, + [ + 'druplicon' => 'core/misc/druplicon.png', + 'foo' => 'core/modules/system/tests/modules/icon_test/icons/flat/foo.png', ], - ], - 'core/modules/system/tests/modules/icon_test', + 'core/modules/system/tests/modules/icon_test', + ] ]; } @@ -122,23 +100,37 @@ public static function providerGetFilesFromSourcesPath(): iterable { * @param array<string> $sources * The list of remote. * @param array<string, string> $expected - * The expected result. + * The expected result as icon_id => source. * @param string $relativePath * The relative path to simulate an icon in the module/theme definition. * * @dataProvider providerGetFilesFromSourcesPath */ - public function testGetFilesFromSourcesPath(array $sources, array $expected, string $relativePath = ''): void { - $result = $this->iconFinder->getFilesFromSources( - $sources, - $relativePath, - ); - - foreach ($expected as $key => $value) { - $expected[$key]['absolute_path'] = str_replace('{appRoot}', $this->appRoot, $expected[$key]['absolute_path']); + public function testGetFilesFromSourcesPath(array $sources, array $expected, string $relativePath): void { + $base_path_test = ['/', '/foo/', '/foo/bar/']; + + foreach ($base_path_test as $base_path) { + // @todo Remove or adapt as part of https://www.example.com/node/2529170. + $GLOBALS['base_path'] = $base_path; + + $result = $this->iconFinder->getFilesFromSources( + $sources, + $relativePath, + ); + + // Prepare result array matching processFoundFiles() to minimize test data. + $expected_result = []; + foreach ($expected as $key => $expected_value) { + $expected_result[$key] = [ + 'icon_id' => $key, + 'source' => $base_path . $expected_value, + 'absolute_path' => DRUPAL_ROOT . '/' . $expected_value, + 'group' => NULL, + ]; + } + + $this->assertEquals($result, $expected_result); } - - $this->assertEquals($result, $expected); } } -- GitLab From 8f9691e69845183404112eaf4c11db6e0ebb7727 Mon Sep 17 00:00:00 2001 From: Jean Valverde <moimog33@gmail.com> Date: Tue, 11 Feb 2025 11:06:55 +0000 Subject: [PATCH 5/7] style: fix styling --- .../KernelTests/Core/Theme/Icon/IconFinderKernelTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php index 6d4cca5031b1..350ca73dc772 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php @@ -90,7 +90,7 @@ public static function providerGetFilesFromSourcesPath(): array { 'foo' => 'core/modules/system/tests/modules/icon_test/icons/flat/foo.png', ], 'core/modules/system/tests/modules/icon_test', - ] + ], ]; } @@ -108,7 +108,7 @@ public static function providerGetFilesFromSourcesPath(): array { */ public function testGetFilesFromSourcesPath(array $sources, array $expected, string $relativePath): void { $base_path_test = ['/', '/foo/', '/foo/bar/']; - + foreach ($base_path_test as $base_path) { // @todo Remove or adapt as part of https://www.example.com/node/2529170. $GLOBALS['base_path'] = $base_path; @@ -117,7 +117,7 @@ public function testGetFilesFromSourcesPath(array $sources, array $expected, str $sources, $relativePath, ); - + // Prepare result array matching processFoundFiles() to minimize test data. $expected_result = []; foreach ($expected as $key => $expected_value) { @@ -128,7 +128,7 @@ public function testGetFilesFromSourcesPath(array $sources, array $expected, str 'group' => NULL, ]; } - + $this->assertEquals($result, $expected_result); } } -- GitLab From 2e6a38ceed7d9406b67e37a3cca080836418616d Mon Sep 17 00:00:00 2001 From: Jean Valverde <moimog33@gmail.com> Date: Wed, 12 Feb 2025 09:08:35 +0000 Subject: [PATCH 6/7] tests: add tearDown to avoid any side effect --- .../KernelTests/Core/Theme/Icon/IconFinderKernelTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php index 350ca73dc772..4aaae22c46d7 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php @@ -60,6 +60,14 @@ protected function setUp(): void { ); } + /** + * {@inheritdoc} + */ + public function tearDown(): void { + $GLOBALS['base_path'] = '/'; + parent::tearDown(); + } + /** * Test the IconFinder::_construct method. */ -- GitLab From 5363d154fe3f4668f008c9233f8fe3d9d7ffca26 Mon Sep 17 00:00:00 2001 From: Jean Valverde <moimog33@gmail.com> Date: Fri, 21 Mar 2025 12:06:10 +0000 Subject: [PATCH 7/7] doc: wrong issue url domain --- .../Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php | 2 +- core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php index 4aaae22c46d7..a9bfb80dfd3a 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/Icon/IconFinderKernelTest.php @@ -118,7 +118,7 @@ public function testGetFilesFromSourcesPath(array $sources, array $expected, str $base_path_test = ['/', '/foo/', '/foo/bar/']; foreach ($base_path_test as $base_path) { - // @todo Remove or adapt as part of https://www.example.com/node/2529170. + // @todo Remove or adapt as part of https://www.drupal.org/node/2529170. $GLOBALS['base_path'] = $base_path; $result = $this->iconFinder->getFilesFromSources( diff --git a/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php b/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php index 23d29e7664e0..ccdecd31ae1d 100644 --- a/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php @@ -852,7 +852,7 @@ public function testGetFileContents(string $uri, bool $expected): void { } -// @todo Remove as part of https://www.example.com/node/2529170. +// @todo Remove as part of https://www.drupal.org/node/2529170. namespace Drupal\Core\Theme\Icon; if (!function_exists('base_path')) { -- GitLab