Skip to content

Commit c8c65b7

Browse files
author
Anna Bukatar
committed
Merge branch 'ACP2E-517' of https://github.com/magento-l3/magento2ce into PR-2022-03-11
2 parents 5b50b3f + c321168 commit c8c65b7

File tree

11 files changed

+108
-24
lines changed

11 files changed

+108
-24
lines changed

app/code/Magento/Deploy/Package/Processor/PreProcessor/Less.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Deploy\Package\Processor\PreProcessor;
78

89
use Magento\Deploy\Console\DeployStaticOptions;
910
use Magento\Deploy\Package\Package;
1011
use Magento\Deploy\Package\PackageFile;
1112
use Magento\Deploy\Package\Processor\ProcessorInterface;
1213
use Magento\Deploy\Service\DeployStaticFile;
13-
use Magento\Framework\View\Asset\PreProcessor\FileNameResolver;
14-
use Magento\Framework\View\Asset\Minification;
1514
use Magento\Framework\Css\PreProcessor\Instruction\Import;
15+
use Magento\Framework\View\Asset\Minification;
1616
use Magento\Framework\View\Asset\NotationResolver;
17+
use Magento\Framework\View\Asset\PreProcessor\FileNameResolver;
1718
use Magento\Framework\View\Asset\Repository;
1819

1920
/**
@@ -67,10 +68,10 @@ class Less implements ProcessorInterface
6768
* @param Minification $minification
6869
*/
6970
public function __construct(
70-
FileNameResolver $fileNameResolver,
71+
FileNameResolver $fileNameResolver,
7172
NotationResolver\Module $notationResolver,
72-
DeployStaticFile $deployStaticFile,
73-
Minification $minification
73+
DeployStaticFile $deployStaticFile,
74+
Minification $minification
7475
) {
7576
$this->fileNameResolver = $fileNameResolver;
7677
$this->notationResolver = $notationResolver;
@@ -139,8 +140,10 @@ private function hasOverrides(PackageFile $parentFile, Package $package)
139140
}
140141

