init
This commit is contained in:
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Css\PreProcessor\Adapter;
|
||||
|
||||
use Pelago\Emogrifier\CssInliner as EmogrifierCssInliner;
|
||||
|
||||
class CssInlinerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Css\PreProcessor\Adapter\CssInliner
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->model = $this->objectManager->create(\Magento\Framework\Css\PreProcessor\Adapter\CssInliner::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $htmlFilePath
|
||||
* @param string $cssFilePath
|
||||
* @param string $cssExpected
|
||||
* @dataProvider getFilesDataProvider
|
||||
*/
|
||||
public function testGetFiles($htmlFilePath, $cssFilePath, $cssExpected)
|
||||
{
|
||||
$html = file_get_contents($htmlFilePath);
|
||||
$css = file_get_contents($cssFilePath);
|
||||
$this->model->setHtml($html);
|
||||
$this->model->setCss($css);
|
||||
$result = $this->model->process();
|
||||
$this->assertStringContainsString($cssExpected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilesDataProvider()
|
||||
{
|
||||
$fixtureDir = dirname(dirname(__DIR__));
|
||||
return [
|
||||
'noSpacesCss'=>[
|
||||
'resultHtml' => $fixtureDir . "/_files/css/test-input.html",
|
||||
'cssWithoutSpaces' => $fixtureDir . "/_files/css/test-css-no-spaces.css",
|
||||
'vertical-align: top; padding: 10px 10px 10px 0; width: 50%;'
|
||||
],
|
||||
'withSpacesCss'=>[
|
||||
'resultHtml' => $fixtureDir . "/_files/css/test-input.html",
|
||||
'cssWithSpaces' => $fixtureDir . "/_files/css/test-css-with-spaces.css",
|
||||
'vertical-align: top; padding: 10px 10px 10px 0; width: 50%;'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $htmlFilePath
|
||||
* @param string $cssFilePath
|
||||
* @param string $cssExpected
|
||||
* @dataProvider getFilesDataProviderEmogrifier
|
||||
*/
|
||||
public function testGetFilesEmogrifier($htmlFilePath, $cssFilePath, $cssExpected)
|
||||
{
|
||||
$html = file_get_contents($htmlFilePath);
|
||||
$css = file_get_contents($cssFilePath);
|
||||
$result = EmogrifierCssInliner::fromHtml($html)->inlineCss($css)->render();
|
||||
|
||||
/**
|
||||
* This test was implemented for the issue which existed in the older version of Emogrifier.
|
||||
* Test was updated, as the library got updated as well.
|
||||
*/
|
||||
$this->assertStringContainsString($cssExpected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilesDataProviderEmogrifier()
|
||||
{
|
||||
$fixtureDir = dirname(dirname(__DIR__));
|
||||
return [
|
||||
'noSpacesCss'=>[
|
||||
'resultHtml' => $fixtureDir . "/_files/css/test-input.html",
|
||||
'cssWithoutSpaces' => $fixtureDir . "/_files/css/test-css-no-spaces.css",
|
||||
'vertical-align: top; padding: 10px 10px 10px 0; width: 50%;'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\Css\PreProcessor\File\Collector;
|
||||
|
||||
use Magento\Framework\App\Bootstrap;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
/**
|
||||
* @magentoComponentsDir Magento/Framework/Css/PreProcessor/_files/code/Magento
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class AggregatedTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Css\PreProcessor\File\Collector\Aggregated
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize(
|
||||
[
|
||||
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => [
|
||||
DirectoryList::LIB_WEB => [
|
||||
DirectoryList::PATH => dirname(dirname(__DIR__)) . '/_files/lib/web',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Theme\Model\Theme\Registration $registration */
|
||||
$registration = $this->objectManager->get(
|
||||
\Magento\Theme\Model\Theme\Registration::class
|
||||
);
|
||||
$registration->register();
|
||||
$this->objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
|
||||
|
||||
/** @var \Magento\Framework\Filesystem $filesystem */
|
||||
$filesystem = $this->objectManager->create(
|
||||
\Magento\Framework\Filesystem::class,
|
||||
[
|
||||
'directoryList' => $this->objectManager->create(
|
||||
\Magento\Framework\App\Filesystem\DirectoryList::class,
|
||||
[
|
||||
'root' => BP,
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
/** @var \Magento\Framework\View\File\Collector\Base $sourceBase */
|
||||
$sourceBase = $this->objectManager->create(
|
||||
\Magento\Framework\View\File\Collector\Base::class,
|
||||
['filesystem' => $filesystem, 'subDir' => 'web']
|
||||
);
|
||||
/** @var \Magento\Framework\View\File\Collector\Base $sourceBase */
|
||||
$overriddenBaseFiles = $this->objectManager->create(
|
||||
\Magento\Framework\View\File\Collector\Override\Base::class,
|
||||
['filesystem' => $filesystem, 'subDir' => 'web']
|
||||
);
|
||||
$this->model = $this->objectManager->create(
|
||||
\Magento\Framework\Css\PreProcessor\File\Collector\Aggregated::class,
|
||||
['baseFiles' => $sourceBase, 'overriddenBaseFiles' => $overriddenBaseFiles]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
* @param string $path
|
||||
* @param string $themeName
|
||||
* @param string[] $expectedFiles
|
||||
* @dataProvider getFilesDataProvider
|
||||
* @magentoComponentsDir Magento/Framework/Css/PreProcessor/_files/design
|
||||
*/
|
||||
public function testGetFiles($path, $themeName, array $expectedFiles)
|
||||
{
|
||||
/** @var \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory */
|
||||
$themeFactory = $this->objectManager->get(\Magento\Framework\View\Design\Theme\FlyweightFactory::class);
|
||||
$theme = $themeFactory->create($themeName);
|
||||
$files = $this->model->getFiles($theme, $path);
|
||||
$actualFiles = [];
|
||||
foreach ($files as $file) {
|
||||
$actualFiles[] = $file->getFilename();
|
||||
}
|
||||
$this->assertEquals($expectedFiles, $actualFiles);
|
||||
|
||||
/** @var $file \Magento\Framework\View\File */
|
||||
foreach ($files as $file) {
|
||||
if (!in_array($file->getFilename(), $expectedFiles)) {
|
||||
$this->fail(sprintf('File "%s" is not expected but found', $file->getFilename()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilesDataProvider()
|
||||
{
|
||||
$fixtureDir = dirname(dirname(__DIR__));
|
||||
return [
|
||||
'file in theme and parent theme' => [
|
||||
'1.file',
|
||||
'FrameworkCssTest/default',
|
||||
[
|
||||
str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
"$fixtureDir/_files/design/frontend/Test/default/web/1.file"
|
||||
),
|
||||
str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
"$fixtureDir/_files/design/frontend/Test/parent/MagentoFrameworkCssTest_Second/web/1.file"
|
||||
),
|
||||
str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
"$fixtureDir/_files/design/frontend/Test/default/MagentoFrameworkCssTest_Module/web/1.file"
|
||||
),
|
||||
],
|
||||
],
|
||||
'file in library' => [
|
||||
'2.file',
|
||||
'FrameworkCssTest/default',
|
||||
[
|
||||
str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
"$fixtureDir/_files/lib/web/2.file"
|
||||
)
|
||||
],
|
||||
],
|
||||
'non-existing file' => [
|
||||
'doesNotExist',
|
||||
'FrameworkCssTest/default',
|
||||
[],
|
||||
],
|
||||
'file in library, module, and theme' => [
|
||||
'3.less',
|
||||
'FrameworkCssTest/default',
|
||||
[
|
||||
str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
"$fixtureDir/_files/lib/web/3.less"
|
||||
),
|
||||
str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
"$fixtureDir/_files/code/Magento/Other/view/frontend/web/3.less"
|
||||
),
|
||||
str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
"$fixtureDir/_files/design/frontend/Test/default/MagentoFrameworkCssTest_Third/web/3.less"
|
||||
)
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'MagentoFrameworkCssTest_Other', __DIR__);
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @category design
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// dummy less file for module
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'MagentoFrameworkCssTest_Third', __DIR__);
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @category design
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// dummy less file for module
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @category design
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// dummy less file for module
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/FrameworkCssTest/default', __DIR__);
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
|
||||
<title>Test Default</title>
|
||||
<parent>FrameworkCssTest/parent</parent>
|
||||
</theme>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/FrameworkCssTest/parent', __DIR__);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
|
||||
<title>Test Parent</title>
|
||||
</theme>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @category design
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// dummy less file
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
div.import_in_magento_import_lib {
|
||||
color: white;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
@import "import_dir/import_in_magento_import.less";
|
||||
div.magento_import_lib {
|
||||
color: green;
|
||||
}
|
||||
+1
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user