ltsecurityinc安防产品在线商城代码
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Config\Processor;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class DesignThemeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Verifies that empty 'design/theme/theme_id' config value is processed without errors.
|
||||
*/
|
||||
public function testProcessWithEmptyThemeId()
|
||||
{
|
||||
$designTheme = Bootstrap::getObjectManager()->create(DesignTheme::class);
|
||||
|
||||
$config = [
|
||||
'default' => [
|
||||
'design' => ['theme' => ['theme_id' => '']],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($config, $designTheme->process($config));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Theme\Model\Config;
|
||||
|
||||
use Magento\Email\Model\Template;
|
||||
|
||||
/**
|
||||
* Class ValidatorTest to test \Magento\Theme\Model\Design\Config\Validator
|
||||
*/
|
||||
class ValidatorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const TEMPLATE_CODE = 'email_exception_fixture';
|
||||
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Design\Config\Validator
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $templateFactoryMock;
|
||||
|
||||
/**
|
||||
* @var \Magento\Email\Model\Template
|
||||
*/
|
||||
private $templateModel;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\AreaList::class)
|
||||
->getArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE)
|
||||
->load(\Magento\Framework\App\Area::PART_CONFIG);
|
||||
$objectManager->get(\Magento\Framework\App\State::class)
|
||||
->setAreaCode(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
|
||||
$this->templateFactoryMock = $this->getMockBuilder(\Magento\Framework\Mail\TemplateInterfaceFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->templateModel = $objectManager->create(\Magento\Email\Model\Template::class);
|
||||
$this->templateModel->load(self::TEMPLATE_CODE, 'template_code');
|
||||
$this->templateFactoryMock->expects($this->once())
|
||||
->method("create")
|
||||
->willReturn($this->templateModel);
|
||||
$this->model = $objectManager->create(
|
||||
\Magento\Theme\Model\Design\Config\Validator::class,
|
||||
[ 'templateFactory' => $this->templateFactoryMock ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Email/Model/_files/email_template.php
|
||||
*/
|
||||
public function testValidateHasRecursiveReference()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
|
||||
if (!$this->templateModel->getId()) {
|
||||
$this->fail('Cannot load Template model');
|
||||
}
|
||||
|
||||
$fieldConfig = [
|
||||
'path' => 'design/email/header_template',
|
||||
'fieldset' => 'other_settings/email',
|
||||
'field' => 'email_header_template'
|
||||
];
|
||||
|
||||
$designConfigMock = $this->getMockBuilder(\Magento\Theme\Api\Data\DesignConfigInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
$designConfigExtensionMock =
|
||||
$this->getMockBuilder(\Magento\Theme\Api\Data\DesignConfigExtensionInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
$designElementMock = $this->getMockBuilder(\Magento\Theme\Model\Data\Design\Config\Data::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
|
||||
$designConfigMock->expects($this->once())
|
||||
->method('getExtensionAttributes')
|
||||
->willReturn($designConfigExtensionMock);
|
||||
$designConfigExtensionMock->expects($this->once())
|
||||
->method('getDesignConfigData')
|
||||
->willReturn([$designElementMock]);
|
||||
$designElementMock->expects($this->any())->method('getFieldConfig')->willReturn($fieldConfig);
|
||||
$designElementMock->expects($this->once())->method('getPath')->willReturn($fieldConfig['path']);
|
||||
$designElementMock->expects($this->once())->method('getValue')->willReturn($this->templateModel->getId());
|
||||
|
||||
$this->model->validate($designConfigMock);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
'The "email_header_template" template contains an incorrect configuration, with a reference to itself. '
|
||||
. 'Remove or change the reference, then try again.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Email/Model/_files/email_template.php
|
||||
*/
|
||||
public function testValidateNoRecursiveReference()
|
||||
{
|
||||
$this->templateFactoryMock->expects($this->once())
|
||||
->method("create")
|
||||
->willReturn($this->templateModel);
|
||||
|
||||
$fieldConfig = [
|
||||
'path' => 'design/email/footer_template',
|
||||
'fieldset' => 'other_settings/email',
|
||||
'field' => 'email_footer_template'
|
||||
];
|
||||
|
||||
$designConfigMock = $this->getMockBuilder(\Magento\Theme\Api\Data\DesignConfigInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
$designConfigExtensionMock =
|
||||
$this->getMockBuilder(\Magento\Theme\Api\Data\DesignConfigExtensionInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
$designElementMock = $this->getMockBuilder(\Magento\Theme\Model\Data\Design\Config\Data::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
|
||||
$designConfigMock->expects($this->once())
|
||||
->method('getExtensionAttributes')
|
||||
->willReturn($designConfigExtensionMock);
|
||||
$designConfigExtensionMock->expects($this->once())
|
||||
->method('getDesignConfigData')
|
||||
->willReturn([$designElementMock]);
|
||||
$designElementMock->expects($this->any())->method('getFieldConfig')->willReturn($fieldConfig);
|
||||
$designElementMock->expects($this->once())->method('getPath')->willReturn($fieldConfig['path']);
|
||||
$designElementMock->expects($this->once())->method('getValue')->willReturn($this->templateModel->getId());
|
||||
|
||||
$this->model->validate($designConfigMock);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Design\Backend;
|
||||
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
|
||||
class ExceptionsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Design\Backend\Exceptions
|
||||
*/
|
||||
private $exceptions = null;
|
||||
|
||||
/** @var Json */
|
||||
private $serializer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->exceptions = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design\Backend\Exceptions::class
|
||||
);
|
||||
$this->exceptions->setScope('default');
|
||||
$this->exceptions->setScopeId(0);
|
||||
$this->exceptions->setPath('design/theme/ua_regexp');
|
||||
$this->serializer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(Json::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic test, checks that saved value contains all required entries and is saved as an array
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSaveValueIsFormedNicely()
|
||||
{
|
||||
$value = [
|
||||
'1' => ['search' => '/Opera/', 'value' => 'Magento/blank'],
|
||||
'2' => ['search' => '/Firefox/', 'value' => 'Magento/blank'],
|
||||
];
|
||||
|
||||
$this->exceptions->setValue($value);
|
||||
$this->exceptions->save();
|
||||
|
||||
$processedValue = $this->serializer->unserialize($this->exceptions->getValue());
|
||||
$this->assertEquals(count($processedValue), 2, 'Number of saved values is wrong');
|
||||
|
||||
$entry = $processedValue['1'];
|
||||
$this->assertArrayHasKey('search', $entry);
|
||||
$this->assertArrayHasKey('value', $entry);
|
||||
$this->assertArrayHasKey('regexp', $entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSaveEmptyValueIsSkipped()
|
||||
{
|
||||
$value = [
|
||||
'1' => ['search' => '/Opera/', 'value' => 'Magento/blank'],
|
||||
'2' => ['search' => '', 'value' => 'Magento/blank'],
|
||||
'3' => ['search' => '/Firefox/', 'value' => 'Magento/blank'],
|
||||
];
|
||||
|
||||
$this->exceptions->setValue($value);
|
||||
$this->exceptions->save();
|
||||
|
||||
$processedValue = $this->serializer->unserialize($this->exceptions->getValue());
|
||||
$emptyIsSkipped = isset($processedValue['1']) && !isset($processedValue['2']) && isset($processedValue['3']);
|
||||
$this->assertTrue($emptyIsSkipped);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $designException
|
||||
* @param string $regexp
|
||||
* @dataProvider saveExceptionDataProvider
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSaveException($designException, $regexp)
|
||||
{
|
||||
$this->exceptions->setValue(['1' => $designException]);
|
||||
$this->exceptions->save();
|
||||
|
||||
$processedValue = $this->serializer->unserialize($this->exceptions->getValue());
|
||||
$this->assertEquals($processedValue['1']['regexp'], $regexp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function saveExceptionDataProvider()
|
||||
{
|
||||
$result = [
|
||||
[['search' => 'Opera', 'value' => 'Magento/blank'], '/Opera/i'],
|
||||
[['search' => '/Opera/', 'value' => 'Magento/blank'], '/Opera/'],
|
||||
[['search' => '#iPad|iPhone#i', 'value' => 'Magento/blank'], '#iPad|iPhone#i'],
|
||||
[
|
||||
['search' => 'Mozilla (3.6+)/Firefox', 'value' => 'Magento/blank'],
|
||||
'/Mozilla \\(3\\.6\\+\\)\\/Firefox/i'
|
||||
],
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array $value
|
||||
* @dataProvider saveWrongExceptionDataProvider
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testSaveWrongException($value)
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
|
||||
$this->exceptions->setValue($value);
|
||||
$this->exceptions->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function saveWrongExceptionDataProvider()
|
||||
{
|
||||
$result = [
|
||||
[
|
||||
[
|
||||
'1' => ['search' => '/Opera/', 'value' => 'Magento/blank'],
|
||||
'2' => ['search' => '/invalid_regexp(/', 'value' => 'Magento/blank'],
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'1' => ['search' => '/invalid_regexp', 'value' => 'Magento/blank'],
|
||||
'2' => ['search' => '/Opera/', 'value' => 'Magento/blank'],
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'1' => ['search' => 'invalid_regexp/iU', 'value' => 'Magento/blank'],
|
||||
'2' => ['search' => '/Opera/', 'value' => 'Magento/blank'],
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'1' => ['search' => 'invalid_regexp#', 'value' => 'Magento/blank'],
|
||||
'2' => ['search' => '/Opera/', 'value' => 'Magento/blank'],
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'1' => ['search' => '/Firefox/'],
|
||||
'2' => ['search' => '/Opera/', 'value' => 'Magento/blank'],
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'1' => ['value' => 'Magento/blank'],
|
||||
'2' => ['search' => '/Opera/', 'value' => 'Magento/blank'],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Theme\Model\Design;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Theme\Model\Design\Config\Storage.
|
||||
*/
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Design\Config\Storage
|
||||
*/
|
||||
private $storage;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->storage = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design\Config\Storage::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test design/header/welcome if it is saved in db as empty(null) it should be shown on backend as empty.
|
||||
*
|
||||
* @magentoDataFixture Magento/Theme/_files/config_data.php
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
$data = $this->storage->load('stores', 1);
|
||||
foreach ($data->getExtensionAttributes()->getDesignConfigData() as $configData) {
|
||||
if ($configData->getPath() == 'design/header/welcome') {
|
||||
$this->assertSame('', $configData->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model;
|
||||
|
||||
use Magento\Backend\Block\Widget\Grid\Serializer;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
|
||||
class DesignTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Design
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoadChange()
|
||||
{
|
||||
$this->_model->loadChange(1);
|
||||
$this->assertNull($this->_model->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Theme/_files/design_change.php
|
||||
*/
|
||||
public function testChangeDesign()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
|
||||
->setAreaCode('frontend');
|
||||
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
);
|
||||
$storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getDefaultStoreView()->getId();
|
||||
// fixture design_change
|
||||
$designChange = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design::class
|
||||
);
|
||||
$designChange->loadChange($storeId)->changeDesign($design);
|
||||
$this->assertEquals('Magento/luma', $design->getDesignTheme()->getThemePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testCRUD()
|
||||
{
|
||||
$this->_model->setData(
|
||||
[
|
||||
'store_id' => 1,
|
||||
'design' => 'Magento/blank',
|
||||
'date_from' => date('Y-m-d', strtotime('-1 day')),
|
||||
'date_to' => date('Y-m-d', strtotime('+1 day')),
|
||||
]
|
||||
);
|
||||
$this->_model->save();
|
||||
$this->assertNotEmpty($this->_model->getId());
|
||||
|
||||
try {
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design::class
|
||||
);
|
||||
$model->loadChange(1);
|
||||
$this->assertEquals($this->_model->getId(), $model->getId());
|
||||
|
||||
/* Design change that intersects with existing ones should not be saved, so exception is expected */
|
||||
try {
|
||||
$model->setId(null);
|
||||
$model->save();
|
||||
$this->fail('A validation failure is expected.');
|
||||
} catch (\Magento\Framework\Exception\LocalizedException $e) {
|
||||
}
|
||||
|
||||
$this->_model->delete();
|
||||
} catch (\Exception $e) {
|
||||
$this->_model->delete();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design::class
|
||||
);
|
||||
$model->loadChange(1);
|
||||
$this->assertEmpty($model->getId());
|
||||
}
|
||||
|
||||
public function testCollection()
|
||||
{
|
||||
$collection = $this->_model->getCollection()->joinStore()->addDateFilter();
|
||||
/**
|
||||
* @todo fix and add addStoreFilter method
|
||||
*/
|
||||
$this->assertEmpty($collection->getItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Theme/_files/design_change.php
|
||||
* @magentoConfigFixture current_store general/locale/timezone UTC
|
||||
*/
|
||||
public function testLoadChangeCache()
|
||||
{
|
||||
$date = (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
|
||||
$storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getDefaultStoreView()->getId();
|
||||
// fixture design_change
|
||||
// phpcs:ignore Magento2.Security.InsecureFunction
|
||||
$cacheId = 'design_change_' . md5($storeId . $date);
|
||||
|
||||
/** @var \Magento\Theme\Model\Design $design */
|
||||
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design::class
|
||||
);
|
||||
$design->loadChange($storeId, $date);
|
||||
|
||||
$cachedDesign = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\CacheInterface::class
|
||||
)->load(
|
||||
$cacheId
|
||||
);
|
||||
$serializer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(SerializerInterface::class);
|
||||
$cachedDesign = $serializer->unserialize($cachedDesign);
|
||||
|
||||
$this->assertIsArray($cachedDesign);
|
||||
$this->assertArrayHasKey('design', $cachedDesign);
|
||||
$this->assertEquals($cachedDesign['design'], $design->getDesign());
|
||||
|
||||
$design->setDesign('Magento/blank')->save();
|
||||
|
||||
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design::class
|
||||
);
|
||||
$design->loadChange($storeId, $date);
|
||||
|
||||
$cachedDesign = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\CacheInterface::class
|
||||
)->load(
|
||||
$cacheId
|
||||
);
|
||||
|
||||
$cachedDesign = $serializer->unserialize($cachedDesign);
|
||||
|
||||
$this->assertIsArray($cachedDesign);
|
||||
$this->assertEquals($cachedDesign['design'], $design->getDesign());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Theme/_files/design_change_timezone.php
|
||||
* @dataProvider loadChangeTimezoneDataProvider
|
||||
*/
|
||||
public function testLoadChangeTimezone($storeCode, $storeTimezone, $storeUtcOffset)
|
||||
{
|
||||
if (date_default_timezone_get() != 'UTC') {
|
||||
$this->markTestSkipped('Test requires UTC to be the default timezone.');
|
||||
}
|
||||
$utcDatetime = time();
|
||||
$utcDate = date('Y-m-d', $utcDatetime);
|
||||
$storeDatetime = strtotime($storeUtcOffset, $utcDatetime);
|
||||
$storeDate = date('Y-m-d', $storeDatetime);
|
||||
|
||||
if ($storeDate == $utcDate) {
|
||||
$expectedDesign = "{$storeCode}_today_design";
|
||||
} else {
|
||||
if ($storeDatetime > $utcDatetime) {
|
||||
$expectedDesign = "{$storeCode}_tomorrow_design";
|
||||
} else {
|
||||
$expectedDesign = "{$storeCode}_yesterday_design";
|
||||
}
|
||||
}
|
||||
|
||||
$store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore(
|
||||
$storeCode
|
||||
);
|
||||
$defaultTimeZonePath = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class
|
||||
)->getDefaultTimezonePath();
|
||||
$store->setConfig($defaultTimeZonePath, $storeTimezone);
|
||||
$storeId = $store->getId();
|
||||
|
||||
/** @var $locale \Magento\Framework\Stdlib\DateTime\TimezoneInterface */
|
||||
$locale = $this->createMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
|
||||
$locale->expects(
|
||||
$this->once()
|
||||
)->method(
|
||||
'scopeTimeStamp'
|
||||
)->with(
|
||||
$storeId
|
||||
)->willReturn(
|
||||
$storeDatetime
|
||||
);
|
||||
// store time must stay unchanged during test execution
|
||||
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Design::class,
|
||||
['localeDate' => $locale]
|
||||
);
|
||||
$design->loadChange($storeId);
|
||||
$actualDesign = $design->getDesign();
|
||||
|
||||
$this->assertEquals($expectedDesign, $actualDesign);
|
||||
}
|
||||
|
||||
public function loadChangeTimezoneDataProvider()
|
||||
{
|
||||
/**
|
||||
* Depending on the current UTC time, either UTC-12:00, or UTC+12:00 timezone points to the different date.
|
||||
* If UTC time is between 00:00 and 12:00, UTC+12:00 points to the same day, and UTC-12:00 to the previous day.
|
||||
* If UTC time is between 12:00 and 24:00, UTC-12:00 points to the same day, and UTC+12:00 to the next day.
|
||||
* Testing the design change with both UTC-12:00 and UTC+12:00 store timezones guarantees
|
||||
* that the proper design change is chosen for the timezone with the date different from the UTC.
|
||||
*/
|
||||
return [
|
||||
'default store - UTC+12:00' => ['default', 'Etc/GMT-12', '+12 hours'],
|
||||
'default store - UTC-12:00' => ['default', 'Etc/GMT+12', '-12 hours'],
|
||||
'admin store - UTC+12:00' => ['admin', 'Etc/GMT-12', '+12 hours'],
|
||||
'admin store - UTC-12:00' => ['admin', 'Etc/GMT+12', '-12 hours']
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* \Magento\Theme\Model\Layout\Config\Reader
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Layout\Config;
|
||||
|
||||
class ReaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Layout\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/** @var \Magento\Framework\Config\FileResolverInterface/PHPUnit\Framework\MockObject_MockObject */
|
||||
protected $_fileResolverMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = $objectManager->create(\Magento\Framework\App\Cache::class);
|
||||
$cache->clean();
|
||||
$this->_fileResolverMock = $this->getMockBuilder(
|
||||
\Magento\Framework\Config\FileResolverInterface::class
|
||||
)->disableOriginalConstructor()->getMock();
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\Theme\Model\Layout\Config\Reader::class,
|
||||
['fileResolver' => $this->_fileResolverMock]
|
||||
);
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$fileList = [file_get_contents(__DIR__ . '/../_files/page_layouts.xml')];
|
||||
$this->_fileResolverMock->expects($this->any())->method('get')->willReturn($fileList);
|
||||
$result = $this->_model->read('global');
|
||||
$expected = [
|
||||
'empty' => [
|
||||
'label' => 'Empty',
|
||||
'code' => 'empty',
|
||||
],
|
||||
'1column' => [
|
||||
'label' => '1 column',
|
||||
'code' => '1column',
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMergeCompleteAndPartial()
|
||||
{
|
||||
$fileList = [
|
||||
file_get_contents(__DIR__ . '/../_files/page_layouts.xml'),
|
||||
file_get_contents(__DIR__ . '/../_files/page_layouts2.xml'),
|
||||
];
|
||||
$this->_fileResolverMock->expects($this->any())->method('get')->willReturn($fileList);
|
||||
|
||||
$result = $this->_model->read('global');
|
||||
$expected = [
|
||||
'empty' => [
|
||||
'label' => 'Empty',
|
||||
'code' => 'empty',
|
||||
],
|
||||
'1column' => [
|
||||
'label' => '1 column modified',
|
||||
'code' => '1column',
|
||||
],
|
||||
'2columns-left' => [
|
||||
'label' => '2 columns with left bar',
|
||||
'code' => '2columns-left',
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* \Magento\Theme\Model\Layout\Config
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Layout;
|
||||
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Layout\Config
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $cache \Magento\Framework\App\Cache */
|
||||
$cache = $objectManager->create(\Magento\Framework\App\Cache::class);
|
||||
$cache->clean();
|
||||
$configFile = file_get_contents(__DIR__ . '/_files/page_layouts.xml');
|
||||
$fileResolverMock = $this->getMockBuilder(\Magento\Framework\Config\FileResolverInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$fileResolverMock->expects($this->any())
|
||||
->method('get')
|
||||
->willReturn([$configFile]);
|
||||
$reader = $objectManager->create(
|
||||
\Magento\Theme\Model\Layout\Config\Reader::class,
|
||||
['fileResolver' => $fileResolverMock]
|
||||
);
|
||||
$dataStorage = $objectManager->create(\Magento\Theme\Model\Layout\Config\Data::class, ['reader' => $reader]);
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\Theme\Model\Layout\Config::class,
|
||||
['dataStorage' => $dataStorage]
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetPageLayouts()
|
||||
{
|
||||
$empty = [
|
||||
'label' => 'Empty',
|
||||
'code' => 'empty',
|
||||
];
|
||||
$oneColumn = [
|
||||
'label' => '1 column',
|
||||
'code' => '1column',
|
||||
];
|
||||
$result = $this->_model->getPageLayouts();
|
||||
$this->assertEquals($empty, $result['empty']->getData());
|
||||
$this->assertEquals($oneColumn, $result['1column']->getData());
|
||||
}
|
||||
|
||||
public function testGetPageLayout()
|
||||
{
|
||||
$empty = [
|
||||
'label' => 'Empty',
|
||||
'code' => 'empty',
|
||||
];
|
||||
$this->assertEquals($empty, $this->_model->getPageLayout('empty')->getData());
|
||||
$this->assertFalse($this->_model->getPageLayout('unknownLayoutCode'));
|
||||
}
|
||||
|
||||
public function testGetPageLayoutHandles()
|
||||
{
|
||||
$expected = ['empty' => 'empty', '1column' => '1column'];
|
||||
$this->assertEquals($expected, $this->_model->getPageLayoutHandles());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
|
||||
<layout id="empty">
|
||||
<label translate="true">Empty</label>
|
||||
</layout>
|
||||
<layout id="1column">
|
||||
<label translate="true">1 column</label>
|
||||
</layout>
|
||||
</page_layouts>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
|
||||
<layout id="1column">
|
||||
<label translate="true">1 column modified</label>
|
||||
</layout>
|
||||
<layout id="2columns-left">
|
||||
<label translate="true">2 columns with left bar</label>
|
||||
</layout>
|
||||
</page_layouts>
|
||||
@@ -0,0 +1,382 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\ResourceModel\Theme;
|
||||
|
||||
use Magento\Framework\View\Design\ThemeInterface;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->configure(
|
||||
['preferences' => [\Magento\Theme\Model\Theme::class => \Magento\Theme\Model\Theme\Data::class]]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Magento\Theme\Model\ResourceModel\Theme\Collection
|
||||
*/
|
||||
protected static function _getThemesCollection()
|
||||
{
|
||||
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\ResourceModel\Theme\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testCollection()
|
||||
{
|
||||
$oldTotalRecords = self::_getThemesCollection()->getSize();
|
||||
|
||||
$collection = $this->setThemeFixture();
|
||||
$oldThemes = $collection->toArray();
|
||||
|
||||
$newThemeCollection = self::_getThemesCollection();
|
||||
$newThemes = $newThemeCollection->toArray();
|
||||
|
||||
$expectedTotalRecords = $oldTotalRecords + count(self::getThemeList());
|
||||
$this->assertEquals($expectedTotalRecords, $newThemes['totalRecords']);
|
||||
$this->assertEquals($oldThemes['items'], $newThemes['items']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fullPath
|
||||
* @param bool $shouldExist
|
||||
* @magentoDataFixture setThemeFixture
|
||||
* @dataProvider getThemeByFullPathDataProvider
|
||||
*/
|
||||
public function testGetThemeByFullPath($fullPath, $shouldExist)
|
||||
{
|
||||
$themeCollection = self::_getThemesCollection();
|
||||
$hasFound = false;
|
||||
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
|
||||
foreach ($themeCollection as $theme) {
|
||||
if ($theme->getFullPath() == $fullPath) {
|
||||
$hasFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$message = $shouldExist ? 'Theme not found' : 'Theme is found but it should not';
|
||||
$this->assertEquals($shouldExist, $hasFound, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getThemeByFullPathDataProvider()
|
||||
{
|
||||
return [
|
||||
['test_area/test/default', true],
|
||||
['test_area2/test/pro', true],
|
||||
['test_area/test/pro', false],
|
||||
['test_area2/test/default', false],
|
||||
['', false],
|
||||
['test_area', false],
|
||||
['test_area/test', false],
|
||||
['test_area/test/something', false]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture setThemeFixture
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider addAreaFilterDataProvider
|
||||
*/
|
||||
public function testAddAreaFilter($area, $themeCount)
|
||||
{
|
||||
/** @var $themeCollection \Magento\Theme\Model\ResourceModel\Theme\Collection */
|
||||
$themeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\ResourceModel\Theme\Collection::class
|
||||
);
|
||||
$themeCollection->addAreaFilter($area);
|
||||
$this->assertCount($themeCount, $themeCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function addAreaFilterDataProvider()
|
||||
{
|
||||
return [
|
||||
['area' => 'test_area', 'themeCount' => 1],
|
||||
['area' => 'test_area2', 'themeCount' => 1],
|
||||
['area' => 'test_area4', 'themeCount' => 0]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture setThemeFixture
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider addTypeFilterDataProvider
|
||||
* @covers \Magento\Theme\Model\ResourceModel\Theme\Collection::addAreaFilter
|
||||
*/
|
||||
public function testAddTypeFilter($themeType, $themeCount)
|
||||
{
|
||||
/** @var $themeCollection \Magento\Theme\Model\ResourceModel\Theme\Collection */
|
||||
$themeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\ResourceModel\Theme\Collection::class
|
||||
);
|
||||
$themeCollection->addAreaFilter('test_area3');
|
||||
if ($themeType !== false) {
|
||||
$themeCollection->addTypeFilter($themeType);
|
||||
}
|
||||
$this->assertCount($themeCount, $themeCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function addTypeFilterDataProvider()
|
||||
{
|
||||
return [
|
||||
['themeType' => ThemeInterface::TYPE_PHYSICAL, 'themeCount' => 1],
|
||||
['themeType' => ThemeInterface::TYPE_VIRTUAL, 'themeCount' => 1],
|
||||
['themeType' => ThemeInterface::TYPE_STAGING, 'themeCount' => 1],
|
||||
['themeType' => false, 'themeCount' => 3]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture setThemeFixture
|
||||
* @magentoDbIsolation enabled
|
||||
* @covers \Magento\Theme\Model\ResourceModel\Theme\Collection::filterVisibleThemes
|
||||
*/
|
||||
public function testFilterVisibleThemes()
|
||||
{
|
||||
/** @var $themeCollection \Magento\Theme\Model\ResourceModel\Theme\Collection */
|
||||
$themeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\ResourceModel\Theme\Collection::class
|
||||
);
|
||||
$themeCollection->addAreaFilter('test_area3')->filterVisibleThemes();
|
||||
$this->assertCount(2, $themeCollection);
|
||||
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
|
||||
foreach ($themeCollection as $theme) {
|
||||
$this->assertTrue(
|
||||
in_array($theme->getType(), [ThemeInterface::TYPE_PHYSICAL, ThemeInterface::TYPE_VIRTUAL])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture setInheritedThemeFixture
|
||||
*/
|
||||
public function testCheckParentInThemes()
|
||||
{
|
||||
$collection = self::_getThemesCollection();
|
||||
//->checkParentInThemes();
|
||||
foreach (self::getInheritedThemeList() as $themeData) {
|
||||
$fullPath = $themeData['area'] . '/' . $themeData['theme_path'];
|
||||
$parentIdActual = $collection->clear()->getThemeByFullPath($fullPath)->getParentId();
|
||||
if ($themeData['parent_id']) {
|
||||
$parentFullPath = trim($themeData['parent_id'], '{}');
|
||||
$parentIdExpected = (int)$collection->clear()->getThemeByFullPath($parentFullPath)->getId();
|
||||
$this->assertEquals(
|
||||
$parentIdActual,
|
||||
$parentIdExpected,
|
||||
sprintf('Invalid parent_id for theme "%s"', $fullPath)
|
||||
);
|
||||
} else {
|
||||
$parentIdExpected = 0;
|
||||
$this->assertEquals(
|
||||
$parentIdExpected,
|
||||
$parentIdActual,
|
||||
sprintf('Parent id should be null for "%s"', $fullPath)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set themes fixtures
|
||||
*
|
||||
* @return \Magento\Theme\Model\ResourceModel\Theme\Collection
|
||||
*/
|
||||
public static function setThemeFixture()
|
||||
{
|
||||
$themeCollection = self::_getThemesCollection();
|
||||
$themeCollection->load();
|
||||
foreach (self::getThemeList() as $themeData) {
|
||||
/** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
|
||||
$themeModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Design\ThemeInterface::class
|
||||
);
|
||||
$themeModel->setData($themeData);
|
||||
$themeCollection->addItem($themeModel);
|
||||
}
|
||||
return $themeCollection->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setInheritedThemeFixture()
|
||||
{
|
||||
$fixture = self::getInheritedThemeList();
|
||||
$idByPath = [];
|
||||
foreach ($fixture as $themeData) {
|
||||
/** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
|
||||
$themeModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Design\ThemeInterface::class
|
||||
);
|
||||
$themeModel->setData($themeData);
|
||||
|
||||
if ($themeData['parent_id'] && isset($idByPath[$themeData['parent_id']])) {
|
||||
$themeModel->setParentId($idByPath[$themeData['parent_id']]);
|
||||
}
|
||||
$themeModel->save();
|
||||
|
||||
$idByPath[$themeModel->getFullPath()] = $themeModel->getId();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get themes for making fixture
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getThemeList()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'parent_id' => '0',
|
||||
'theme_path' => 'test/default',
|
||||
'code' => 'test/default',
|
||||
'theme_title' => 'Test',
|
||||
'preview_image' => 'test_default.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'test_area',
|
||||
'type' => ThemeInterface::TYPE_PHYSICAL,
|
||||
],
|
||||
[
|
||||
'parent_id' => '0',
|
||||
'theme_path' => 'test/pro',
|
||||
'code' => 'test/pro',
|
||||
'theme_title' => 'Professional Test',
|
||||
'preview_image' => 'test_default.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'test_area2',
|
||||
'type' => ThemeInterface::TYPE_VIRTUAL
|
||||
],
|
||||
[
|
||||
'parent_id' => '0',
|
||||
'theme_path' => 'test/fixed1',
|
||||
'code' => 'test/fixed1',
|
||||
'theme_title' => 'Theme test 1',
|
||||
'preview_image' => 'test_default.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'test_area3',
|
||||
'type' => ThemeInterface::TYPE_STAGING
|
||||
],
|
||||
[
|
||||
'parent_id' => '0',
|
||||
'theme_path' => 'test/fixed2',
|
||||
'code' => 'test/fixed2',
|
||||
'theme_title' => 'Theme test 2',
|
||||
'preview_image' => 'test_default.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'test_area3',
|
||||
'type' => ThemeInterface::TYPE_PHYSICAL
|
||||
],
|
||||
[
|
||||
'parent_id' => '0',
|
||||
'theme_path' => 'test/fixed3',
|
||||
'code' => 'test/fixed3',
|
||||
'theme_title' => 'Theme test 3',
|
||||
'preview_image' => 'test_default.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'test_area3',
|
||||
'type' => ThemeInterface::TYPE_VIRTUAL
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getInheritedThemeList()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'parent_id' => '0',
|
||||
'theme_path' => 'test1/test1',
|
||||
'code' => 'test1/test1',
|
||||
'theme_title' => 'Test1',
|
||||
'preview_image' => 'test1_test1.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'area51',
|
||||
'type' => ThemeInterface::TYPE_PHYSICAL,
|
||||
],
|
||||
[
|
||||
'parent_id' => 'area51/test1/test1',
|
||||
'theme_path' => 'test1/test2',
|
||||
'code' => 'test1/test2',
|
||||
'theme_title' => 'Test2',
|
||||
'preview_image' => 'test1_test2.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'area51',
|
||||
'type' => ThemeInterface::TYPE_VIRTUAL
|
||||
],
|
||||
[
|
||||
'parent_id' => 'area51/test1/test2',
|
||||
'theme_path' => 'test1/test3',
|
||||
'code' => 'test1/test3',
|
||||
'theme_title' => 'Test3',
|
||||
'preview_image' => 'test1_test3.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'area51',
|
||||
'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL
|
||||
],
|
||||
[
|
||||
'parent_id' => 'area51/test1/test0',
|
||||
'theme_path' => 'test1/test4',
|
||||
'code' => 'test1/test4',
|
||||
'theme_title' => 'Test4',
|
||||
'preview_image' => 'test1_test4.jpg',
|
||||
'is_featured' => '1',
|
||||
'area' => 'area51',
|
||||
'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Theme\Model\ResourceModel\Theme\Collection::filterPhysicalThemes
|
||||
*/
|
||||
public function testFilterPhysicalThemesPerPage()
|
||||
{
|
||||
$collection = $this->_getThemesCollection();
|
||||
$collection->filterPhysicalThemes(1, \Magento\Theme\Model\ResourceModel\Theme\Collection::DEFAULT_PAGE_SIZE);
|
||||
|
||||
$this->assertLessThanOrEqual(
|
||||
\Magento\Theme\Model\ResourceModel\Theme\Collection::DEFAULT_PAGE_SIZE,
|
||||
$collection->count()
|
||||
);
|
||||
|
||||
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
|
||||
foreach ($collection as $theme) {
|
||||
$this->assertEquals(\Magento\Framework\App\Area::AREA_FRONTEND, $theme->getArea());
|
||||
$this->assertEquals(ThemeInterface::TYPE_PHYSICAL, $theme->getType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Theme\Model\ResourceModel\Theme\Collection::filterPhysicalThemes
|
||||
*/
|
||||
public function testFilterPhysicalThemes()
|
||||
{
|
||||
$collection = $this->_getThemesCollection()->filterPhysicalThemes();
|
||||
|
||||
$this->assertGreaterThan(0, $collection->count());
|
||||
|
||||
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
|
||||
foreach ($collection as $theme) {
|
||||
$this->assertEquals(\Magento\Framework\App\Area::AREA_FRONTEND, $theme->getArea());
|
||||
$this->assertEquals(ThemeInterface::TYPE_PHYSICAL, $theme->getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for filesystem themes collection
|
||||
*/
|
||||
namespace Magento\Theme\Model\Theme;
|
||||
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
/**
|
||||
* @magentoComponentsDir Magento/Theme/Model/_files/design
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Theme\Collection
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$directoryList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Filesystem\DirectoryList::class,
|
||||
[
|
||||
'root' => DirectoryList::ROOT,
|
||||
]
|
||||
);
|
||||
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\Filesystem::class,
|
||||
['directoryList' => $directoryList]
|
||||
);
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Theme\Model\Theme\Collection::class,
|
||||
['filesystem' => $filesystem]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test load themes collection from filesystem
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testLoadThemesFromFileSystem()
|
||||
{
|
||||
$this->_model->addConstraint(\Magento\Theme\Model\Theme\Collection::CONSTRAINT_AREA, 'frontend');
|
||||
$this->assertNotEmpty($this->_model->getItemById('frontend/Magento_FrameworkThemeTest/default'));
|
||||
$this->assertEmpty($this->_model->getItemById('adminhtml/FrameworkThemeTest/test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from configuration
|
||||
*
|
||||
* @dataProvider expectedThemeDataFromConfiguration
|
||||
*/
|
||||
public function testLoadFromConfiguration($area, $vendor, $themeName, $expectedData)
|
||||
{
|
||||
$this->_model->addConstraint(\Magento\Theme\Model\Theme\Collection::CONSTRAINT_AREA, $area);
|
||||
$this->_model->addConstraint(\Magento\Theme\Model\Theme\Collection::CONSTRAINT_VENDOR, $vendor);
|
||||
$this->_model->addConstraint(\Magento\Theme\Model\Theme\Collection::CONSTRAINT_THEME_NAME, $themeName);
|
||||
$theme = $this->_model->getFirstItem();
|
||||
$this->assertEquals($expectedData, $theme->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Expected theme data from configuration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function expectedThemeDataFromConfiguration()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'frontend', 'Magento_FrameworkThemeTest', 'default',
|
||||
[
|
||||
'area' => 'frontend',
|
||||
'theme_title' => 'Default',
|
||||
'parent_id' => null,
|
||||
'parent_theme_path' => null,
|
||||
'theme_path' => 'Magento_FrameworkThemeTest/default',
|
||||
'code' => 'Magento_FrameworkThemeTest/default',
|
||||
'preview_image' => null,
|
||||
'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL,
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if theme present in file system
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Theme\Model\Theme\Collection::hasTheme
|
||||
*/
|
||||
public function testHasThemeInCollection()
|
||||
{
|
||||
/** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
|
||||
$themeModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Design\ThemeInterface::class
|
||||
);
|
||||
$themeModel->setData(
|
||||
[
|
||||
'area' => 'space_area',
|
||||
'theme_title' => 'Space theme',
|
||||
'parent_id' => null,
|
||||
'is_featured' => false,
|
||||
'theme_path' => 'default_space',
|
||||
'preview_image' => 'images/preview.png',
|
||||
'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL,
|
||||
]
|
||||
);
|
||||
|
||||
$this->_model->addConstraint(Collection::CONSTRAINT_AREA, Area::AREA_FRONTEND);
|
||||
$this->assertFalse($this->_model->hasTheme($themeModel));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Theme\Domain;
|
||||
|
||||
use Magento\Framework\View\Design\ThemeInterface;
|
||||
|
||||
class VirtualTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_themes = [
|
||||
'physical' => [
|
||||
'parent_id' => null,
|
||||
'theme_path' => 'test/test',
|
||||
'theme_title' => 'Test physical theme',
|
||||
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
|
||||
'type' => ThemeInterface::TYPE_PHYSICAL,
|
||||
'code' => 'physical',
|
||||
],
|
||||
'virtual' => [
|
||||
'parent_id' => null,
|
||||
'theme_path' => '',
|
||||
'theme_title' => 'Test virtual theme',
|
||||
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
|
||||
'type' => ThemeInterface::TYPE_VIRTUAL,
|
||||
'code' => 'virtual',
|
||||
],
|
||||
'staging' => [
|
||||
'parent_id' => null,
|
||||
'theme_path' => '',
|
||||
'theme_title' => 'Test staging theme',
|
||||
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
|
||||
'type' => ThemeInterface::TYPE_STAGING,
|
||||
'code' => 'staging',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_physicalThemeId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_virtualThemeId;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testGetPhysicalTheme()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
//1. set up fixture
|
||||
/** @var $physicalTheme \Magento\Framework\View\Design\ThemeInterface */
|
||||
$physicalTheme = $objectManager->create(\Magento\Framework\View\Design\ThemeInterface::class);
|
||||
$physicalTheme->setData($this->_themes['physical']);
|
||||
$physicalTheme->save();
|
||||
|
||||
$this->_themes['virtual']['parent_id'] = $physicalTheme->getId();
|
||||
|
||||
/** @var $virtualTheme \Magento\Framework\View\Design\ThemeInterface */
|
||||
$virtualTheme = $objectManager->create(\Magento\Framework\View\Design\ThemeInterface::class);
|
||||
$virtualTheme->setData($this->_themes['virtual']);
|
||||
$virtualTheme->save();
|
||||
|
||||
$this->_themes['staging']['parent_id'] = $virtualTheme->getId();
|
||||
|
||||
/** @var $stagingTheme \Magento\Framework\View\Design\ThemeInterface */
|
||||
$stagingTheme = $objectManager->create(\Magento\Framework\View\Design\ThemeInterface::class);
|
||||
$stagingTheme->setData($this->_themes['staging']);
|
||||
$stagingTheme->save();
|
||||
|
||||
$this->_physicalThemeId = $physicalTheme->getId();
|
||||
$this->_virtualThemeId = $virtualTheme->getId();
|
||||
|
||||
//2. run test
|
||||
/** @var $virtualTheme \Magento\Framework\View\Design\ThemeInterface */
|
||||
$virtualTheme = $objectManager->create(\Magento\Framework\View\Design\ThemeInterface::class);
|
||||
$virtualTheme->load($this->_virtualThemeId);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->_physicalThemeId,
|
||||
$virtualTheme->getDomainModel(
|
||||
\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL
|
||||
)->getPhysicalTheme()->getId()
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_physicalThemeId = null;
|
||||
$this->_virtualThemeId = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Theme;
|
||||
|
||||
class FileTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Theme\File
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_data = [];
|
||||
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Theme
|
||||
*/
|
||||
protected $_theme;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_model = $objectManager->create(\Magento\Theme\Model\Theme\File::class);
|
||||
/** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
|
||||
$themeModel = $objectManager->create(\Magento\Framework\View\Design\ThemeInterface::class);
|
||||
$this->_theme = $themeModel->getCollection()->getFirstItem();
|
||||
$this->_data = [
|
||||
'file_path' => 'main.css',
|
||||
'file_type' => 'css',
|
||||
'content' => 'content files',
|
||||
'order' => 0,
|
||||
'theme' => $this->_theme,
|
||||
'theme_id' => $this->_theme->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_model = null;
|
||||
$this->_data = [];
|
||||
$this->_theme = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test crud operations for theme files model using valid data
|
||||
*/
|
||||
public function testCrud()
|
||||
{
|
||||
$this->_model->setData($this->_data);
|
||||
|
||||
$crud = new \Magento\TestFramework\Entity($this->_model, ['file_path' => 'rename.css']);
|
||||
$crud->testCrud();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Theme;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class RegistrationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Theme\Registration
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Theme\Model\Theme
|
||||
*/
|
||||
protected $_theme;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
ComponentRegistrar::register(
|
||||
ComponentRegistrar::THEME,
|
||||
'frontend/Test/test_theme',
|
||||
dirname(__DIR__) . '/_files/design/frontend/Test/test_theme'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize base models
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\App\AreaList::class)
|
||||
->getArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE)
|
||||
->load(\Magento\Framework\App\Area::PART_CONFIG);
|
||||
|
||||
$objectManager->get(\Magento\Framework\App\State::class)
|
||||
->setAreaCode(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
$this->_theme = $objectManager
|
||||
->create(\Magento\Framework\View\Design\ThemeInterface::class);
|
||||
$this->_model = $objectManager
|
||||
->create(\Magento\Theme\Model\Theme\Registration::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register themes
|
||||
* Use this method only with database isolation
|
||||
*
|
||||
* @return \Magento\Theme\Model\Theme\RegistrationTest
|
||||
*/
|
||||
protected function registerThemes()
|
||||
{
|
||||
$this->_model->register();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method only with database isolation
|
||||
*
|
||||
* @return \Magento\Theme\Model\Theme
|
||||
*/
|
||||
protected function _getTestTheme()
|
||||
{
|
||||
$theme = $this->_theme->getCollection()->getThemeByFullPath(
|
||||
implode(\Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR, ['frontend', 'Test/test_theme'])
|
||||
);
|
||||
$this->assertNotEmpty($theme->getId());
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testVirtualByVirtualRelation()
|
||||
{
|
||||
$this->registerThemes();
|
||||
$theme = $this->_getTestTheme();
|
||||
|
||||
$virtualTheme = clone $this->_theme;
|
||||
$virtualTheme->setData($theme->getData())->setId(null);
|
||||
$virtualTheme->setType(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL)->save();
|
||||
|
||||
$subVirtualTheme = clone $this->_theme;
|
||||
$subVirtualTheme->setData($theme->getData())->setId(null);
|
||||
$subVirtualTheme->setParentId(
|
||||
$virtualTheme->getId()
|
||||
)->setType(
|
||||
\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL
|
||||
)->save();
|
||||
|
||||
$this->registerThemes();
|
||||
$parentId = $subVirtualTheme->getParentId();
|
||||
$subVirtualTheme->load($subVirtualTheme->getId());
|
||||
$this->assertNotEquals($parentId, $subVirtualTheme->getParentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testPhysicalThemeElimination()
|
||||
{
|
||||
$this->registerThemes();
|
||||
$theme = $this->_getTestTheme();
|
||||
|
||||
$testTheme = clone $this->_theme;
|
||||
$testTheme->setData($theme->getData())->setThemePath('empty')->setId(null);
|
||||
$testTheme->setType(\Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL)->save();
|
||||
|
||||
$this->registerThemes();
|
||||
$testTheme->load($testTheme->getId());
|
||||
$this->assertNotEquals(
|
||||
(int)$testTheme->getType(),
|
||||
\Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testRegister()
|
||||
{
|
||||
$this->registerThemes();
|
||||
$themePath = implode(
|
||||
\Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR,
|
||||
['frontend', 'Test/test_theme']
|
||||
);
|
||||
$theme = $this->_model->getThemeFromDb($themePath);
|
||||
$this->assertEquals($themePath, $theme->getFullPath());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Theme\Source;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Theme Test
|
||||
*
|
||||
*/
|
||||
class ThemeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetAllOptions()
|
||||
{
|
||||
/** @var $model \Magento\Theme\Model\Theme\Source\Theme */
|
||||
$model = Bootstrap::getObjectManager()->create(\Magento\Theme\Model\Theme\Source\Theme::class);
|
||||
|
||||
/** @var $expectedCollection \Magento\Theme\Model\Theme\Collection */
|
||||
$expectedCollection = Bootstrap::getObjectManager()
|
||||
->create(\Magento\Theme\Model\ResourceModel\Theme\Collection::class);
|
||||
$expectedCollection->addFilter('area', 'frontend');
|
||||
|
||||
$expectedItemsCount = count($expectedCollection);
|
||||
|
||||
$labelsCollection = $model->getAllOptions(false);
|
||||
$this->assertEquals($expectedItemsCount, count($labelsCollection));
|
||||
|
||||
$labelsCollection = $model->getAllOptions(true);
|
||||
$this->assertEquals(++$expectedItemsCount, count($labelsCollection));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
|
||||
<title>Theme D</title>
|
||||
</theme>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
|
||||
<title>Theme E</title>
|
||||
</theme>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
|
||||
<title>Default</title>
|
||||
</theme>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
|
||||
<title>Theme G</title>
|
||||
<parent>Magento/default</parent>
|
||||
</theme>
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Theme\Model\Theme;
|
||||
|
||||
use Magento\Framework\App\Config\MutableScopeConfigInterface;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory;
|
||||
use Magento\Theme\Model\ResourceModel\Theme\Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class StoreThemesResolverInterfaceTest extends TestCase
|
||||
{
|
||||
const XML_PATH_THEME_USER_AGENT = 'design/theme/ua_regexp';
|
||||
/**
|
||||
* @var StoreThemesResolverInterface
|
||||
*/
|
||||
private $model;
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
private $themesCollection;
|
||||
/**
|
||||
* @var MutableScopeConfigInterface
|
||||
*/
|
||||
private $mutableScopeConfig;
|
||||
/**
|
||||
* @var Json
|
||||
*/
|
||||
private $serializer;
|
||||
/**
|
||||
* @var StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $userAgentDesignConfig;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->model = $objectManager->get(StoreThemesResolverInterface::class);
|
||||
$themesCollectionFactory = $objectManager->get(CollectionFactory::class);
|
||||
$this->themesCollection = $themesCollectionFactory->create();
|
||||
$this->mutableScopeConfig = $objectManager->get(MutableScopeConfigInterface::class);
|
||||
$this->serializer = $objectManager->get(Json::class);
|
||||
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
|
||||
$scopeConfig = $objectManager->get(ScopeConfigInterface::class);
|
||||
$this->userAgentDesignConfig = $scopeConfig->getValue(
|
||||
self::XML_PATH_THEME_USER_AGENT,
|
||||
ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->mutableScopeConfig->setValue(
|
||||
self::XML_PATH_THEME_USER_AGENT,
|
||||
$this->userAgentDesignConfig,
|
||||
ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param array $expected
|
||||
* @dataProvider getThemesDataProvider
|
||||
*/
|
||||
public function testGetThemes(array $config, array $expected): void
|
||||
{
|
||||
$store = $this->storeManager->getStore();
|
||||
$registeredThemes = [];
|
||||
foreach ($this->themesCollection as $theme) {
|
||||
$registeredThemes[$theme->getCode()] = $theme->getId();
|
||||
}
|
||||
// convert themes code to id
|
||||
foreach ($config as $key => $item) {
|
||||
$config[$key]['value'] = $registeredThemes[$item['value']];
|
||||
}
|
||||
$this->mutableScopeConfig->setValue(
|
||||
self::XML_PATH_THEME_USER_AGENT,
|
||||
$config ? $this->serializer->serialize($config) : null,
|
||||
ScopeInterface::SCOPE_STORE,
|
||||
$store->getCode()
|
||||
);
|
||||
$expected = array_map(
|
||||
function ($theme) use ($registeredThemes) {
|
||||
return $registeredThemes[$theme];
|
||||
},
|
||||
$expected
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->model->getThemes($store),
|
||||
'',
|
||||
0.0,
|
||||
10,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getThemesDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
],
|
||||
[
|
||||
'Magento/luma'
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
[
|
||||
'search' => '\/Chrome\/i',
|
||||
'regexp' => '\/Chrome\/i',
|
||||
'value' => 'Magento/blank',
|
||||
]
|
||||
],
|
||||
[
|
||||
'Magento/luma',
|
||||
'Magento/blank'
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\Theme;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Theme\Model\Theme;
|
||||
use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection;
|
||||
use Magento\TestFramework\Helper\CacheCleaner;
|
||||
|
||||
class ThemeProviderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ThemeProvider
|
||||
*/
|
||||
private $themeProviderOne;
|
||||
|
||||
/**
|
||||
* @var ThemeProvider
|
||||
*/
|
||||
private $themeProviderTwo;
|
||||
|
||||
/**
|
||||
* @var ThemeCollection
|
||||
*/
|
||||
private $themeCollection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->themeProviderOne = $objectManager->create(ThemeProvider::class);
|
||||
$this->themeProviderTwo = clone $this->themeProviderOne;
|
||||
$this->themeCollection = $objectManager->create(ThemeCollection::class);
|
||||
}
|
||||
|
||||
public function testGetThemeById()
|
||||
{
|
||||
/** @var Theme $theme */
|
||||
foreach ($this->themeCollection as $theme) {
|
||||
$theme = $this->themeProviderOne->getThemeById($theme->getId());
|
||||
$this->assertSame(
|
||||
$theme,
|
||||
$this->themeProviderOne->getThemeById($theme->getId())
|
||||
);
|
||||
$this->assertSame(
|
||||
$theme->getData(),
|
||||
$this->themeProviderTwo->getThemeById($theme->getId())->getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetThemeByFullPath()
|
||||
{
|
||||
/** @var Theme $theme */
|
||||
foreach ($this->themeCollection as $theme) {
|
||||
$theme = $this->themeProviderOne->getThemeByFullPath($theme->getFullPath());
|
||||
$this->assertSame(
|
||||
$theme,
|
||||
$this->themeProviderOne->getThemeByFullPath($theme->getFullPath())
|
||||
);
|
||||
$this->assertSame(
|
||||
$theme->getData(),
|
||||
$this->themeProviderTwo->getThemeByFullPath($theme->getFullPath())->getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model;
|
||||
|
||||
class ThemeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test crud operations for theme model using valid data
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testCrud()
|
||||
{
|
||||
/** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
|
||||
$themeModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\View\Design\ThemeInterface::class
|
||||
);
|
||||
$themeModel->setData($this->_getThemeValidData());
|
||||
|
||||
$crud = new \Magento\TestFramework\Entity($themeModel, []);
|
||||
$crud->testCrud();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme valid data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getThemeValidData()
|
||||
{
|
||||
return [
|
||||
'area' => 'space_area',
|
||||
'theme_title' => 'Space theme',
|
||||
'parent_id' => null,
|
||||
'is_featured' => false,
|
||||
'theme_path' => 'default/space',
|
||||
'preview_image' => 'images/preview.png',
|
||||
'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test theme on child relations
|
||||
*/
|
||||
public function testChildRelation()
|
||||
{
|
||||
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
|
||||
$theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\Design\ThemeInterface::class
|
||||
);
|
||||
$collection = $theme->getCollection()
|
||||
->addTypeFilter(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL);
|
||||
/** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */
|
||||
foreach ($collection as $currentTheme) {
|
||||
$parentTheme = $currentTheme->getParentTheme();
|
||||
if (!empty($parentTheme)) {
|
||||
$this->assertTrue($parentTheme->hasChildThemes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoComponentsDir Magento/Theme/Model/_files/design
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testGetInheritedThemes()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\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 */
|
||||
$themeFactory = $objectManager->get(
|
||||
\Magento\Framework\View\Design\Theme\FlyweightFactory::class
|
||||
);
|
||||
$theme = $themeFactory->create('Vendor_FrameworkThemeTest/custom_theme');
|
||||
$this->assertCount(2, $theme->getInheritedThemes());
|
||||
$expected = [];
|
||||
foreach ($theme->getInheritedThemes() as $someTheme) {
|
||||
$expected[] = $someTheme->getFullPath();
|
||||
}
|
||||
$this->assertEquals(
|
||||
['frontend/Vendor_FrameworkThemeTest/default', 'frontend/Vendor_FrameworkThemeTest/custom_theme'],
|
||||
$expected
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Theme\Model\View;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
|
||||
/**
|
||||
* @magentoComponentsDir Magento/Theme/Model/_files/design
|
||||
* @magentoDbIsolation enabled
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class DesignTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\View\DesignInterface
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\View\FileSystem
|
||||
*/
|
||||
protected $_viewFileSystem;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\View\ConfigInterface
|
||||
*/
|
||||
protected $_viewConfig;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Framework\Filesystem $filesystem */
|
||||
$filesystem = $objectManager->get(\Magento\Framework\Filesystem::class);
|
||||
$themeDir = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
|
||||
$themeDir->delete('theme/frontend');
|
||||
$themeDir->delete('theme/_merged');
|
||||
|
||||
$libDir = $filesystem->getDirectoryWrite(DirectoryList::LIB_WEB);
|
||||
$libDir->copyFile('prototype/prototype.js', 'prototype/prototype.min.js');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
/** @var \Magento\Framework\Filesystem $filesystem */
|
||||
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\Filesystem::class);
|
||||
$libDir = $filesystem->getDirectoryWrite(DirectoryList::LIB_WEB);
|
||||
$libDir->delete('prototype/prototype.min.js');
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\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\DesignInterface::class);
|
||||
$this->_viewFileSystem = $objectManager->create(\Magento\Framework\View\FileSystem::class);
|
||||
$this->_viewConfig = $objectManager->create(\Magento\Framework\View\ConfigInterface::class);
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
|
||||
}
|
||||
|
||||
/**
|
||||
* Emulate fixture design theme
|
||||
*
|
||||
* @param string $themePath
|
||||
*/
|
||||
protected function _emulateFixtureTheme($themePath = 'Test_FrameworkThemeTest/default')
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('frontend');
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\View\DesignInterface::class)->setDesignTheme($themePath);
|
||||
|
||||
$this->_viewFileSystem = $objectManager->create(\Magento\Framework\View\FileSystem::class);
|
||||
$this->_viewConfig = $objectManager->create(\Magento\Framework\View\ConfigInterface::class);
|
||||
}
|
||||
|
||||
public function testSetGetArea()
|
||||
{
|
||||
$this->assertEquals(\Magento\Framework\View\DesignInterface::DEFAULT_AREA, $this->_model->getArea());
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
|
||||
->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
|
||||
$this->assertEquals(\Magento\Framework\App\Area::AREA_ADMINHTML, $this->_model->getArea());
|
||||
}
|
||||
|
||||
public function testSetDesignTheme()
|
||||
{
|
||||
$this->_model->setDesignTheme('Magento/blank', 'frontend');
|
||||
$this->assertEquals('Magento/blank', $this->_model->getDesignTheme()->getThemePath());
|
||||
}
|
||||
|
||||
public function testGetDesignTheme()
|
||||
{
|
||||
$this->assertInstanceOf(\Magento\Framework\View\Design\ThemeInterface::class, $this->_model->getDesignTheme());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store design/theme/theme_id 0
|
||||
*/
|
||||
public function testGetConfigurationDesignThemeDefaults()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$themes = ['frontend' => 'test_f', 'adminhtml' => 'test_a'];
|
||||
$design = $objectManager->create(\Magento\Theme\Model\View\Design::class, ['themes' => $themes]);
|
||||
$objectManager->addSharedInstance($design, \Magento\Theme\Model\View\Design::class);
|
||||
|
||||
$model = $objectManager->get(\Magento\Theme\Model\View\Design::class);
|
||||
|
||||
$this->assertEquals('test_f', $model->getConfigurationDesignTheme());
|
||||
$this->assertEquals('test_f', $model->getConfigurationDesignTheme('frontend'));
|
||||
$this->assertEquals('test_f', $model->getConfigurationDesignTheme('frontend', ['store' => 0]));
|
||||
$this->assertEquals('test_f', $model->getConfigurationDesignTheme('frontend', ['store' => null]));
|
||||
$this->assertEquals('test_a', $model->getConfigurationDesignTheme('adminhtml'));
|
||||
$this->assertEquals('test_a', $model->getConfigurationDesignTheme('adminhtml', ['store' => uniqid()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store design/theme/theme_id one
|
||||
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
|
||||
*/
|
||||
public function testGetConfigurationDesignThemeStore()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableConfig */
|
||||
$mutableConfig = $objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
|
||||
$mutableConfig->setValue('design/theme/theme_id', 'two', ScopeInterface::SCOPE_STORE, 'fixturestore');
|
||||
|
||||
$storeId = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
|
||||
->getStore()
|
||||
->getId();
|
||||
$this->assertEquals('one', $this->_model->getConfigurationDesignTheme());
|
||||
$this->assertEquals('one', $this->_model->getConfigurationDesignTheme(null, ['store' => $storeId]));
|
||||
$this->assertEquals('one', $this->_model->getConfigurationDesignTheme('frontend', ['store' => $storeId]));
|
||||
$this->assertEquals('two', $this->_model->getConfigurationDesignTheme(null, ['store' => 'fixturestore']));
|
||||
$this->assertEquals(
|
||||
'two',
|
||||
$this->_model->getConfigurationDesignTheme('frontend', ['store' => 'fixturestore'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilenameDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetFilename($file, $params)
|
||||
{
|
||||
$this->_emulateFixtureTheme();
|
||||
$this->assertFileExists($this->_viewFileSystem->getFilename($file, $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilenameDataProvider()
|
||||
{
|
||||
return [
|
||||
['theme_file.txt', ['module' => 'Magento_Catalog']],
|
||||
['Magento_Catalog::theme_file.txt', []],
|
||||
['Magento_Catalog::theme_file_with_2_dots..txt', []],
|
||||
['Magento_Catalog::theme_file.txt', ['module' => 'Overridden_Module']]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetViewConfig()
|
||||
{
|
||||
$this->_emulateFixtureTheme();
|
||||
$config = $this->_viewConfig->getViewConfig();
|
||||
$this->assertInstanceOf(\Magento\Framework\Config\View::class, $config);
|
||||
$this->assertEquals(['var1' => 'value1', 'var2' => 'value2'], $config->getVars('Namespace_Module'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetConfigCustomized()
|
||||
{
|
||||
$this->_emulateFixtureTheme();
|
||||
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
|
||||
$theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->getDesignTheme();
|
||||
$customConfigFile = $theme->getCustomization()->getCustomViewConfigPath();
|
||||
/** @var $filesystem \Magento\Framework\Filesystem */
|
||||
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Framework\Filesystem::class);
|
||||
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
|
||||
$relativePath = $directory->getRelativePath($customConfigFile);
|
||||
try {
|
||||
$directory->writeFile(
|
||||
$relativePath,
|
||||
'<?xml version="1.0" encoding="UTF-8"?>
|
||||
<view><vars module="Namespace_Module"><var name="customVar">custom value</var></vars></view>'
|
||||
);
|
||||
|
||||
$config = $this->_viewConfig->getViewConfig();
|
||||
$this->assertInstanceOf(\Magento\Framework\Config\View::class, $config);
|
||||
$this->assertEquals(['customVar' => 'custom value'], $config->getVars('Namespace_Module'));
|
||||
} catch (\Exception $e) {
|
||||
$directory->delete($relativePath);
|
||||
throw $e;
|
||||
}
|
||||
$directory->delete($relativePath);
|
||||
}
|
||||
}
|
||||
@@ -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/FrameworkThemeTest/test', __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>Default</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::THEME, 'area_two/FrameworkThemeTest/theme_one', __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>Theme One</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::THEME, 'design_area/FrameworkThemeTest/theme_one', __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>Theme One</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::THEME, 'frontend/Magento_FrameworkThemeTest/default', __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>Default</title>
|
||||
<version>0.1.0</version>
|
||||
</theme>
|
||||
|
After Width: | Height: | Size: 10 KiB |
@@ -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/Magento_FrameworkThemeTest/default_iphone', __DIR__);
|
||||
@@ -0,0 +1,14 @@
|
||||
<!--
|
||||
/**
|
||||
* 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>Iphone</title>
|
||||
<media>
|
||||
<preview_image>images/preview_image.jpg</preview_image>
|
||||
</media>
|
||||
<version>0.1.0</version>
|
||||
<parent>Magento_FrameworkThemeTest/default</parent>
|
||||
</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/Test_FrameworkThemeTest/cache_test_theme', __DIR__);
|
||||
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
/**
|
||||
* 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>Cache Test Theme</title>
|
||||
<version>0.1.0</version>
|
||||
<parent>Test_FrameworkThemeTest/default</parent>
|
||||
</theme>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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"/>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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"/>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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"/>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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"/>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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"/>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?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">
|
||||
<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 name="test.nonexisting.block" class="Magento\Framework\View\Element\Text\ListText"/>
|
||||
<referenceBlock name="test.nonexisting.block" remove="true"/>
|
||||
<referenceBlock name="test.nonexisting.block">
|
||||
<action method="getSomething"/>
|
||||
</referenceBlock>
|
||||
</layout>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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>
|
||||
<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>
|
||||
<block class="Magento\Backend\Block\Page" name="root" output="1" template="Magento_Backend::page.phtml">
|
||||
<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>
|
||||
</page>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
|
||||
<vars module="Magento_Store">
|
||||
<var name="var1">Store Value1</var>
|
||||
</vars>
|
||||
<vars module="Namespace_Module">
|
||||
<var name="var1">value1</var>
|
||||
<var name="var2">value2</var>
|
||||
</vars>
|
||||
</view>
|
||||
@@ -0,0 +1,2 @@
|
||||
"Design value to translate","Design translated value"
|
||||
"translation to the same value","translation to the same value"
|
||||
|
@@ -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/Test_FrameworkThemeTest/default', __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>Default</title>
|
||||
<version>0.1.0</version>
|
||||
</theme>
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
#header{color: #4d926f}h2{color: #4d926f}#header{-webkit-border-radius: 5px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;border-radius: 5px}#footer{-webkit-border-radius: 10px;-moz-border-radius: 10px;-ms-border-radius: 10px;-o-border-radius: 10px;border-radius: 10px}#header h1{font-size: 26px;font-weight: bold}#header p{font-size: 12px}#header p a{text-decoration: none}#header p a:hover{border-width: 1px}#header{color: #333;border-left: 1px;border-right: 2px}#footer{color: #141;border-color: #7d2717}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
#header {
|
||||
color: #4d926f;
|
||||
}
|
||||
h2 {
|
||||
color: #4d926f;
|
||||
}
|
||||
#header {
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-ms-border-radius: 5px;
|
||||
-o-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
#footer {
|
||||
-webkit-border-radius: 10px;
|
||||
-moz-border-radius: 10px;
|
||||
-ms-border-radius: 10px;
|
||||
-o-border-radius: 10px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
#header h1 {
|
||||
font-size: 26px;
|
||||
font-weight: bold;
|
||||
}
|
||||
#header p {
|
||||
font-size: 12px;
|
||||
}
|
||||
#header p a {
|
||||
text-decoration: none;
|
||||
}
|
||||
#header p a:hover {
|
||||
border-width: 1px;
|
||||
}
|
||||
#header {
|
||||
color: #333333;
|
||||
border-left: 1px;
|
||||
border-right: 2px;
|
||||
}
|
||||
#footer {
|
||||
color: #114411;
|
||||
border-color: #7d2717;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// /**
|
||||
// * Copyright © Magento, Inc. All rights reserved.
|
||||
// * See COPYING.txt for license details.
|
||||
// */
|
||||
|
||||
@color: #4D926F;
|
||||
|
||||
#header {
|
||||
color: @color;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: @color;
|
||||
}
|
||||
|
||||
// Mixins
|
||||
|
||||
.rounded-corners (@radius: 5px) {
|
||||
-webkit-border-radius: @radius;
|
||||
-moz-border-radius: @radius;
|
||||
-ms-border-radius: @radius;
|
||||
-o-border-radius: @radius;
|
||||
border-radius: @radius;
|
||||
}
|
||||
|
||||
#header {
|
||||
.rounded-corners;
|
||||
}
|
||||
|
||||
#footer {
|
||||
.rounded-corners(10px);
|
||||
}
|
||||
|
||||
// Nested Rules
|
||||
|
||||
#header {
|
||||
h1 {
|
||||
font-size: 26px;
|
||||
font-weight: bold;
|
||||
}
|
||||
p { font-size: 12px;
|
||||
a {
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
border-width: 1px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Functions & Operations
|
||||
|
||||
@the-border: 1px;
|
||||
@base-color: #111;
|
||||
@red: #842210;
|
||||
|
||||
#header {
|
||||
color: (@base-color * 3);
|
||||
border-left: @the-border;
|
||||
border-right: (@the-border * 2);
|
||||
}
|
||||
|
||||
#footer {
|
||||
color: (@base-color + #003300);
|
||||
border-color: desaturate(@red, 10%);
|
||||
}
|
||||
@@ -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/Test_FrameworkThemeTest/publication', __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>Default</title>
|
||||
<version>0.1.0</version>
|
||||
</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/Test_FrameworkThemeTest/test_theme', __DIR__);
|
||||
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
/**
|
||||
* 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>
|
||||
<version>0.1.0</version>
|
||||
<parent>Test_FrameworkThemeTest/default</parent>
|
||||
</theme>
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
/* modular fixture view file located inside the nested view of the 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_FrameworkThemeTest/custom_theme', __DIR__);
|
||||
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
/**
|
||||
* 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>
|
||||
<version>0.1.0</version>
|
||||
<parent>Vendor_FrameworkThemeTest/default</parent>
|
||||
</theme>
|
||||
|
After Width: | Height: | Size: 36 B |
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
@@ -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_FrameworkThemeTest/default', __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>Default</title>
|
||||
<version>0.1.0</version>
|
||||
</theme>
|
||||
|
After Width: | Height: | Size: 36 B |
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
li.test {
|
||||
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlNmU2ZTYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
|
||||
}
|
||||
|
After Width: | Height: | Size: 36 B |
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
dt {background: url('../../recursive2.gif')}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
li.rogue {background: url(../access_violation.php);}
|
||||
li.test {background: url(../../access_violation.php);}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
@import url(../recursive.css);
|
||||
@import url("deep/recursive.css");
|
||||
body {background: url(body.gif);}
|
||||
p {background: url(1.gif?param);}
|
||||
h1 {background: url('../h1.gif#param');} h2 {background: url(../images/h2.gif?test);}
|
||||
a {background: url(data:image/png;)}
|
||||
|
||||
ul {background: url(/absolute.gif);}
|
||||
ol {background: url(http://example.com/absolute.gif);}
|
||||
li {background: url("https://example.com/absolute.gif");}
|
||||
|
||||
ol.valid {background: url(Namespace_Module::absolute_valid_module.gif)} /* theme file modular */
|
||||
ol.favicon {background: url(Magento_Theme::favicon.ico)} /* base file */
|
||||
|
After Width: | Height: | Size: 36 B |
|
After Width: | Height: | Size: 36 B |
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
dl {background: url(recursive.gif)}
|
||||
|
After Width: | Height: | Size: 36 B |
|
After Width: | Height: | Size: 36 B |
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
/* scripts.js */
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||