‪TYPO3CMS  ‪main
RelativeCssPathFixerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪RelativeCssPathFixerTest extends UnitTestCase
26 {
27  public static function ‪fixRelativeUrlPathsDataProvider(): array
28  {
29  return [
30  '@import from fileadmin with relative' => [
31  '@import url(../tests/test.css); body { background: #ffffff; }',
32  '/fileadmin/css/',
33  '@import url(\'/fileadmin/tests/test.css\'); body { background: #ffffff; }',
34  ],
35  '@import from fileadmin with no relative' => [
36  '@import url(test.css); body { background: #ffffff; }',
37  'fileadmin/css/',
38  '@import url(\'fileadmin/css/test.css\'); body { background: #ffffff; }',
39  ],
40  '@import from sitepackage with no relative' => [
41  '@import url(test.css); body { background: #ffffff; }',
42  'typo3conf/ext/sitepackage/Resources/Public/Css/',
43  '@import url(\'typo3conf/ext/sitepackage/Resources/Public/Css/test.css\'); body { background: #ffffff; }',
44  ],
45  'url() from sitepackage with relative' => [
46  '@font-face {
47  font-family: "Testfont"
48  src: url("../fonts/testfont.woff2") format("woff2"),
49  url("../fonts/testfont.woff") format("woff");
50  }',
51  '../../../typo3conf/ext/sitepackage/Resources/Public/Css/',
52  '@font-face {
53  font-family: "Testfont"
54  src: url(\'../../../typo3conf/ext/sitepackage/Resources/Public/fonts/testfont.woff2\') format("woff2"),
55  url(\'../../../typo3conf/ext/sitepackage/Resources/Public/fonts/testfont.woff\') format("woff");
56  }',
57  ],
58  'url() from fileadmin with no relative' => [
59  '@font-face {
60  font-family: "Testfont"
61  src: url("../fonts/testfont.woff2") format("woff2"),
62  url("../fonts/testfont.woff") format("woff");
63  }',
64  'fileadmin/css/',
65  '@font-face {
66  font-family: "Testfont"
67  src: url(\'fileadmin/fonts/testfont.woff2\') format("woff2"),
68  url(\'fileadmin/fonts/testfont.woff\') format("woff");
69  }',
70  ],
71  ];
72  }
73 
74  #[DataProvider('fixRelativeUrlPathsDataProvider')]
75  #[Test]
76  public function ‪fixRelativeUrlPaths(string $css, string $newDir, string $expected): void
77  {
78  $subject = new ‪RelativeCssPathFixer();
79  $fixedCssPath = $subject->fixRelativeUrlPaths($css, $newDir);
80  self::assertSame($expected, $fixedCssPath);
81  }
82 }
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\RelativeCssPathFixerTest\fixRelativeUrlPathsDataProvider
‪static fixRelativeUrlPathsDataProvider()
Definition: RelativeCssPathFixerTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Resource\RelativeCssPathFixerTest
Definition: RelativeCssPathFixerTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\RelativeCssPathFixerTest\fixRelativeUrlPaths
‪fixRelativeUrlPaths(string $css, string $newDir, string $expected)
Definition: RelativeCssPathFixerTest.php:76
‪TYPO3\CMS\Core\Resource\RelativeCssPathFixer
Definition: RelativeCssPathFixer.php:29