‪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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 final class ‪RelativeCssPathFixerTest extends UnitTestCase
24 {
25  public static function ‪fixRelativeUrlPathsDataProvider(): array
26  {
27  return [
28  '@import from fileadmin with relative' => [
29  '@import url(../tests/test.css); body { background: #ffffff; }',
30  '/fileadmin/css/',
31  '@import url(\'/fileadmin/tests/test.css\'); body { background: #ffffff; }',
32  ],
33  '@import from fileadmin with no relative' => [
34  '@import url(test.css); body { background: #ffffff; }',
35  'fileadmin/css/',
36  '@import url(\'fileadmin/css/test.css\'); body { background: #ffffff; }',
37  ],
38  '@import from sitepackage with no relative' => [
39  '@import url(test.css); body { background: #ffffff; }',
40  'typo3conf/ext/sitepackage/Resources/Public/Css/',
41  '@import url(\'typo3conf/ext/sitepackage/Resources/Public/Css/test.css\'); body { background: #ffffff; }',
42  ],
43  'url() from sitepackage with relative' => [
44  '@font-face {
45  font-family: "Testfont"
46  src: url("../fonts/testfont.woff2") format("woff2"),
47  url("../fonts/testfont.woff") format("woff");
48  }',
49  '../../../typo3conf/ext/sitepackage/Resources/Public/Css/',
50  '@font-face {
51  font-family: "Testfont"
52  src: url(\'../../../typo3conf/ext/sitepackage/Resources/Public/fonts/testfont.woff2\') format("woff2"),
53  url(\'../../../typo3conf/ext/sitepackage/Resources/Public/fonts/testfont.woff\') format("woff");
54  }',
55  ],
56  'url() from fileadmin with no relative' => [
57  '@font-face {
58  font-family: "Testfont"
59  src: url("../fonts/testfont.woff2") format("woff2"),
60  url("../fonts/testfont.woff") format("woff");
61  }',
62  'fileadmin/css/',
63  '@font-face {
64  font-family: "Testfont"
65  src: url(\'fileadmin/fonts/testfont.woff2\') format("woff2"),
66  url(\'fileadmin/fonts/testfont.woff\') format("woff");
67  }',
68  ],
69  ];
70  }
71 
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:25
‪TYPO3\CMS\Core\Tests\Unit\Resource\RelativeCssPathFixerTest
Definition: RelativeCssPathFixerTest.php:24
‪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