141142
/**
142-
* @param string $fileName
143-
* @param string $parentFile
143+
* Checks if there is a LESS file in current package which used for generating given CSS from parent package
144+
*
145+
* @param string $fileName
146+
* @param string $parentFile
144147
* @param array $map
145148
* @return bool
146149
*/
@@ -151,7 +154,9 @@ private function inParentFiles($fileName, $parentFile, $map)
151154
return true;
152155
} else {
153156
foreach ($map[$parentFile] as $pFile) {
154-
return $this->inParentFiles($fileName, $pFile, $map);
157+
if ($this->inParentFiles($fileName, $pFile, $map)) {
158+
return true;
159+
}
155160
}
156161
}
157162
}
@@ -171,12 +176,14 @@ private function buildMap($filePath, $packagePath, $contentType)
171176
$content = $this->deployStaticFile->readTmpFile($filePath, $packagePath);
172177
$replaceCallback = function ($matchedContent) use ($filePath, $packagePath, $contentType) {
173178
$matchedFileId = $matchedContent['path'];
179+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
174180
if (!pathinfo($matchedContent['path'], PATHINFO_EXTENSION)) {
175181
$matchedFileId .= '.' . $contentType;
176182
}
177183
if (strpos($matchedFileId, Repository::FILE_ID_SEPARATOR) !== false) {
178184
$basePath = $packagePath;
179185
} else {
186+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
180187
$basePath = pathinfo($filePath, PATHINFO_DIRNAME);
181188
}
182189
$resolvedPath = str_replace(Repository::FILE_ID_SEPARATOR, '/', $matchedFileId);

dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class DeployTest extends \PHPUnit\Framework\TestCase
7979
Options::NO_HTML_MINIFY => false,
8080
Options::AREA => ['frontend'],
8181
Options::EXCLUDE_AREA => ['none'],
82-
Options::THEME => ['Magento/zoom1', 'Magento/zoom2', 'Magento/zoom3'],
82+
Options::THEME => ['Magento/zoom1', 'Magento/zoom2', 'Magento/zoom3', 'Vendor/parent', 'Vendor/child'],
8383
Options::EXCLUDE_THEME => ['none'],
8484
Options::LANGUAGE => ['en_US', 'fr_FR', 'pl_PL'],
8585
Options::EXCLUDE_LANGUAGE => ['none'],
@@ -147,7 +147,10 @@ public function testDeploy()
147147
$this->assertLessPreProcessor($actualFileContent);
148148
$this->assertCssUrlFixerPostProcessor($actualFileContent);
149149

150-
foreach (['Magento/zoom1', 'Magento/zoom2', 'Magento/zoom3'] as $theme) {
150+
$actualFileContent = $this->staticDir->readFile('frontend/Vendor/child/default/css/styles-m.css');
151+
$this->assertCssFromChildTheme($actualFileContent);
152+
153+
foreach (['Magento/zoom1', 'Magento/zoom2', 'Magento/zoom3', 'Vendor/parent', 'Vendor/child'] as $theme) {
151154
$this->assertBundleSize($theme);
152155
$this->assertExcluded($theme, $this->config->getExcludedFiles());
153156
$this->assertExcluded($theme, $this->config->getExcludedDir());
@@ -162,7 +165,7 @@ public function testDeploy()
162165
*/
163166
private function assertFileExistsIsGenerated($fileName)
164167
{
165-
foreach (['Magento/zoom1', 'Magento/zoom2', 'Magento/zoom3'] as $theme) {
168+
foreach (['Magento/zoom1', 'Magento/zoom2', 'Magento/zoom3', 'Vendor/parent', 'Vendor/child'] as $theme) {
166169
foreach ($this->options[Options::LANGUAGE] as $locale) {
167170
$this->assertFileExists(
168171
$this->staticDir->getAbsolutePath(
@@ -213,6 +216,21 @@ private function assertCssUrlFixerPostProcessor($actualRootCssContent)
213216
$this->assertStringContainsString('color:#111', $actualRootCssContent);
214217
}
215218

219+
/**
220+
* Assert CSS from child post-processor
221+
*
222+
* @param $actualRootCssContent
223+
* @return void
224+
*/
225+
private function assertCssFromChildTheme($actualRootCssContent)
226+
{
227+
//assert CssUrlFixer fix urls
228+
$this->assertStringContainsString(
229+
'super-test-class-for-easy-find',
230+
$actualRootCssContent
231+
);
232+
}
233+
216234
/**
217235
* Assert correct bundle size according to configuration set in view.xml
218236
*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/Vendor/child', __DIR__);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!--
2+
~ /**
3+
~ * Copyright © Magento, Inc. All rights reserved.
4+
~ * See COPYING.txt for license details.
5+
~ */
6+
-->
7+
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
8+
<title>Vendor Child</title>
9+
<parent>Vendor/parent</parent>
10+
</theme>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
& when (@media-common = true) {
2+
.super-test-class-for-easy-find {
3+
text-align: right;
4+
}
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/Vendor/parent', __DIR__);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!--
2+
~ /**
3+
~ * Copyright © Magento, Inc. All rights reserved.
4+
~ * See COPYING.txt for license details.
5+
~ */
6+
-->
7+
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
8+
<title>Vendor Parent</title>
9+
<parent>Magento/blank</parent>
10+
</theme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This is overridden in B2B theme
2+
// https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/css-guide/css_quick_guide_approach.html
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import '_extend-child.less';
2+

dev/tests/integration/testsuite/Magento/Deploy/_files/theme.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function rcopy($src, $destination)
3838
foreach ($iterator as $file) {
3939
if ($file->isFile()) {
4040
copy($file->getRealPath(), $destination . '/' . $file->getFilename());
41-
} else if (!$file->isDot() && $file->isDir()) {
41+
} elseif (!$file->isDot() && $file->isDir()) {
4242
rcopy($file->getRealPath(), $destination . '/' . $file);
4343
}
4444
}
@@ -48,10 +48,6 @@ function rcopy($src, $destination)
4848
/** @var ComponentRegistrar $registrar */
4949
$registrar = $objectManager->get(ComponentRegistrar::class);
5050

51-
//rcopy(
52-
// __DIR__ . '/zoom1',
53-
// $appDir->getAbsolutePath() . 'design/frontend/Magento/zoom1'
54-
//);
5551
if (!$registrar->getPath(ComponentRegistrar::THEME, 'frontend/Magento/zoom1')) {
5652
ComponentRegistrar::register(
5753
ComponentRegistrar::THEME,
@@ -60,10 +56,6 @@ function rcopy($src, $destination)
6056
);
6157
}
6258

63-
//rcopy(
64-
// __DIR__ . '/zoom2',
65-
// $appDir->getAbsolutePath() . 'design/frontend/Magento/zoom2'
66-
//);
6759
if (!$registrar->getPath(ComponentRegistrar::THEME, 'frontend/Magento/zoom2')) {
6860
ComponentRegistrar::register(
6961
ComponentRegistrar::THEME,
@@ -72,10 +64,6 @@ function rcopy($src, $destination)
7264
);
7365
}
7466

75-
//rcopy(
76-
// __DIR__ . '/zoom3',
77-
// $appDir->getAbsolutePath() . 'design/frontend/Magento/zoom3'
78-
//);
7967
if (!$registrar->getPath(ComponentRegistrar::THEME, 'frontend/Magento/zoom3')) {
8068
ComponentRegistrar::register(
8169
ComponentRegistrar::THEME,
@@ -84,6 +72,22 @@ function rcopy($src, $destination)
8472
);
8573
}
8674

75+
if (!$registrar->getPath(ComponentRegistrar::THEME, 'frontend/Vendor/parent')) {
76+
ComponentRegistrar::register(
77+
ComponentRegistrar::THEME,
78+
'frontend/Vendor/parent',
79+
__DIR__ . '/Vendor/parent'
80+
);
81+
}
82+
83+
if (!$registrar->getPath(ComponentRegistrar::THEME, 'frontend/Vendor/child')) {
84+
ComponentRegistrar::register(
85+
ComponentRegistrar::THEME,
86+
'frontend/Vendor/child',
87+
__DIR__ . '/Vendor/child'
88+
);
89+
}
90+
8791
/** @var \Magento\Theme\Model\Theme\Registration $themeRegistration */
8892
$themeRegistration = $objectManager->get(\Magento\Theme\Model\Theme\Registration::class);
8993
$themeRegistration->register();

0 commit comments

Comments
 (0)