This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,301 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Asset;
use Exception;
use Magento\Deploy\Console\ConsoleLogger;
use Magento\Deploy\Console\DeployStaticOptions as Options;
use Magento\Deploy\Service\DeployStaticContent;
use Magento\Deploy\Strategy\DeployStrategyFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManagerFactory;
use Magento\Framework\App\Request\Http;
use Magento\Framework\App\Response\FileInterface;
use Magento\Framework\App\State as AppState;
use Magento\Framework\App\StaticResource;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\App\View\Deployment\Version\StorageInterface;
use Magento\Framework\Code\Minifier\AdapterInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\TestFramework\App\State;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;
use Magento\Theme\Model\Theme\Registration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\ConsoleOutput;
/**
* Tests for minifier
*
* @magentoComponentsDir Magento/Framework/View/_files/static/theme
* @magentoDbIsolation enabled
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class MinifierTest extends TestCase
{
/**
* @var WriteInterface
*/
private $staticDir;
/**
* @var ObjectManager
*/
protected $objectManager;
/**
* @var string
*/
private $origMode;
/**
* {@inheritDoc}
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getInstance()->getObjectManager();
/** @var Registration $registration */
$registration = $this->objectManager->get(Registration::class);
$registration->register();
/** @var State $appState */
$appState = $this->objectManager->get(State::class);
$this->origMode = $appState->getMode();
$appState->setMode(AppState::MODE_DEFAULT);
/** @var Filesystem $filesystem */
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
$this->staticDir = $filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
}
/**
* {@inheritDoc}
*/
protected function tearDown(): void
{
/** @var State $appState */
$appState = $this->objectManager->get(State::class);
$appState->setMode($this->origMode);
if ($this->staticDir->isExist('frontend/FrameworkViewMinifier')) {
$this->staticDir->delete('frontend/FrameworkViewMinifier');
}
parent::tearDown();
}
/**
* CSS Minifier library test
*
* When fails on library update or minification handler replacement:
* 1 - minify `_files/static/css/styles.css` with new library manually
* 2 - use DIFF tools to see difference between new minified CSS and old minified one
* 3 - ensure that all differences are acceptable
* 4 - ensure that new minified CSS is fully workable in all supported browsers
* 5 - replace `_files/static/css/styles.magento.min.css` with new minified css
*/
public function testCSSminLibrary()
{
/** @var AdapterInterface $adapter */
$adapter = $this->objectManager->get('cssMinificationAdapter');
$this->assertEquals(
file_get_contents(dirname(__DIR__) . '/_files/static/expected/styles.magento.min.css'),
$adapter->minify(file_get_contents(dirname(__DIR__) . '/_files/static/theme/web/css/styles.css')),
'Minified CSS differs from initial minified CSS snapshot. '
. 'Ensure that new CSS is fully valid for all supported browsers '
. 'and replace old minified snapshot with new one.'
);
}
/**
* Test JS minification library
*
* @return void
*/
public function testJshrinkLibrary()
{
/** @var AdapterInterface $adapter */
$adapter = $this->objectManager->get('jsMinificationAdapter');
$this->assertEquals(
file_get_contents(dirname(__DIR__) . '/_files/static/expected/test.min.js'),
$adapter->minify(file_get_contents(dirname(__DIR__) . '/_files/static/theme/web/js/test.js')),
'Minified JS differs from initial minified JS snapshot. '
. 'Ensure that new JS is fully valid for all supported browsers '
. 'and replace old minified snapshot with new one.'
);
}
/**
* Test CSS minification
*
* @param string $requestedUri
* @param callable $assertionCallback
* @throws LocalizedException|Exception
*/
private function checkCssMinification(string $requestedUri, callable $assertionCallback): void
{
/** @var Http $request */
$request = $this->objectManager->get(Http::class);
$request->setRequestUri($requestedUri);
$request->setParam('resource', $requestedUri);
$response = $this->getMockBuilder(FileInterface::class)
->setMethods(['setFilePath'])
->getMockForAbstractClass();
$response
->expects($this->any())
->method('setFilePath')
->willReturnCallback($assertionCallback);
/** @var StaticResource $staticResourceApp */
$staticResourceApp = $this->objectManager->create(
StaticResource::class,
['response' => $response]
);
$staticResourceApp->launch();
}
/**
* @magentoConfigFixture current_store dev/css/minify_files 0
* @magentoAppIsolation enabled
*/
public function testCssMinificationOff()
{
$this->checkCssMinification(
'/frontend/FrameworkViewMinifier/default/en_US/css/styles.css',
function ($path) {
$content = file_get_contents($path);
$this->assertNotEmpty($content);
$this->assertStringContainsString('FrameworkViewMinifier/frontend', $content);
$this->assertNotEquals(
file_get_contents(
dirname(__DIR__)
. '/_files/static/expected/styles.magento.min.css'
),
$content,
'CSS is minified when minification turned off'
);
}
);
}
/**
* @magentoConfigFixture current_store dev/css/minify_files 1
*/
public function testCssMinification()
{
$this->checkCssMinification(
'/frontend/FrameworkViewMinifier/default/en_US/css/styles.min.css',
function ($path) {
$this->assertEquals(
file_get_contents(
dirname(__DIR__)
. '/_files/static/expected/styles.magento.min.css'
),
file_get_contents($path),
'Minified files are not equal or minification did not work for requested CSS'
);
}
);
}
/**
* @magentoConfigFixture current_store dev/css/minify_files 1
*/
public function testCssMinificationForMinifiedFiles()
{
$this->checkCssMinification(
'/frontend/FrameworkViewMinifier/default/en_US/css/preminified-styles.min.css',
function ($path) {
$content = file_get_contents($path);
$this->assertNotEmpty($content);
$this->assertStringContainsString('Magento/backend', $content);
$this->assertStringContainsString('semi-minified file', $content);
}
);
}
/**
* @magentoConfigFixture current_store dev/css/minify_files 1
*/
public function testDeploymentWithMinifierEnabled()
{
$staticPath = $this->staticDir->getAbsolutePath();
$fileToBePublished = $staticPath . '/frontend/FrameworkViewMinifier/default/en_US/css/styles.min.css';
$fileToTestPublishing = dirname(__DIR__) . '/_files/static/theme/web/css/styles.css';
$omFactory = $this->createPartialMock(ObjectManagerFactory::class, ['create']);
$omFactory->expects($this->any())
->method('create')
->willReturn($this->objectManager);
$filesUtil = $this->createMock(Files::class);
$filesUtil->expects($this->any())
->method('getStaticLibraryFiles')
->willReturn([]);
$filesUtil->expects($this->any())
->method('getPhtmlFiles')
->willReturn([]);
$filesUtil->expects($this->any())
->method('getStaticPreProcessingFiles')
->willReturn(
[
['frontend', 'FrameworkViewMinifier/default', '', '', 'css/styles.css', $fileToTestPublishing]
]
);
$this->objectManager->addSharedInstance($filesUtil, Files::class);
$output = $this->objectManager->create(ConsoleOutput::class);
$logger = $this->objectManager->create(ConsoleLogger::class, ['output' => $output]);
$versionStorage = $this->createPartialMock(StorageInterface::class, ['save', 'load']);
/** @var DeployStaticContent $deployService */
$deployService = $this->objectManager->create(
DeployStaticContent::class,
[
'objectManager' => $this->objectManager,
'logger' => $logger,
'versionStorage' => $versionStorage,
]
);
$deployService->deploy(
[
Options::DRY_RUN => false,
Options::NO_JAVASCRIPT => true,
Options::NO_CSS => false,
Options::NO_LESS => false,
Options::NO_IMAGES => true,
Options::NO_FONTS => true,
Options::NO_HTML => true,
Options::NO_MISC => true,
Options::NO_HTML_MINIFY => true,
Options::AREA => ['frontend'],
Options::EXCLUDE_AREA => ['none'],
Options::THEME => ['FrameworkViewMinifier/default'],
Options::EXCLUDE_THEME => ['none'],
Options::LANGUAGE => ['en_US'],
Options::EXCLUDE_LANGUAGE => ['none'],
Options::JOBS_AMOUNT => 0,
Options::SYMLINK_LOCALE => false,
Options::STRATEGY => DeployStrategyFactory::DEPLOY_STRATEGY_QUICK,
Options::NO_PARENT => false,
]
);
$this->assertFileExists($fileToBePublished);
$this->assertEquals(
file_get_contents(dirname(__DIR__) . '/_files/static/expected/styles.magento.min.css'),
file_get_contents($fileToBePublished),
'Minified file is not equal or minification did not work for deployed CSS'
);
}
}
@@ -0,0 +1,273 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Design\Fallback;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Filesystem;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Factory Test
* @magentoComponentsDir Magento/Framework/View/_files/fallback
* @magentoDbIsolation enabled
*/
class RulePoolTest extends \PHPUnit\Framework\TestCase
{
/**
* @var RulePool
*/
protected $model;
/**
* @var array
*/
protected $defaultParams;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Theme\Model\Theme\Registration $registration */
$registration = $objectManager->get(
\Magento\Theme\Model\Theme\Registration::class
);
$registration->register();
$this->model = $objectManager->create(\Magento\Framework\View\Design\Fallback\RulePool::class);
/** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $collection */
$collection = $objectManager->create(\Magento\Theme\Model\ResourceModel\Theme\Collection::class);
/** @var \Magento\Theme\Model\Theme $theme */
$theme = $collection->getThemeByFullPath('frontend/Vendor_ViewTest/custom_theme');
$this->defaultParams = [
'area' => 'area',
'theme' => $theme,
'module_name' => 'ViewTest_Module',
'locale' => 'en_US',
];
}
protected function tearDown(): void
{
$this->model = null;
$this->defaultParams = [];
}
public function testGetRuleUnsupportedType()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Fallback rule \'unsupported_type\' is not supported');
$this->model->getRule('unsupported_type');
}
/**
* @param string $type
* @param array $overriddenParams
* @param string $expectedErrorMessage
*
* @dataProvider getPatternDirsExceptionDataProvider
*/
public function testGetPatternDirsException($type, array $overriddenParams, $expectedErrorMessage)
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage($expectedErrorMessage);
$params = $overriddenParams + $this->defaultParams;
$this->model->getRule($type)->getPatternDirs($params);
}
/**
* @return array
*/
public function getPatternDirsExceptionDataProvider()
{
$exceptions = [
'no theme' => [
['theme' => null],
'Parameter "theme" should be specified and should implement the theme interface',
],
'no area' => [
['area' => null],
"Required parameter 'area' was not passed",
],
];
$exceptionsPerTypes = [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_LOCALE_FILE => [
'no theme',
],
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_FILE => [
'no theme', 'no area',
],
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE => [
'no theme', 'no area',
],
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE => [
'no theme', 'no area',
],
];
$data = [];
foreach ($exceptionsPerTypes as $type => $exceptionKeys) {
foreach ($exceptionKeys as $key) {
$data[$type . ', ' . $key] = [$type, $exceptions[$key][0], $exceptions[$key][1]];
}
}
return $data;
}
/**
* @param string $type
* @param array $overriddenParams
* @param array $expectedResult
*
* @dataProvider getPatternDirsDataProvider
*/
public function testGetPatternDirs($type, array $overriddenParams, array $expectedResult)
{
$actualResult = $this->model->getRule($type)
->getPatternDirs($overriddenParams + $this->defaultParams);
$this->assertEquals($expectedResult, $actualResult);
}
/**
* @return array
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getPatternDirsDataProvider()
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar */
$componentRegistrar = $objectManager->get(
\Magento\Framework\Component\ComponentRegistrarInterface::class
);
$coreModulePath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Theme');
/** @var \Magento\Framework\Filesystem $filesystem */
$filesystem = $objectManager->get(\Magento\Framework\Filesystem::class);
$libPath = rtrim($filesystem->getDirectoryRead(DirectoryList::LIB_WEB)->getAbsolutePath(), '/');
$themeOnePath = BP . '/dev/tests/integration/testsuite/Magento/Framework/View/_files/fallback/design/frontend/'
. 'Vendor/custom_theme';
$themeTwoPath = BP . '/dev/tests/integration/testsuite/Magento/Framework/View/_files/fallback/design/frontend/'
. 'Vendor/default';
$modulePath = BP . '/dev/tests/integration/testsuite/Magento/Framework/View/_files/fallback/app/code/'
. 'ViewTest_Module';
return [
'locale' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_LOCALE_FILE,
[],
[
$themeOnePath,
$themeTwoPath,
],
],
'file, modular' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_FILE,
[],
[
$themeOnePath . '/ViewTest_Module',
$themeTwoPath . '/ViewTest_Module',
$modulePath . '/view/area',
$modulePath . '/view/base',
],
],
'file, non-modular' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_FILE,
['namespace' => null, 'module_name' => null],
[
$themeOnePath,
$themeTwoPath,
],
],
'template, modular' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE,
[],
[
$themeOnePath . '/ViewTest_Module/templates',
$themeTwoPath . '/ViewTest_Module/templates',
$modulePath . '/view/area/templates',
$modulePath . '/view/base/templates',
],
],
'template, non-modular' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE,
['namespace' => null, 'module_name' => null],
[
$themeOnePath . '/templates',
$themeTwoPath . '/templates',
],
],
'template, non-modular-magento-core' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE,
['module_name' => 'Magento_Theme'],
[
$themeOnePath . '/Magento_Theme/templates',
$themeTwoPath . '/Magento_Theme/templates',
$coreModulePath . '/view/area/templates',
$coreModulePath . '/view/base/templates',
],
],
'view, modular localized' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE,
[],
[
$themeOnePath . '/ViewTest_Module/web/i18n/en_US',
$themeOnePath . '/ViewTest_Module/web',
$themeTwoPath . '/ViewTest_Module/web/i18n/en_US',
$themeTwoPath . '/ViewTest_Module/web',
$modulePath . '/view/area/web/i18n/en_US',
$modulePath . '/view/base/web/i18n/en_US',
$modulePath . '/view/area/web',
$modulePath . '/view/base/web',
],
],
'view, modular non-localized' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE,
['locale' => null],
[
$themeOnePath . '/ViewTest_Module/web',
$themeTwoPath . '/ViewTest_Module/web',
$modulePath . '/view/area/web',
$modulePath . '/view/base/web',
],
],
'view, non-modular localized' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE,
['module_name' => null],
[
$themeOnePath . '/web/i18n/en_US',
$themeOnePath . '/web',
$themeTwoPath . '/web/i18n/en_US',
$themeTwoPath . '/web',
$libPath,
],
],
'view, non-modular non-localized' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE,
['module_name' => null, 'locale' => null],
[
$themeOnePath . '/web',
$themeTwoPath . '/web',
$libPath,
],
],
// Single test, as emails will always be loaded in a modular context with no locale specificity
'email' => [
\Magento\Framework\View\Design\Fallback\RulePool::TYPE_EMAIL_TEMPLATE,
[],
[
$themeOnePath . '/ViewTest_Module/email',
$themeTwoPath . '/ViewTest_Module/email',
$modulePath . '/view/area/email',
],
],
];
}
}
@@ -0,0 +1,319 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Design\FileResolution;
use Magento\Framework\App\Bootstrap as AppBootstrap;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoComponentsDir Magento/Framework/View/_files/fallback
* @magentoDbIsolation enabled
*/
class FallbackTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Design\Theme\FlyweightFactory
*/
private $themeFactory;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Theme\Model\Theme\Registration $registration */
$registration = $objectManager->get(
\Magento\Theme\Model\Theme\Registration::class
);
$registration->register();
/** @var \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory */
$this->themeFactory = $objectManager
->get(\Magento\Framework\View\Design\Theme\FlyweightFactory::class);
}
/**
* Reinitialize environment with test directories
*
* Since the testGetEmailTemplateFile test uses a @magentoDataFixture that reinitializes the environment, we
* must reinitialize the environment only when a test specifically requests it
*
* @return void
*/
protected function reinitializeEnvironment()
{
Bootstrap::getInstance()->reinitialize([
AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => [
DirectoryList::LIB_WEB => [
'path' => __DIR__ . '/../../_files/fallback/lib/web',
],
],
]);
}
/**
* @param string $file
* @param string $themePath
* @param string|null $module
* @param string|null $expectedFilename
*
* @dataProvider getTemplateFileDataProvider
*/
public function testGetTemplateFile($file, $themePath, $module, $expectedFilename)
{
$this->reinitializeEnvironment();
/** @var \Magento\Framework\View\Design\FileResolution\Fallback\TemplateFile $model */
$model = Bootstrap::getObjectManager()
->create(\Magento\Framework\View\Design\FileResolution\Fallback\TemplateFile::class);
$themeModel = $this->themeFactory->create($themePath);
$actualFilename = $model->getFile('frontend', $themeModel, $file, $module);
if ($expectedFilename) {
$this->assertIsString($actualFilename);
$this->assertStringMatchesFormat($expectedFilename, $actualFilename);
$this->assertFileExists($actualFilename);
} else {
$this->assertFalse($actualFilename);
}
}
/**
* @return array
*/
public function getTemplateFileDataProvider()
{
return [
'non-modular: no default inheritance' => [
'fixture_template.phtml', 'Vendor_ViewTest/standalone_theme', null,
null,
],
'non-modular: inherit parent theme' => [
'fixture_template.phtml', 'Vendor_ViewTest/custom_theme', null,
'%s/frontend/Vendor/default/templates/fixture_template.phtml',
],
'non-modular: inherit grandparent theme' => [
'fixture_template.phtml', 'Vendor_ViewTest/custom_theme2', null,
'%s/frontend/Vendor/default/templates/fixture_template.phtml',
],
'modular: no default inheritance' => [
'fixture_template.phtml', 'Vendor_ViewTest/standalone_theme', 'ViewTest_Module',
null,
],
'modular: no fallback to non-modular file' => [
'nonexistent_fixture_script.phtml', 'Vendor_ViewTest/default', 'ViewTest_Module',
null,
],
'modular: inherit parent theme' => [
'fixture_template.phtml', 'Vendor_ViewTest/custom_theme', 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/templates/fixture_template.phtml',
],
'modular: inherit grandparent theme' => [
'fixture_template.phtml', 'Vendor_ViewTest/custom_theme2', 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/templates/fixture_template.phtml',
],
];
}
/**
* @param string $themePath
* @param string $locale
* @param string|null $expectedFilename
*
* @dataProvider getLocaleFileDataProvider
*/
public function testGetI18nCsvFile($themePath, $locale, $expectedFilename)
{
$this->reinitializeEnvironment();
/** @var \Magento\Framework\View\Design\FileResolution\Fallback\File $model */
$model = Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\FileResolution\Fallback\File::class
);
$themeModel = $this->themeFactory->create($themePath);
$actualFilename = $model->getFile('frontend', $themeModel, 'i18n/' . $locale . '.csv');
if ($expectedFilename) {
$this->assertIsString($actualFilename);
$this->assertStringMatchesFormat($expectedFilename, $actualFilename);
$this->assertFileExists($actualFilename);
} else {
$this->assertFalse($actualFilename);
}
}
public function getLocaleFileDataProvider()
{
return [
'no default inheritance' => [
'Vendor_ViewTest/standalone_theme', 'en_US',
null,
],
'inherit parent theme' => [
'Vendor_ViewTest/custom_theme', 'en_US',
'%s/frontend/Vendor/custom_theme/i18n/en_US.csv',
],
'inherit grandparent theme' => [
'Vendor_ViewTest/custom_theme2', 'en_US',
'%s/frontend/Vendor/custom_theme/i18n/en_US.csv',
],
];
}
/**
* Test for the static files fallback according to the themes inheritance
*
* @param string $file
* @param string $themePath
* @param string $locale
* @param string $module
* @param string|null $expectedFilename
*
* @dataProvider getViewFileDataProvider
*/
public function testGetViewFile($file, $themePath, $locale, $module, $expectedFilename)
{
$this->reinitializeEnvironment();
/** @var \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $model */
$model = Bootstrap::getObjectManager()
->create(\Magento\Framework\View\Design\FileResolution\Fallback\StaticFile::class);
$themeModel = $this->themeFactory->create($themePath);
$actualFilename = $model->getFile('frontend', $themeModel, $locale, $file, $module);
if ($expectedFilename) {
$this->assertIsString($actualFilename);
$this->assertStringMatchesFormat($expectedFilename, $actualFilename);
$this->assertFileExists($actualFilename);
} else {
$this->assertFalse($actualFilename);
}
}
public function getViewFileDataProvider()
{
return [
'non-modular: no default inheritance' => [
'fixture_script.js', 'Vendor_ViewTest/standalone_theme', null, null,
null,
],
'non-modular: inherit same package & parent theme' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme', null, null,
'%s/frontend/Vendor/default/web/fixture_script.js',
],
'non-modular: inherit same package & grandparent theme' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme2', null, null,
'%s/frontend/Vendor/default/web/fixture_script.js',
],
'non-modular: fallback to non-localized file' => [
'fixture_script.js', 'Vendor_ViewTest/default', 'en_US', null,
'%s/frontend/Vendor/default/web/fixture_script.js',
],
'non-modular: localized file' => [
'fixture_script.js', 'Vendor_ViewTest/default', 'ru_RU', null,
'%s/frontend/Vendor/default/web/i18n/ru_RU/fixture_script.js',
],
'non-modular: override js lib file' => [
'mage/script.js', 'Vendor_ViewTest/custom_theme', null, null,
'%s/frontend/Vendor/custom_theme/web/mage/script.js',
],
'non-modular: inherit js lib file' => [
'mage/script.js', 'Vendor_ViewTest/default', null, null,
'%s/lib/web/mage/script.js',
],
'modular: no default inheritance' => [
'fixture_script.js', 'Vendor_ViewTest/standalone_theme', null, 'ViewTest_Module',
null,
],
'modular: no fallback to non-modular file' => [
'nonexistent_fixture_script.js', 'Vendor_ViewTest/default', null, 'ViewTest_Module',
null,
],
'modular: no fallback to js lib file' => [
'mage/script.js', 'Vendor_ViewTest/default', null, 'ViewTest_Module',
null,
],
'modular: no fallback to non-modular localized file' => [
'nonexistent_fixture_script.js', 'Vendor_ViewTest/default', 'ru_RU', 'ViewTest_Module',
null,
],
'modular: inherit same package & parent theme' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme', null, 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/web/fixture_script.js',
],
'modular: inherit same package & grandparent theme' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme2', null, 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/web/fixture_script.js',
],
'modular: fallback to non-localized file' => [
'fixture_script.js', 'Vendor_ViewTest/default', 'en_US', 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/web/fixture_script.js',
],
'modular: localized file' => [
'fixture_script.js', 'Vendor_ViewTest/custom_theme2', 'ru_RU', 'ViewTest_Module',
'%s/frontend/Vendor/default/ViewTest_Module/web/i18n/ru_RU/fixture_script.js',
],
];
}
/**
* Test for the email template files fallback according to the themes inheritance
*
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
* @magentoComponentsDir Magento/Email/Model/_files/design
*
* @param string $file
* @param string $themePath
* @param string $module
* @param string|null $expectedFilename
*
* @dataProvider getEmailTemplateFileDataProvider
*/
public function testGetEmailTemplateFile($file, $themePath, $module, $expectedFilename)
{
$area = \Magento\Framework\App\Area::AREA_FRONTEND;
/** @var \Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile $model */
$model = Bootstrap::getObjectManager()
->create(\Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile::class);
$themeModel = $this->themeFactory->create($themePath);
$locale = \Magento\Setup\Module\I18n\Locale::DEFAULT_SYSTEM_LOCALE;
$actualFilename = $model->getFile($area, $themeModel, $locale, $file, $module);
if ($expectedFilename) {
$this->assertIsString($actualFilename);
$this->assertStringMatchesFormat($expectedFilename, $actualFilename);
$this->assertFileExists($actualFilename);
} else {
$this->assertFalse($actualFilename);
}
}
/**
* @return array
*/
public function getEmailTemplateFileDataProvider()
{
return [
'no fallback' => [
'account_new.html',
'Vendor_EmailTest/custom_theme',
'Magento_Customer',
'%s/frontend/Vendor/custom_theme/Magento_Customer/email/account_new.html',
],
'inherit same package & parent theme' => [
'account_new_confirmation.html',
'Vendor_EmailTest/custom_theme',
'Magento_Customer',
'%s/frontend/Vendor/default/Magento_Customer/email/account_new_confirmation.html',
],
'inherit parent package & grandparent theme' => [
'account_new_confirmed.html',
'Vendor_EmailTest/custom_theme',
'Magento_Customer',
'%s/frontend/Magento/default/Magento_Customer/email/account_new_confirmed.html',
],
];
}
}
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Design\Theme;
class LabelTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Design\Theme\Label
*/
protected $_model;
protected function setUp(): void
{
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\Theme\Label::class
);
}
/**
* @covers \Magento\Framework\View\Design\Theme\Label::getLabelsCollection
*/
public function testGetLabelsCollection()
{
/** @var $expectedCollection \Magento\Theme\Model\ResourceModel\Theme\Collection */
$expectedCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\Theme\Label\ListInterface::class
);
$expectedItemsCount = count($expectedCollection->getLabels());
$labelsCollection = $this->_model->getLabelsCollection();
$this->assertEquals($expectedItemsCount, count($labelsCollection));
$labelsCollection = $this->_model->getLabelsCollection('-- Please Select --');
$this->assertEquals(++$expectedItemsCount, count($labelsCollection));
}
}
@@ -0,0 +1,89 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test theme data validator
*/
namespace Magento\Framework\View\Design\Theme;
class ValidatorTest extends \PHPUnit\Framework\TestCase
{
/**
* Test validator with valid data
*/
public function testValidateWithValidData()
{
/** @var $validator \Magento\Framework\View\Design\Theme\Validator */
$validator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\Theme\Validator::class
);
$themeModel = $this->_getThemeModel();
$themeModel->setData($this->_getThemeValidData());
$this->assertTrue($validator->validate($themeModel));
}
/**
* Test validator with invalid data
*/
public function testValidateWithInvalidData()
{
/** @var $validator \Magento\Framework\View\Design\Theme\Validator */
$validator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\Theme\Validator::class
);
$themeModel = $this->_getThemeModel();
$themeModel->setData($this->_getThemeInvalidData());
$this->assertFalse($validator->validate($themeModel));
}
/**
* Get theme model
*
* @return \Magento\Framework\Model\AbstractModel
*/
protected function _getThemeModel()
{
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Design\ThemeInterface::class
);
}
/**
* Get theme valid data
*
* @return array
*/
protected function _getThemeValidData()
{
return [
'theme_code' => 'space',
'theme_title' => 'Space theme',
'parent_theme' => null,
'theme_path' => 'default/space',
'preview_image' => 'images/preview.png'
];
}
/**
* Get theme invalid data
*
* @return array
*/
protected function _getThemeInvalidData()
{
return [
'theme_code' => 'space',
'theme_title' => '',
'parent_theme' => null,
'theme_path' => 'default/space',
'preview_image' => 'images/preview.png'
];
}
}
@@ -0,0 +1,681 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Element;
use Magento\Framework\Math\Random;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Framework\Session\SidResolverInterface;
use Magento\TestFramework\Helper\Bootstrap;
/**
* @magentoAppIsolation enabled
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AbstractBlockTest extends \PHPUnit\Framework\TestCase
{
/**
* @var AbstractBlock
*/
protected $_block;
/**
* @var \Magento\Framework\View\LayoutInterface
*/
protected $_layout = null;
/**
* @var array
*/
protected static $_mocks = [];
/**
* @var SessionManagerInterface
*/
private $session;
protected function setUp(): void
{
/** @var \Magento\Framework\App\State $state */
$state = Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class);
$state->setAreaCode('frontend');
/** @var \Magento\Framework\View\DesignInterface $design */
$design = Bootstrap::getObjectManager()->get(\Magento\Framework\View\DesignInterface::class);
$design->setDefaultDesignTheme();
$this->_block = $this->getMockForAbstractClass(
AbstractBlock::class,
[
Bootstrap::getObjectManager()->get(
\Magento\Framework\View\Element\Context::class
),
['module_name' => 'Magento_Theme']
]
);
$this->session = Bootstrap::getObjectManager()->get(SessionManagerInterface::class);
}
/**
* Checks, that not existing image in CSS not affected own publication
*
* @magentoAppIsolation enabled
*/
public function testCssWithWrongImage()
{
$cssUrl = $this->_block->getViewFileUrl(
'css/wrong.css',
['area' => 'frontend', 'theme' => 'Magento/luma', 'locale' => 'en_US']
);
$this->assertStringMatchesFormat('%s/css/wrong.css', $cssUrl);
}
public function testGetRequest()
{
$this->assertInstanceOf(\Magento\Framework\App\RequestInterface::class, $this->_block->getRequest());
}
/**
* @magentoAppIsolation enabled
*/
public function testGetParentBlock()
{
// Without layout
$this->assertFalse($this->_block->getParentBlock());
// Need to create blocks through layout
$parentBlock = $this->_createBlockWithLayout('block1', 'block1', \Magento\Framework\View\Element\Text::class);
$childBlock = $this->_createBlockWithLayout('block2', 'block2');
$this->assertEmpty($childBlock->getParentBlock());
$parentBlock->setChild('block2', $childBlock);
$this->assertSame($parentBlock, $childBlock->getParentBlock());
}
/**
* @covers \Magento\Framework\View\Element\AbstractBlock::addChild
*/
public function testAddChild()
{
$parentBlock = $this->_createBlockWithLayout(
'testAddChild',
'testAddChild',
\Magento\Framework\View\Element\Text::class
);
$child = $parentBlock->addChild(
'testAddChildAlias',
\Magento\Framework\View\Element\Text::class,
['content' => 'content']
);
$this->assertInstanceOf(\Magento\Framework\View\Element\Text::class, $child);
$this->assertEquals('testAddChild.testAddChildAlias', $child->getNameInLayout());
$this->assertEquals($child, $parentBlock->getChildBlock('testAddChildAlias'));
$this->assertEquals('content', $child->getContent());
}
public function testSetGetNameInLayout()
{
// Basic setting/getting
$this->assertEmpty($this->_block->getNameInLayout());
$name = uniqid('name');
$this->_block->setNameInLayout($name);
$this->assertEquals($name, $this->_block->getNameInLayout());
// Setting second time, along with the layout
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
);
$layout->createBlock(\Magento\Framework\View\Element\Template::class, $name);
$block = $layout->getBlock($name);
$this->assertInstanceOf(AbstractBlock::class, $block);
$block->setNameInLayout($name);
$this->assertInstanceOf(AbstractBlock::class, $layout->getBlock($name));
$this->assertEquals($name, $block->getNameInLayout());
$this->assertTrue($layout->hasElement($name));
$newName = 'new_name';
$block->setNameInLayout($newName);
$this->assertTrue($layout->hasElement($newName));
$this->assertFalse($layout->hasElement($name));
}
/**
* @magentoAppIsolation enabled
* @covers \Magento\Framework\View\Element\AbstractBlock::getChildNames
* @covers \Magento\Framework\View\Element\AbstractBlock::insert
*/
public function testGetChildNames()
{
// Without layout
$this->assertEquals([], $this->_block->getChildNames());
// With layout
$parent = $this->_createBlockWithLayout('parent', 'parent');
$block1 = $this->_createBlockWithLayout('block1');
$block2 = $this->_createBlockWithLayout('block2');
$block3 = $this->_createBlockWithLayout('block3');
$block4 = $this->_createBlockWithLayout('block4');
$parent->insert($block1);
// add one block
$parent->insert($block2, 'block1', false);
// add second to the 1st position
$parent->insert($block3, 'block1', false);
// add third to the 2nd position
$parent->insert($block4, 'block3', true);
// add fourth block to the 3rd position
$this->assertEquals(['block2', 'block3', 'block4', 'block1'], $parent->getChildNames());
}
public function testSetAttribute()
{
$this->assertEmpty($this->_block->getSomeValue());
$this->_block->setAttribute('some_value', 'value');
$this->assertEquals('value', $this->_block->getSomeValue());
}
/**
* @magentoAppIsolation enabled
*/
public function testSetGetUnsetChild()
{
// With layout
$parent = $this->_createBlockWithLayout('parent', 'parent');
// Regular block
$nameOne = uniqid('block.');
$blockOne = $this->_createBlockWithLayout($nameOne, $nameOne);
$parent->setChild('block1', $blockOne);
$this->assertSame($blockOne, $parent->getChildBlock('block1'));
// Block factory name
$blockTwo = $this->_createBlockWithLayout('parent_block2', 'parent_block2');
$blockTwo->setChild('block2', $nameOne);
$this->assertSame($blockOne, $blockTwo->getChildBlock('block2'));
// No name block
$blockThree = $this->_createBlockWithLayout('');
$parent->setChild('block3', $blockThree);
$this->assertSame($blockThree, $parent->getChildBlock('block3'));
// Unset
$parent->unsetChild('block3');
$this->assertNotSame($blockThree, $parent->getChildBlock('block3'));
$parent->insert($blockOne, '', true, 'block1');
$this->assertContains($nameOne, $parent->getChildNames());
$parent->unsetChild('block1');
$this->assertNotSame($blockOne, $parent->getChildBlock('block1'));
$this->assertNotContains($nameOne, $parent->getChildNames());
}
/**
* @magentoAppIsolation enabled
*/
public function testUnsetCallChild()
{
$blockParent = $this->_createBlockWithLayout('parent', 'parent');
$block = $this->_createBlockWithLayout('block1', 'block1');
$block->setSomeValue(true);
$blockParent->setChild('block1', $block);
$this->assertSame($block, $blockParent->getChildBlock('block1'));
$blockParent->unsetCallChild('block1', 'getSomeValue', true, []);
$this->assertNotSame($block, $blockParent->getChildBlock('block1'));
}
/**
* @magentoAppIsolation enabled
* @covers \Magento\Framework\View\Element\AbstractBlock::unsetChildren
* @covers \Magento\Framework\View\Element\AbstractBlock::getChildBlock
*/
public function testUnsetChildren()
{
$parent = $this->_createBlockWithLayout('block', 'block');
$this->assertEquals([], $parent->getChildNames());
$blockOne = $this->_createBlockWithLayout('block1', 'block1');
$blockTwo = $this->_createBlockWithLayout('block2', 'block2');
$parent->setChild('block1', $blockOne);
$parent->setChild('block2', $blockTwo);
$this->assertSame($blockOne, $parent->getChildBlock('block1'));
$this->assertSame($blockTwo, $parent->getChildBlock('block2'));
$parent->unsetChildren();
$this->assertEquals([], $parent->getChildNames());
}
/**
* @magentoAppIsolation enabled
*/
public function testGetChildBlock()
{
$childAlias = 'child_alias';
$childName = 'child';
$parentName = 'parent';
// Without layout
$this->assertFalse($this->_block->getChildBlock($childAlias));
// With layout
/** @var $layout \Magento\Framework\View\Layout */
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
);
$child = $layout->createBlock(\Magento\Framework\View\Element\Text::class, $childName);
$layout->addBlock($this->_block, $parentName);
$this->_block->setChild($childAlias, $child);
$result = $this->_block->getChildBlock($childAlias);
$this->assertInstanceOf(\Magento\Framework\View\Element\Text::class, $result);
$this->assertEquals($childName, $result->getNameInLayout());
$this->assertEquals($child, $result);
}
/**
* @magentoAppIsolation enabled
* @covers \Magento\Framework\View\Element\AbstractBlock::getChildHtml
* @covers \Magento\Framework\View\Element\AbstractBlock::getChildChildHtml
*/
public function testGetChildHtml()
{
// Without layout
$this->assertEmpty($this->_block->getChildHtml());
$this->assertEmpty($this->_block->getChildHtml('block'));
// With layout
$parent = $this->_createBlockWithLayout('parent', 'parent');
$blockOne = $this->_createBlockWithLayout('block1', 'block1', \Magento\Framework\View\Element\Text::class);
$blockTwo = $this->_createBlockWithLayout('block2', 'block2', \Magento\Framework\View\Element\Text::class);
$blockOne->setText('one');
$blockTwo->setText('two');
$parent->insert($blockTwo, '-', false, 'block2');
// make block2 1st
$parent->insert($blockOne, '-', false, 'block1');
// make block1 1st
$this->assertEquals('one', $parent->getChildHtml('block1'));
$this->assertEquals('two', $parent->getChildHtml('block2'));
// GetChildChildHtml
$blockTwo->setChild('block11', $blockOne);
$this->assertEquals('one', $parent->getChildChildHtml('block2'));
$this->assertEquals('', $parent->getChildChildHtml(''));
$this->assertEquals('', $parent->getChildChildHtml('block3'));
}
/**
* @magentoAppIsolation enabled
*/
public function testGetChildChildHtml()
{
// Without layout
$this->assertEmpty($this->_block->getChildChildHtml('alias'));
// With layout
$parent1 = $this->_createBlockWithLayout('parent1', 'parent1');
$parent2 = $this->_createBlockWithLayout('parent2', 'parent2');
$block1 = $this->_createBlockWithLayout('block1', 'block1', \Magento\Framework\View\Element\Text::class);
$block2 = $this->_createBlockWithLayout('block2', 'block2', \Magento\Framework\View\Element\Text::class);
$block3 = $this->_createBlockWithLayout('block3', 'block3', \Magento\Framework\View\Element\Text::class);
$block4 = $this->_createBlockWithLayout('block4', 'block4', \Magento\Framework\View\Element\Text::class);
$block1->setText('one');
$block2->setText('two');
$block3->setText('three');
$block4->setText('four');
$parent1->insert($parent2);
$parent2->insert($block1, '-', false, 'block1');
$parent2->insert($block2, '-', false, 'block2');
$parent2->insert($block3, '-', true, 'block3');
$parent1->insert($block4);
$this->assertEquals('twoonethree', $parent1->getChildChildHtml('parent2'));
}
public function testGetBlockHtml()
{
// Without layout
/** @var $blockFactory \Magento\Framework\View\Element\BlockFactory */
$blockFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\Element\BlockFactory::class
);
$block1 = $blockFactory->createBlock(\Magento\Framework\View\Element\Text::class);
$block1->setText('Block text');
$block1->setNameInLayout('block');
$html = $this->_block->getBlockHtml('block');
$this->assertIsString($html);
$this->assertEmpty($html);
// With layout
$expected = 'Block2';
$block2 = $this->_createBlockWithLayout('block2', 'block2', \Magento\Framework\View\Element\Text::class);
$block3 = $this->_createBlockWithLayout('block3', 'block3');
$block2->setText($expected);
$html = $block3->getBlockHtml('block2');
$this->assertIsString($html);
$this->assertEquals($expected, $html);
}
/**
* @magentoAppIsolation enabled
*/
public function testInsertBlockWithoutName()
{
$parent = $this->_createBlockWithLayout('parent', 'parent');
$block = $this->_createBlockWithLayout('');
$parent->setChild('', $block);
$this->assertContains('abstractblockmock_0', $parent->getChildNames());
}
/**
* @magentoAppIsolation enabled
*/
public function testInsertBlockWithAlias()
{
$parent = $this->_createBlockWithLayout('parent', 'parent');
$block = $this->_createBlockWithLayout('block_name');
$parent->insert($block, '', true, 'block_alias');
$this->assertContains('block_name', $parent->getChildNames());
$this->assertSame($block, $parent->getChildBlock('block_alias'));
}
public function testInsertWithSibling()
{
$name1 = 'block_one';
$parent = $this->_createBlockWithLayout('parent', 'parent');
$blockOne = $this->_createBlockWithLayout($name1);
$parent->insert($blockOne);
$this->assertContains($name1, $parent->getChildNames());
$name2 = 'block_two';
$blockTwo = $this->_createBlockWithLayout($name2);
$parent->insert($blockTwo, 'wrong_sibling', false);
$this->assertSame(1, array_search($name2, $parent->getChildNames()));
$name3 = 'block_three';
$blockThree = $this->_createBlockWithLayout($name3);
$parent->insert($blockThree, $name2, false);
$this->assertSame(1, array_search($name3, $parent->getChildNames()));
$name4 = 'block_four';
$blockFour = $this->_createBlockWithLayout($name4);
$parent->insert($blockFour, $name1, true);
$this->assertSame(1, array_search($name4, $parent->getChildNames()));
}
/**
* @magentoAppIsolation enabled
*/
public function testInsertWithoutCreateBlock()
{
$this->expectException(\OutOfBoundsException::class);
$parent = $this->_createBlockWithLayout('parent', 'parent');
$parent->insert('block');
}
/**
* @magentoAppIsolation enabled
*/
public function testInsertContainer()
{
$parentName = 'parent';
$name = 'container';
$parent = $this->_createBlockWithLayout($parentName, $parentName);
$layout = $parent->getLayout();
$this->assertEmpty($layout->getChildNames($parentName));
$layout->addContainer($name, 'Container');
$parent->insert($name);
$this->assertEquals([$name], $layout->getChildNames($parentName));
}
/**
* @magentoAppIsolation enabled
*/
public function testAppend()
{
$parent = $this->_createBlockWithLayout('parent', 'parent');
$child1 = $this->_createBlockWithLayout('child1');
$parent->append($child1, 'child1');
$child2 = $this->_createBlockWithLayout('child2');
$parent->append($child2);
$this->assertEquals(['child1', 'child2'], $parent->getChildNames());
}
/**
* @magentoAppIsolation enabled
* @covers \Magento\Framework\View\Element\AbstractBlock::getGroupChildNames
* @covers \Magento\Framework\View\Layout::addToParentGroup
*/
public function testAddToParentGroup()
{
$parent = $this->_createBlockWithLayout('parent', 'parent');
$block1 = $this->_createBlockWithLayout('block1', 'block1');
$block2 = $this->_createBlockWithLayout('block2', 'block2');
$parent->setChild('block1', $block1)->setChild('block2', $block2);
$this->_layout->addToParentGroup('block1', 'group');
$this->_layout->addToParentGroup('block2', 'group');
$group = $parent->getGroupChildNames('group');
$this->assertContains('block1', $group);
$this->assertContains('block2', $group);
$this->assertSame($group[0], 'block1');
$this->assertSame($group[1], 'block2');
}
public function testGetChildData()
{
$parent = $this->_createBlockWithLayout('parent', 'parent');
$block = $this->_createBlockWithLayout('block', 'block');
$block->setSomeProperty('some_value');
$parent->setChild('block1', $block);
// all child data
$actualChildData = $parent->getChildData('block1');
$this->assertArrayHasKey('some_property', $actualChildData);
$this->assertEquals('some_value', $actualChildData['some_property']);
// specific child data key
$this->assertEquals('some_value', $parent->getChildData('block1', 'some_property'));
// non-existing child block
$this->assertNull($parent->getChildData('unknown_block'));
}
public function testGetUrl()
{
$base = 'http://localhost/index.php/';
$withRoute = "{$base}catalog/product/view/id/10/";
$this->assertEquals($base, $this->_block->getUrl());
$this->assertEquals($withRoute, $this->_block->getUrl('catalog/product/view', ['id' => 10]));
}
public function testGetViewFileUrl()
{
$actualResult = $this->_block->getViewFileUrl('css/styles.css');
$this->assertStringMatchesFormat(
'http://localhost/static/%s/frontend/%s/en_US/css/styles.css',
$actualResult
);
}
public function testGetModuleName()
{
$this->assertEquals('Magento_Theme', $this->_block->getModuleName());
$this->assertEquals('Magento_Theme', $this->_block->getData('module_name'));
}
/**
* @dataProvider escapeHtmlDataProvider
*/
public function testEscapeHtml($data, $expected)
{
$actual = $this->_block->escapeHtml($data);
$this->assertEquals($expected, $actual);
}
/**
* @return array
*/
public function escapeHtmlDataProvider()
{
return [
'array data' => [
'data' => ['one', '<two>three</two>'],
'expected' => ['one', '&lt;two&gt;three&lt;/two&gt;'],
],
'string data conversion' => [
'data' => '<two>three</two>',
'expected' => '&lt;two&gt;three&lt;/two&gt;',
],
'string data no conversion' => ['data' => 'one', 'expected' => 'one']
];
}
public function testStripTags()
{
$str = '<p>text</p>';
$this->assertEquals('text', $this->_block->stripTags($str));
}
public function testEscapeUrl()
{
$url = 'http://example.com/?wsdl=1';
$this->assertEquals($url, $this->_block->escapeUrl($url));
}
public function testEscapeJsQuote()
{
$script = "var s = 'text';";
$this->assertEquals('var s = \\\'text\\\';', $this->_block->escapeJsQuote($script));
}
public function testGetCacheKeyInfo()
{
$name = uniqid('block.');
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Framework\View\Element\Text::class
);
$block->setNameInLayout($name);
$this->assertEquals([$name], $block->getCacheKeyInfo());
}
public function testGetCacheKey()
{
$name = uniqid('block.');
$block = Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Framework\View\Element\Text::class
);
$block->setNameInLayout($name);
$key = $block->getCacheKey();
$this->assertNotEmpty($key);
$this->assertNotEquals('key', $key);
$this->assertNotEquals($name, $key);
$block->setCacheKey('key');
$this->assertEquals(AbstractBlock::CUSTOM_CACHE_KEY_PREFIX . 'key', $block->getCacheKey());
}
/**
* Check that SIDs inside blocks are not being replaced.
*
* @return void
* @magentoCache block_html enabled
*/
public function testNoSid(): void
{
$blockId = 'block-with-sid' .Random::getRandomNumber(1, 9999);
$block = $this->_createBlockWithLayout(
$blockId,
$blockId,
\Magento\Framework\View\Element\Text::class
);
$outerId = 'block-outer' .Random::getRandomNumber(1, 9999);
$outer = $this->_createBlockWithLayout($outerId, $outerId);
$block->setText(
$text = 'Some text with ' .SidResolverInterface::SESSION_ID_QUERY_PARAM
.'=' .$this->session->getSessionId()
);
$block->setData('cache_lifetime', 3600);
//Caching the block's content
$outer->getBlockHtml($blockId);
//New ID generated, must not be replace in block's content.
$this->session->regenerateId();
$html = $outer->getBlockHtml($blockId);
$this->assertEquals($text, $html);
}
/**
* Create <N> sample blocks
*
* @param int $qty
* @param bool $withLayout
* @param string $className
* @return array
*/
protected function _createSampleBlocks(
$qty,
$withLayout = true,
$className = \Magento\Framework\View\Element\Template::class
) {
$blocks = [];
$names = [];
$layout = false;
if ($withLayout) {
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
);
}
for ($i = 0; $i < $qty; $i++) {
$name = uniqid('block.');
if ($layout) {
$block = $layout->createBlock($className, $name);
} else {
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create($className);
$block->setNameInLayout($name);
}
$blocks[] = $block;
$names[] = $name;
}
return [$blocks, $names];
}
/**
* Create Block with Layout
*
* @param string $name
* @param null|string $alias
* @param null|string $type
* @return \Magento\Framework\View\Element\AbstractBlock
*/
protected function _createBlockWithLayout(
$name = 'block',
$alias = null,
$type = AbstractBlock::class
) {
$typePart = explode('\\', $type);
$mockClass = array_pop($typePart) . 'Mock';
if (!isset(self::$_mocks[$mockClass])) {
self::$_mocks[$mockClass] = $this->getMockForAbstractClass(
$type,
[
Bootstrap::getObjectManager()->get(
\Magento\Framework\View\Element\Context::class
),
['module_name' => 'Magento_Theme']
],
$mockClass
);
}
if ($this->_layout === null) {
$this->_layout = Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
);
}
$block = $this->_layout->addBlock($mockClass, $name, '', $alias);
return $block;
}
}
@@ -0,0 +1,122 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Element;
use Magento\Framework\App\Area;
class TemplateTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Element\Template
*/
protected $_block;
/**
* @var \Magento\TestFramework\ObjectManager
*/
protected $objectManager;
/**
* @var string
*/
private $origMode;
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$params = ['layout' => $this->objectManager->create(\Magento\Framework\View\Layout::class, [])];
$context = $this->objectManager->create(\Magento\Framework\View\Element\Template\Context::class, $params);
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Framework\View\Element\Template::class,
'',
['context' => $context]
);
/** @var \Magento\TestFramework\App\State $appState */
$appState = $this->objectManager->get(\Magento\TestFramework\App\State::class);
$this->origMode = $appState->getMode();
}
/**
* {@inheritDoc}
*/
protected function tearDown(): void
{
/** @var \Magento\TestFramework\App\State $appState */
$appState = $this->objectManager->get(\Magento\TestFramework\App\State::class);
$appState->setMode($this->origMode);
parent::tearDown();
}
public function testConstruct()
{
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Framework\View\Element\Template::class,
'',
['data' => ['template' => 'value']]
);
$this->assertEquals('value', $block->getTemplate());
}
public function testSetGetTemplate()
{
$this->assertEmpty($this->_block->getTemplate());
$this->_block->setTemplate('value');
$this->assertEquals('value', $this->_block->getTemplate());
}
public function testGetArea()
{
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
->setAreaCode('frontend');
$this->assertEquals('frontend', $this->_block->getArea());
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\App\State::class
)->setAreaCode(Area::AREA_ADMINHTML);
$this->assertEquals(Area::AREA_ADMINHTML, $this->_block->getArea());
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\App\State::class
)->setAreaCode(Area::AREA_GLOBAL);
$this->assertEquals(Area::AREA_GLOBAL, $this->_block->getArea());
}
/**
* @covers \Magento\Framework\View\Element\AbstractBlock::toHtml
* @see testAssign()
*/
public function testToHtml()
{
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
->setAreaCode(Area::AREA_GLOBAL);
/** @var \Magento\TestFramework\App\State $appState */
$appState = $this->objectManager->get(\Magento\TestFramework\App\State::class);
$appState->setMode(\Magento\TestFramework\App\State::MODE_DEFAULT);
$this->assertEmpty($this->_block->toHtml());
$this->_block->setTemplate(uniqid('invalid_filename.phtml'));
$this->assertEmpty($this->_block->toHtml());
}
public function testGetBaseUrl()
{
$this->assertEquals('http://localhost/index.php/', $this->_block->getBaseUrl());
}
public function testGetObjectData()
{
$object = new \Magento\Framework\DataObject(['key' => 'value']);
$this->assertEquals('value', $this->_block->getObjectData($object, 'key'));
}
public function testGetCacheKeyInfo()
{
$this->_block->setTemplate('non-existing-template.phtml');
$this->assertArrayHasKey('template', $this->_block->getCacheKeyInfo());
}
}
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Element\Text;
class ListTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\LayoutInterface
*/
protected $_layout;
/**
* @var \Magento\Framework\View\Element\Text\ListText
*/
protected $_block;
protected function setUp(): void
{
$this->_layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
);
$this->_block = $this->_layout->createBlock(\Magento\Framework\View\Element\Text\ListText::class);
}
public function testToHtml()
{
$children = [
['block1', \Magento\Framework\View\Element\Text::class, 'text1'],
['block2', \Magento\Framework\View\Element\Text::class, 'text2'],
['block3', \Magento\Framework\View\Element\Text::class, 'text3'],
];
foreach ($children as $child) {
$this->_layout->addBlock($child[1], $child[0], $this->_block->getNameInLayout())->setText($child[2]);
}
$html = $this->_block->toHtml();
$this->assertEquals('text1text2text3', $html);
}
public function testToHtmlWithContainer()
{
$listName = $this->_block->getNameInLayout();
$block1 = $this->_layout->addBlock(\Magento\Framework\View\Element\Text::class, '', $listName);
$this->_layout->addContainer('container', 'Container', [], $listName);
$block2 = $this->_layout->addBlock(\Magento\Framework\View\Element\Text::class, '', 'container');
$block3 = $this->_layout->addBlock(\Magento\Framework\View\Element\Text::class, '', $listName);
$block1->setText('text1');
$block2->setText('text2');
$block3->setText('text3');
$html = $this->_block->toHtml();
$this->assertEquals('text1text2text3', $html);
}
}
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Element;
class TextTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Element\Text
*/
protected $_block;
protected function setUp(): void
{
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\View\LayoutInterface::class
)->createBlock(
\Magento\Framework\View\Element\Text::class
);
}
public function testSetGetText()
{
$this->_block->setText('text');
$this->assertEquals('text', $this->_block->getText());
}
public function testAddText()
{
$this->_block->addText('a');
$this->assertEquals('a', $this->_block->getText());
$this->_block->addText('b');
$this->assertEquals('ab', $this->_block->getText());
$this->_block->addText('c', false);
$this->assertEquals('abc', $this->_block->getText());
$this->_block->addText('-', true);
$this->assertEquals('-abc', $this->_block->getText());
}
public function testToHtml()
{
$this->_block->setText('test');
$this->assertEquals('test', $this->_block->toHtml());
}
}
@@ -0,0 +1,78 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Element\UiComponent\Config\Provider;
use \Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\CacheCleaner;
/**
* @magentoComponentsDir Magento/Framework/View/_files/UiComponent/theme
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
class TemplateTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var \Magento\Framework\View\Element\UiComponent\Config\Provider\Template
*/
private $model;
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->registerThemes();
$this->objectManager->addSharedInstance(
$this->objectManager->create(
\Magento\Framework\App\Arguments\ValidationState::class,
['appMode' => 'default']
),
\Magento\Framework\App\Arguments\ValidationState::class
);
$this->model = $this->objectManager->create(
\Magento\Framework\View\Element\UiComponent\Config\Provider\Template::class
);
}
public function testGetTemplate()
{
$expected = file_get_contents(__DIR__ . '/../../../../_files/UiComponent/expected/config.xml');
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('adminhtml');
$this->objectManager->get(\Magento\Framework\View\DesignInterface::class)
->setDesignTheme('FrameworkViewUiComponent/default');
$resultOne = $this->model->getTemplate('test.xml');
$resultTwo = $this->model->getTemplate('test.xml');
$this->assertXmlStringEqualsXmlString($expected, $resultOne);
$this->assertXmlStringEqualsXmlString($expected, $resultTwo);
}
/**
* Register themes in the fixture folder
*/
protected function registerThemes()
{
/** @var \Magento\Theme\Model\Theme\Registration $registration */
$registration = $this->objectManager->get(
\Magento\Theme\Model\Theme\Registration::class
);
$registration->register();
}
protected function tearDown(): void
{
$this->objectManager->removeSharedInstance(
\Magento\Framework\App\Arguments\ValidationState::class
);
}
}
@@ -0,0 +1,104 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\View\Element\UiComponent;
use Magento\Framework\Api\Search\SearchCriteria;
use Magento\Framework\App\RequestInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Ui\Component\Form;
use Magento\Ui\Component\FormFactory;
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface;
/**
* Test UI component context.
*/
class ContextTest extends TestCase
{
/**
* @var RequestInterface
*/
private $request;
/**
* @var ContextFactory
*/
private $contextFactory;
/**
* @var FormFactory
*/
private $componentFactory;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->request = Bootstrap::getObjectManager()->get(RequestInterface::class);
$this->contextFactory = Bootstrap::getObjectManager()->get(ContextFactory::class);
$this->componentFactory = Bootstrap::getObjectManager()->get(FormFactory::class);
}
/**
* Generate provider for the test.
*
* @return DataProviderInterface
*/
private function generateMockProvider(): DataProviderInterface
{
/** @var DataProviderInterface|MockObject $mock */
$mock = $this->getMockForAbstractClass(DataProviderInterface::class);
$mock->method('getName')->willReturn('test');
$mock->method('getPrimaryFieldName')->willReturn('id');
$mock->method('getRequestFieldName')->willReturn('id');
$mock->method('getData')->willReturn(['id' => ['some_field' => '${\'some_value\'}']]);
$mock->method('getConfigData')->willReturn([]);
$mock->method('getFieldMetaInfo')->willReturn([]);
$mock->method('getFieldSetMetaInfo')->willReturn('id');
$mock->method('getFieldsMetaInfo')->willReturn('id');
$mock->method('getSearchCriteria')->willReturn(new SearchCriteria());
$mock->method('getSearchResult')->willReturn([]);
return $mock;
}
/**
* Check processed provider data.
*
* @return void
*/
public function testGetDataSourceData(): void
{
$dataProvider = $this->generateMockProvider();
$context = $this->contextFactory->create(['dataProvider' => $dataProvider]);
/** @var Form $component */
$component = $this->componentFactory->create(['context' => $context]);
$this->request->setParams(['id' => 'id']);
$data = $context->getDataSourceData($component);
$this->assertEquals(
[
'test' => [
'type' => 'dataSource',
'name' => 'test',
'dataScope' => null,
'config' => [
'data' => ['some_field' => '${\'some_value\'}', '__disableTmpl' => ['some_field' => true]],
'params' => [
'namespace' => null,
'id' => 'id'
]]
]
],
$data
);
}
}
@@ -0,0 +1,175 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\View\Element\UiComponent\DataProvider;
use Magento\Framework\Api\Filter;
use Magento\Framework\Api\Search\FilterGroup;
use Magento\Framework\Api\Search\SearchCriteriaInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Represents FilterPool methods test class
*/
class ReportingTest extends TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
}
/**
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php
* @magentoDbIsolation disabled
* @dataProvider filtersDataProvider
* @param array $filters
* @param int $expectedCount
*/
public function testSearchItemsByOrCondition(array $filters, int $expectedCount): void
{
$filterGroups = [];
$filterGroups[] = $this->objectManager->create(FilterGroup::class)
->setFilters(
[
$this->objectManager->create(Filter::class, ['data' => $filters[0]]),
$this->objectManager->create(Filter::class, ['data' => $filters[1]]),
]
);
$filterGroups[] = $this->objectManager->create(FilterGroup::class)
->setFilters([$this->objectManager->create(Filter::class, ['data' => $filters[2]])]);
if (isset($filters[3], $filters[4])) {
$filterGroups[] = $this->objectManager->create(FilterGroup::class)
->setFilters(
[
$this->objectManager->create(Filter::class, ['data' => $filters[3]]),
$this->objectManager->create(Filter::class, ['data' => $filters[4]]),
]
);
}
/** @var SearchCriteriaInterface $searchCriteria */
$searchCriteria = $this->objectManager->get(SearchCriteriaInterface::class);
$searchCriteria->setFilterGroups($filterGroups);
$searchCriteria->setRequestName('customer_listing_data_source');
$searchCriteria->setSortOrders([]);
/** @var Reporting $reporting */
$reporting = $this->objectManager->get(Reporting::class);
$collection = $reporting->search($searchCriteria);
self::assertCount($expectedCount, $collection->getItems(), 'Wrong collection filters applied');
}
/**
* @return array[]
*/
public function filtersDataProvider()
{
return [
'variation 1 (filter OR filter) AND filter' => [
'filters' => [
[
'field' => 'email',
'value' => '%1%',
'condition_type' => 'like',
],
[
'field' => 'email',
'value' => '%2%',
'condition_type' => 'like',
],
[
'field' => 'name',
'value' => 'John Smith',
'condition_type' => 'eq',
],
],
'expected_count' => 2,
],
'variation 2 (filter OR filter) AND filter' => [
'filters' => [
[
'field' => 'email',
'value' => '%1%',
'condition_type' => 'like',
],
[
'field' => 'name',
'value' => 'John Smith',
'condition_type' => 'eq',
],
[
'field' => 'email',
'value' => '%example%',
'condition_type' => 'like',
],
],
'expected_count' => 5,
],
'variation 3 (filter OR filter) AND filter' => [
'filters' => [
[
'field' => 'email',
'value' => 'customer%',
'condition_type' => 'like',
],
[
'field' => 'name',
'value' => 'John%',
'condition_type' => 'like',
],
[
'field' => 'email',
'value' => 'customer2@example.com',
'condition_type' => 'eq',
],
],
'expected_count' => 1,
],
'variation (filter OR filter) AND filter AND (filter OR filter)' => [
'filters' => [
[
'field' => 'email',
'value' => 'customer%',
'condition_type' => 'like',
],
[
'field' => 'name',
'value' => 'Test',
'condition_type' => 'eq',
],
[
'field' => 'email',
'value' => 'customer%@example.com',
'condition_type' => 'like',
],
[
'field' => 'name',
'value' => 'non existing',
'condition_type' => 'like',
],
[
'field' => 'email',
'value' => 'customer3%',
'condition_type' => 'like',
],
],
'expected_count' => 1,
],
];
}
}
@@ -0,0 +1,168 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\View\Element;
use Magento\Framework\Api\Search\SearchCriteria;
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Framework\Config\DataInterface as ConfigData;
use Magento\Framework\Config\DataInterfaceFactory as ConfigDataFactory;
/**
* Test the component factory.
*/
class UiComponentFactoryTest extends TestCase
{
/**
* @var UiComponentFactoryFactory
*/
private $factory;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->factory = Bootstrap::getObjectManager()->get(UiComponentFactoryFactory::class);
}
/**
* Create factory with mock config provided.
*
* @param array $mockConfig
* @return UiComponentFactory
*/
private function createFactory(array $mockConfig): UiComponentFactory
{
$dataMock = $this->getMockForAbstractClass(ConfigData::class);
$dataMock->method('get')->willReturnCallback(
function (string $id) use ($mockConfig) : array {
return $mockConfig[$id];
}
);
$dataFactoryMock = $this->getMockBuilder(ConfigDataFactory::class)
->disableOriginalConstructor()
->getMock();
$dataFactoryMock->method('create')->willReturn($dataMock);
return $this->factory->create(['configFactory' => $dataFactoryMock]);
}
/**
* Test creating a component.
*
* @return void
* @magentoAppArea adminhtml
*/
public function testCreate(): void
{
//Mocking component config.
$factory = $this->createFactory([
'test' => [
'arguments' => ['data' => ['config' => ['component' => 'uiComponent']]],
'attributes' => [
'name' => 'test',
'sorting' => true,
'class' => 'Magento\Ui\Component\Listing',
'component' => 'uiComponent'
],
'children' => [
'test_child' => [
'arguments' => [
'data' => ['config' => ['component' => 'uiComponent']],
'dataProvider' => $this->generateMockProvider()
],
'attributes' => [
'name' => 'test_child',
'sorting' => true,
'class' => 'Magento\Ui\Component\Listing',
'component' => 'uiComponent'
],
'children' => []
]
]
],
'test_child_child' => [
'arguments' => [
'data' => [
'config' => [
'component' => 'uiComponent',
'label' => '${\'Label\'}',
'componentType' => 'component'
]
],
],
'attributes' => [
'name' => 'test_child_child',
'sorting' => true,
'class' => 'Magento\Ui\Component\Listing',
'component' => 'uiComponent'
],
'children' => []
]
]);
$component = $factory->create('test', null, ['data' => ['label' => '${\'Label\'}']]);
$componentData = $component->getData();
//Arguments passed must be sanitized
$this->assertArrayHasKey('__disableTmpl', $componentData);
$this->assertEquals(['label' => true], $componentData['__disableTmpl']);
//Metadata provided by the dataProvider must be sanitized as well.
$this->assertArrayHasKey('test_child_child', $childData = $component->getChildComponents());
$childData = $component->getChildComponents()['test_child_child']->getData()['config'];
$this->assertArrayHasKey('__disableTmpl', $childData);
$this->assertEquals(['label' => true], $childData['__disableTmpl']);
}
/**
* Generate provider for the test.
*
* @return DataProviderInterface
*/
private function generateMockProvider(): DataProviderInterface
{
/** @var DataProviderInterface|MockObject $mock */
$mock = $this->getMockForAbstractClass(DataProviderInterface::class);
$mock->method('getName')->willReturn('test');
$mock->method('getPrimaryFieldName')->willReturn('id');
$mock->method('getRequestFieldName')->willReturn('id');
$mock->method('getData')->willReturn([]);
$mock->method('getConfigData')->willReturn([]);
$mock->method('getFieldMetaInfo')->willReturn([]);
$mock->method('getFieldSetMetaInfo')->willReturn('id');
$mock->method('getFieldsMetaInfo')->willReturn('id');
$mock->method('getSearchCriteria')->willReturn(new SearchCriteria());
$mock->method('getSearchResult')->willReturn([]);
$mock->method('getMeta')->willReturn(
[
'test_child_child' => [
'arguments' => [
'data' => [
'config' => [
'component' => 'uiComponent',
'label' => '${\'Label\'}',
'componentType' => 'component'
]
],
],
'attributes' => [
'name' => 'test_child_child',
'sorting' => true,
'class' => 'Magento\Ui\Component\Listing',
'component' => 'uiComponent'
]
]
]
);
return $mock;
}
}
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
.test {background: url(../images/nonexistent_file.png);}
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View;
use \Magento\TestFramework\Helper\Bootstrap;
/**
* Tests for the view layer fallback mechanism
* @magentoComponentsDir Magento/Theme/Model/_files/design
* @magentoDbIsolation enabled
*/
class FileSystemTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\FileSystem
*/
protected $_model = null;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
/** @var \Magento\Theme\Model\Theme\Registration $registration */
$registration = $objectManager->get(
\Magento\Theme\Model\Theme\Registration::class
);
$registration->register();
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
$this->_model = $objectManager->create(
\Magento\Framework\View\FileSystem::class
);
$objectManager->get(
\Magento\Framework\View\DesignInterface::class
)->setDesignTheme(
'Test_FrameworkThemeTest/default'
);
}
public function testGetTemplateFileName()
{
$expected = '%s/frontend/Test/default/Magento_Catalog/templates/theme_template.phtml';
$actual = $this->_model->getTemplateFileName('Magento_Catalog::theme_template.phtml', []);
$this->_testExpectedVersusActualFilename($expected, $actual);
}
public function testGetFileNameAccordingToLocale()
{
$expected = '%s/frontend/Test/default/web/i18n/fr_FR/logo.gif';
$actual = $this->_model->getStaticFileName('logo.gif', ['locale' => 'fr_FR']);
$this->_testExpectedVersusActualFilename($expected, $actual);
}
/**
* @magentoComponentsDir Magento/Framework/View/_files/Fixture_Module
*/
public function testGetViewFile()
{
$expected = '%s/frontend/Vendor/custom_theme/Fixture_Module/web/fixture_script.js';
$params = ['theme' => 'Vendor_FrameworkThemeTest/custom_theme'];
$actual = $this->_model->getStaticFileName('Fixture_Module::fixture_script.js', $params);
$this->_testExpectedVersusActualFilename($expected, $actual);
}
/**
* Tests expected vs actual found fallback filename
*
* @param string $expected
* @param string $actual
*/
protected function _testExpectedVersusActualFilename($expected, $actual)
{
$this->assertStringMatchesFormat($expected, $actual);
$this->assertFileExists($actual);
}
}
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Fixture\Block;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
use Magento\Framework\View\LayoutInterface;
class BrokenAction extends \Magento\Framework\View\Element\AbstractBlock
{
/**
* @param LayoutInterface $layout
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setLayout(LayoutInterface $layout)
{
return $this;
}
/**
* @param string $action
* @throws LocalizedException
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function initAction($action)
{
throw new LocalizedException(new Phrase('Init action problem.'));
}
/**
* Produce and return block's html output
*
* @return string
*/
public function toHtml()
{
return '<p>Rendered with action problem.</p>';
}
}
@@ -0,0 +1,30 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Fixture\Block;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
class BrokenConstructor extends \Magento\Framework\View\Element\AbstractBlock
{
/**
* @throws LocalizedException
*/
public function __construct()
{
throw new LocalizedException(new Phrase('Construction problem.'));
}
/**
* Produce and return block's html output
*
* @return string
*/
public function toHtml()
{
return '<p>Rendered with construction problem.</p>';
}
}
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Fixture\Block;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
use Magento\Framework\View\LayoutInterface;
class BrokenLayout extends \Magento\Framework\View\Element\AbstractBlock
{
/**
* @param LayoutInterface $layout
* @throws LocalizedException
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setLayout(LayoutInterface $layout)
{
throw new LocalizedException(new Phrase('Prepare layout problem.'));
}
/**
* Produce and return block's html output
*
* @return string
*/
public function toHtml()
{
return '<p>Rendered with layout problem.</p>';
}
}
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\View\Helper;
use Magento\TestFramework\TestCase\AbstractController;
/**
* Test the secure HTML helper and templates.
*
* @magentoAppArea frontend
*/
class SecureHtmlRendererTemplateTest extends AbstractController
{
/**
* Test using the helper inside templates.
*
* @return void
*/
public function testTemplateUsage(): void
{
$this->getRequest()->setMethod('GET');
$this->dispatch('securehtml/secure/helper');
$content = $this->getResponse()->getContent();
$this->assertStringContainsString(
'<h1 onclick="alert&#x28;&#x29;">Hello there!</h1>',
$content
);
$this->assertStringContainsString(
'<script src="http&#x3A;&#x2F;&#x2F;my.magento.com&#x2F;static&#x2F;script.js"></script>',
$content
);
$this->assertStringContainsString(
"<script>\n let myVar = 1;\n</script>",
$content
);
$this->assertStringContainsString(
'<div>I am just &lt;a&gt; text</div>',
$content
);
}
}
@@ -0,0 +1,141 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\View\Helper;
use Magento\Framework\View\Helper\SecureHtmlRender\TagData;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Test for the secure HTML helper.
*/
class SecureHtmlRendererTest extends TestCase
{
/**
* @var SecureHtmlRenderer
*/
private $helper;
/**
* @inheritDoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
//Clearing the processors list to ensure stable results.
$this->helper = $objectManager->create(SecureHtmlRenderer::class, ['processors' => []]);
}
/**
* Provides tags to render.
*
* @return array
*/
public function getTags(): array
{
return [
[
new TagData('div', ['style' => 'display: none;', 'width' => '20px'], 'some <text>', true),
'<div style="display&#x3A;&#x20;none&#x3B;" width="20px">some &lt;text&gt;</div>'
],
[
new TagData('div', [], 'some <b>HTML</b>', false),
'<div>some <b>HTML</b></div>'
],
[
new TagData('img', ['src' => 'https://magento.com/img.jpg'], null, true),
'<img src="https&#x3A;&#x2F;&#x2F;magento.com&#x2F;img.jpg"/>'
]
];
}
/**
* Test tag rendering.
*
* @param TagData $tagData
* @param string $expected Expected HTML.
* @return void
* @dataProvider getTags
*/
public function testRenderTag(TagData $tagData, string $expected): void
{
$this->assertEquals(
$expected,
$this->helper->renderTag(
$tagData->getTag(),
$tagData->getAttributes(),
$tagData->getContent(),
$tagData->isTextContent()
)
);
}
/**
* Test rendering an event listener.
*
* @return void
*/
public function testRenderEventHandler(): void
{
$this->assertEquals(
'onclick="alert&#x28;this.parent.getAttribute&#x28;&quot;data-title&quot;&#x29;&#x29;"',
$this->helper->renderEventListener('onclick', 'alert(this.parent.getAttribute("data-title"))')
);
}
/**
* Test rendering JS listeners as separate tags.
*
* @return void
*/
public function testRenderEventListenerAsTag(): void
{
$html = $this->helper->renderEventListenerAsTag('onclick', 'alert(1)', '#id');
$this->assertStringContainsString('alert(1)', $html);
$this->assertStringContainsString('#id', $html);
$this->assertStringContainsString('click', $html);
}
/**
* Check handler validation
*
* @return void
*/
public function testInvalidEventListener(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->helper->renderEventListenerAsTag('nonevent', '', '');
}
/**
* Test rendering "style" attribute as separate tag.
*
* @return void
*/
public function testRenderStyleAsTag(): void
{
$html = $this->helper->renderStyleAsTag('display: none; font-size: 3em; ', '#id');
$this->assertStringContainsString('#id', $html);
$this->assertStringContainsString('display', $html);
$this->assertStringContainsString('none', $html);
$this->assertStringContainsString('fontSize', $html);
$this->assertStringContainsString('3em', $html);
}
/**
* Check style validation
*
* @return void
*/
public function testInvalidStyle(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->helper->renderStyleAsTag('display;', '');
}
}
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Layout;
class ElementTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Layout\Element
*/
protected $model;
public function testPrepare()
{
/**
* @TODO: Need to use ObjectManager instead 'new'.
* On this moment we have next bug MAGETWO-4274 which blocker for this key.
*/
$this->model = new \Magento\Framework\View\Layout\Element(__DIR__ . '/_files/_layout_update.xml', 0, true);
list($blockNode) = $this->model->xpath('//block[@name="nodeForTesting"]');
list($actionNode) = $this->model->xpath('//action[@method="setSomething"]');
$this->assertEmpty($blockNode->attributes()->parent);
$this->assertEmpty($actionNode->attributes()->block);
$this->model->prepare();
$this->assertEquals('root', (string)$blockNode->attributes()->parent);
$this->assertEquals(\Magento\Backend\Block\Page::class, (string)$blockNode->attributes()->class);
$this->assertEquals('nodeForTesting', (string)$actionNode->attributes()->block);
}
}
@@ -0,0 +1,470 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Layout;
use Magento\Framework\App\State;
use Magento\Framework\Phrase;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class MergeTest extends \PHPUnit\Framework\TestCase
{
/**
* Fixture XML instruction(s) to be used in tests
*/
// @codingStandardsIgnoreStart
const FIXTURE_LAYOUT_XML = '<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>';
// @codingStandardsIgnoreEnd
/**
* @var \Magento\Framework\View\Model\Layout\Merge
*/
protected $_model;
/**
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $_resource;
/**
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $_appState;
/**
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $_cache;
/**
* @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $_serializer;
/**
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $_theme;
/**
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $scope;
/**
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $_logger;
/**
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $_layoutValidator;
/**
* @var \Magento\Framework\View\Page\Config|\PHPUnit\Framework\MockObject\MockObject
*/
protected $pageConfig;
/**
* @var LayoutCacheKeyInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $layoutCacheKeyMock;
protected function setUp(): void
{
$files = [];
$fileDriver = new \Magento\Framework\Filesystem\Driver\File();
foreach ($fileDriver->readDirectory(__DIR__ . '/_mergeFiles/layout/') as $filename) {
$files[] = new \Magento\Framework\View\File($filename, 'Magento_Widget');
}
$fileSource = $this->getMockForAbstractClass(\Magento\Framework\View\File\CollectorInterface::class);
$fileSource->expects($this->any())->method('getFiles')->willReturn($files);
$pageLayoutFileSource = $this->getMockForAbstractClass(\Magento\Framework\View\File\CollectorInterface::class);
$pageLayoutFileSource->expects($this->any())->method('getFiles')->willReturn([]);
$design = $this->getMockForAbstractClass(\Magento\Framework\View\DesignInterface::class);
$this->scope = $this->createMock(\Magento\Framework\Url\ScopeInterface::class);
$this->scope->expects($this->any())->method('getId')->willReturn(20);
$scopeResolver = $this->getMockForAbstractClass(\Magento\Framework\Url\ScopeResolverInterface::class);
$scopeResolver->expects($this->once())->method('getScope')->with(null)->willReturn($this->scope);
$this->_resource = $this->createMock(\Magento\Widget\Model\ResourceModel\Layout\Update::class);
$this->_appState = $this->createMock(\Magento\Framework\App\State::class);
$this->_logger = $this->createMock(\Psr\Log\LoggerInterface::class);
$this->_layoutValidator = $this->createMock(\Magento\Framework\View\Model\Layout\Update\Validator::class);
$this->_cache = $this->getMockForAbstractClass(\Magento\Framework\Cache\FrontendInterface::class);
$this->_serializer = $this->getMockForAbstractClass(\Magento\Framework\Serialize\SerializerInterface::class);
$this->_theme = $this->createMock(\Magento\Theme\Model\Theme::class);
$this->_theme->expects($this->any())->method('isPhysical')->willReturn(true);
$this->_theme->expects($this->any())->method('getArea')->willReturn('area');
$this->_theme->expects($this->any())->method('getId')->willReturn(100);
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->pageConfig = $this->getMockBuilder(\Magento\Framework\View\Page\Config::class)
->disableOriginalConstructor()
->getMock();
$readFactory = $this->createMock(\Magento\Framework\Filesystem\File\ReadFactory::class);
$fileReader = $this->createMock(\Magento\Framework\Filesystem\File\Read::class);
$readFactory->expects($this->any())->method('create')->willReturn($fileReader);
$fileDriver = $objectHelper->getObject(\Magento\Framework\Filesystem\Driver\File::class);
$fileReader->expects($this->any())->method('readAll')
->willReturnCallback(
function ($filename) use ($fileDriver) {
return $fileDriver->fileGetContents(__DIR__ . '/_mergeFiles/layout/' . $filename);
}
);
$this->layoutCacheKeyMock = $this->getMockForAbstractClass(LayoutCacheKeyInterface::class);
$this->layoutCacheKeyMock->expects($this->any())
->method('getCacheKeys')
->willReturn([]);
$this->_model = $objectHelper->getObject(
\Magento\Framework\View\Model\Layout\Merge::class,
[
'design' => $design,
'scopeResolver' => $scopeResolver,
'fileSource' => $fileSource,
'pageLayoutFileSource' => $pageLayoutFileSource,
'resource' => $this->_resource,
'appState' => $this->_appState,
'cache' => $this->_cache,
'serializer' => $this->_serializer,
'theme' => $this->_theme,
'validator' => $this->_layoutValidator,
'logger' => $this->_logger,
'readFactory' => $readFactory,
'pageConfig' => $this->pageConfig,
'layoutCacheKey' => $this->layoutCacheKeyMock,
]
);
}
public function testAddUpdate()
{
$this->assertEmpty($this->_model->asArray());
$this->assertEmpty($this->_model->asString());
$this->_model->addUpdate('test');
$this->assertEquals(['test'], $this->_model->asArray());
$this->assertEquals('test', $this->_model->asString());
}
public function testAddHandle()
{
$this->assertEmpty($this->_model->getHandles());
$this->_model->addHandle('test');
$this->assertEquals(['test'], $this->_model->getHandles());
}
public function testRemoveHandle()
{
$this->_model->addHandle('test');
$this->_model->removeHandle('test');
$this->assertEmpty($this->_model->getHandles());
}
public function testAddPageHandles()
{
/* add a non-page handle to verify that it won't be affected during page handles manipulation */
$nonPageHandles = ['non_page_handle'];
$this->_model->addHandle($nonPageHandles);
$this->assertFalse($this->_model->addPageHandles(['non_existing_handle']));
$this->assertEmpty($this->_model->getPageHandles());
$this->assertEquals($nonPageHandles, $this->_model->getHandles());
/* test that only the first existing handle is taken into account */
$handlesToTry = [
'default',
'catalog_category_default',
'catalog_product_view',
'catalog_product_view_type_simple',
];
$expectedPageHandles = [
'default',
'catalog_category_default',
'catalog_product_view',
'catalog_product_view_type_simple',
];
$this->assertTrue($this->_model->addPageHandles($handlesToTry));
$this->assertEquals($expectedPageHandles, $this->_model->getPageHandles());
$this->assertEquals(array_merge($nonPageHandles, $expectedPageHandles), $this->_model->getHandles());
/* test that new handles override the previous ones */
$expectedPageHandles = ['default', 'checkout_index_index'];
$this->_model->removeHandle('catalog_category_default');
$this->_model->removeHandle('catalog_product_view');
$this->_model->removeHandle('catalog_product_view_type_simple');
$this->assertTrue($this->_model->addPageHandles(['default', 'checkout_index_index']));
$this->assertEquals($expectedPageHandles, $this->_model->getPageHandles());
$this->assertEquals(array_merge($nonPageHandles, $expectedPageHandles), $this->_model->getHandles());
}
/**
* @dataProvider pageHandleExistsDataProvider
*/
public function testPageHandleExists($inputPageHandle, $expectedResult)
{
$this->assertSame($expectedResult, $this->_model->pageHandleExists($inputPageHandle));
}
public function pageHandleExistsDataProvider()
{
return [
'non-existing handle' => ['non_existing_handle', false],
'existing page type' => ['default', true],
];
}
public function testLoadFileSystem()
{
$handles = ['fixture_handle_one', 'fixture_handle_two'];
$this->assertEmpty($this->_model->getHandles());
$this->assertEmpty($this->_model->asString());
$this->_model->load($handles);
$this->assertEquals($handles, $this->_model->getHandles());
$expectedResult = '
<root>
<body>
<block class="Magento\Framework\View\Element\Template"
template="Magento_Framework::fixture_template_one.phtml"/>
</body>
<body>
<block class="Magento\Framework\View\Element\Template"
template="Magento_Framework::fixture_template_two.phtml"/>
</body>
</root>
';
$actualResult = '<root>' . $this->_model->asString() . '</root>';
$this->assertXmlStringEqualsXmlString($expectedResult, $actualResult);
}
public function testLoadFileSystemWithPageLayout()
{
$handles = ['fixture_handle_with_page_layout'];
$expectedHandles = ['fixture_handle_with_page_layout'];
$expectedResult = '
<root>
<body>
<referenceContainer name="main.container">
<block class="Magento\Framework\View\Element\Template"
template="Magento_Framework::fixture_template_one.phtml"/>
</referenceContainer>
</body>
</root>
';
$this->assertEmpty($this->_model->getHandles());
$this->assertEmpty($this->_model->asString());
$this->_model->load($handles);
$this->assertEquals($expectedHandles, $this->_model->getHandles());
$actualResult = '<root>' . $this->_model->asString() . '</root>';
$this->assertXmlStringEqualsXmlString($expectedResult, $actualResult);
$this->assertEquals('fixture_handle_page_layout', $this->_model->getPageLayout());
}
public function testLoadCache()
{
$cacheValue = [
"pageLayout" => "1column",
"layout" => self::FIXTURE_LAYOUT_XML
];
$this->_cache
->method('load')
->withConsecutive(['LAYOUT_area_STORE20_100c6a4ccd050e33acef0553f24ef399961_page_layout_merged'])
->willReturnOnConsecutiveCalls(json_encode($cacheValue));
$this->_serializer->expects($this->once())->method('unserialize')->willReturn($cacheValue);
$this->assertEmpty($this->_model->getHandles());
$this->assertEmpty($this->_model->asString());
$handles = ['fixture_handle_one', 'fixture_handle_two'];
$this->_model->load($handles);
$this->assertEquals($handles, $this->_model->getHandles());
$this->assertEquals(self::FIXTURE_LAYOUT_XML, $this->_model->asString());
}
public function testLoadDbApp()
{
$this->_resource->expects(
$this->any()
)->method(
'fetchUpdatesByHandle'
)->with(
'fixture_handle',
$this->_theme,
$this->scope
)->willReturn(
self::FIXTURE_LAYOUT_XML
);
$this->assertEmpty($this->_model->getHandles());
$this->assertEmpty($this->_model->asString());
$handles = ['fixture_handle_one'];
$this->_model->load($handles);
$this->assertEquals($handles, $this->_model->getHandles());
$this->assertXmlStringEqualsXmlString(
'<body>' . self::FIXTURE_LAYOUT_XML . '</body>',
$this->_model->asString()
);
}
public function testGetFileLayoutUpdatesXml()
{
$errorString = "Theme layout update file '" . __DIR__ . "/_mergeFiles/layout/file_wrong.xml' is not valid.";
$this->_logger->expects($this->atLeastOnce())->method('info')
->with($this->stringStartsWith($errorString));
$actualXml = $this->_model->getFileLayoutUpdatesXml();
$this->assertXmlStringEqualsXmlFile(__DIR__ . '/_mergeFiles/merged.xml', $actualXml->asNiceXml());
}
public function testGetContainers()
{
$this->_model->addPageHandles(['default']);
$this->_model->addPageHandles(['catalog_product_view']);
$this->_model->addPageHandles(['catalog_product_view_type_configurable']);
$this->_model->load();
$expected = [
'content' => 'Main Content Area',
'product.info.extrahint' => 'Product View Extra Hint',
'product.info.configurable.extra' => 'Configurable Product Extra Info',
];
$this->assertEquals($expected, $this->_model->getContainers());
}
public function testGetAllDesignAbstractions()
{
$expected = [
'customer_account' => [
'name' => 'customer_account',
'label' => new Phrase('Customer My Account (All Pages)'),
'design_abstraction' => 'custom',
],
'page_empty' => [
'name' => 'page_empty',
'label' => new Phrase('All Empty Layout Pages'),
'design_abstraction' => 'page_layout',
],
];
$this->assertEquals($expected, $this->_model->getAllDesignAbstractions());
}
public function testIsPageLayoutDesignAbstractions()
{
$expected = [
'customer_account' => [
'name' => 'customer_account',
'label' => 'Customer My Account (All Pages)',
'design_abstraction' => 'custom',
],
'page_empty' => [
'name' => 'page_empty',
'label' => 'All Empty Layout Pages',
'design_abstraction' => 'page_layout',
],
'empty_data' => [],
];
$this->assertTrue($this->_model->isPageLayoutDesignAbstraction($expected['page_empty']));
$this->assertFalse($this->_model->isPageLayoutDesignAbstraction($expected['customer_account']));
$this->assertFalse($this->_model->isPageLayoutDesignAbstraction($expected['empty_data']));
}
public function testIsCustomDesignAbstractions()
{
$expected = [
'customer_account' => [
'name' => 'customer_account',
'label' => 'Customer My Account (All Pages)',
'design_abstraction' => 'custom',
],
'page_empty' => [
'name' => 'page_empty',
'label' => 'All Empty Layout Pages',
'design_abstraction' => 'page_layout',
],
'empty_data' => [],
];
$this->assertTrue($this->_model->isCustomerDesignAbstraction($expected['customer_account']));
$this->assertFalse($this->_model->isCustomerDesignAbstraction($expected['page_empty']));
$this->assertFalse($this->_model->isCustomerDesignAbstraction($expected['empty_data']));
}
/**
*/
public function testLoadWithInvalidArgumentThrowsException()
{
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->expectExceptionMessage('Invalid layout update handle');
$this->_model->load(123);
}
/**
* Test loading invalid layout
*
*/
public function testLoadWithInvalidLayout()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Layout is invalid.');
$this->_model->addPageHandles(['default']);
$this->_appState->expects($this->once())->method('getMode')->willReturn(State::MODE_DEVELOPER);
$this->_layoutValidator->expects($this->any())
->method('getMessages')
->willReturn(['testMessage1', 'testMessage2']);
$this->_layoutValidator->expects($this->any())
->method('isValid')
->willThrowException(new \Exception('Layout is invalid.'));
// phpcs:ignore Magento2.Security.InsecureFunction
$suffix = md5(implode('|', $this->_model->getHandles()));
$cacheId = "LAYOUT_{$this->_theme->getArea()}_STORE{$this->scope->getId()}"
. "_{$this->_theme->getId()}{$suffix}_page_layout_merged";
$messages = $this->_layoutValidator->getMessages();
// Testing error message is logged with logger
$this->_logger->expects($this->once())->method('info')
->with(
'Cache file with merged layout: ' . $cacheId . ' and handles default' . ': ' . array_shift($messages)
);
$this->_model->load();
}
/**
*/
public function testLayoutUpdateFileIsNotValid()
{
$this->expectException(\Magento\Framework\Config\Dom\ValidationException::class);
$this->expectExceptionMessageMatches('/_mergeFiles\\/layout\\/file_wrong\\.xml\\\' is not valid/');
$this->_appState->expects($this->once())->method('getMode')->willReturn(State::MODE_DEVELOPER);
$this->_model->addPageHandles(['default']);
}
}
@@ -0,0 +1,109 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Layout\Reader;
class BlockTest extends \PHPUnit\Framework\TestCase
{
const IDX_TYPE = 0;
const IDX_PARENT = 2;
/**
* @var Block
*/
private $block;
/**
* @var Context
*/
private $readerContext;
/**
* @var string
*/
private $blockName = 'test.block';
/**
* @var string
*/
private $childBlockName = 'test.child.block';
protected function setUp(): void
{
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Layout\Reader\Block::class
);
$this->readerContext = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Layout\Reader\Context::class
);
}
public function testInterpretBlockDirective()
{
$pageXml = new \Magento\Framework\View\Layout\Element(
__DIR__ . '/_files/_layout_update_block.xml',
0,
true
);
$parentElement = new \Magento\Framework\View\Layout\Element('<page></page>');
foreach ($pageXml->xpath('body/block') as $blockElement) {
$this->assertTrue(in_array($blockElement->getName(), $this->block->getSupportedNodes()));
$this->block->interpret($this->readerContext, $blockElement, $parentElement);
}
$structure = $this->readerContext->getScheduledStructure();
$this->assertArrayHasKey($this->blockName, $structure->getStructure());
$this->assertEquals('block', $structure->getStructure()[$this->blockName][self::IDX_TYPE]);
$resultElementData = $structure->getStructureElementData($this->blockName);
$this->assertEquals(
[
Block::ATTRIBUTE_GROUP => 'test.group',
Block::ATTRIBUTE_CLASS => 'Dummy\Class',
Block::ATTRIBUTE_TEMPLATE => 'test.phtml',
Block::ATTRIBUTE_TTL => 3,
Block::ATTRIBUTE_DISPLAY => '',
Block::ATTRIBUTE_ACL => '',
'visibilityConditions' => [],
],
$resultElementData['attributes']
);
$this->assertEquals(
['test_arg' => 'test-argument-value'],
$resultElementData['arguments']
);
$this->assertEquals('block', $structure->getStructure()[$this->childBlockName][self::IDX_TYPE]);
$this->assertEquals($this->blockName, $structure->getStructure()[$this->childBlockName][self::IDX_PARENT]);
}
public function testInterpretReferenceBlockDirective()
{
$pageXml = new \Magento\Framework\View\Layout\Element(
__DIR__ . '/_files/_layout_update_reference.xml',
0,
true
);
$parentElement = new \Magento\Framework\View\Layout\Element('<page></page>');
foreach ($pageXml->xpath('body/*') as $element) {
$this->assertTrue(in_array($element->getName(), $this->block->getSupportedNodes()));
$this->block->interpret($this->readerContext, $element, $parentElement);
}
$structure = $this->readerContext->getScheduledStructure();
$this->assertArrayHasKey($this->blockName, $structure->getStructure());
$this->assertEquals('block', $structure->getStructure()[$this->blockName][self::IDX_TYPE]);
$resultElementData = $structure->getStructureElementData($this->blockName);
$this->assertEquals(
['test_arg' => 'test-argument-value'],
$resultElementData['arguments']
);
}
}
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<block class="Dummy\Class" name="test.block" group="test.group" template="test.phtml" ttl="3">
<arguments>
<argument name="test_arg" xsi:type="string">test-argument-value</argument>
</arguments>
<block class="Dummy\Class" name="test.child.block"/>
</block>
</body>
</page>
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<block class="Dummy\Class" name="test.block"/>
<referenceBlock name="test.block">
<arguments>
<argument name="test_arg" xsi:type="string">test-argument-value</argument>
</arguments>
</referenceBlock>
</body>
</page>
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Magento Admin</title>
<script src="prototype/prototype.js"/>
<script src="prototype/window.js"/>
<script src="prototype/deprecation.js"/>
</head>
<block class="Magento\Backend\Block\Page" name="root" output="1" template="Magento_Backend::page.phtml">
<block class="Magento\Backend\Block\Page" name="nodeForTesting">
<action method="setSomething"/>
</block>
<block class="Magento\Backend\Block\Page\Header" name="header" as="header"/>
<block class="Magento\Backend\Block\Menu" name="menu" as="menu"/>
<block class="Magento\Framework\View\Element\Messages" name="messages" as="messages"/>
<block class="Magento\Framework\View\Element\Text" as="no_name"/>
</block>
<update handle="layout_test_handle_sample"/>
<referenceBlock name="header" remove="true"/>
<referenceBlock name="menu" remove="true"/>
<referenceBlock name="some_element_1" remove="true"/>
<referenceBlock name="some_element_2" remove="true"/>
<referenceBlock name="root">
<action method="setTemplate">
<argument name="template" xsi:type="string">popup.phtml</argument>
</action>
</referenceBlock>
<referenceBlock name="some_element_1"/>
<block class="Magento\Framework\View\Element\Text\ListText" name="test.nonexisting.block"/>
<referenceBlock name="test.nonexisting.block" remove="true"/>
<referenceBlock name="test.nonexisting.block">
<action method="getSomething"/>
</referenceBlock>
<referenceBlock name="after.body.start">
<block class="Magento\Framework\View\Element\Html\Calendar" name="head.calendar" as="calendar" template="Magento_Framework::page/js/calendar.phtml"/>
</referenceBlock>
</page>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page/>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page/>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page>
<body>
<container name="product.info.extrahint" as="extrahint" label="Product View Extra Hint"/>
</body>
</page>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page>
<body>
<container name="product.info.configurable.extra" as="product_type_data_extra" label="Configurable Product Extra Info"/>
</body>
</page>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page/>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page/>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page label="Customer My Account (All Pages)" design_abstraction="custom"/>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page>
<body>
<container name="content" as="content" label="Main Content Area"/>
</body>
</page>
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page>
<container name="content" as="content" label="Main Content Area"/>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page>
<body>
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
</body>
</page>
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout>
<container name="main.container" />
</layout>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page>
<body>
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_two.phtml"/>
</body>
</page>
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page layout="fixture_handle_page_layout">
<body>
<referenceContainer name="main.container">
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page label="Handle that Is Not a Page Type"/>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page label="All Empty Layout Pages" design_abstraction="page_layout"/>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page/>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page/>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page/>
@@ -0,0 +1,57 @@
<?xml version="1.0"?>
<!--
/**
* Layout instructions merged from sibling XML files. To be used as an expectation for a test.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layouts>
<handle id="catalog_category_default"/>
<handle id="catalog_category_layered"/>
<handle id="catalog_product_view">
<body>
<container name="product.info.extrahint" as="extrahint" label="Product View Extra Hint"/>
</body>
</handle>
<handle id="catalog_product_view_type_configurable">
<body>
<container name="product.info.configurable.extra" as="product_type_data_extra" label="Configurable Product Extra Info"/>
</body>
</handle>
<handle id="catalog_product_view_type_simple"/>
<handle id="checkout_index_index"/>
<handle id="customer_account" label="Customer My Account (All Pages)" design_abstraction="custom"/>
<handle id="default">
<body>
<container name="content" as="content" label="Main Content Area"/>
</body>
</handle>
<handle id="fixture_handle_one">
<body>
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
</body>
</handle>
<layout id="fixture_handle_page_layout">
<container name="main.container"/>
</layout>
<handle id="fixture_handle_two">
<body>
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_two.phtml"/>
</body>
</handle>
<handle id="fixture_handle_with_page_layout" layout="fixture_handle_page_layout">
<body>
<referenceContainer name="main.container">
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
</referenceContainer>
</body>
</handle>
<handle id="not_a_page_type" label="Handle that Is Not a Page Type"/>
<handle id="page_empty" label="All Empty Layout Pages" design_abstraction="page_layout"/>
<handle id="print"/>
<handle id="sales_guest_print"/>
<handle id="sales_order_print"/>
</layouts>
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View;
/**
* Dummy layout argument updater model
*/
class LayoutArgumentObjectUpdater implements \Magento\Framework\View\Layout\Argument\UpdaterInterface
{
/**
* Update specified argument
*
* @param \Magento\Framework\Data\Collection $argument
* @return \Magento\Framework\Data\Collection
*/
public function update($argument)
{
$calls = $argument->getUpdaterCall();
$calls[] = 'updater call';
$argument->setUpdaterCall($calls);
return $argument;
}
}
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View;
/**
* Dummy layout argument updater model
*/
class LayoutArgumentSimpleUpdater implements \Magento\Framework\View\Layout\Argument\UpdaterInterface
{
/**
* Update specified argument
*
* @param int $argument
* @return int
*/
public function update($argument)
{
$argument++;
return $argument;
}
}
@@ -0,0 +1,324 @@
<?php
/**
* Set of tests of layout directives handling behavior
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View;
use Magento\Framework\App\State;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class LayoutDirectivesTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\LayoutFactory
*/
protected $layoutFactory;
/**
* @var \Magento\Framework\View\Layout\BuilderFactory
*/
protected $builderFactory;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $objectManager;
/**
* @var \Magento\Framework\App\State
*/
protected $state;
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->layoutFactory = $this->objectManager->get(\Magento\Framework\View\LayoutFactory::class);
$this->state = $this->objectManager->get(\Magento\Framework\App\State::class);
}
/**
* Prepare a layout model with pre-loaded fixture of an update XML
*
* @param string $fixtureFile
* @return \Magento\Framework\View\LayoutInterface
*/
protected function _getLayoutModel($fixtureFile)
{
$this->objectManager->get(\Magento\Framework\App\Cache\Type\Layout::class)->clean();
$layout = $this->layoutFactory->create();
/** @var $xml \Magento\Framework\View\Layout\Element */
$xml = simplexml_load_file(
__DIR__ . "/_files/layout_directives_test/{$fixtureFile}",
\Magento\Framework\View\Layout\Element::class
);
$layout->loadString($xml->asXml());
$layout->generateElements();
return $layout;
}
/**
* Test scheduled operations in the rendering of elements
*
* Expected behavior:
* 1) block1 was not declared at the moment when "1" invocation declared. The operation is scheduled
* 2) block1 creation directive schedules adding "2" as well
* 3) block2 is generated with "3"
* 4) yet another action schedules replacing value of block2 into "4"
* 5) when entire layout is read, all scheduled operations are executed in the same order as declared
* (blocks are instantiated first, of course)
* The end result can be observed in container1
*
* @magentoAppIsolation enabled
*/
public function testRenderElement()
{
$layout = $this->_getLayoutModel('render.xml');
$this->assertEquals('124', $layout->renderElement('container_one'));
$this->assertEquals('12', $layout->renderElement('block_one'));
}
/**
* @magentoAppIsolation enabled
*/
public function testRenderNonExistentElementShouldThrowException()
{
$this->expectException(\OutOfBoundsException::class);
$layout = $this->_getLayoutModel('render.xml');
$this->assertEmpty($layout->renderElement('nonexisting_element'));
$this->expectExceptionMessage(
'The element with the "nonexisting_element" ID wasn\'t found. Verify the ID and try again.'
);
}
/**
* Invoke getBlock() while layout is being generated
*
* Assertions in this test are pure formalism. The point is to emulate situation where block refers to other block
* while the latter hasn't been generated yet, and assure that there is no crash
*/
public function testGetBlockUnscheduled()
{
$layout = $this->_getLayoutModel('get_block.xml');
$this->assertInstanceOf(\Magento\Framework\View\Element\Text::class, $layout->getBlock('block_first'));
$this->assertInstanceOf(\Magento\Framework\View\Element\Text::class, $layout->getBlock('block_second'));
}
public function testLayoutArgumentsDirective()
{
$layout = $this->_getLayoutModel('arguments.xml');
$this->assertEquals('1', $layout->getBlock('block_with_args')->getOne());
$this->assertEquals('two', $layout->getBlock('block_with_args')->getTwo());
$this->assertEquals('3', $layout->getBlock('block_with_args')->getThree());
}
public function testLayoutArgumentsDirectiveIfComplexValues()
{
$layout = $this->_getLayoutModel('arguments_complex_values.xml');
$this->assertEquals(
['parameters' => ['first' => '1', 'second' => '2']],
$layout->getBlock('block_with_args_complex_values')->getOne()
);
$this->assertEquals('two', $layout->getBlock('block_with_args_complex_values')->getTwo());
$this->assertEquals(
['extra' => ['key1' => 'value1', 'key2' => 'value2']],
$layout->getBlock('block_with_args_complex_values')->getThree()
);
}
public function testLayoutObjectArgumentsDirective()
{
$layout = $this->_getLayoutModel('arguments_object_type.xml');
$this->assertInstanceOf(
\Magento\Framework\Data\Collection::class,
$layout->getBlock('block_with_object_args')->getOne()
);
$this->assertInstanceOf(
\Magento\Framework\Data\Collection::class,
$layout->getBlock('block_with_object_args')->getTwo()
);
$this->assertEquals(3, $layout->getBlock('block_with_object_args')->getThree());
}
public function testLayoutUrlArgumentsDirective()
{
$layout = $this->_getLayoutModel('arguments_url_type.xml');
$this->assertStringContainsString('customer/account/login', $layout->getBlock('block_with_url_args')->getOne());
$this->assertStringContainsString(
'customer/account/logout',
$layout->getBlock('block_with_url_args')->getTwo()
);
$this->assertStringContainsString('customer_id/3', $layout->getBlock('block_with_url_args')->getTwo());
}
public function testLayoutObjectArgumentUpdatersDirective()
{
$this->markTestSkipped('Will be fixed after MAGETWO-33840 will be done');
$layout = $this->_getLayoutModel('arguments_object_type_updaters.xml');
$expectedObjectData = [0 => 'updater call', 1 => 'updater call'];
$expectedSimpleData = 1;
$dataSource = $layout->getBlock('block_with_object_updater_args')->getOne();
$this->assertInstanceOf(\Magento\Framework\Data\Collection::class, $dataSource);
$this->assertEquals($expectedObjectData, $dataSource->getUpdaterCall());
$this->assertEquals($expectedSimpleData, $layout->getBlock('block_with_object_updater_args')->getTwo());
}
/**
* @magentoAppIsolation enabled
*/
public function testMoveSameAlias()
{
$layout = $this->_getLayoutModel('move_the_same_alias.xml');
$this->assertEquals('container1', $layout->getParentName('no_name3'));
}
/**
* @magentoAppIsolation enabled
*/
public function testMoveNewAlias()
{
$layout = $this->_getLayoutModel('move_new_alias.xml');
$this->assertEquals('new_alias', $layout->getElementAlias('no_name3'));
}
public function testActionAnonymousParentBlock()
{
$layout = $this->_getLayoutModel('action_for_anonymous_parent_block.xml');
$this->assertEquals('schedule_block0', $layout->getParentName('test.block.insert'));
$this->assertEquals('schedule_block1', $layout->getParentName('test.block.append'));
}
/**
* @magentoAppIsolation enabled
*/
public function testRemove()
{
$layout = $this->_getLayoutModel('remove.xml');
$this->assertFalse($layout->getBlock('no_name2'));
$this->assertFalse($layout->getBlock('child_block1'));
$this->assertTrue($layout->isBlock('child_block2'));
}
/**
* @magentoAppIsolation enabled
*/
public function testRemoveCancellation()
{
$layout = $this->_getLayoutModel('remove_cancellation.xml');
$this->assertTrue($layout->isContainer('container1'));
$this->assertTrue($layout->isBlock('child_block1'));
$this->assertTrue($layout->isBlock('no_name2'));
$this->assertFalse($layout->getBlock('not_exist'));
}
/**
* @magentoAppIsolation enabled
*/
public function testMove()
{
$layout = $this->_getLayoutModel('move.xml');
$this->assertEquals('container2', $layout->getParentName('container1'));
$this->assertEquals('container1', $layout->getParentName('no.name2'));
$this->assertEquals('block_container', $layout->getParentName('no_name3'));
// verify `after` attribute
$this->assertEquals('block_container', $layout->getParentName('no_name'));
$childrenOrderArray = array_keys($layout->getChildBlocks($layout->getParentName('no_name')));
$positionAfter = array_search('child_block1', $childrenOrderArray);
$positionToVerify = array_search('no_name', $childrenOrderArray);
$this->assertEquals($positionAfter, --$positionToVerify);
// verify `before` attribute
$this->assertEquals('block_container', $layout->getParentName('no_name4'));
$childrenOrderArray = array_keys($layout->getChildBlocks($layout->getParentName('no_name4')));
$positionBefore = array_search('child_block2', $childrenOrderArray);
$positionToVerify = array_search('no_name4', $childrenOrderArray);
$this->assertEquals($positionBefore, ++$positionToVerify);
}
/**
*/
public function testMoveBroken()
{
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->_getLayoutModel('move_broken.xml');
}
/**
*/
public function testMoveAliasBroken()
{
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
$this->_getLayoutModel('move_alias_broken.xml');
}
public function testRemoveBroken()
{
if ($this->state->getMode() === State::MODE_DEVELOPER) {
$this->expectException('OutOfBoundsException');
}
$this->_getLayoutModel('remove_broken.xml');
}
/**
* @param string $case
* @param string $expectedResult
* @dataProvider sortSpecialCasesDataProvider
* @magentoAppIsolation enabled
*/
public function testSortSpecialCases($case, $expectedResult)
{
$layout = $this->_getLayoutModel($case);
$this->assertEquals($expectedResult, $layout->renderElement('root'));
}
/**
* @return array
*/
public function sortSpecialCasesDataProvider()
{
return [
'Before element which is after' => ['sort_before_after.xml', '312'],
'Before element which is previous' => ['sort_before_before.xml', '213'],
'After element which is after' => ['sort_after_after.xml', '312'],
'After element which is previous' => ['sort_after_previous.xml', '321']
];
}
/**
* @magentoConfigFixture current_store true_options 1
* @magentoAppIsolation enabled
*/
public function testIfConfigForBlock()
{
$layout = $this->_getLayoutModel('ifconfig.xml');
$this->assertFalse($layout->getBlock('block1'));
$this->assertFalse($layout->getBlock('block2'));
$this->assertInstanceOf(\Magento\Framework\View\Element\BlockInterface::class, $layout->getBlock('block3'));
$this->assertFalse($layout->getBlock('block4'));
}
/**
* @magentoConfigFixture current_store true_options 1
* @magentoAppIsolation enabled
*/
public function testBlockGroups()
{
$layout = $this->_getLayoutModel('group.xml');
$childNames = $layout->getBlock('block1')->getGroupChildNames('group1');
$this->assertEquals(['block2', 'block3'], $childNames);
}
}
@@ -0,0 +1,627 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
/**
* Layout integration tests
*
* Note that some methods are not covered here, see the \Magento\Framework\View\LayoutDirectivesTest
*
* @see \Magento\Framework\View\LayoutDirectivesTest
*/
namespace Magento\Framework\View;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Element\Messages;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Text;
use Magento\Framework\View\Element\Text\ListText;
use Magento\Framework\View\Layout\Data\Structure;
use Magento\Framework\View\Layout\Element;
use Magento\Framework\View\Layout\ProcessorInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class LayoutTest extends TestCase
{
/**
* @var Layout
*/
private $layout;
/**
* @var LayoutFactory
*/
private $layoutFactory;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->layoutFactory = $objectManager->get(LayoutFactory::class);
$this->layout = $this->layoutFactory->create();
$objectManager->get(\Magento\Framework\App\Cache\Type\Layout::class)->clean();
}
/**
* @return void
*/
public function testConstructorStructure(): void
{
$objectManager = Bootstrap::getObjectManager();
$structure = $objectManager->get(Structure::class);
$structure->createElement('test.container', []);
/** @var $layout LayoutInterface */
$layout = $this->layoutFactory->create(['structure' => $structure]);
$this->assertTrue($layout->hasElement('test.container'));
}
/**
* @magentoAppIsolation enabled
* @magentoAppArea frontend
*
* @return void
*/
public function testDestructor(): void
{
$this->layout->addBlock(Text::class, 'test');
$this->assertNotEmpty($this->layout->getAllBlocks());
$this->layout->__destruct();
$this->assertEmpty($this->layout->getAllBlocks());
}
/**
* @return void
*/
public function testGetUpdate(): void
{
$this->assertInstanceOf(ProcessorInterface::class, $this->layout->getUpdate());
}
/**
* @return void
*/
public function testGenerateXml(): void
{
$layoutUtility = new Utility\Layout($this);
/** @var $layout LayoutInterface */
$layout = $this->getMockBuilder(Layout::class)
->onlyMethods(['getUpdate'])
->setConstructorArgs($layoutUtility->getLayoutDependencies())
->getMock();
$merge = $this->getMockBuilder(\StdClass::class)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
->addMethods(['asSimplexml'])
->getMock();
$merge->expects($this->once())
->method('asSimplexml')
->willReturn(
simplexml_load_string(
'<layout><container name="container1"></container></layout>',
Element::class
)
);
$layout->expects($this->once())->method('getUpdate')->willReturn($merge);
$this->assertEmpty($layout->getXpath('/layout/container[@name="container1"]'));
$layout->generateXml();
$this->assertNotEmpty($layout->getXpath('/layout/container[@name="container1"]'));
}
/**
* A smoke test for generating elements.
*
* See sophisticated tests at \Magento\Framework\View\LayoutDirectivesTest
* @see \Magento\Framework\View\LayoutDirectivesTest
* @magentoAppIsolation enabled
*
* @return void
*/
public function testGenerateGetAllBlocks(): void
{
$this->layout->setXml(
simplexml_load_string(
'<layout>
<block class="Magento\Framework\View\Element\Text" name="block1">
<block class="Magento\Framework\View\Element\Text"/>
</block>
<block class="Magento\Framework\View\Element\Text" template="test" ttl="360"/>
<block class="Magento\Framework\View\Element\Text"/>
</layout>',
Element::class
)
);
$this->assertEquals([], $this->layout->getAllBlocks());
$this->layout->generateElements();
$expected = ['block1', 'block1_schedule_block0', 'schedule_block1', 'schedule_block2'];
$this->assertSame($expected, array_keys($this->layout->getAllBlocks()));
$child = $this->layout->getBlock('block1_schedule_block0');
$this->assertSame($this->layout->getBlock('block1'), $child->getParentBlock());
$this->assertEquals('test', $this->layout->getBlock('schedule_block1')->getData('template'));
$this->assertEquals('360', $this->layout->getBlock('schedule_block1')->getData('ttl'));
$this->assertFalse($this->layout->getBlock('nonexisting'));
}
/**
* @return void
*/
public function testGetElementProperty(): void
{
$name = 'test';
$this->layout->addContainer($name, 'Test', ['option1' => 1, 'option2' => 2]);
$this->assertEquals(
'Test',
$this->layout->getElementProperty($name, Element::CONTAINER_OPT_LABEL)
);
$this->assertEquals(
Element::TYPE_CONTAINER,
$this->layout->getElementProperty($name, 'type')
);
$this->assertSame(2, $this->layout->getElementProperty($name, 'option2'));
$this->layout->addBlock(Text::class, 'text', $name);
$this->assertEquals(
Element::TYPE_BLOCK,
$this->layout->getElementProperty('text', 'type')
);
$this->assertSame(
['text' => 'text'],
$this->layout->getElementProperty($name, \Magento\Framework\Data\Structure::CHILDREN)
);
}
/**
* @magentoAppIsolation enabled
*
* @return void
*/
public function testIsBlock(): void
{
$this->assertFalse($this->layout->isBlock('container'));
$this->assertFalse($this->layout->isBlock('block'));
$this->layout->addContainer('container', 'Container');
$this->layout->addBlock(Text::class, 'block');
$this->assertFalse($this->layout->isBlock('container'));
$this->assertTrue($this->layout->isBlock('block'));
}
/**
* @return void
*/
public function testSetUnsetBlock(): void
{
$expectedBlockName = 'block_' . __METHOD__;
$expectedBlock = $this->layout->createBlock(Text::class);
$this->layout->setBlock($expectedBlockName, $expectedBlock);
$this->assertSame($expectedBlock, $this->layout->getBlock($expectedBlockName));
$this->layout->unsetElement($expectedBlockName);
$this->assertFalse($this->layout->getBlock($expectedBlockName));
$this->assertFalse($this->layout->hasElement($expectedBlockName));
}
/**
* @return void
* @dataProvider createBlockDataProvider
*/
public function testCreateBlock($blockType, $blockName, array $blockData, $expectedName): void
{
$expectedData = $blockData + ['type' => $blockType];
$block = $this->layout->createBlock($blockType, $blockName, ['data' => $blockData]);
$this->assertMatchesRegularExpression($expectedName, $block->getNameInLayout());
$this->assertEquals($expectedData, $block->getData());
}
/**
* @return array
*/
public function createBlockDataProvider(): array
{
return [
'named block' => [Template::class,
'some_block_name_full_class',
['type' => Template::class, 'is_anonymous' => false],
'/^some_block_name_full_class$/',
],
'no name block' => [ListText::class,
'',
['type' => ListText::class, 'key1' => 'value1'],
'/text\\\\list/',
]
];
}
/**
* @return void
* @dataProvider blockNotExistsDataProvider
*/
public function testCreateBlockNotExists($name): void
{
$this->expectException(LocalizedException::class);
$this->layout->createBlock($name);
}
/**
* @return array
*/
public function blockNotExistsDataProvider(): array
{
return [[''], ['block_not_exists']];
}
/**
* @return void
*/
public function testAddBlock(): void
{
$this->assertInstanceOf(
Text::class,
$this->layout->addBlock(Text::class, 'block1')
);
$block2 = Bootstrap::getObjectManager()->create(
Text::class
);
$block2->setNameInLayout('block2');
$this->layout->addBlock($block2, '', 'block1');
$this->assertTrue($this->layout->hasElement('block1'));
$this->assertTrue($this->layout->hasElement('block2'));
$this->assertEquals('block1', $this->layout->getParentName('block2'));
}
/**
* @magentoAppIsolation enabled
* @return void
* @dataProvider addContainerDataProvider()
*/
public function testAddContainer($htmlTag): void
{
$this->assertFalse($this->layout->hasElement('container'));
$this->layout->addContainer('container', 'Container', ['htmlTag' => $htmlTag]);
$this->assertTrue($this->layout->hasElement('container'));
$this->assertTrue($this->layout->isContainer('container'));
$this->assertEquals($htmlTag, $this->layout->getElementProperty('container', 'htmlTag'));
$this->layout->addContainer('container1', 'Container 1', [], 'container', 'c1');
$this->assertEquals('container1', $this->layout->getChildName('container', 'c1'));
}
/**
* @return array
*/
public function addContainerDataProvider(): array
{
return [
['aside'],
['dd'],
['div'],
['dl'],
['fieldset'],
['main'],
['nav'],
['header'],
['footer'],
['ol'],
['p'],
['section'],
['table'],
['tfoot'],
['ul'],
['article'],
['h1'],
['h2'],
['h3'],
['h4'],
['h5'],
['h6'],
];
}
/**
* @magentoAppIsolation enabled
* @return void
*/
public function testAddContainerInvalidHtmlTag(): void
{
$msg = 'Html tag "span" is forbidden for usage in containers. ' .
'Consider to use one of the allowed: aside, dd, div, dl, fieldset, main, nav, ' .
'header, footer, ol, p, section, table, tfoot, ul, article, h1, h2, h3, h4, h5, h6.';
$this->expectException(LocalizedException::class);
$this->expectExceptionMessage($msg);
$this->layout->addContainer('container', 'Container', ['htmlTag' => 'span']);
}
/**
* @magentoAppIsolation enabled
* @return void
*/
public function testGetChildBlock(): void
{
$this->layout->addContainer('parent', 'Parent');
$block = $this->layout->addBlock(
Text::class,
'block',
'parent',
'block_alias'
);
$this->layout->addContainer('container', 'Container', [], 'parent', 'container_alias');
$this->assertSame($block, $this->layout->getChildBlock('parent', 'block_alias'));
$this->assertFalse($this->layout->getChildBlock('parent', 'container_alias'));
}
/**
* @return Layout
*/
public function testSetChild(): Layout
{
$this->layout->addContainer('one', 'One');
$this->layout->addContainer('two', 'Two');
$this->layout->addContainer('three', 'Three');
$this->assertSame($this->layout, $this->layout->setChild('one', 'two', ''));
$this->layout->setChild('one', 'three', 'three_alias');
$this->assertSame(['two', 'three'], $this->layout->getChildNames('one'));
return $this->layout;
}
/**
* @param LayoutInterface $layout
* @depends testSetChild
* @return void
*/
public function testReorderChild(LayoutInterface $layout): void
{
$layout->addContainer('four', 'Four', [], 'one');
// offset +1
$layout->reorderChild('one', 'four', 1);
$this->assertSame(['two', 'four', 'three'], $layout->getChildNames('one'));
// offset -2
$layout->reorderChild('one', 'three', 2, false);
$this->assertSame(['two', 'three', 'four'], $layout->getChildNames('one'));
// after sibling
$layout->reorderChild('one', 'two', 'three');
$this->assertSame(['three', 'two', 'four'], $layout->getChildNames('one'));
// after everyone
$layout->reorderChild('one', 'three', '-');
$this->assertSame(['two', 'four', 'three'], $layout->getChildNames('one'));
// before sibling
$layout->reorderChild('one', 'four', 'two', false);
$this->assertSame(['four', 'two', 'three'], $layout->getChildNames('one'));
// before everyone
$layout->reorderChild('one', 'two', '-', false);
$this->assertSame(['two', 'four', 'three'], $layout->getChildNames('one'));
//reorder by sibling alias
$layout->reorderChild('one', 'two', 'three_alias', true);
$this->assertSame(['four', 'three', 'two'], $layout->getChildNames('one'));
}
/**
* @magentoAppIsolation enabled
* @return void
*/
public function testGetChildBlocks(): void
{
$this->layout->addContainer('parent', 'Parent');
$block1 = $this->layout->addBlock(Text::class, 'block1', 'parent');
$this->layout->addContainer('container', 'Container', [], 'parent');
$block2 = $this->layout->addBlock(Template::class, 'block2', 'parent');
$this->assertSame(['block1' => $block1, 'block2' => $block2], $this->layout->getChildBlocks('parent'));
}
/**
* @return void
*/
public function testAddBlockInvalidType(): void
{
$this->expectException(LocalizedException::class);
$this->layout->addBlock('invalid_name', 'child');
}
/**
* @magentoAppIsolation enabled
*
* @return void
*/
public function testIsContainer(): void
{
$block = 'block';
$container = 'container';
$this->layout->addBlock(Text::class, $block);
$this->layout->addContainer($container, 'Container');
$this->assertFalse($this->layout->isContainer($block));
$this->assertTrue($this->layout->isContainer($container));
$this->assertFalse($this->layout->isContainer('invalid_name'));
}
/**
* @return void
*/
public function testIsManipulationAllowed(): void
{
$this->layout->addBlock(Text::class, 'block1');
$this->layout->addBlock(Text::class, 'block2', 'block1');
$this->assertFalse($this->layout->isManipulationAllowed('block1'));
$this->assertFalse($this->layout->isManipulationAllowed('block2'));
$this->layout->addContainer('container1', 'Container 1');
$this->layout->addBlock(Text::class, 'block3', 'container1');
$this->layout->addContainer('container2', 'Container 2', [], 'container1');
$this->assertFalse($this->layout->isManipulationAllowed('container1'));
$this->assertTrue($this->layout->isManipulationAllowed('block3'));
$this->assertTrue($this->layout->isManipulationAllowed('container2'));
}
/**
* @return void
*/
public function testRenameElement(): void
{
$blockName = 'block';
$expBlockName = 'block_renamed';
$containerName = 'container';
$expContainerName = 'container_renamed';
$block = $this->layout->createBlock(Text::class, $blockName);
$this->layout->addContainer($containerName, 'Container');
$this->assertEquals($block, $this->layout->getBlock($blockName));
$this->layout->renameElement($blockName, $expBlockName);
$this->assertEquals($block, $this->layout->getBlock($expBlockName));
$this->layout->hasElement($containerName);
$this->layout->renameElement($containerName, $expContainerName);
$this->layout->hasElement($expContainerName);
}
/**
* @return void
*/
public function testGetBlock(): void
{
$this->assertFalse($this->layout->getBlock('test'));
$block = Bootstrap::getObjectManager()->get(
Layout::class
)->createBlock(
Text::class
);
$this->layout->setBlock('test', $block);
$this->assertSame($block, $this->layout->getBlock('test'));
}
/**
* @magentoAppIsolation enabled
*
* @return void
*/
public function testGetParentName(): void
{
$this->layout->addContainer('one', 'One');
$this->layout->addContainer('two', 'Two', [], 'one');
$this->assertFalse($this->layout->getParentName('one'));
$this->assertEquals('one', $this->layout->getParentName('two'));
}
/**
* @return void
*/
public function testGetElementAlias(): void
{
$this->layout->addContainer('one', 'One');
$this->layout->addContainer('two', 'One', [], 'one', '1');
$this->assertFalse($this->layout->getElementAlias('one'));
$this->assertEquals('1', $this->layout->getElementAlias('two'));
}
/**
* @covers \Magento\Framework\View\Layout::addOutputElement
* @covers \Magento\Framework\View\Layout::getOutput
* @covers \Magento\Framework\View\Layout::removeOutputElement
*
* @return void
*/
public function testGetOutput(): void
{
$blockName = 'block_' . __METHOD__;
$expectedText = "some_text_for_{$blockName}";
$block = $this->layout->addBlock(Text::class, $blockName);
$block->setText($expectedText);
$this->layout->addOutputElement($blockName);
// add the same element twice should not produce output duplicate
$this->layout->addOutputElement($blockName);
$this->assertEquals($expectedText, $this->layout->getOutput());
$this->layout->removeOutputElement($blockName);
$this->assertEmpty($this->layout->getOutput());
}
/**
* @return void
*/
public function testGetMessagesBlock(): void
{
$this->assertInstanceOf(Messages::class, $this->layout->getMessagesBlock());
}
/**
* @return void
*/
public function testGetBlockSingleton(): void
{
$block = $this->layout->getBlockSingleton(Text::class);
$this->assertInstanceOf(Text::class, $block);
$this->assertSame($block, $this->layout->getBlockSingleton(Text::class));
}
/**
* @return void
*/
public function testUpdateContainerAttributes(): void
{
$this->layout->setXml(
simplexml_load_file(
__DIR__ . '/_files/layout/container_attributes.xml',
Element::class
)
);
$this->layout->generateElements();
$result = $this->layout->renderElement('container1', false);
$this->assertEquals('<div id="container1-2" class="class12">Test11Test12</div>', $result);
$result = $this->layout->renderElement('container2', false);
$this->assertEquals('<div id="container2-2" class="class22">Test21Test22</div>', $result);
}
/**
* @return void
*/
public function testIsCacheable(): void
{
$this->layout->setXml(
simplexml_load_file(
__DIR__ . '/_files/layout/cacheable.xml',
Element::class
)
);
$this->layout->generateElements();
$this->assertTrue($this->layout->isCacheable());
}
/**
* @return void
*/
public function testIsNonCacheable(): void
{
$this->layout->setXml(
simplexml_load_file(
__DIR__ . '/_files/layout/non_cacheable.xml',
Element::class
)
);
$this->layout->generateElements();
$this->assertFalse($this->layout->isCacheable());
}
}
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View;
use Magento\Framework\App\State;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Layout\Element;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Class to test Layout model functionality with exceptions
*/
class LayoutTestWithExceptions extends TestCase
{
/**
* @var Layout
*/
protected $layout;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$layoutFactory = $objectManager->get(LayoutFactory::class);
$this->layout = $layoutFactory->create();
$layoutElement = new Element(
__DIR__ . '/_files/layout_with_exceptions/layout.xml',
0,
true
);
$this->layout->setXml($layoutElement);
$objectManager->get(\Magento\Framework\App\Cache\Type\Layout::class)->clean();
}
/**
* Test to Create structure of elements from the loaded XML configuration with exception
*/
public function testProcessWithExceptionsDeveloperMode()
{
$this->expectException(LocalizedException::class);
$this->expectExceptionMessage('Construction problem.');
$this->layout->generateElements();
}
/**
* Test to Get all blocks marked for output with exceptions
*
* @magentoAppIsolation enabled
*/
public function testProcessWithExceptions()
{
Bootstrap::getObjectManager()->get(State::class)
->setMode(State::MODE_DEFAULT);
$this->layout->generateElements();
$this->layout->addOutputElement('block.with.broken.constructor');
$this->layout->addOutputElement('block.with.broken.layout');
$this->layout->addOutputElement('block.with.broken.action');
$this->assertEmpty($this->layout->getOutput());
}
}
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Model\Layout;
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
class MergeTest extends \PHPUnit\Framework\TestCase
{
/**
* Fixture XML instruction(s) to be used in tests
*/
const FIXTURE_LAYOUT_XML
= '<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture.phtml"/>';
/**
* @var \Magento\Framework\View\Model\Layout\Merge
*/
protected $model;
/**
* @var LayoutCacheKeyInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $layoutCacheKeyMock;
protected function setUp(): void
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
$theme = $objectManager->create(\Magento\Framework\View\Design\ThemeInterface::class);
$theme->load(1);
/** @var $layoutUpdate1 \Magento\Widget\Model\Layout\Update */
$layoutUpdate1 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Widget\Model\Layout\Update::class
);
$layoutUpdate1->setHandle('fixture_handle_one');
$layoutUpdate1->setXml(
'<body>
<block class="Magento\Framework\View\Element\Template"
template="Magento_Framework::fixture_template_one.phtml"/>
</body>'
);
$layoutUpdate1->setHasDataChanges(true);
$layoutUpdate1->save();
$link1 = $objectManager->create(\Magento\Widget\Model\Layout\Link::class);
$link1->setThemeId($theme->getId());
$link1->setLayoutUpdateId($layoutUpdate1->getId());
$link1->save();
/** @var $layoutUpdate2 \Magento\Widget\Model\Layout\Update */
$layoutUpdate2 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Widget\Model\Layout\Update::class
);
$layoutUpdate2->setHandle('fixture_handle_two');
$layoutUpdate2->setXml(
'<body>
<block class="Magento\Framework\View\Element\Template"
template="Magento_Framework::fixture_template_two.phtml"/>
</body>'
);
$layoutUpdate2->setHasDataChanges(true);
$layoutUpdate2->save($layoutUpdate2);
$link2 = $objectManager->create(\Magento\Widget\Model\Layout\Link::class);
$link2->setThemeId($theme->getId());
$link2->setLayoutUpdateId($layoutUpdate2->getId());
$link2->save();
$this->layoutCacheKeyMock = $this->getMockForAbstractClass(LayoutCacheKeyInterface::class);
$this->layoutCacheKeyMock->expects($this->any())
->method('getCacheKeys')
->willReturn([]);
$this->model = $objectManager->create(
\Magento\Framework\View\Model\Layout\Merge::class,
[
'theme' => $theme,
'layoutCacheKey' => $this->layoutCacheKeyMock,
]
);
}
public function testLoadDbApp()
{
$this->assertEmpty($this->model->getHandles());
$this->assertEmpty($this->model->asString());
$handles = ['fixture_handle_one', 'fixture_handle_two'];
$this->model->load($handles);
$expectedResult = '
<root>
<body>
<block class="Magento\Framework\View\Element\Template"
template="Magento_Framework::fixture_template_one.phtml"/>
</body>
<body>
<block class="Magento\Framework\View\Element\Template"
template="Magento_Framework::fixture_template_two.phtml"/>
</body>
</root>
';
$actualResult = '<root>' . $this->model->asString() . '</root>';
$this->assertXmlStringEqualsXmlString($expectedResult, $actualResult);
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page>
<body>
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_one.phtml"/>
</body>
</page>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page>
<body>
<block class="Magento\Framework\View\Element\Template" template="Magento_Framework::fixture_template_two.phtml"/>
</body>
</page>
@@ -0,0 +1,27 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Page\Config\Reader;
class HtmlTest extends \PHPUnit\Framework\TestCase
{
public function testInterpret()
{
/** @var \Magento\Framework\View\Layout\Reader\Context $readerContext */
$readerContext = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Layout\Reader\Context::class
);
$pageXml = new \Magento\Framework\View\Layout\Element(__DIR__ . '/_files/_layout_update.xml', 0, true);
$parentElement = new \Magento\Framework\View\Layout\Element('<page></page>');
$html = new Html();
foreach ($pageXml->xpath('html') as $htmlElement) {
$html->interpret($readerContext, $htmlElement, $parentElement);
}
$structure = $readerContext->getPageConfigStructure();
$this->assertEquals(['html' => ['test-name' => 'test-value']], $structure->getElementAttributes());
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<html>
<attribute name="test-name" value="test-value"/>
</html>
</page>
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\View\TemplateEngine;
use Magento\Framework\View\Element\BlockInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Testing .phtml templating.
*/
class PhpTest extends TestCase
{
/**
* @var Php
*/
private $templateEngine;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->templateEngine = $objectManager->get(Php::class);
}
/**
* See that templates get access to certain variables.
*
* @return void
*/
public function testVariablesAvailable(): void
{
$block = new class implements BlockInterface {
/**
* @inheritDoc
*/
public function toHtml()
{
return '<b>BLOCK</b>';
}
};
$rendered = $this->templateEngine->render($block, __DIR__ .'/../_files/test_template.phtml');
$this->assertEquals(
'<p>This template has access to &lt;b&gt;$escaper&lt;/b&gt; and $block &quot;<b>BLOCK</b>&quot;</p>'
.PHP_EOL,
$rendered
);
}
}
@@ -0,0 +1,119 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Core layout utility
*/
namespace Magento\Framework\View\Utility;
/**
* The integration testsuite for Layout view utility
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Layout
{
/**
* @var \PHPUnit\Framework\TestCase
*/
protected $_testCase;
/**
* @param \PHPUnit\Framework\TestCase $testCase
*/
public function __construct(\PHPUnit\Framework\TestCase $testCase)
{
$this->_testCase = $testCase;
}
/**
* Retrieve new layout update model instance with XML data from a fixture file
*
* @param string|array $layoutUpdatesFile
* @return \Magento\Framework\View\Layout\ProcessorInterface
*/
public function getLayoutUpdateFromFixture($layoutUpdatesFile)
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Framework\View\File\Factory $fileFactory */
$fileFactory = $objectManager->get(\Magento\Framework\View\File\Factory::class);
$files = [];
foreach ((array)$layoutUpdatesFile as $filename) {
$files[] = $fileFactory->create($filename, 'Magento_View');
}
$fileSource = $this->_testCase
->getMockBuilder(\Magento\Framework\View\File\CollectorInterface::class)->getMockForAbstractClass();
$fileSource->expects(
\PHPUnit\Framework\TestCase::any()
)->method(
'getFiles'
)->will(
\PHPUnit\Framework\TestCase::returnValue($files)
);
$pageLayoutFileSource = $this->_testCase
->getMockBuilder(\Magento\Framework\View\File\CollectorInterface::class)->getMockForAbstractClass();
$pageLayoutFileSource->expects(\PHPUnit\Framework\TestCase::any())
->method('getFiles')
->willReturn([]);
$cache = $this->_testCase
->getMockBuilder(\Magento\Framework\Cache\FrontendInterface::class)->getMockForAbstractClass();
return $objectManager->create(
\Magento\Framework\View\Layout\ProcessorInterface::class,
['fileSource' => $fileSource, 'pageLayoutFileSource' => $pageLayoutFileSource, 'cache' => $cache]
);
}
/**
* Retrieve new layout model instance with layout updates from a fixture file
*
* @param string|array $layoutUpdatesFile
* @param array $args
* @return \Magento\Framework\View\Layout|\PHPUnit\Framework\MockObject\MockObject
*/
public function getLayoutFromFixture($layoutUpdatesFile, array $args = [])
{
$layout = $this->_testCase->getMockBuilder(\Magento\Framework\View\Layout::class)
->setMethods(['getUpdate'])
->setConstructorArgs($args)
->getMock();
$layoutUpdate = $this->getLayoutUpdateFromFixture($layoutUpdatesFile);
$layoutUpdate->asSimplexml();
$layout->expects(
\PHPUnit\Framework\TestCase::any()
)->method(
'getUpdate'
)->will(
\PHPUnit\Framework\TestCase::returnValue($layoutUpdate)
);
return $layout;
}
/**
* Retrieve object that will be used for layout instantiation
*
* @return array
*/
public function getLayoutDependencies()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
return [
'processorFactory' => $objectManager->get(\Magento\Framework\View\Layout\ProcessorFactory::class),
'eventManager' => $objectManager->get(\Magento\Framework\Event\ManagerInterface::class),
'structure' => $objectManager->create(\Magento\Framework\View\Layout\Data\Structure::class, []),
'messageManager' => $objectManager->get(\Magento\Framework\Message\ManagerInterface::class),
'themeResolver' => $objectManager->get(\Magento\Framework\View\Design\Theme\ResolverInterface::class),
'readerPool' => $objectManager->get('commonRenderPool'),
'generatorPool' => $objectManager->get(\Magento\Framework\View\Layout\GeneratorPool::class),
'cache' => $objectManager->get(\Magento\Framework\App\Cache\Type\Layout::class),
'readerContextFactory' => $objectManager->get(\Magento\Framework\View\Layout\Reader\ContextFactory::class),
'generatorContextFactory' => $objectManager->get(
\Magento\Framework\View\Layout\Generator\ContextFactory::class
),
'appState' => $objectManager->get(\Magento\Framework\App\State::class),
'logger' => $objectManager->get(\Psr\Log\LoggerInterface::class),
];
}
}
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Utility;
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Filesystem\DirectoryList;
class LayoutTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Utility\Layout
*/
protected $_utility;
protected function setUp(): void
{
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize(
[
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => [
DirectoryList::APP => ['path' => BP . '/dev/tests/integration'],
],
]
);
$this->_utility = new \Magento\Framework\View\Utility\Layout($this);
}
/**
* Assert that the actual layout update instance represents the expected layout update file
*
* @param string $expectedUpdateFile
* @param \Magento\Framework\View\Layout\ProcessorInterface $actualUpdate
*/
protected function _assertLayoutUpdate($expectedUpdateFile, $actualUpdate)
{
$this->assertInstanceOf(\Magento\Framework\View\Layout\ProcessorInterface::class, $actualUpdate);
$layoutUpdateXml = $actualUpdate->getFileLayoutUpdatesXml();
$this->assertInstanceOf(\Magento\Framework\View\Layout\Element::class, $layoutUpdateXml);
$this->assertXmlStringEqualsXmlFile($expectedUpdateFile, $layoutUpdateXml->asNiceXml());
}
/**
* @param string|array $inputFiles
* @param string $expectedFile
*
* @dataProvider getLayoutFromFixtureDataProvider
*/
public function testGetLayoutUpdateFromFixture($inputFiles, $expectedFile)
{
$layoutUpdate = $this->_utility->getLayoutUpdateFromFixture($inputFiles);
$this->_assertLayoutUpdate($expectedFile, $layoutUpdate);
}
/**
* @param string|array $inputFiles
* @param string $expectedFile
*
* @dataProvider getLayoutFromFixtureDataProvider
*/
public function testGetLayoutFromFixture($inputFiles, $expectedFile)
{
$layout = $this->_utility->getLayoutFromFixture($inputFiles, $this->_utility->getLayoutDependencies());
$this->assertInstanceOf(\Magento\Framework\View\LayoutInterface::class, $layout);
$this->_assertLayoutUpdate($expectedFile, $layout->getUpdate());
}
public function getLayoutFromFixtureDataProvider()
{
return [
'single fixture file' => [
__DIR__ . '/_files/layout/handle_two.xml',
__DIR__ . '/_files/layout_merged/single_handle.xml',
],
'multiple fixture files' => [
glob(__DIR__ . '/_files/layout/*.xml'),
__DIR__ . '/_files/layout_merged/multiple_handles.xml',
]
];
}
}
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<block class="Magento\Framework\View\Element\Text" name="some_text_block">
<action method="setText">
<text>Some Default Text</text>
</action>
</block>
</page>
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page label="Handle Three" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="handle_one"/>
</page>
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page label="Handle Two" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="handle_one"/>
<referenceBlock name="some_text_block">
<action method="setText">
<text>Some Custom Text</text>
</action>
</referenceBlock>
</page>
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layouts>
<handle id="handle_one">
<block class="Magento\Framework\View\Element\Text" name="some_text_block">
<action method="setText">
<text>Some Default Text</text>
</action>
</block>
</handle>
<handle id="handle_three" label="Handle Three">
<update handle="handle_one"/>
</handle>
<handle id="handle_two" label="Handle Two">
<update handle="handle_one"/>
<referenceBlock name="some_text_block">
<action method="setText">
<text>Some Custom Text</text>
</action>
</referenceBlock>
</handle>
</layouts>
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layouts>
<handle id="handle_two" label="Handle Two">
<update handle="handle_one"/>
<referenceBlock name="some_text_block">
<action method="setText">
<text>Some Custom Text</text>
</action>
</referenceBlock>
</handle>
</layouts>
@@ -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, 'Fixture_Module', __DIR__);
@@ -0,0 +1,858 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Action "Back" as cross */
[class^=" catalog-product-"] .page-actions .action-back,
[class^=" catalog-product-"] .page-actions .action-back:hover,
[class^=" catalog-product-"] .page-actions .action-back:active,
[class^=" newsletter-"] .page-actions .action-back,
[class^=" newsletter-"] .page-actions .action-back:hover,
[class^=" newsletter-"] .page-actions .action-back:active {
overflow: hidden;
padding: 5px 6px 3px;
margin-left: 12px;
color: #7a7976;
}
[class^=" catalog-product-"] .page-actions .action-back:hover,
[class^=" newsletter-"] .page-actions .action-back:hover {
color: #000;
}
[class^=" catalog-product-"] .page-actions .action-back.mage-error,
[class^=" newsletter-"] .page-actions .action-back.mage-error {
color: #b57c72;
}
[class^=" catalog-product-"] .page-actions .action-back:before,
[class^=" newsletter-"] .page-actions .action-back:before {
display: inline-block;
font-family: 'MUI-Icons';
font-style: normal;
speak: none;
font-weight: normal;
-webkit-font-smoothing: antialiased;
content: '\e07d'; /* close icon */
font-size: 16px;
}
[class^=" catalog-product-"] .page-actions .action-back span,
[class^=" newsletter-"] .page-actions .action-back span {
display: inline-block;
overflow: hidden;
text-indent: -999em;
}
.page-actions .switcher {
display: inline-block;
vertical-align: top;
margin: 6px 17px 6px 6px;
}
/* Image Management */
.images {
position: relative;
border: 2px dotted #ccc;
border-radius: 5px;
margin-bottom: 2px;
padding: 5px;
}
.image,
.gallery .ui-state-highlight {
position: relative;
width: 17.874%;
border: 1px solid #ccc;
border-radius: 4px;
float: left;
margin: 5px 1%;
overflow: hidden;
background: #fff;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.image .spacer {
width: 100%;
}
.image .product-image {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
width: 100%;
z-index: 1;
}
.image-label {
visibility: hidden;
position: absolute;
top: 0;
left: 0;
width: 33px;
height: 33px;
background: url(Magento_ModuleB::images/gallery-image-base-label.png) no-repeat;
content: '';
z-index: 2;
}
.image.base-image .image-label {
visibility: visible;
}
.image-fade {
visibility: hidden;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: rgba(247, 242, 236, .8);
content: attr(data-image-hidden-label);
text-align: center;
text-transform: uppercase;
color: #a69a8f;
font: 18px/110px Arial, sans-serif;
font-weight: 500;
z-index: 3;
}
.eq-ie8 .image-fade {
background: #f7f2ec;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
}
.image.hidden-for-front .image-fade {
visibility: visible;
}
.gallery .image.hidden-for-front .image-fade {
line-height: 160px;
}
.image.active {
box-shadow: 0 0 10px #2ea9ec;
}
.image .actions {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
text-align: center;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
z-index: 1;
}
.image .actions [class^="action-"],
.image[data-image-hidden]:hover .actions [class^="action-"],
.image.hidden-for-front:hover .actions [class^="action-"] {
visibility: hidden;
}
.image:hover .actions [class^="action-"],
.image[data-image-hidden]:hover .actions .action-delete,
.hidden-for-front:hover .actions .action-delete {
visibility: visible;
}
.image .action-delete {
position: absolute;
top: 2px;
right: 2px;
z-index: 2;
}
.image .action-make-base {
position: absolute;
bottom: 20px;
left: 10%;
right: 10%;
padding: 5px;
margin: auto;
}
.image.base-image .action-make-base {
display: none;
}
.image .draggable-handle:before {
content: '';
}
.gallery .image .action-delete {
top: 5px;
right: 5px;
}
.image.ui-sortable-placeholder {
background: #d7ebf5;
border: 1px dotted #93dbff;
visibility: visible !important;
}
.image-placeholder .fileinput-button {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.image-placeholder .fileinput-button > span {
display: none;
}
.image-placeholder input[type="file"] {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
opacity: 0;
border: 500px solid transparent;
font-size: 10em;
z-index: 2;
cursor: pointer;
}
.image-placeholder-text {
padding: 0 10px;
position: absolute;
left: 0;
right: 0;
bottom: 0;
font-size: 11px;
font-weight: bold;
line-height: 1.333;
text-align: center;
color: #cac8c4;
}
.gallery .image-placeholder {
background-position: 50% 30%;
}
.gallery .image-placeholder-text {
margin-bottom: 15%;
}
@media screen and (max-width: 1200px) {
.gallery .image-placeholder-text {
margin-bottom: 5px;
}
}
/* Gallery image panel */
.image-panel {
display: none;
position: relative;
top: 5px;
clear: both;
background: #fff;
margin: 0 -18px 15px;
padding: 20px 15px;
box-shadow: 0 1px 3px #aaa inset;
border-bottom: 1px solid #cfd0cb;
}
.eq-ie8 .image-panel {
border: solid #d6d3d0;
border-width: 2px 1px 1px;
}
.eq-ie8 .image-pointer {
top: -13px;
}
.image-panel-controls,
.image-panel-preview {
float: left;
width: 65.95744680199999%;
margin-left: 2.127659574%;
}
.image-panel-preview {
margin-left: 0;
}
.image-panel-controls {
width: 29.914893614%;
padding: 28px 1% 0 1%;
}
.image-panel-controls .image-name {
display: block;
margin: 0 0 3px;
color: #666;
}
.image-file-params {
margin: 0 0 10px 0;
font-size: 11px;
color: #666;
}
.image-panel-controls .action-remove,
.image-panel-controls .action-remove:hover,
.image-panel-controls .action-remove:active,
.image-panel-controls .action-remove:focus,
.image-panel-controls .action-remove[disabled] {
color: #a29c94;
font: 12px/1.333 Arial, Verdana, sans-serif;
text-decoration: underline;
margin: 0 0 46px 0;
}
.image-panel-controls .fieldset-image-panel {
padding: 0 5px 0 0;
}
.image-panel-controls .fieldset-image-panel .field {
margin-bottom: 30px;
}
.image-panel-controls .fieldset-image-panel .label {
width: 100%;
text-align: left;
margin-bottom: 10px;
padding-top: 0;
}
.image-panel-controls .fieldset-image-panel .field > .control,
.image-panel-controls textarea {
width: 100%;
resize: vertical;
}
.image-panel-preview img {
width: 100%;
}
.image-panel .action-close {
position: absolute;
top: 15px;
right: 15px;
}
.image-panel .action-close:before {
font-family: 'MUI-Icons';
font-style: normal;
speak: none;
font-weight: normal;
-webkit-font-smoothing: antialiased;
content: '\e07d'; /* close icon */
font-size: 16px;
color: #bbb;
}
.image-panel .action-close span {
display: none;
}
/* action in fieldset wrapper */
#group-fields-product-details-wrapper .attribute-selector {
visibility: hidden;
}
#group-fields-product-details-wrapper.opened .attribute-selector {
visibility: visible;
}
.action-manage-images {
font: 11px/1.666 Arial, Verdana, sans-serif;
color: #a29c94;
text-decoration: underline;
}
/* Quantity filed on product */
.field-quantity_and_stock_status input[type="text"],
.field-weight .control .field:first-child {
width: 140px;
margin-right: 15px;
}
.field-quantity_and_stock_status select {
vertical-align: middle;
}
/* Weight field */
.field-weight .control {
display: table;
width: 100%;
}
.field-weight .control .field:first-child .control {
width: 100%;
}
.field-weight .choice {
padding-top: 3px;
}
.field-weight .choice input {
margin-right: 5px;
vertical-align: bottom;
}
.field-price .addon > input {
width: 99px;
float: left;
}
/* Validation for Product Fields with addons */
.field-price .control,
.field-special_price .control,
.field-msrp .control,
.field-weight .control,
.field-quantity_and_stock_status .control {
position: relative;
}
.field-price label.mage-error,
.field-special_price label.mage-error,
.field-msrp label.mage-error,
.field-weight label.mage-error,
.field-quantity_and_stock_status label.mage-error {
position: absolute;
left: 0;
top: 30px;
}
.field-tax_class_id .addon select {
border-radius: 4px;
}
.actions-select .dropdown-menu {
margin-top: 1px;
min-width: 38px;
}
.actions-select .dropdown-menu li {
padding: 5px;
text-align: center;
}
.actions-select .action-toggle,
.actions-select .action-toggle:hover,
.actions-select .action-toggle:active,
.actions-select .action-toggle:focus,
.actions-select .action-toggle[disabled] {
background: #fff;
padding: 4px 4px 3px 7px;
color: #888;
filter: none;
}
.actions-select .action-toggle > span {
display: inline-block;
font-family: Arial, Verdana, sans-serif;
margin-right: 3px;
}
.actions-select .action-toggle:before {
display: inline-block;
float: right;
color: #888;
}
/* Variations Search Field */
#variations-search-field {
margin-bottom: 16px;
}
#variations-search-field > .control {
position: relative;
width: 42%;
}
#variations-search-field > .control > input {
padding-right: 25px;
}
#configurable-attributes-container .field-variation > .label {
margin-left: -7px;
}
#configurable-attributes-container .field-variation > .control {
width: 43%;
}
#configurable-attributes-container .col-name {
width: 65%;
}
#configurable-attributes-container .col-include {
width: 80px;
}
#configurable-attributes-container .col-actions {
width: 80px;
}
#configurable-attributes-container .col-change-price {
width: 150px;
}
#configurable-attributes-container .field-change-pricing .field {
float: left;
}
#configurable-attributes-container .field-change-pricing .field-pricing-value {
width: 75px;
}
#configurable-attributes-container .field-change-pricing .action-toggle {
min-width: 40px;
}
@media screen and (max-width: 960px) {
[class^="fields-group-"] .field {
width: auto !important;
}
}
#configurable-attributes-container .field-pricing-value .control {
width: 75px;
}
#configurable-attributes-container .field-pricing-value .pricing-value {
width: 100%;
padding: 4px;
border-right: none;
border-radius: 4px 0 0 4px;
}
#configurable-attributes-container .field-pricing-measure select {
border-radius: 0 4px 4px 0;
}
/* "Generate Variations" button */
.generate {
margin-bottom: 18px;
}
#product-variations-matrix > .title {
margin-bottom: 10px;
}
/* Variations Image Uploader */
.eq-ie8 .actions-image-uploader .action-upload {
filter: none;
}
.actions-image-uploader .action-toggle,
.actions-image-uploader .action-toggle:hover,
.actions-image-uploader .action-toggle:active,
.actions-image-uploader .action-toggle:focus,
.actions-image-uploader .action-toggle[disabled] {
position: relative;
height: 33px;
padding-left: 2px;
padding-right: 2px;
background: #fff;
filter: none;
color: #888;
}
.actions-image-uploader.active .action-toggle {
border-radius: 0 5px 0 0;
}
.actions-image-uploader.active .action-toggle:after {
position: absolute;
left: 0;
right: 0;
bottom: -1px;
height: 1px;
background: #fff;
z-index: 991;
content: '';
}
.actions-image-uploader .dropdown-menu {
margin-top: -1px;
border-radius: 3px 0 3px 3px;
}
#product-variations-matrix img.variation {
position: relative;
border: 0;
width: 32px;
height: 32px;
z-index: 2;
}
#product-variations-matrix .action-upload {
position: relative;
border: 1px solid #b7b2a7;
background: #fff;
border-radius: 0;
padding: 0;
width: 31px;
height: 31px;
line-height: 31px;
text-align: center;
color: #9f9a91;
overflow: hidden;
cursor: default;
filter: none;
}
#product-variations-matrix .action-upload input[type="file"] {
position: absolute;
left: 0;
top: 0;
width: 31px;
height: 31px;
background: none;
border: 500px solid transparent;
font-size: 10em;
z-index: 3;
cursor: pointer;
}
#product-variations-matrix .action-upload:hover {
color: #7e7e7e;
}
#product-variations-matrix .action-upload:before {
font-family: 'MUI-Icons';
font-style: normal;
speak: none;
font-weight: normal;
-webkit-font-smoothing: antialiased;
content: '\e02d'; /* plus icon */
font-size: 22px;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: 1;
text-align: center;
}
#product-variations-matrix .action-upload.loading:before {
content: '';
}
#product-variations-matrix .action-upload.loading:after {
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: 0;
width: 31px;
height: 31px;
z-index: 4;
}
#product-variations-matrix .action-upload span,
#product-variations-matrix .action-choose span {
display: none;
}
#product-variations-matrix .action-choose,
#product-variations-matrix .action-choose:hover,
#product-variations-matrix .action-choose[disabled] {
color: #b8b3a7;
float: right;
margin: 6px 0 0 5px;
}
#product-variations-matrix .action-choose:hover {
color: #7e7e7e;
}
#product-variations-matrix .action-choose:before {
font-family: 'MUI-Icons';
font-style: normal;
speak: none;
font-weight: normal;
-webkit-font-smoothing: antialiased;
content: '\e03f'; /* user icon */
}
#product-variations-matrix .col-name > a + .action-choose:before {
content: '\e040'; /* user icon */
color: #a09a8c;
}
#product-variations-matrix .col-name > input {
width: 88%;
}
#product-variations-matrix .col-actions {
width: 60px;
}
#product-variations-matrix .col-name {
width: 30%;
}
#product-variations-matrix .col-sku {
width: 20%;
}
#product-variations-matrix .col-display,
#product-variations-matrix .col-qty,
#product-variations-matrix .col-weight {
width: 5%;
}
/* Select Associated Product popup window */
#configurable_associated_products_grid .filter-actions,
#configurable_associated_products_grid .filter {
display: none;
}
#product_options_container .data-table td,
#attribute-tier_price-container .data-table td {
vertical-align: top;
}
#product_options_container .product-option-scope-checkbox {
margin: 10px 5px 10px 0;
}
#product_options_container .select + .product-option-scope-checkbox {
margin: 0 5px;
}
#allow_open_amount {
margin-top: 8px;
}
.mage-new-category-dialog .ui-dialog-content .fieldset {
padding: 0;
margin: 0;
}
.mage-new-category-dialog .ui-dialog-content .label {
width: 25%;
}
.mage-new-category-dialog .ui-dialog-content .control {
width: 75%;
}
.mage-new-category-dialog .ui-dialog-buttonset {
text-align: left;
}
.mage-new-category-dialog .ui-dialog-buttonset .action-create {
margin: 0 0 0 25%;
vertical-align: middle;
}
/*
Advanced Pricing tab
-------------------------------------- */
/* Change Attribute Set */
#product_info_tabs li.removed,
.field.removed {
display: none !important;
}
/*
Custom Options
-------------------------------------- */
#product_options_container_top .field-option-title {
width: 500px;
}
#product_options_container_top .field-option-input-type {
width: 170px;
}
#product_options_container_top .col-draggable .draggable-handle {
top: 7px;
}
#product_options_container_top .col-name,
#product_options_container_top .col-sku {
width: 38%;
}
#product_options_container_top .add-select-row ~ label.mage-error {
display: block;
margin: 5px 0 0;
}
.eq-ie8 #product_options_container_top .fieldset,
.eq-ie8 #product_options_container_top .fieldset-alt {
margin-bottom: 0;
}
/*
Tier Price Table
-------------------------------------- */
.tiers_table .col-qty {
text-align: left;
width: 150px;
}
.tiers_table .col-qty > input {
width: 40%;
margin-right: 5px;
}
.tiers_table .col-qty > .nobr {
width: 50%;
float: right;
margin-top: 6px;
text-overflow: ellipsis;
overflow: hidden;
}
.tiers_table .col-price {
width: 16%;
}
.new-variation-set {
margin-left: 2.127659574%;
}
.not-applicable-attribute {
display: none;
}
.attribute-selector {
margin: -3px -4px 0 0;
}
.attribute-selector .dropdown-menu {
left: auto;
right: 0;
}
.attribute-selector .action-choose {
margin: 0;
}
.attribute-selector .mage-suggest-dropdown > ul {
position: relative;
max-height: 200px;
overflow: auto;
z-index: 1;
}
.attribute-selector .dropdown-menu .actions {
padding: 14px 12px;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

@@ -0,0 +1,13 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
.pp-general-uk > .entry-edit-head > .config-heading .heading strong,
.pp-method-payflow > .entry-edit-head > .config-heading .heading strong,
.pp-method-express > .entry-edit-head > .config-heading .heading strong,
.pp-method-general > .entry-edit-head > .config-heading .heading strong { padding-left:90px; background:url(images/logo.png) no-repeat 0 0px; line-height: 23px; }
.pp-method-general > .entry-edit-head > .config-heading:before { content:url(images/allinone.png); float:right; }
.payflow-settings-notice {padding-bottom: 1em;max-width: 660px;}
.payflow-settings-notice .important-label {color:red;}
.payflow-settings-notice ul.options-list {list-style:disc;padding:0 2em;}
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array" type="array">
<item name="buttons" xsi:type="array">
<item name="save" xsi:type="string">Magento\Catalog\Block\Adminhtml\Product\Edit\Button\CreateCategory</item>
</item>
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">new_category_form.new_category_form_data_source</item>
</item>
</argument>
</form>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">new_category_form.new_category_form_data_source</item>
</item>
</argument>
</form>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="buttons" xsi:type="array">
<item name="save" xsi:type="string">Magento\Catalog\Block\Adminhtml\Product\Edit\Button\CreateCategory</item>
</item>
</argument>
</form>
@@ -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, 'adminhtml/FrameworkViewUiComponent/default', __DIR__);
@@ -0,0 +1,9 @@
<!--
/**
* 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 theme</title>
</theme>
@@ -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, 'ViewTest_Module', __DIR__);
@@ -0,0 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
Modular file in the package/custom_theme
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Modular file in package/custom_theme */
@@ -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/Vendor_ViewTest/custom_theme', __DIR__);
@@ -0,0 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
Non-modular file in package/custom_theme
@@ -0,0 +1,10 @@
<!--
/**
* 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>Custom Theme</title>
<parent>Vendor_ViewTest/default</parent>
</theme>
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Non-modular file in package/custom_theme */
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Non-modular file in package/custom_theme, which overrides js lib file */
@@ -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/Vendor_ViewTest/custom_theme2', __DIR__);
@@ -0,0 +1,10 @@
<!--
/**
* 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>Custom Theme 2</title>
<parent>Vendor_ViewTest/custom_theme</parent>
</theme>
@@ -0,0 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
Modular file in package/default
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Modular file in package/default */
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Localized modular file in package/default */
@@ -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/Vendor_ViewTest/default', __DIR__);
@@ -0,0 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
Non-modular file in package/default
@@ -0,0 +1,9 @@
<!--
/**
* 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>Default</title>
</theme>
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Non-modular file in package/default */
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Localized non-modular file in package/default */
@@ -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/Vendor_ViewTest/standalone_theme', __DIR__);
@@ -0,0 +1,9 @@
<!--
/**
* 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>Standalone Theme</title>
</theme>
@@ -0,0 +1,5 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Fixture js lib file */
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
<container name="cachable_container1-1" label="test1" htmlTag="div" htmlId="cachable_container11" htmlClass="class11">
<block class="Magento\Framework\View\Element\Text" name="block-1-in-cacheable-container1">
<action method="setText">
<argument name="text" xsi:type="string">Test11</argument>
</action>
</block>
</container>
</layout>
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
<container name="container1" label="test1" htmlTag="div" htmlId="container1-1" htmlClass="class11">
<block class="Magento\Framework\View\Element\Text" name="block11">
<action method="setText">
<argument name="text" xsi:type="string">Test11</argument>
</action>
</block>
</container>
<referenceContainer name="container1" label="test1" htmlId="container1-2" htmlClass="class12">
<block class="Magento\Framework\View\Element\Text" name="block12">
<action method="setText">
<argument name="text" xsi:type="string">Test12</argument>
</action>
</block>
</referenceContainer>
<container name="container2" label="test2" htmlTag="div" htmlClass="class21">
<block class="Magento\Framework\View\Element\Text" name="block21">
<action method="setText">
<argument name="text" xsi:type="string">Test21</argument>
</action>
</block>
</container>
<referenceContainer name="container2" label="test2" htmlId="container2-2" htmlClass="class22">
<block class="Magento\Framework\View\Element\Text" name="block22">
<action method="setText">
<argument name="text" xsi:type="string">Test22</argument>
</action>
</block>
</referenceContainer>
</layout>
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
<container name="non_cachable_container1-1" label="test1" htmlTag="div" htmlId="non_cachable_container11" htmlClass="class11">
<block class="Magento\Framework\View\Element\Text" name="block-1-in-non-cacheable-container1" cacheable="false">
<action method="setText">
<argument name="text" xsi:type="string">Test11</argument>
</action>
</block>
</container>
</layout>

Some files were not shown because too many files have changed in this diff Show More