Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CssResolverTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\View\Url\CssResolver;
9 
10 class CssResolverTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $object;
16 
17  protected function setUp()
18  {
19  $this->object = new CssResolver();
20  }
21 
22  public function testRelocateRelativeUrls()
23  {
24  $relatedPath = '/some/directory/two/another/file.ext';
25  $filePath = '/some/directory/one/file.ext';
26 
27  $fixturePath = __DIR__ . '/_files/';
28  $source = file_get_contents($fixturePath . 'source.css');
29  $result = file_get_contents($fixturePath . 'resultNormalized.css');
30 
31  $this->assertEquals($result, $this->object->relocateRelativeUrls($source, $relatedPath, $filePath));
32  }
33 
39  public function testAggregateImportDirectives($cssContent, $expectedResult)
40  {
41  $this->assertEquals($expectedResult, $this->object->aggregateImportDirectives($cssContent));
42  }
43 
48  {
49  $fixturePath = __DIR__ . '/_files/';
50  $source = file_get_contents($fixturePath . 'sourceImport.css');
51  $result = file_get_contents($fixturePath . 'resultImport.css');
52  $sourceNoImport = 'li {background: url("https://example.com/absolute.gif");}';
53 
54  return [
55  'empty' => ['', ''],
56  'data without patterns' => [$sourceNoImport, $sourceNoImport],
57  'data with patterns' => [$source, $result]
58  ];
59  }
60 
67  public function testReplaceRelativeUrls($cssContent, $inlineCallback, $expectedResult)
68  {
69  $actual = $this->object->replaceRelativeUrls($cssContent, $inlineCallback);
70  $this->assertEquals($expectedResult, $actual);
71  }
72 
76  public static function replaceRelativeUrlsDataProvider()
77  {
78  $fixturePath = __DIR__ . '/_files/';
79  $callback = '\Magento\Framework\View\Test\Unit\Url\CssResolverTest::replaceRelativeUrl';
80  $source = file_get_contents($fixturePath . 'source.css');
81  $result = file_get_contents($fixturePath . 'result.css');
82  $sourceNoPatterns = 'li {background: url("https://example.com/absolute.gif");}';
83 
84  return [
85  'empty' => ['', '\Magento\Framework\View\Test\Unit\Url\CssResolverTest::doNothing', ''],
86  'data without patterns' => [$sourceNoPatterns, $callback, $sourceNoPatterns],
87  'data with patterns' => [$source, $callback, $result]
88  ];
89  }
90 
97  public static function replaceRelativeUrl($relativeUrl)
98  {
99  return '../two/another/' . $relativeUrl;
100  }
101 
105  public static function doNothing()
106  {
107  // do nothing
108  }
109 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$source
Definition: source.php:23
testAggregateImportDirectives($cssContent, $expectedResult)
testReplaceRelativeUrls($cssContent, $inlineCallback, $expectedResult)