init
This commit is contained in:
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Api;
|
||||
|
||||
use Magento\TestModuleExtensionAttributes\Model\Data\FakeRegionFactory;
|
||||
use Magento\TestModuleExtensionAttributes\Api\Data\FakeRegionExtension;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Framework\Api\AbstractExtensibleObject
|
||||
*/
|
||||
class AbstractExtensibleObjectTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
private $_objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_objectManager->configure(
|
||||
[
|
||||
'preferences' => [
|
||||
\Magento\TestModuleExtensionAttributes\Api\Data\FakeAddressInterface::class =>
|
||||
\Magento\TestModuleExtensionAttributes\Model\FakeAddress::class,
|
||||
\Magento\TestModuleExtensionAttributes\Api\Data\FakeRegionInterface::class =>
|
||||
\Magento\TestModuleExtensionAttributes\Model\FakeRegion::class,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setExtensionAttributes and getExtensionAttributes for \Magento\Framework\Api\AbstractExtensibleObject
|
||||
*
|
||||
* @param array $expectedDataBefore
|
||||
* @param array $expectedDataAfter
|
||||
* @dataProvider extensionAttributesDataProvider
|
||||
*/
|
||||
public function testExtensionAttributes($expectedDataBefore, $expectedDataAfter)
|
||||
{
|
||||
/** @var \Magento\Framework\Api\ExtensionAttributesFactory $regionExtensionFactory */
|
||||
$regionExtensionFactory = $this->_objectManager->get(\Magento\Framework\Api\ExtensionAttributesFactory::class);
|
||||
/** @var FakeRegionFactory $regionFactory */
|
||||
$regionFactory = $this->_objectManager->get(FakeRegionFactory::class);
|
||||
|
||||
/** @var \Magento\TestModuleExtensionAttributes\Model\Data\FakeRegion $region */
|
||||
$region = $regionFactory->create();
|
||||
|
||||
$regionCode = 'test_code';
|
||||
/** @var \Magento\TestModuleExtensionAttributes\Model\Data\FakeRegionExtensionInterface $regionExtension */
|
||||
$regionExtension = $regionExtensionFactory->create(
|
||||
\Magento\TestModuleExtensionAttributes\Model\Data\FakeRegion::class,
|
||||
['data' => $expectedDataBefore]
|
||||
);
|
||||
$region->setRegionCode($regionCode)->setExtensionAttributes($regionExtension);
|
||||
$this->assertInstanceOf(\Magento\TestModuleExtensionAttributes\Model\Data\FakeRegion::class, $region);
|
||||
|
||||
$extensionAttributes = $region->getExtensionAttributes();
|
||||
$this->assertInstanceOf(FakeRegionExtension::class, $extensionAttributes);
|
||||
$this->assertEquals($expectedDataBefore, $extensionAttributes->__toArray());
|
||||
$this->assertEquals($regionCode, $region->getRegionCode());
|
||||
|
||||
$regionCode = 'changed_test_code';
|
||||
$region->setExtensionAttributes(
|
||||
$regionExtensionFactory->create(
|
||||
\Magento\TestModuleExtensionAttributes\Model\Data\FakeRegion::class,
|
||||
['data' => $expectedDataAfter]
|
||||
)
|
||||
)->setRegionCode($regionCode); // change $regionCode to test AbstractExtensibleObject::setData
|
||||
$extensionAttributes = $region->getExtensionAttributes();
|
||||
$this->assertEquals($expectedDataAfter, $extensionAttributes->__toArray());
|
||||
$this->assertEquals($regionCode, $region->getRegionCode());
|
||||
}
|
||||
|
||||
public function extensionAttributesDataProvider()
|
||||
{
|
||||
return [
|
||||
'boolean' => [
|
||||
[true],
|
||||
[false]
|
||||
],
|
||||
'integer' => [
|
||||
[1],
|
||||
[2]
|
||||
],
|
||||
'string' => [
|
||||
['test'],
|
||||
['test test']
|
||||
],
|
||||
'array' => [
|
||||
[[1]],
|
||||
[[1, 2]]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Api;
|
||||
|
||||
use Magento\Framework\Api\Fixture\DataObjectInterface;
|
||||
use Magento\Framework\Api\Fixture\DataObjectFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DataObjectHelperTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var DataObjectHelper
|
||||
*/
|
||||
private $dataObjectHelper;
|
||||
|
||||
/**
|
||||
* @var DataObjectFactory
|
||||
*/
|
||||
private $dataObjectFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
|
||||
$this->dataObjectFactory = Bootstrap::getObjectManager()->get(DataObjectFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test object is populated with data from array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPopulateWithArray(): void
|
||||
{
|
||||
$inputArray = [
|
||||
'first_a_second' => '1',
|
||||
'first_at_second' => '1',
|
||||
'first_a_t_m_second' => '1',
|
||||
'random_attribute' => 'random'
|
||||
];
|
||||
$expectedData = [
|
||||
'first_a_second' => '1',
|
||||
'first_at_second' => '1',
|
||||
'first_a_t_m_second' => '1',
|
||||
];
|
||||
$object = $this->dataObjectFactory->create();
|
||||
$this->dataObjectHelper->populateWithArray($object, $inputArray, DataObjectInterface::class);
|
||||
$this->assertEquals($expectedData, $object->getData());
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Api\ExtensionAttribute\Config;
|
||||
|
||||
/**
|
||||
* Tests for \Magento\Framework\Api\ExtensionAttribute\Config\Reader
|
||||
*/
|
||||
class ReaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Api\ExtensionAttribute\Config\Reader
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_fileList;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Arguments\FileResolver\Primary
|
||||
*/
|
||||
protected $_fileResolverMock;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Arguments\ValidationState
|
||||
*/
|
||||
protected $_validationState;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\ExtensionAttribute\Config\SchemaLocator
|
||||
*/
|
||||
protected $_schemaLocator;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\ExtensionAttribute\Config\Converter
|
||||
*/
|
||||
protected $_converter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$fixturePath = realpath(__DIR__ . '/_files') . '/';
|
||||
$this->_fileList = [
|
||||
file_get_contents($fixturePath . 'config_one.xml'),
|
||||
file_get_contents($fixturePath . 'config_two.xml'),
|
||||
];
|
||||
|
||||
$this->_fileResolverMock = $this->getMockBuilder(\Magento\Framework\App\Arguments\FileResolver\Primary::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['get'])
|
||||
->getMock();
|
||||
$this->_fileResolverMock->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn($this->_fileList);
|
||||
|
||||
$this->_converter = new \Magento\Framework\Api\ExtensionAttribute\Config\Converter();
|
||||
|
||||
$this->_validationState = new \Magento\Framework\App\Arguments\ValidationState(
|
||||
\Magento\Framework\App\State::MODE_DEFAULT
|
||||
);
|
||||
$this->_schemaLocator = new \Magento\Framework\Api\ExtensionAttribute\Config\SchemaLocator(
|
||||
new \Magento\Framework\Config\Dom\UrnResolver()
|
||||
);
|
||||
}
|
||||
|
||||
public function testMerge()
|
||||
{
|
||||
$model = new \Magento\Framework\Api\ExtensionAttribute\Config\Reader(
|
||||
$this->_fileResolverMock,
|
||||
$this->_converter,
|
||||
$this->_schemaLocator,
|
||||
$this->_validationState
|
||||
);
|
||||
|
||||
$expectedArray = [
|
||||
\Magento\Tax\Api\Data\TaxRateInterface::class => [],
|
||||
\Magento\Catalog\Api\Data\Product::class => [
|
||||
'stock_item' => [
|
||||
"type" => "Magento\CatalogInventory\Api\Data\StockItem",
|
||||
"resourceRefs" => [],
|
||||
"join" => null,
|
||||
],
|
||||
],
|
||||
\Magento\Customer\Api\Data\CustomerInterface::class => [
|
||||
'custom_1' => [
|
||||
"type" => "Magento\Customer\Api\Data\CustomerCustom",
|
||||
"resourceRefs" => [],
|
||||
"join" => null,
|
||||
],
|
||||
'custom_2' => [
|
||||
"type" => "Magento\CustomerExtra\Api\Data\CustomerCustom22",
|
||||
"resourceRefs" => [],
|
||||
"join" => null,
|
||||
],
|
||||
'custom_3' => [
|
||||
"type" => "Magento\Customer\Api\Data\CustomerCustom3",
|
||||
"resourceRefs" => [],
|
||||
"join" => null,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedArray, $model->read('global'));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
|
||||
<extension_attributes for="Magento\Tax\Api\Data\TaxRateInterface">
|
||||
</extension_attributes>
|
||||
<extension_attributes for="Magento\Catalog\Api\Data\Product">
|
||||
<attribute code="stock_item" type="Magento\CatalogInventory\Api\Data\StockItem" />
|
||||
</extension_attributes>
|
||||
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
|
||||
<attribute code="custom_1" type="Magento\Customer\Api\Data\CustomerCustom" />
|
||||
<attribute code="custom_2" type="Magento\CustomerExtra\Service\V1\Data\CustomerCustom21" />
|
||||
</extension_attributes>
|
||||
</config>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
|
||||
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
|
||||
<attribute code="custom_2" type="Magento\CustomerExtra\Api\Data\CustomerCustom22" />
|
||||
<attribute code="custom_3" type="Magento\Customer\Api\Data\CustomerCustom3" />
|
||||
</extension_attributes>
|
||||
</config>
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Api\ExtensionAttribute;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\Data\ProductExtensionInterface;
|
||||
use Magento\Customer\Api\Data\CustomerInterface;
|
||||
use Magento\Customer\Api\Data\CustomerExtensionInterface;
|
||||
|
||||
/**
|
||||
* Class to test the automatic generation of extension attributes object.
|
||||
*/
|
||||
class ExtensionAttributesGenerationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test extension attributes generation for extensible models.
|
||||
*
|
||||
* Make sure that extension attributes object is not empty after instantiation
|
||||
* of objects inherited from @see \Magento\Framework\Model\AbstractExtensibleModel.
|
||||
*
|
||||
* In addition, verify that empty objects are not generated for complex extension attributes.
|
||||
*/
|
||||
public function testAttributeObjectGenerationForExtensibleModel()
|
||||
{
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var ProductInterface $product */
|
||||
$product = $objectManager->get(ProductInterface::class);
|
||||
|
||||
$extensionAttributes = $product->getExtensionAttributes();
|
||||
$this->assertInstanceOf(ProductExtensionInterface::class, $extensionAttributes);
|
||||
|
||||
$stockItemExtensionAttribute = $extensionAttributes->getStockItem();
|
||||
$this->assertNull($stockItemExtensionAttribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extension attributes generation for extensible objects.
|
||||
*
|
||||
* Make sure that extension attributes object is not empty after instantiation
|
||||
* of objects inherited from @see \Magento\Framework\Api\AbstractExtensibleObject
|
||||
*/
|
||||
public function testAttributeObjectGenerationForExtensibleObject()
|
||||
{
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var CustomerInterface $customer */
|
||||
$customer = $objectManager->get(CustomerInterface::class);
|
||||
|
||||
$extensionAttributes = $customer->getExtensionAttributes();
|
||||
$this->assertInstanceOf(CustomerExtensionInterface::class, $extensionAttributes);
|
||||
}
|
||||
}
|
||||
+444
@@ -0,0 +1,444 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Api\ExtensionAttribute;
|
||||
|
||||
use Magento\Framework\Api\ExtensionAttribute\Config\Converter;
|
||||
use Magento\Framework\Api\ExtensionAttribute\Config\Reader;
|
||||
use Magento\Framework\Api\ExtensionAttribute\JoinData;
|
||||
use Magento\Framework\Api\ExtensionAttribute\JoinDataInterfaceFactory;
|
||||
use Magento\Framework\Reflection\TypeProcessor;
|
||||
use Magento\Framework\App\ResourceConnection as AppResource;
|
||||
use Magento\Framework\Api\ExtensionAttributesFactory;
|
||||
|
||||
/**
|
||||
* Class to test the JoinProcessor functionality
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class JoinProcessorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessor
|
||||
*/
|
||||
private $joinProcessor;
|
||||
|
||||
/**
|
||||
* @var Reader|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var JoinDataInterfaceFactory|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $extensionAttributeJoinDataFactory;
|
||||
|
||||
/**
|
||||
* @var TypeProcessor|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $typeProcessor;
|
||||
|
||||
/**
|
||||
* @var AppResource|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $appResource;
|
||||
|
||||
/**
|
||||
* @var ExtensionAttributesFactory|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $extensionAttributesFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorHelper
|
||||
*/
|
||||
private $joinProcessorHelper;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->config = $this->getMockBuilder(\Magento\Framework\Api\ExtensionAttribute\Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->extensionAttributeJoinDataFactory = $this
|
||||
->getMockBuilder(\Magento\Framework\Api\ExtensionAttribute\JoinDataInterfaceFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->typeProcessor = $this->getMockBuilder(\Magento\Framework\Reflection\TypeProcessor::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->extensionAttributesFactory = $this->getMockBuilder(
|
||||
\Magento\Framework\Api\ExtensionAttributesFactory::class
|
||||
)->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->appResource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
|
||||
|
||||
$this->joinProcessorHelper = $objectManager->create(
|
||||
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorHelper::class,
|
||||
[
|
||||
'config' => $this->config,
|
||||
'joinDataInterfaceFactory' => $this->extensionAttributeJoinDataFactory
|
||||
]
|
||||
);
|
||||
|
||||
$this->joinProcessor = $objectManager->create(
|
||||
\Magento\Framework\Api\ExtensionAttribute\JoinProcessor::class,
|
||||
[
|
||||
'objectManager' => $objectManager,
|
||||
'typeProcessor' => $this->typeProcessor,
|
||||
'joinProcessorHelper' => $this->joinProcessorHelper
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the processing of the join config for a particular type
|
||||
*/
|
||||
public function testProcess()
|
||||
{
|
||||
$this->config->expects($this->once())
|
||||
->method('get')
|
||||
->willReturn($this->getConfig());
|
||||
|
||||
$collection = $this->getMockBuilder(\Magento\Framework\Data\Collection\AbstractDb::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['joinExtensionAttribute'])
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$extensionAttributeJoinData = new JoinData();
|
||||
$this->extensionAttributeJoinDataFactory
|
||||
->expects($this->once())
|
||||
->method('create')
|
||||
->willReturn($extensionAttributeJoinData);
|
||||
|
||||
$collection->expects($this->once())->method('joinExtensionAttribute')->with($extensionAttributeJoinData);
|
||||
|
||||
$this->joinProcessor->process($collection, \Magento\Catalog\Api\Data\ProductInterface::class);
|
||||
$expectedTableName = 'reviews';
|
||||
$this->assertEquals($expectedTableName, $extensionAttributeJoinData->getReferenceTable());
|
||||
$this->assertEquals('extension_attribute_review_id', $extensionAttributeJoinData->getReferenceTableAlias());
|
||||
$this->assertEquals('product_id', $extensionAttributeJoinData->getReferenceField());
|
||||
$this->assertEquals('id', $extensionAttributeJoinData->getJoinField());
|
||||
$this->assertEquals(
|
||||
[
|
||||
[
|
||||
'external_alias' => 'review_id',
|
||||
'internal_alias' => 'extension_attribute_review_id_db_review_id',
|
||||
'with_db_prefix' => 'extension_attribute_review_id.db_review_id',
|
||||
'setter' => 'setReviewId',
|
||||
]
|
||||
],
|
||||
$extensionAttributeJoinData->getSelectFields()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return the data that is expected from the config object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getConfig()
|
||||
{
|
||||
return [\Magento\Catalog\Api\Data\ProductInterface::class => [
|
||||
'review_id' => [
|
||||
Converter::DATA_TYPE => 'string',
|
||||
Converter::RESOURCE_PERMISSIONS => [],
|
||||
Converter::JOIN_DIRECTIVE => [
|
||||
Converter::JOIN_REFERENCE_TABLE => "reviews",
|
||||
Converter::JOIN_REFERENCE_FIELD => "product_id",
|
||||
Converter::JOIN_FIELDS => [
|
||||
[
|
||||
Converter::JOIN_FIELD => "review_id",
|
||||
Converter::JOIN_FIELD_COLUMN => "db_review_id",
|
||||
],
|
||||
],
|
||||
Converter::JOIN_ON_FIELD => "id",
|
||||
],
|
||||
],
|
||||
], \Magento\Customer\Api\Data\CustomerInterface::class => [
|
||||
'library_card_id' => [
|
||||
Converter::DATA_TYPE => 'string',
|
||||
Converter::RESOURCE_PERMISSIONS => [],
|
||||
Converter::JOIN_DIRECTIVE => [
|
||||
Converter::JOIN_REFERENCE_TABLE => "library_account",
|
||||
Converter::JOIN_FIELDS => [
|
||||
[
|
||||
Converter::JOIN_FIELD => "library_card_id",
|
||||
Converter::JOIN_FIELD_COLUMN => "",
|
||||
],
|
||||
],
|
||||
Converter::JOIN_ON_FIELD => "customer_id",
|
||||
],
|
||||
],
|
||||
'reviews' => [
|
||||
Converter::DATA_TYPE => 'Magento\Reviews\Api\Data\Reviews[]',
|
||||
Converter::RESOURCE_PERMISSIONS => [],
|
||||
Converter::JOIN_DIRECTIVE => [
|
||||
Converter::JOIN_REFERENCE_TABLE => "reviews",
|
||||
Converter::JOIN_FIELDS => [
|
||||
[
|
||||
Converter::JOIN_FIELD => "comment",
|
||||
Converter::JOIN_FIELD_COLUMN => "",
|
||||
],
|
||||
[
|
||||
Converter::JOIN_FIELD => "rating",
|
||||
Converter::JOIN_FIELD_COLUMN => "",
|
||||
],
|
||||
],
|
||||
Converter::JOIN_ON_FIELD => "customer_id",
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testProcessSqlSelectVerification()
|
||||
{
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Framework\Api\ExtensionAttribute\Config $config */
|
||||
$config = $objectManager->get(\Magento\Framework\Api\ExtensionAttribute\Config::class);
|
||||
$config->reset();
|
||||
|
||||
$extensionConfigFileResolverMock = $this->getMockBuilder(\Magento\Framework\Config\FileResolverInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$extensionConfigFilePath = __DIR__ . '/../_files/extension_attributes.xml';
|
||||
$extensionConfigFileContent = file_get_contents($extensionConfigFilePath);
|
||||
$extensionConfigFileResolverMock->expects($this->any())
|
||||
->method('get')
|
||||
->willReturn([$extensionConfigFilePath => $extensionConfigFileContent]);
|
||||
$configReader = $objectManager->create(
|
||||
\Magento\Framework\Api\ExtensionAttribute\Config\Reader::class,
|
||||
['fileResolver' => $extensionConfigFileResolverMock]
|
||||
);
|
||||
/** @var \Magento\Framework\Api\ExtensionAttribute\Config $config */
|
||||
$config = $objectManager->create(
|
||||
\Magento\Framework\Api\ExtensionAttribute\Config::class,
|
||||
['reader' => $configReader]
|
||||
);
|
||||
|
||||
/** @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessorHelper $extensionAttributesProcessorHelper */
|
||||
$extensionAttributesProcessorHelper = $objectManager->create(
|
||||
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorHelper::class,
|
||||
['config' => $config]
|
||||
);
|
||||
|
||||
/** @var \Magento\Framework\Api\ExtensionAttribute\JoinProcessor $extensionAttributesProcessor */
|
||||
$extensionAttributesProcessor = $objectManager->create(
|
||||
\Magento\Framework\Api\ExtensionAttribute\JoinProcessor::class,
|
||||
['joinProcessorHelper' => $extensionAttributesProcessorHelper]
|
||||
);
|
||||
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
|
||||
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
|
||||
$extensionAttributesProcessor->process($collection);
|
||||
$config->reset();
|
||||
|
||||
$catalogProductEntity = $this->appResource->getTableName('catalog_product_entity');
|
||||
$catalogInventoryStockItem = $this->appResource->getTableName('cataloginventory_stock_item');
|
||||
$reviews = $this->appResource->getTableName('reviews');
|
||||
$expectedSql = <<<EXPECTED_SQL
|
||||
SELECT `e`.*,
|
||||
`extension_attribute_stock_item`.`qty` AS `extension_attribute_stock_item_qty`,
|
||||
`extension_attribute_reviews`.`comment` AS `extension_attribute_reviews_comment`,
|
||||
`extension_attribute_reviews`.`rating` AS `extension_attribute_reviews_rating`,
|
||||
`extension_attribute_reviews`.`date` AS `extension_attribute_reviews_date` FROM `$catalogProductEntity` AS `e`
|
||||
LEFT JOIN `$catalogInventoryStockItem` AS `extension_attribute_stock_item` ON e.id = extension_attribute_stock_item.id
|
||||
LEFT JOIN `$reviews` AS `extension_attribute_reviews` ON e.id = extension_attribute_reviews.product_id
|
||||
EXPECTED_SQL;
|
||||
$resultSql = $collection->getSelectSql(true);
|
||||
$formattedResultSql = str_replace(',', ",\n ", $resultSql);
|
||||
$this->assertStringContainsString($expectedSql, $formattedResultSql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
*/
|
||||
public function testGetListWithExtensionAttributesAbstractModel()
|
||||
{
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
|
||||
$firstProductId = (int)$productRepository->get('simple')->getId();
|
||||
$firstProductQty = 11;
|
||||
$secondProductId = (int)$productRepository->get('custom-design-simple-product')->getId();
|
||||
$secondProductQty = 22;
|
||||
/** @var \Magento\CatalogInventory\Api\StockItemRepositoryInterface $stockItemRepository */
|
||||
$stockItemRepository = $objectManager->get(\Magento\CatalogInventory\Api\StockItemRepositoryInterface::class);
|
||||
|
||||
/** Prepare stock items */
|
||||
$firstStockItem = $productRepository->getById($firstProductId)->getExtensionAttributes()->getStockItem();
|
||||
$firstStockItem->setQty($firstProductQty);
|
||||
$stockItemRepository->save($firstStockItem);
|
||||
$this->assertEquals(
|
||||
$firstProductQty,
|
||||
$productRepository->getById($firstProductId)->getExtensionAttributes()->getStockItem()->getQty(),
|
||||
'Precondition failed.'
|
||||
);
|
||||
$secondStockItem = $productRepository->getById($secondProductId)->getExtensionAttributes()->getStockItem();
|
||||
$secondStockItem->setQty($secondProductQty);
|
||||
$stockItemRepository->save($secondStockItem);
|
||||
$this->assertEquals(
|
||||
$secondProductQty,
|
||||
$productRepository->getById($secondProductId)->getExtensionAttributes()->getStockItem()->getQty(),
|
||||
'Precondition failed.'
|
||||
);
|
||||
|
||||
/** @var \Magento\Framework\Api\Search\FilterGroup $searchCriteriaGroup */
|
||||
$searchCriteriaGroup = $objectManager->create(\Magento\Framework\Api\Search\FilterGroup::class);
|
||||
/** @var \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria */
|
||||
$searchCriteria = $objectManager->create(\Magento\Framework\Api\SearchCriteriaInterface::class);
|
||||
$searchCriteria->setFilterGroups([$searchCriteriaGroup]);
|
||||
$products = $productRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
/** Ensure that simple extension attributes were populated correctly */
|
||||
$this->assertEquals(
|
||||
$firstProductQty,
|
||||
$products[$firstProductId]->getExtensionAttributes()->getTestStockItemQty()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$secondProductQty,
|
||||
$products[$secondProductId]->getExtensionAttributes()->getTestStockItemQty()
|
||||
);
|
||||
|
||||
/** Check population of complex extension attributes */
|
||||
$this->assertEquals(
|
||||
$firstProductQty,
|
||||
$products[$firstProductId]->getExtensionAttributes()->getTestStockItem()->getQty()
|
||||
);
|
||||
$this->assertNotEmpty($products[$firstProductId]->getExtensionAttributes()->getTestStockItem()->getItemId());
|
||||
|
||||
$this->assertArrayNotHasKey(
|
||||
'extension_attribute_test_stock_item_qty_qty',
|
||||
$products[$firstProductId]->getData(),
|
||||
"Selected extension field should be unset after it is added to extension attributes object."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_group.php
|
||||
*/
|
||||
public function testGetListWithExtensionAttributesAbstractObject()
|
||||
{
|
||||
$customerId = 1;
|
||||
$customerGroupName = 'General';
|
||||
$taxClassId = 3;
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->get(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
/** @var \Magento\Framework\Api\Search\FilterGroup $searchCriteriaGroup */
|
||||
$searchCriteriaGroup = $objectManager->create(\Magento\Framework\Api\Search\FilterGroup::class);
|
||||
/** @var \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria */
|
||||
$searchCriteria = $objectManager->create(\Magento\Framework\Api\SearchCriteriaInterface::class);
|
||||
$searchCriteria->setFilterGroups([$searchCriteriaGroup]);
|
||||
$customers = $customerRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
/** Ensure that simple extension attributes were populated correctly */
|
||||
$customer = $customers[0];
|
||||
$this->assertEquals($customerId, $customer->getId(), 'Precondition failed');
|
||||
$this->assertEquals($customerGroupName, $customer->getExtensionAttributes()->getTestGroupCode());
|
||||
|
||||
/** Check population of complex extension attributes */
|
||||
$this->assertEquals($taxClassId, $customer->getExtensionAttributes()->getTestGroup()->getTaxClassId());
|
||||
$this->assertEquals($customerGroupName, $customer->getExtensionAttributes()->getTestGroup()->getCode());
|
||||
}
|
||||
|
||||
public function testGetListWithFilterBySimpleDummyAttributeWithMapping()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$groupRepository = $objectManager->create(\Magento\Customer\Api\GroupRepositoryInterface::class);
|
||||
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $objectManager->create(\Magento\Framework\Api\SearchCriteriaBuilder::class);
|
||||
$builder = $objectManager->create(\Magento\Framework\Api\FilterBuilder::class);
|
||||
$joinedExtensionAttribute = 'test_dummy_attribute';
|
||||
$joinedExtensionAttributeValue = 'website_id';
|
||||
$filter = $builder->setField($joinedExtensionAttribute)
|
||||
->setValue($joinedExtensionAttributeValue)
|
||||
->create();
|
||||
$searchCriteriaBuilder->addFilters([$filter]);
|
||||
$searchResults = $groupRepository->getList($searchCriteriaBuilder->create());
|
||||
$items = $searchResults->getItems();
|
||||
$this->assertCount(1, $items, 'Filtration by extension attribute does not work.');
|
||||
$expectedGroupCode = 'General';
|
||||
$this->assertEquals($expectedGroupCode, $items[0]->getCode(), 'Invalid group loaded.');
|
||||
$this->assertNotNull($items[0]->getExtensionAttributes(), "Extension attributes not loaded");
|
||||
$this->assertEquals(
|
||||
$joinedExtensionAttributeValue,
|
||||
$items[0]->getExtensionAttributes()->getTestDummyAttribute(),
|
||||
"Extension attributes were not loaded correctly"
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetListWithFilterByComplexDummyAttributeWithSetterMapping()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$groupRepository = $objectManager->create(\Magento\Customer\Api\GroupRepositoryInterface::class);
|
||||
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $objectManager->create(\Magento\Framework\Api\SearchCriteriaBuilder::class);
|
||||
$builder = $objectManager->create(\Magento\Framework\Api\FilterBuilder::class);
|
||||
$joinedExtensionAttribute = 'test_complex_dummy_attribute.frontend_label';
|
||||
$joinedExtensionAttributeValue = 'firstname';
|
||||
$filter = $builder->setField($joinedExtensionAttribute)
|
||||
->setValue($joinedExtensionAttributeValue)
|
||||
->create();
|
||||
$searchCriteriaBuilder->addFilters([$filter]);
|
||||
$searchResults = $groupRepository->getList($searchCriteriaBuilder->create());
|
||||
$items = $searchResults->getItems();
|
||||
$this->assertCount(1, $items, 'Filtration by extension attribute does not work.');
|
||||
$expectedGroupCode = 'General';
|
||||
$this->assertEquals($expectedGroupCode, $items[0]->getCode(), 'Invalid group loaded.');
|
||||
$this->assertNotNull($items[0]->getExtensionAttributes(), "Extension attributes not loaded");
|
||||
$this->assertNotNull(
|
||||
$items[0]->getExtensionAttributes()->getTestComplexDummyAttribute(),
|
||||
"Complex extension attribute not loaded"
|
||||
);
|
||||
$this->assertEquals(
|
||||
'user',
|
||||
$items[0]->getExtensionAttributes()->getTestComplexDummyAttribute()->getAttributeCode(),
|
||||
"Extension attributes were not loaded correctly"
|
||||
);
|
||||
$this->assertEquals(
|
||||
$joinedExtensionAttributeValue,
|
||||
$items[0]->getExtensionAttributes()->getTestComplexDummyAttribute()->getFrontendLabel(),
|
||||
"Extension attributes were not loaded correctly"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/invoice.php
|
||||
*/
|
||||
public function testGetListWithExtensionAttributesAutoGeneratedRepository()
|
||||
{
|
||||
$this->markTestSkipped(
|
||||
'Invoice repository is not autogenerated anymore and does not have joined extension attributes'
|
||||
);
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$searchCriteriaBuilder = $objectManager->create(\Magento\Framework\Api\SearchCriteriaBuilder::class);
|
||||
/** @var \Magento\Sales\Api\InvoiceRepositoryInterface $invoiceRepository */
|
||||
$invoiceRepository = $objectManager->create(\Magento\Sales\Api\InvoiceRepositoryInterface::class);
|
||||
$invoices = $invoiceRepository->getList($searchCriteriaBuilder->create())->getItems();
|
||||
$this->assertCount(1, $invoices, "Invalid number of loaded invoices.");
|
||||
$invoice = reset($invoices);
|
||||
|
||||
/** @var \Magento\Eav\Model\Entity\Attribute $joinedEntity */
|
||||
$joinedEntity = $objectManager->create(\Magento\Eav\Model\Entity\Attribute::class);
|
||||
$joinedEntity->load($invoice->getId());
|
||||
$joinedExtensionAttributeValue = $joinedEntity->getAttributeCode();
|
||||
|
||||
$this->assertNotNull($invoice->getExtensionAttributes(), "Extension attributes not loaded");
|
||||
$this->assertEquals(
|
||||
$joinedExtensionAttributeValue,
|
||||
$invoice->getExtensionAttributes()->getTestDummyAttribute(),
|
||||
"Extension attributes were not loaded correctly"
|
||||
);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Api;
|
||||
|
||||
class ExtensionAttributesFactoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Framework\Api\ExtensionAttributesFactory */
|
||||
private $factory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/** @var \Magento\Framework\ObjectManagerInterface */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->factory = $objectManager->create(
|
||||
\Magento\Framework\Api\ExtensionAttributesFactory::class,
|
||||
['objectManager' => $objectManager]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testCreateThrowExceptionIfInterfaceNotImplemented()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$this->factory->create(\Magento\Framework\Api\ExtensionAttributesFactoryTest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testCreateThrowExceptionIfInterfaceNotOverridden()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$this->factory->create(\Magento\TestModuleExtensionAttributes\Model\Data\FakeExtensibleOne::class);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testCreateThrowExceptionIfReturnIsIncorrect()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$this->factory->create(\Magento\TestModuleExtensionAttributes\Model\Data\FakeExtensibleTwo::class);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
\Magento\TestModuleExtensionAttributes\Api\Data\FakeRegionExtension::class,
|
||||
$this->factory->create(\Magento\TestModuleExtensionAttributes\Model\Data\FakeRegion::class)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateWithLogicException()
|
||||
{
|
||||
$this->expectException('LogicException');
|
||||
$this->expectExceptionMessage(
|
||||
"Class 'Magento\\Framework\\Api\\ExtensionAttributesFactoryTest' must implement an interface, "
|
||||
. "which extends from 'Magento\\Framework\\Api\\ExtensibleDataInterface'"
|
||||
);
|
||||
$this->factory->create(get_class($this));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Api\Fixture;
|
||||
|
||||
use Magento\Framework\Model\AbstractExtensibleModel;
|
||||
|
||||
class DataObject extends AbstractExtensibleModel implements DataObjectInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setFirstASecond(string $value): void
|
||||
{
|
||||
$this->setData('first_a_second', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setFirstAtSecond(string $value): void
|
||||
{
|
||||
$this->setData('first_at_second', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setFirstATMSecond(string$value): void
|
||||
{
|
||||
$this->setData('first_a_t_m_second', $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Api\Fixture;
|
||||
|
||||
interface DataObjectInterface
|
||||
{
|
||||
/**
|
||||
* Set A
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFirstASecond(string $value): void;
|
||||
|
||||
/**
|
||||
* Set At
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFirstAtSecond(string $value): void;
|
||||
|
||||
/**
|
||||
* Set ATM
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFirstATMSecond(string $value): void;
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Api;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SimpleDataObjectConverterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var SimpleDataObjectConverter
|
||||
*/
|
||||
private $simpleDataObjectConverter;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->simpleDataObjectConverter = Bootstrap::getObjectManager()->get(SimpleDataObjectConverter::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test snake case to camel case conversion and vice versa.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCaseConversion(): void
|
||||
{
|
||||
$snakeCaseToCamelCase = [
|
||||
'first_a_second' => 'firstASecond',
|
||||
'first_at_second' => 'firstAtSecond',
|
||||
'first_a_t_m_second' => 'firstATMSecond',
|
||||
];
|
||||
|
||||
foreach ($snakeCaseToCamelCase as $snakeCase => $camelCase) {
|
||||
$this->assertEquals(
|
||||
$camelCase,
|
||||
$this->simpleDataObjectConverter->snakeCaseToCamelCase($snakeCase)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$snakeCase,
|
||||
$this->simpleDataObjectConverter->camelCaseToSnakeCase($camelCase)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Api;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test of building the Data Object
|
||||
*/
|
||||
class SortOrderBuilderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var SortOrderBuilder
|
||||
*/
|
||||
private $interceptedBuilder;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->interceptedBuilder = Bootstrap::getObjectManager()->get(SortOrderBuilder::class . '\Interceptor');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Builder successfully creates object when Interceptor instance is provided.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
$this->assertEquals(SortOrder::class, get_class($this->interceptedBuilder->create()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
|
||||
<extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
|
||||
<attribute code="stock_item" type="Magento\CatalogInventory\Api\Data\StockItemInterface">
|
||||
<resources>
|
||||
<resource ref="Magento_CatalogInventory::cataloginventory"/>
|
||||
</resources>
|
||||
<join reference_table="cataloginventory_stock_item"
|
||||
join_on_field="id"
|
||||
reference_field="id"
|
||||
>
|
||||
<field>qty</field>
|
||||
</join>
|
||||
</attribute>
|
||||
<attribute code="reviews" type="Magento\Reviews\Api\Data\Reviews[]">
|
||||
<join reference_table="reviews"
|
||||
reference_field="product_id"
|
||||
join_on_field="id"
|
||||
>
|
||||
<field>comment</field>
|
||||
<field>rating</field>
|
||||
<field>date</field>
|
||||
</join>
|
||||
</attribute>
|
||||
</extension_attributes>
|
||||
<extension_attributes for="Magento\Catalog\Api\Data\ProductLinkInterface">
|
||||
<attribute code="qty" type="float"/>
|
||||
</extension_attributes>
|
||||
</config>
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App;
|
||||
|
||||
use Laminas\Stdlib\Parameters;
|
||||
|
||||
class AreaTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\Area
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\CacheInterface::class)
|
||||
->clean([\Magento\Theme\Model\Design::CACHE_TAG]);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
|
||||
->setAreaCode('frontend');
|
||||
/** @var $_model \Magento\Framework\App\Area */
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Area::class,
|
||||
['areaCode' => 'frontend']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testInitDesign()
|
||||
{
|
||||
$defaultTheme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->setDefaultDesignTheme()->getDesignTheme();
|
||||
$this->_model->load(\Magento\Framework\App\Area::PART_DESIGN);
|
||||
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->setDefaultDesignTheme();
|
||||
|
||||
$this->assertEquals($defaultTheme->getThemePath(), $design->getDesignTheme()->getThemePath());
|
||||
$this->assertEquals('frontend', $design->getArea());
|
||||
|
||||
// try second time and make sure it won't load second time
|
||||
$this->_model->load(\Magento\Framework\App\Area::PART_DESIGN);
|
||||
$designArea = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->getArea();
|
||||
$sameDesign = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
)->setArea(
|
||||
$designArea
|
||||
);
|
||||
$this->assertSame($design, $sameDesign);
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
/**
|
||||
* @magentoConfigFixture current_store design/theme/ua_regexp {"_":{"regexp":"\/firefox\/i","value":"Magento\/blank"}}
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
// @codingStandardsIgnoreEnd
|
||||
public function testDetectDesignUserAgent()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $request \Magento\TestFramework\Request */
|
||||
$request = $objectManager->create(\Magento\TestFramework\Request::class);
|
||||
$request->setServer(new Parameters(['HTTP_USER_AGENT' => 'Mozilla Firefox']));
|
||||
$this->_model->detectDesign($request);
|
||||
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
);
|
||||
$this->assertEquals('Magento/blank', $design->getDesignTheme()->getThemePath());
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
/**
|
||||
* @magentoConfigFixture current_store design/theme/ua_regexp {"_":{"regexp":"\/firefox\/i","value":"Magento\/blank"}}
|
||||
* @magentoDataFixture Magento/Theme/_files/design_change.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
// @codingStandardsIgnoreEnd
|
||||
public function testDetectDesignDesignChange()
|
||||
{
|
||||
$this->_model->detectDesign();
|
||||
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
);
|
||||
$this->assertEquals('Magento/luma', $design->getDesignTheme()->getThemePath());
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
/**
|
||||
* Test that non-frontend areas are not affected neither by user-agent reg expressions, nor by the "design change"
|
||||
*
|
||||
* @magentoConfigFixture current_store design/theme/ua_regexp {"_":{"regexp":"\/firefox\/i","value":"Magento\/blank"}}
|
||||
* magentoDataFixture Magento/Theme/_files/design_change.php
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
// @codingStandardsIgnoreEnd
|
||||
public function testDetectDesignNonFrontend()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$model = $objectManager->create(\Magento\Framework\App\Area::class, ['areaCode' => 'adminhtml']);
|
||||
/** @var $request \Magento\TestFramework\Request */
|
||||
$request = $objectManager->create(\Magento\TestFramework\Request::class);
|
||||
$request->setServer(new Parameters(['HTTP_USER_AGENT' => 'Mozilla Firefox']));
|
||||
$model->detectDesign($request);
|
||||
$design = $objectManager->get(\Magento\Framework\View\DesignInterface::class);
|
||||
$this->assertNotEquals('Magento/blank', $design->getDesignTheme()->getThemePath());
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\Backpressure;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
use Magento\TestModuleControllerBackpressure\Controller\Read\Read;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class ControllerBackpressureTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var Read
|
||||
*/
|
||||
private $index;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->index = Bootstrap::getObjectManager()->get(Read::class);
|
||||
$this->index->resetCounter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that backpressure is enforced for controllers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBackpressure(): void
|
||||
{
|
||||
$nOfReqs = 6;
|
||||
|
||||
for ($i = 0; $i < $nOfReqs; $i++) {
|
||||
$this->dispatch('testbackpressure/read/read');
|
||||
}
|
||||
|
||||
$counter = json_decode($this->getResponse()->getBody(), true)['counter'];
|
||||
$this->assertGreaterThan(0, $counter);
|
||||
$this->assertLessThan($nOfReqs, $counter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\Cache\Frontend;
|
||||
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\Cache\Backend\Redis;
|
||||
use Magento\Framework\Cache\FrontendInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FactoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Object Manager
|
||||
*
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Factory
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
/**
|
||||
* @var Area
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @ingeritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->factory = $this->objectManager->create(Factory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check RemoteSynchronizedCache
|
||||
* Removing any cache item in the RemoteSynchronizedCache must invalidate all cache items
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testRemoteSynchronizedCache()
|
||||
{
|
||||
$data = 'data';
|
||||
$identifier = 'identifier';
|
||||
$secondIdentifier = 'secondIdentifier';
|
||||
$secondData = 'secondData';
|
||||
|
||||
$frontendOptions = ['backend' => 'remote_synchronized_cache'];
|
||||
$this->model = $this->factory->create($frontendOptions);
|
||||
|
||||
//Saving data
|
||||
$this->assertTrue($this->model->save($data, $identifier));
|
||||
$this->assertTrue($this->model->save($secondData, $secondIdentifier));
|
||||
|
||||
//Checking data
|
||||
$this->assertEquals($this->model->load($identifier), $data);
|
||||
$this->assertEquals($this->model->load($secondIdentifier), $secondData);
|
||||
|
||||
//Removing data
|
||||
sleep(2);
|
||||
$this->assertTrue($this->model->remove($secondIdentifier));
|
||||
$this->assertTrue($this->model->remove($identifier));
|
||||
$this->assertEquals($this->model->load($identifier), false);
|
||||
$this->assertEquals($this->model->load($secondIdentifier), false);
|
||||
|
||||
//Saving data
|
||||
$this->assertTrue($this->model->save($data, $identifier));
|
||||
$this->assertTrue($this->model->save($secondData, $secondIdentifier));
|
||||
|
||||
//Checking data
|
||||
$this->assertEquals($this->model->load($identifier), $data);
|
||||
$this->assertEquals($this->model->load($secondIdentifier), $secondData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify factory will create cache frontend instance with default options in case Redis is not available.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateCacheFrontedInstanceWithFallbackToDefaultOptions(): void
|
||||
{
|
||||
$options = [
|
||||
'backend_options' => [
|
||||
'server' => null,
|
||||
],
|
||||
'id_prefix' => 'test_prefix',
|
||||
'backend' => Redis::class,
|
||||
];
|
||||
|
||||
self::assertInstanceOf(FrontendInterface::class, $this->factory->create($options));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\App\Cache\Frontend;
|
||||
|
||||
use Magento\Framework\ObjectManager\ConfigInterface as ObjectManagerConfig;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* This superfluous comment can be removed as soon as the sniffs have been updated to match the coding guide lines.
|
||||
*/
|
||||
class PoolTest extends TestCase
|
||||
{
|
||||
public function testPageCacheNotSameAsDefaultCacheDirectory(): void
|
||||
{
|
||||
/** @var ObjectManagerConfig $diConfig */
|
||||
$diConfig = ObjectManager::getInstance()->get(ObjectManagerConfig::class);
|
||||
$argumentConfig = $diConfig->getArguments(\Magento\Framework\App\Cache\Frontend\Pool::class);
|
||||
|
||||
$pageCacheDir = $argumentConfig['frontendSettings']['page_cache']['backend_options']['cache_dir'] ?? null;
|
||||
$defaultCacheDir = $argumentConfig['frontendSettings']['default']['backend_options']['cache_dir'] ?? null;
|
||||
|
||||
$noPageCacheMessage = "No default page_cache directory set in di.xml: \n" . var_export($argumentConfig, true);
|
||||
$this->assertNotEmpty($pageCacheDir, $noPageCacheMessage);
|
||||
|
||||
$sameCacheDirMessage = 'The page_cache and default cache storages share the same cache directory';
|
||||
$this->assertNotSame($pageCacheDir, $defaultCacheDir, $sameCacheDirMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Framework\App\Cache\Frontend\Pool::_getCacheSettings
|
||||
* @depends testPageCacheNotSameAsDefaultCacheDirectory
|
||||
*/
|
||||
public function testCleaningDefaultCachePreservesPageCache()
|
||||
{
|
||||
$testData = 'test data';
|
||||
$testKey = 'test-key';
|
||||
|
||||
/** @var \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool */
|
||||
$cacheFrontendPool = ObjectManager::getInstance()->get(\Magento\Framework\App\Cache\Frontend\Pool::class);
|
||||
|
||||
$pageCache = $cacheFrontendPool->get('page_cache');
|
||||
$pageCache->save($testData, $testKey);
|
||||
|
||||
$defaultCache = $cacheFrontendPool->get('default');
|
||||
$defaultCache->clean();
|
||||
|
||||
$this->assertSame($testData, $pageCache->load($testKey));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Config;
|
||||
|
||||
class BaseTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root><key>value</key></root>
|
||||
XML;
|
||||
$config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Config\Base::class,
|
||||
['sourceData' => $xml]
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(\Magento\Framework\App\Config\Element::class, $config->getNode('key'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Config;
|
||||
|
||||
use Magento\Framework\App\Config;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
|
||||
class DataTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const SAMPLE_CONFIG_PATH = 'web/unsecure/base_url';
|
||||
|
||||
const SAMPLE_VALUE = 'http://example.com/';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Config\Value
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Config\Storage\WriterInterface::class
|
||||
)->save(
|
||||
self::SAMPLE_CONFIG_PATH,
|
||||
self::SAMPLE_VALUE
|
||||
);
|
||||
self::_refreshConfiguration();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Config\Storage\WriterInterface::class
|
||||
)->delete(
|
||||
self::SAMPLE_CONFIG_PATH
|
||||
);
|
||||
self::_refreshConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove cached configuration and reinitialize the application
|
||||
*/
|
||||
protected static function _refreshConfiguration()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\CacheInterface::class)
|
||||
->clean([\Magento\Framework\App\Config::CACHE_TAG]);
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize();
|
||||
$appConfig = ObjectManager::getInstance()->get(Config::class);
|
||||
$appConfig->clean();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Config\Value::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsValueChanged()
|
||||
{
|
||||
// load the model
|
||||
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Config\Model\ResourceModel\Config\Data\Collection::class
|
||||
);
|
||||
$collection->addFieldToFilter(
|
||||
'path',
|
||||
self::SAMPLE_CONFIG_PATH
|
||||
)->addFieldToFilter(
|
||||
'scope_id',
|
||||
0
|
||||
)->addFieldToFilter(
|
||||
'scope',
|
||||
'default'
|
||||
);
|
||||
foreach ($collection as $configData) {
|
||||
$this->_model = $configData;
|
||||
break;
|
||||
}
|
||||
$this->assertNotEmpty($this->_model->getId());
|
||||
|
||||
// assert
|
||||
$this->assertFalse($this->_model->isValueChanged());
|
||||
$this->_model->setValue(uniqid());
|
||||
$this->assertTrue($this->_model->isValueChanged());
|
||||
}
|
||||
|
||||
public function testGetOldValue()
|
||||
{
|
||||
$this->_model->setPath(self::SAMPLE_CONFIG_PATH);
|
||||
$this->assertEquals(self::SAMPLE_VALUE, $this->_model->getOldValue());
|
||||
|
||||
$this->_model->setWebsiteCode('base');
|
||||
$this->assertEquals(self::SAMPLE_VALUE, $this->_model->getOldValue());
|
||||
|
||||
$this->_model->setStoreCode('default');
|
||||
$this->assertEquals(self::SAMPLE_VALUE, $this->_model->getOldValue());
|
||||
}
|
||||
|
||||
public function testGetFieldsetDataValue()
|
||||
{
|
||||
$this->assertNull($this->_model->getFieldsetDataValue('key'));
|
||||
$this->_model->setFieldsetData(['key' => 'value']);
|
||||
$this->assertEquals('value', $this->_model->getFieldsetDataValue('key'));
|
||||
}
|
||||
|
||||
public function testCRUD()
|
||||
{
|
||||
$this->_model->setData(
|
||||
['scope' => 'default', 'scope_id' => 0, 'path' => 'test/config/path', 'value' => 'test value']
|
||||
);
|
||||
$crud = new \Magento\TestFramework\Entity($this->_model, ['value' => 'new value']);
|
||||
$crud->testCrud();
|
||||
}
|
||||
|
||||
public function testCollection()
|
||||
{
|
||||
$collection = $this->_model->getCollection();
|
||||
$collection->addScopeFilter(
|
||||
'test',
|
||||
0,
|
||||
'test'
|
||||
)->addPathFilter(
|
||||
'not_existing_path'
|
||||
)->addValueFilter(
|
||||
'not_existing_value'
|
||||
);
|
||||
$this->assertEmpty($collection->getItems());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Config;
|
||||
|
||||
use Magento\TestFramework\Helper\CacheCleaner;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\App\Config\Initial as Config;
|
||||
|
||||
class InitialTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
public function testGetMetadata()
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->objectManager->create(Config::class)->getMetadata(),
|
||||
$this->objectManager->create(Config::class)->getMetadata()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $scope
|
||||
* @dataProvider getDataDataProvider
|
||||
*/
|
||||
public function testGetData($scope)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->objectManager->create(Config::class)->getData($scope),
|
||||
$this->objectManager->create(Config::class)->getData($scope)
|
||||
);
|
||||
}
|
||||
|
||||
public function getDataDataProvider()
|
||||
{
|
||||
return [
|
||||
['default'],
|
||||
['stores|default'],
|
||||
['websites|default']
|
||||
];
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\Filesystem;
|
||||
|
||||
use Magento\Framework\App\Response\Http\FileFactory;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Laminas\Http\Header\ContentType;
|
||||
|
||||
/**
|
||||
* Class CreatePdfFileTest
|
||||
*
|
||||
* Integration test for testing a file creation from string
|
||||
*/
|
||||
class CreatePdfFileTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testGenerateFileFromString()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var FileFactory $fileFactory */
|
||||
$fileFactory = $objectManager->get(FileFactory::class);
|
||||
/** @var Filesystem $filesystem */
|
||||
$filesystem = $objectManager->get(Filesystem::class);
|
||||
$filename = 'test.pdf';
|
||||
$contentType = 'application/pdf';
|
||||
$fileContent = ['type' => 'string', 'value' => ''];
|
||||
$response = $fileFactory->create($filename, $fileContent, DirectoryList::VAR_DIR, $contentType);
|
||||
ob_start();
|
||||
$response->sendResponse();
|
||||
ob_end_clean();
|
||||
/** @var ContentType $contentTypeHeader */
|
||||
$contentTypeHeader = $response->getHeader('Content-type');
|
||||
|
||||
/* Check the system returns the correct type */
|
||||
self::assertEquals("Content-Type: $contentType", $contentTypeHeader->toString());
|
||||
|
||||
$varDirectory = $filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
|
||||
$varDirectory->isFile($filename);
|
||||
|
||||
/* Check the file is generated */
|
||||
self::assertTrue($varDirectory->isFile($filename));
|
||||
|
||||
/* Check the file is removed after generation if the corresponding option is set */
|
||||
$fileContent = ['type' => 'string', 'value' => '', 'rm' => true];
|
||||
$response = $fileFactory->create($filename, $fileContent, DirectoryList::VAR_DIR, $contentType);
|
||||
ob_start();
|
||||
$response->sendResponse();
|
||||
ob_end_clean();
|
||||
|
||||
self::assertFalse($varDirectory->isFile($filename));
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\App\Filesystem;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test class for the \Magento\Framework\App\Filesystem\DirectoryResolver verification.
|
||||
*/
|
||||
class DirectoryResolverTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Filesystem\DirectoryResolver
|
||||
*/
|
||||
private $directoryResolver;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Filesystem
|
||||
*/
|
||||
private $filesystem;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->directoryResolver = $this->objectManager
|
||||
->create(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
|
||||
$this->filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $directoryConfig
|
||||
* @param bool $expectation
|
||||
* @dataProvider validatePathDataProvider
|
||||
* @throws \Magento\Framework\Exception\FileSystemException
|
||||
* @magentoAppIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testValidatePath($path, $directoryConfig, $expectation)
|
||||
{
|
||||
$directory = $this->filesystem
|
||||
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
|
||||
$path = $directory->getAbsolutePath() .'/' .$path;
|
||||
$this->assertEquals($expectation, $this->directoryResolver->validatePath($path, $directoryConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testValidatePathWithException()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\FileSystemException::class);
|
||||
|
||||
$directory = $this->filesystem
|
||||
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
|
||||
$path = $directory->getAbsolutePath();
|
||||
$this->directoryResolver->validatePath($path, 'wrong_dir');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $directoryConfig
|
||||
* @param bool $expectation
|
||||
* @dataProvider validatePathDataProvider
|
||||
* @throws \Magento\Framework\Exception\FileSystemException
|
||||
* @magentoAppIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testValidatePathWithSymlink($path, $directoryConfig, $expectation)
|
||||
{
|
||||
$directory = $this->filesystem
|
||||
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::PUB);
|
||||
$driver = $directory->getDriver();
|
||||
|
||||
$mediaPath = $directory->getAbsolutePath('media');
|
||||
$mediaMovedPath = $directory->getAbsolutePath('moved-media');
|
||||
|
||||
try {
|
||||
$driver->rename($mediaPath, $mediaMovedPath);
|
||||
$driver->symlink($mediaMovedPath, $mediaPath);
|
||||
$this->testValidatePath($path, $directoryConfig, $expectation);
|
||||
} finally {
|
||||
// be defensive in case some operations failed
|
||||
if ($driver->isExists($mediaPath) && $driver->isExists($mediaMovedPath)) {
|
||||
$driver->deleteFile($mediaPath);
|
||||
$driver->rename($mediaMovedPath, $mediaPath);
|
||||
} elseif ($driver->isExists($mediaMovedPath)) {
|
||||
$driver->rename($mediaMovedPath, $mediaPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validatePathDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'/',
|
||||
DirectoryList::MEDIA,
|
||||
true,
|
||||
],
|
||||
[
|
||||
'/../../pub/',
|
||||
DirectoryList::MEDIA,
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App;
|
||||
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\Request as TestHttpRequest;
|
||||
use Magento\TestFramework\Response;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class FrontControllerEventsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ManagerInterface
|
||||
*/
|
||||
private $eventManager;
|
||||
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var TestHttpRequest
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = ObjectManager::getInstance();
|
||||
$this->setupEventManagerSpy();
|
||||
$this->eventManager = $this->objectManager->get(ManagerInterface::class);
|
||||
$this->request = $this->objectManager->get(TestHttpRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if frontend controller dispatches events
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFrontendControllerDispatchesEvents(): void
|
||||
{
|
||||
$this->setupEventManagerSpy();
|
||||
|
||||
/** @var FrontControllerInterface $frontController */
|
||||
$frontController = ObjectManager::getInstance()->create(FrontControllerInterface::class);
|
||||
$this->configureRequestForAction('cms', 'index', 'index');
|
||||
$frontController->dispatch($this->request);
|
||||
|
||||
$this->assertPreAndPostDispatchEventsAreDispatched();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if no dispatch flag prevents dispatching action
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSettingTheNoDispatchActionFlagProhibitsExecuteAndPostdispatchEvents(): void
|
||||
{
|
||||
$this->setupEventManagerSpy();
|
||||
|
||||
/** @var FrontControllerInterface $frontController */
|
||||
$frontController = ObjectManager::getInstance()->create(FrontControllerInterface::class);
|
||||
$this->configureRequestForAction('cms', 'index', 'index');
|
||||
|
||||
/** @var ActionFlag $actionFlag */
|
||||
$actionFlag = ObjectManager::getInstance()->get(ActionFlag::class);
|
||||
$actionFlag->set('', ActionInterface::FLAG_NO_DISPATCH, true);
|
||||
|
||||
$result1 = $frontController->dispatch($this->request);
|
||||
$this->assertTrue($result1 instanceof Response, 'Action was dispatched!');
|
||||
$this->assertPreDispatchEventsAreDispatched();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare spy on event manager
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setupEventManagerSpy(): void
|
||||
{
|
||||
$eventManager = $this->objectManager->get(ManagerInterface::class);
|
||||
$eventManagerSpy = new class($eventManager) implements ManagerInterface {
|
||||
/**
|
||||
* @var ManagerInterface
|
||||
*/
|
||||
private $delegate;
|
||||
|
||||
/**
|
||||
* @var array[];
|
||||
*/
|
||||
private $dispatchedEvents;
|
||||
|
||||
/**
|
||||
* @param ManagerInterface $delegate
|
||||
*/
|
||||
public function __construct(ManagerInterface $delegate)
|
||||
{
|
||||
$this->delegate = $delegate;
|
||||
}
|
||||
|
||||
public function dispatch($eventName, array $data = [])
|
||||
{
|
||||
$this->dispatchedEvents[$eventName][] = [$eventName, $data];
|
||||
$this->delegate->dispatch($eventName, $data);
|
||||
}
|
||||
|
||||
public function spyOnDispatchedEvent(string $eventName): array
|
||||
{
|
||||
return $this->dispatchedEvents[$eventName] ?? [];
|
||||
}
|
||||
};
|
||||
|
||||
$this->objectManager->addSharedInstance($eventManagerSpy, get_class($eventManager));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if event was dispatched exactly as many times as expected
|
||||
*
|
||||
* @param string $eventName
|
||||
* @param int $expectedCount
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function assertEventDispatchCount(string $eventName, int $expectedCount): void
|
||||
{
|
||||
$message = sprintf('Event %s was expected to be dispatched %d time(s).', $eventName, $expectedCount);
|
||||
$this->assertCount($expectedCount, $this->eventManager->spyOnDispatchedEvent($eventName), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare request for test action
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $actionPath
|
||||
* @param string $actionName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function configureRequestForAction(string $route, string $actionPath, string $actionName): void
|
||||
{
|
||||
$request = $this->request;
|
||||
|
||||
$request->setRouteName($route);
|
||||
$request->setControllerName($actionPath);
|
||||
$request->setActionName($actionName);
|
||||
$request->setDispatched();
|
||||
$request->setRequestUri("$route/$actionPath/$actionName");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check events dispatched before and after execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function assertPreAndPostDispatchEventsAreDispatched(): void
|
||||
{
|
||||
$this->assertEventDispatchCount('controller_action_predispatch', 1);
|
||||
$this->assertEventDispatchCount('controller_action_predispatch_cms', 1);
|
||||
$this->assertEventDispatchCount('controller_action_predispatch_cms_index_index', 1);
|
||||
$this->assertEventDispatchCount('controller_action_postdispatch_cms_index_index', 1);
|
||||
$this->assertEventDispatchCount('controller_action_postdispatch_cms', 1);
|
||||
$this->assertEventDispatchCount('controller_action_postdispatch', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check events are dispatched only before execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function assertPreDispatchEventsAreDispatched(): void
|
||||
{
|
||||
$this->assertEventDispatchCount('controller_action_predispatch', 1);
|
||||
$this->assertEventDispatchCount('controller_action_predispatch_cms', 1);
|
||||
$this->assertEventDispatchCount('controller_action_predispatch_cms_index_index', 1);
|
||||
$this->assertEventDispatchCount('controller_action_postdispatch_cms_index_index', 0);
|
||||
$this->assertEventDispatchCount('controller_action_postdispatch_cms', 0);
|
||||
$this->assertEventDispatchCount('controller_action_postdispatch', 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App;
|
||||
|
||||
use Magento\Framework\App\Request\InvalidRequestException;
|
||||
use Magento\Framework\App\Request\ValidatorInterface;
|
||||
use Magento\Framework\Exception\NotFoundException;
|
||||
use Magento\Framework\Phrase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class FrontControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $_objectManager;
|
||||
|
||||
/**
|
||||
* @var FrontController
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var ValidatorInterface
|
||||
*/
|
||||
private $fakeRequestValidator;
|
||||
|
||||
/**
|
||||
* @return ValidatorInterface
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
|
||||
*/
|
||||
private function createRequestValidator(): ValidatorInterface
|
||||
{
|
||||
if (!$this->fakeRequestValidator) {
|
||||
$this->fakeRequestValidator = new class implements ValidatorInterface {
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $valid;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function validate(
|
||||
RequestInterface $request,
|
||||
ActionInterface $action
|
||||
): void {
|
||||
if (!$this->valid) {
|
||||
throw new InvalidRequestException(new NotFoundException(new Phrase('Not found')));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return $this->fakeRequestValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = Bootstrap::getObjectManager();
|
||||
$this->_model = $this->_objectManager->create(
|
||||
FrontController::class,
|
||||
['requestValidator' => $this->createRequestValidator()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dispatching an empty action.
|
||||
*/
|
||||
public function testDispatch()
|
||||
{
|
||||
if (!Bootstrap::canTestHeaders()) {
|
||||
$this->markTestSkipped('Can\'t test dispatch process without sending headers');
|
||||
}
|
||||
$this->fakeRequestValidator->valid = true;
|
||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||
$this->_objectManager->get(State::class)->setAreaCode('frontend');
|
||||
$request = $this->_objectManager->get(HttpRequest::class);
|
||||
/* empty action */
|
||||
$request->setRequestUri('core/index/index');
|
||||
$this->assertInstanceOf(
|
||||
ResultInterface::class,
|
||||
$this->_model->dispatch($request)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test request validator invalidating given request.
|
||||
*/
|
||||
public function testInvalidRequest()
|
||||
{
|
||||
if (!Bootstrap::canTestHeaders()) {
|
||||
$this->markTestSkipped('Can\'t test dispatch process without sending headers');
|
||||
}
|
||||
$this->fakeRequestValidator->valid = false;
|
||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||
$this->_objectManager->get(State::class)->setAreaCode('frontend');
|
||||
$request = $this->_objectManager->get(HttpRequest::class);
|
||||
/* empty action */
|
||||
$request->setRequestUri('core/index/index');
|
||||
$this->assertInstanceOf(
|
||||
ResultInterface::class,
|
||||
$this->_model->dispatch($request)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\App\Language;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class DictionaryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Language\Dictionary
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Filesystem\Directory\ReadFactory
|
||||
*/
|
||||
private $directoryFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Language\ConfigFactory
|
||||
*/
|
||||
private $configFactory;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->directoryFactory = $this->objectManager->create(
|
||||
\Magento\Framework\Filesystem\Directory\ReadFactory::class
|
||||
);
|
||||
$this->configFactory = $this->objectManager->create(\Magento\Framework\App\Language\ConfigFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $languageCode
|
||||
* @param array $expectation
|
||||
* @dataProvider dictionaryDataProvider
|
||||
* @magentoComponentsDir Magento/Framework/App/Language/_files
|
||||
*/
|
||||
public function testDictionaryGetter($languageCode, $expectation)
|
||||
{
|
||||
$this->model = $this->objectManager->create(
|
||||
\Magento\Framework\App\Language\Dictionary::class,
|
||||
['directoryReadFactory' => $this->directoryFactory, 'configFactory' => $this->configFactory]
|
||||
);
|
||||
$result = $this->model->getDictionary($languageCode);
|
||||
$this->assertSame($expectation, $result);
|
||||
}
|
||||
|
||||
public function dictionaryDataProvider()
|
||||
{
|
||||
return [
|
||||
// First case with multiple inheritance, the obtained dictionary is en_AU
|
||||
'a case with multiple inheritance' => $this->getDataMultipleInheritance(),
|
||||
// Second case with inheritance of package with the same language code
|
||||
'a case with inheritance similar language code' => $this->getDataInheritanceWitSimilarCode(),
|
||||
// Third case with circular inheritance, when two packages depend on each other
|
||||
'a case with circular inheritance' => $this->getDataCircularInheritance(),
|
||||
// Fourth case with multiple inheritance from dev docs
|
||||
'a case with multiple inheritance from dev docs' => $this->getDataMultipleInheritanceFromDevDocs()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getDataMultipleInheritance()
|
||||
{
|
||||
return [
|
||||
// Dictionary that will be requested
|
||||
'language_code' => 'en_AU',
|
||||
// Expected merged dictionary data
|
||||
'expectation' => [
|
||||
'one' => '1.0',
|
||||
'two' => '2',
|
||||
'three' => '3',
|
||||
'four' => '4',
|
||||
'four and 5/10' => '4.50',
|
||||
'four and 75/100' => '4.75',
|
||||
'five' => '5.0',
|
||||
'six' => '6.0',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getDataInheritanceWitSimilarCode()
|
||||
{
|
||||
return [
|
||||
// Dictionary that will be requested
|
||||
'language_code' => 'ru_RU',
|
||||
// Expected merged dictionary data
|
||||
'expectation' => [
|
||||
'one' => '1.0',
|
||||
'two' => '2',
|
||||
'three' => '3',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getDataCircularInheritance()
|
||||
{
|
||||
return [
|
||||
// Dictionary that will be requested
|
||||
'language_code' => 'en_AZ',
|
||||
// Expected merged dictionary data
|
||||
'expectation' => [
|
||||
'one' => '1.0',
|
||||
'two' => '2',
|
||||
'three' => '3',
|
||||
'four' => '4',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* If a language package inherits from two packages:
|
||||
* ...
|
||||
* <code>en_AK</code>
|
||||
* ...
|
||||
* <use vendor="parent-package-one" package="language_package_one"/>
|
||||
* <use vendor= "parent-package-two" package="language_package_two"/>
|
||||
* ...
|
||||
*
|
||||
* In the preceding example:
|
||||
* language_package_one inherits from en_au_package and en_au_package inherits from en_ie_package
|
||||
* language_package_two inherits from en_ca_package and en_ca_package inherits from en_us_package
|
||||
*
|
||||
* If the Magento application cannot find word or phrase in the en_AK package,
|
||||
* it looks in other packages in following sequence:
|
||||
* parent-package-one/language_package_one
|
||||
* <vendorname>/en_au_package
|
||||
* <vendorname>/en_ie_package
|
||||
* parent-package-two/language_package_two
|
||||
* <vendorname>/en_ca_package
|
||||
* <vendorname>/en_us_package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getDataMultipleInheritanceFromDevDocs()
|
||||
{
|
||||
return [
|
||||
// Dictionary that will be requested
|
||||
'language_code' => 'en_AK',
|
||||
// Expected merged dictionary data
|
||||
'expectation' => [
|
||||
'one' => 'en_us_package_one',
|
||||
'two' => 'en_ca_package_two',
|
||||
'three' => 'language_package_two_three',
|
||||
'four' => 'en_ie_package_four',
|
||||
'five' => 'en_au_package_five',
|
||||
'six' => 'language_package_one_six',
|
||||
'seven' => 'en_ak_seven',
|
||||
'eight' => 'en_ak_eight',
|
||||
'nine' => 'en_ak_nine',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
one,1
|
||||
two,2
|
||||
|
@@ -0,0 +1,2 @@
|
||||
three,3
|
||||
four,4
|
||||
|
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_AZ</code>
|
||||
<vendor>bar</vendor>
|
||||
<package>en_az</package>
|
||||
<sort_order>0</sort_order>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'bar_en_az', __DIR__);
|
||||
@@ -0,0 +1,3 @@
|
||||
four and 75/100,4.75
|
||||
four and 5/10,4.50
|
||||
|
||||
|
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_GB</code>
|
||||
<vendor>bar</vendor>
|
||||
<package>en_gb</package>
|
||||
<sort_order>100</sort_order>
|
||||
<use package="en_az" vendor="bar"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'bar_en_gb', __DIR__);
|
||||
@@ -0,0 +1,5 @@
|
||||
one,1.00
|
||||
two,2.00
|
||||
three,3.00
|
||||
four,4.00
|
||||
four and 5/10,4.5
|
||||
|
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_GB</code>
|
||||
<vendor>baz</vendor>
|
||||
<package>en_gb</package>
|
||||
<sort_order>50</sort_order>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'baz_en_gb', __DIR__);
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
seven,en_ak_seven
|
||||
eight,en_ak_eight
|
||||
nine,en_ak_nine
|
||||
|
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_AK</code>
|
||||
<vendor>devdoc</vendor>
|
||||
<package>en_ak</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use vendor="parent-package-one" package="language_package_one"/>
|
||||
<use vendor="parent-package-two" package="language_package_two"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'devdoc_en_ak', __DIR__);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
three,3
|
||||
one,1.0
|
||||
|
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_AZ</code>
|
||||
<vendor>first</vendor>
|
||||
<package>en_az</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use package="en_gb" vendor="second"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'first_en_az', __DIR__);
|
||||
@@ -0,0 +1,2 @@
|
||||
one,1.0
|
||||
five,5.0
|
||||
|
@@ -0,0 +1 @@
|
||||
six,6.0
|
||||
|
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_AU</code>
|
||||
<vendor>foo</vendor>
|
||||
<package>en_au</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use package="en_gb" vendor="bar"/>
|
||||
<use package="en_gb" vendor="baz"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'foo_en_au', __DIR__);
|
||||
@@ -0,0 +1,2 @@
|
||||
three,3
|
||||
one,1.0
|
||||
|
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>ru_RU</code>
|
||||
<vendor>my</vendor>
|
||||
<package>ru_ru</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use package="ru_ru" vendor="theirs"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'my_ru_ru', __DIR__);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
five,en_au_package_five
|
||||
six,en_au_package_six
|
||||
seven,en_au_package_seven
|
||||
eight,en_au_package_eight
|
||||
nine,en_au_package_nine
|
||||
|
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_US</code>
|
||||
<vendor>parent-package-one</vendor>
|
||||
<package>en_au_package</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use vendor="parent-package-one" package="en_ie_package"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-one_en_au_package', __DIR__);
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
four,en_ie_package_four
|
||||
five,en_ie_package_five
|
||||
six,en_ie_package_six
|
||||
seven,en_ie_package_seven
|
||||
eight,en_ie_package_eight
|
||||
nine,en_ie_package_nine
|
||||
|
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_US</code>
|
||||
<vendor>parent-package-one</vendor>
|
||||
<package>en_ie_package</package>
|
||||
<sort_order>0</sort_order>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-one_en_ie_package', __DIR__);
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
six,language_package_one_six
|
||||
seven,language_package_one_seven
|
||||
eight,language_package_one_eight
|
||||
nine,language_package_one_nine
|
||||
|
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_US</code>
|
||||
<vendor>parent-package-one</vendor>
|
||||
<package>language_package_one</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use vendor="parent-package-one" package="en_au_package"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-one_language_package_one', __DIR__);
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
two,en_ca_package_two
|
||||
three,en_ca_package_three
|
||||
four,en_ca_package_four
|
||||
five,en_ca_package_five
|
||||
six,en_ca_package_six
|
||||
seven,en_ca_package_seven
|
||||
eight,en_ca_package_eight
|
||||
nine,en_ca_package_nine
|
||||
|
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_US</code>
|
||||
<vendor>parent-package-two</vendor>
|
||||
<package>en_ca_package</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use vendor="parent-package-two" package="en_us_package"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-two_en_ca_package', __DIR__);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
one,en_us_package_one
|
||||
two,en_us_package_two
|
||||
three,en_us_package_three
|
||||
four,en_us_package_four
|
||||
five,en_us_package_five
|
||||
six,en_us_package_six
|
||||
seven,en_us_package_seven
|
||||
eight,en_us_package_eight
|
||||
nine,en_us_package_nine
|
||||
|
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_US</code>
|
||||
<vendor>parent-package-two</vendor>
|
||||
<package>en_us_package</package>
|
||||
<sort_order>0</sort_order>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-two_en_us_package', __DIR__);
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
three,language_package_two_three
|
||||
four,language_package_two_four
|
||||
five,language_package_two_five
|
||||
six,language_package_two_six
|
||||
seven,language_package_two_seven
|
||||
eight,language_package_two_eight
|
||||
nine,language_package_two_nine
|
||||
|
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_US</code>
|
||||
<vendor>parent-package-two</vendor>
|
||||
<package>language_package_two</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use vendor="parent-package-two" package="en_ca_package"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-two_language_package_two', __DIR__);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
one,1
|
||||
two,2
|
||||
|
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>en_GB</code>
|
||||
<vendor>second</vendor>
|
||||
<package>en_gb</package>
|
||||
<sort_order>0</sort_order>
|
||||
<use package="en_az" vendor="first"/>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'second_en_gb', __DIR__);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
one,1
|
||||
two,2
|
||||
|
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
|
||||
<code>ru_RU</code>
|
||||
<vendor>theirs</vendor>
|
||||
<package>ru_ru</package>
|
||||
<sort_order>0</sort_order>
|
||||
</language>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'theirs_ru_ru', __DIR__);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\ObjectManager;
|
||||
|
||||
use Magento\TestFramework\Helper\CacheCleaner;
|
||||
|
||||
class ConfigLoaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\ObjectManager\ConfigLoader
|
||||
*/
|
||||
private $object;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->object = $objectManager->create(
|
||||
\Magento\Framework\App\ObjectManager\ConfigLoader::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$data = $this->object->load('global');
|
||||
$this->assertNotEmpty($data);
|
||||
$cachedData = $this->object->load('global');
|
||||
$this->assertEquals($data, $cachedData);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\ObjectManager\ConfigWriter;
|
||||
|
||||
class FilesystemTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const CACHE_KEY = 'filesystemtest';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ObjectManager\ConfigWriter\Filesystem
|
||||
*/
|
||||
private $configWriter;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ObjectManager\ConfigLoader
|
||||
*/
|
||||
private $configReader;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->configWriter = $objectManager->create(
|
||||
\Magento\Framework\App\ObjectManager\ConfigWriter\Filesystem::class
|
||||
);
|
||||
$this->configReader = $objectManager->create(
|
||||
\Magento\Framework\App\ObjectManager\ConfigLoader\Compiled::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$sampleData = [
|
||||
'classA' => true,
|
||||
'classB' => false,
|
||||
];
|
||||
|
||||
$this->configWriter->write(self::CACHE_KEY, $sampleData);
|
||||
$this->assertEquals($sampleData, $this->configReader->load(self::CACHE_KEY));
|
||||
}
|
||||
|
||||
public function testOverwrite()
|
||||
{
|
||||
$this->configWriter->write(self::CACHE_KEY, ['hello' => 'world']);
|
||||
|
||||
$sampleData = [
|
||||
'classC' => false,
|
||||
'classD' => true,
|
||||
];
|
||||
|
||||
$this->configWriter->write(self::CACHE_KEY, $sampleData);
|
||||
$this->assertEquals($sampleData, $this->configReader->load(self::CACHE_KEY));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\Request;
|
||||
|
||||
use Magento\Framework\App\ActionInterface;
|
||||
use Magento\Framework\App\CsrfAwareActionInterface;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Framework\Controller\Result\RedirectFactory;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Exception\NotFoundException;
|
||||
use Magento\Framework\Phrase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Laminas\Stdlib\Parameters;
|
||||
use Magento\Framework\App\Response\Http as HttpResponse;
|
||||
use Magento\Framework\App\Response\HttpFactory as HttpResponseFactory;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class CsrfValidatorTest extends TestCase
|
||||
{
|
||||
private const AWARE_URL = 'test/1';
|
||||
|
||||
private const AWARE_VALIDATION_PARAM = 'test_param';
|
||||
|
||||
private const AWARE_MESSAGE = 'custom validation failed';
|
||||
|
||||
/**
|
||||
* @var ActionInterface
|
||||
*/
|
||||
private $mockUnawareAction;
|
||||
|
||||
/**
|
||||
* @var ActionInterface
|
||||
*/
|
||||
private $mockAwareAction;
|
||||
|
||||
/**
|
||||
* @var CsrfValidator
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
/**
|
||||
* @var HttpRequest
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var FormKey
|
||||
*/
|
||||
private $formKey;
|
||||
|
||||
/**
|
||||
* @var HttpResponseFactory
|
||||
*/
|
||||
private $httpResponseFactory;
|
||||
|
||||
/**
|
||||
* @return ActionInterface
|
||||
*/
|
||||
private function createUnawareAction(): ActionInterface
|
||||
{
|
||||
return new class implements ActionInterface {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
throw new NotFoundException(new Phrase('Not implemented'));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActionInterface
|
||||
*/
|
||||
private function createAwareAction(): ActionInterface
|
||||
{
|
||||
$u = self::AWARE_URL;
|
||||
$m = self::AWARE_MESSAGE;
|
||||
$p = self::AWARE_VALIDATION_PARAM;
|
||||
|
||||
return new class($u, $m, $p) implements CsrfAwareActionInterface {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $param;
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param string $message
|
||||
* @param string $param
|
||||
*/
|
||||
public function __construct(
|
||||
string $url,
|
||||
string $message,
|
||||
string $param
|
||||
) {
|
||||
$this->url = $url;
|
||||
$this->message = $message;
|
||||
$this->param = $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
throw new NotFoundException(new Phrase('Not implemented'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createCsrfValidationException(
|
||||
RequestInterface $request
|
||||
): ?InvalidRequestException {
|
||||
/** @var RedirectFactory $redirectFactory */
|
||||
$redirectFactory = Bootstrap::getObjectManager()
|
||||
->get(RedirectFactory::class);
|
||||
$redirect = $redirectFactory->create();
|
||||
$redirect->setUrl($this->url);
|
||||
|
||||
return new InvalidRequestException(
|
||||
$redirect,
|
||||
[new Phrase($this->message)]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function validateForCsrf(RequestInterface $request): ?bool
|
||||
{
|
||||
return (bool)$request->getParam($this->param);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->request = $objectManager->get(HttpRequest::class);
|
||||
$this->validator = $objectManager->get(CsrfValidator::class);
|
||||
$this->mockUnawareAction = $this->createUnawareAction();
|
||||
$this->mockAwareAction = $this->createAwareAction();
|
||||
$this->formKey = $objectManager->get(FormKey::class);
|
||||
$this->httpResponseFactory = $objectManager->get(
|
||||
HttpResponseFactory::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea global
|
||||
*/
|
||||
public function testValidateInWrongArea()
|
||||
{
|
||||
$this->request->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockUnawareAction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testValidateWithValidKey()
|
||||
{
|
||||
$this->request->setPost(
|
||||
new Parameters(['form_key' => $this->formKey->getFormKey()])
|
||||
);
|
||||
$this->request->setMethod(HttpRequest::METHOD_POST);
|
||||
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockUnawareAction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testValidateWithInvalidKey()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\App\Request\InvalidRequestException::class);
|
||||
|
||||
$this->request->setPost(
|
||||
new Parameters(['form_key' => $this->formKey->getFormKey() .'1'])
|
||||
);
|
||||
$this->request->setMethod(HttpRequest::METHOD_POST);
|
||||
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockUnawareAction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testValidateInvalidWithAwareAction()
|
||||
{
|
||||
$this->request->setMethod(HttpRequest::METHOD_POST);
|
||||
|
||||
/** @var InvalidRequestException|null $caught */
|
||||
$caught = null;
|
||||
try {
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockAwareAction
|
||||
);
|
||||
} catch (InvalidRequestException $exception) {
|
||||
$caught = $exception;
|
||||
}
|
||||
|
||||
$this->assertNotNull($caught);
|
||||
$this->assertInstanceOf(Redirect::class, $caught->getReplaceResult());
|
||||
/** @var HttpResponse $response */
|
||||
$response = $this->httpResponseFactory->create();
|
||||
$caught->getReplaceResult()->renderResult($response);
|
||||
$this->assertStringContainsString(
|
||||
self::AWARE_URL,
|
||||
$response->getHeaders()->toString()
|
||||
);
|
||||
$this->assertCount(1, $caught->getMessages());
|
||||
$this->assertEquals(
|
||||
self::AWARE_MESSAGE,
|
||||
$caught->getMessages()[0]->getText()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testValidateValidWithAwareAction()
|
||||
{
|
||||
$this->request->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->request->setPost(
|
||||
new Parameters([self::AWARE_VALIDATION_PARAM => '1'])
|
||||
);
|
||||
|
||||
$this->validator->validate(
|
||||
$this->request,
|
||||
$this->mockAwareAction
|
||||
);
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\Request;
|
||||
|
||||
use Magento\Framework\App\ActionInterface;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
|
||||
class HttpMethodValidatorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var HttpMethodValidator
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
/**
|
||||
* @var HttpRequest
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var HttpMethodMap
|
||||
*/
|
||||
private $map;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->validator = $objectManager->get(HttpMethodValidator::class);
|
||||
$this->request = $objectManager->get(RequestInterface::class);
|
||||
if (!$this->request instanceof HttpRequest) {
|
||||
throw new \RuntimeException('We need HTTP request');
|
||||
}
|
||||
$this->map = $objectManager->get(HttpMethodMap::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getMap(): array
|
||||
{
|
||||
$map = $this->map->getMap();
|
||||
if (count($map) < 2) {
|
||||
throw new \RuntimeException(
|
||||
'We need at least 2 HTTP methods allowed'
|
||||
);
|
||||
}
|
||||
|
||||
$sorted = [];
|
||||
foreach ($map as $method => $interface) {
|
||||
$sorted[] = ['method' => $method, 'interface' => $interface];
|
||||
}
|
||||
|
||||
return $sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test positive case.
|
||||
*
|
||||
* @throws InvalidRequestException
|
||||
*/
|
||||
public function testAllowed()
|
||||
{
|
||||
$map = $this->getMap();
|
||||
|
||||
$action1 = $this->getMockForAbstractClass($map[0]['interface']);
|
||||
$this->request->setMethod($map[0]['method']);
|
||||
$this->validator->validate($this->request, $action1);
|
||||
|
||||
$action2 = $this->getMockForAbstractClass(ActionInterface::class);
|
||||
$this->validator->validate($this->request, $action2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test negative case.
|
||||
*
|
||||
*/
|
||||
public function testNotAllowedMethod()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\App\Request\InvalidRequestException::class);
|
||||
|
||||
$this->request->setMethod('method' .rand(0, 1000));
|
||||
$action = $this->getMockForAbstractClass(ActionInterface::class);
|
||||
|
||||
$this->validator->validate($this->request, $action);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testRestrictedMethod()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\App\Request\InvalidRequestException::class);
|
||||
|
||||
$map = $this->getMap();
|
||||
|
||||
$this->request->setMethod($map[1]['method']);
|
||||
$action = $this->getMockForAbstractClass($map[0]['interface']);
|
||||
|
||||
$this->validator->validate($this->request, $action);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\ResourceConnection;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
class ConnectionFactoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection\ConnectionFactory
|
||||
*/
|
||||
private $model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->model = new \Magento\Framework\App\ResourceConnection\ConnectionFactory(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$dbInstance = \Magento\TestFramework\Helper\Bootstrap::getInstance()
|
||||
->getBootstrap()
|
||||
->getApplication()
|
||||
->getDbInstance();
|
||||
$dbConfig = [
|
||||
'host' => $dbInstance->getHost(),
|
||||
'username' => $dbInstance->getUser(),
|
||||
'password' => $dbInstance->getPassword(),
|
||||
'dbname' => $dbInstance->getSchema(),
|
||||
'active' => true,
|
||||
];
|
||||
$connection = $this->model->create($dbConfig);
|
||||
$this->assertInstanceOf(\Magento\Framework\DB\Adapter\AdapterInterface::class, $connection);
|
||||
$this->assertIsObject($connection);
|
||||
$this->assertTrue(property_exists($connection, 'logger'));
|
||||
$object = new ReflectionClass(get_class($connection));
|
||||
$attribute = $object->getProperty('logger');
|
||||
$attribute->setAccessible(true);
|
||||
$propertyObject = $attribute->getValue($connection);
|
||||
$attribute->setAccessible(false);
|
||||
$this->assertInstanceOf(\Magento\Framework\DB\LoggerInterface::class, $propertyObject);
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Response\HeaderProvider;
|
||||
|
||||
use Laminas\Http\Header\HeaderInterface;
|
||||
use Magento\Framework\App\Response\Http as HttpResponse;
|
||||
|
||||
/**
|
||||
* Class AbstractHeaderTestCase
|
||||
*/
|
||||
abstract class AbstractHeaderTestCase extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @var HttpResponse
|
||||
*/
|
||||
private $interceptedResponse;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_objectManager->configure(
|
||||
[
|
||||
'preferences' => [
|
||||
HttpResponse::class => 'Magento\Framework\App\Response\Http\Interceptor'
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->interceptedResponse = $this->_objectManager->create(HttpResponse::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a given header matches a given value
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
protected function assertHeaderPresent($name, $value)
|
||||
{
|
||||
$value = [$value];
|
||||
$this->interceptedResponse->sendResponse();
|
||||
$header = $this->interceptedResponse->getHeader($name);
|
||||
|
||||
$headerContent = [];
|
||||
if ($header instanceof \ArrayIterator) {
|
||||
foreach ($header as $item) {
|
||||
$headerContent[] = $item->getFieldValue();
|
||||
}
|
||||
} elseif ($header instanceof HeaderInterface) {
|
||||
$headerContent[] = $header->getFieldValue();
|
||||
}
|
||||
|
||||
$this->assertSame(
|
||||
$value,
|
||||
$headerContent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert is no header.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
protected function assertHeaderNotPresent($name)
|
||||
{
|
||||
$this->interceptedResponse->sendResponse();
|
||||
$this->assertFalse($this->interceptedResponse->getHeader($name));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Response\HeaderProvider;
|
||||
|
||||
class HstsTest extends AbstractHeaderTestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAdminConfigFixture web/secure/enable_hsts 1
|
||||
* @magentoAdminConfigFixture web/secure/use_in_frontend 1
|
||||
* @magentoAdminConfigFixture web/secure/use_in_adminhtml 1
|
||||
*/
|
||||
public function testHeaderPresent()
|
||||
{
|
||||
$this->assertHeaderPresent('Strict-Transport-Security', 'max-age=31536000');
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAdminConfigFixture web/secure/enable_hsts 0
|
||||
* @magentoAdminConfigFixture web/secure/use_in_frontend 1
|
||||
* @magentoAdminConfigFixture web/secure/use_in_adminhtml 1
|
||||
*/
|
||||
public function testHeaderNotPresent()
|
||||
{
|
||||
$this->assertHeaderNotPresent('Strict-Transport-Security');
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Response\HeaderProvider;
|
||||
|
||||
class UpgradeInsecureTest extends AbstractHeaderTestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAdminConfigFixture web/secure/enable_upgrade_insecure 1
|
||||
* @magentoAdminConfigFixture web/secure/use_in_frontend 1
|
||||
* @magentoAdminConfigFixture web/secure/use_in_adminhtml 1
|
||||
*/
|
||||
public function testHeaderPresent()
|
||||
{
|
||||
$this->assertHeaderPresent('Content-Security-Policy', 'upgrade-insecure-requests;');
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAdminConfigFixture web/secure/enable_upgrade_insecure 0
|
||||
* @magentoAdminConfigFixture web/secure/use_in_frontend 1
|
||||
* @magentoAdminConfigFixture web/secure/use_in_adminhtml 1
|
||||
*/
|
||||
public function testHeaderNotPresent()
|
||||
{
|
||||
$this->assertHeaderNotPresent('Content-Security-Policy');
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Response\HeaderProvider;
|
||||
|
||||
class XFrameOptionsTest extends AbstractHeaderTestCase
|
||||
{
|
||||
public function testHeaderPresent()
|
||||
{
|
||||
$this->assertHeaderPresent('X-Frame-Options', 'SAMEORIGIN');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Route;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\CacheCleaner;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
class ConfigTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param string $scope
|
||||
* @dataProvider getRouteFrontNameDataProvider
|
||||
*/
|
||||
public function testGetRouteFrontName($route, $scope)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->objectManager->create(Config::class)->getRouteFrontName($route, $scope),
|
||||
$this->objectManager->create(Config::class)->getRouteFrontName($route, $scope)
|
||||
);
|
||||
}
|
||||
|
||||
public function getRouteFrontNameDataProvider()
|
||||
{
|
||||
return [
|
||||
['adminhtml', 'adminhtml'],
|
||||
['catalog', 'frontend'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\App\Router;
|
||||
|
||||
class BaseTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\Router\Base
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$options = ['routerId' => 'standard'];
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Router\Base::class,
|
||||
$options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testMatch()
|
||||
{
|
||||
if (!\Magento\TestFramework\Helper\Bootstrap::canTestHeaders()) {
|
||||
$this->markTestSkipped('Can\'t test get match without sending headers');
|
||||
}
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $request \Magento\TestFramework\Request */
|
||||
$request = $objectManager->get(\Magento\TestFramework\Request::class);
|
||||
|
||||
$this->assertInstanceOf(\Magento\Framework\App\ActionInterface::class, $this->_model->match($request));
|
||||
$request->setRequestUri('framework/index/index');
|
||||
$this->assertInstanceOf(\Magento\Framework\App\ActionInterface::class, $this->_model->match($request));
|
||||
|
||||
$request->setPathInfo(
|
||||
'not_exists/not_exists/not_exists'
|
||||
)->setModuleName(
|
||||
'not_exists'
|
||||
)->setControllerName(
|
||||
'not_exists'
|
||||
)->setActionName(
|
||||
'not_exists'
|
||||
);
|
||||
$this->assertNull($this->_model->match($request));
|
||||
}
|
||||
|
||||
public function testGetControllerClassName()
|
||||
{
|
||||
$this->assertEquals(
|
||||
\Magento\Framework\Controller\Index::class,
|
||||
$this->_model->getActionClassName('Magento_Framework', 'index')
|
||||
);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\TestStubs;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
/**
|
||||
* Stub inheritance based backend action controller for testing purposes.
|
||||
*/
|
||||
class InheritanceBasedBackendAction extends Action
|
||||
{
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
private $pageFactory;
|
||||
|
||||
/**
|
||||
* @param Action\Context $context
|
||||
* @param PageFactory $pageFactory
|
||||
*/
|
||||
public function __construct(Action\Context $context, PageFactory $pageFactory)
|
||||
{
|
||||
parent::__construct($context);
|
||||
$this->pageFactory = $pageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Page
|
||||
*
|
||||
* @return ResponseInterface|ResultInterface|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->pageFactory->create();
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\TestStubs;
|
||||
|
||||
use Magento\Framework\App\Action\Action;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
/**
|
||||
* Stub inheritance based frontend action controller for testing purposes.
|
||||
*/
|
||||
class InheritanceBasedFrontendAction extends Action
|
||||
{
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
private $pageFactory;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $executeWasCalled = false;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param PageFactory $pageFactory
|
||||
*/
|
||||
public function __construct(Context $context, PageFactory $pageFactory)
|
||||
{
|
||||
parent::__construct($context);
|
||||
$this->pageFactory = $pageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs `execute()` method to create Page
|
||||
*
|
||||
* @return ResponseInterface|ResultInterface|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->executeWasCalled = true;
|
||||
return $this->pageFactory->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether execute method was called
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExecuted(): bool
|
||||
{
|
||||
return $this->executeWasCalled;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\TestStubs;
|
||||
|
||||
use Magento\Framework\App\ActionInterface;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
/**
|
||||
* Stub interface action controller implementation for testing purposes.
|
||||
*/
|
||||
class InterfaceOnlyBackendAction implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
private $pageFactory;
|
||||
|
||||
/**
|
||||
* @param PageFactory $pageFactory
|
||||
*/
|
||||
public function __construct(PageFactory $pageFactory)
|
||||
{
|
||||
$this->pageFactory = $pageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Page object
|
||||
*
|
||||
* @return ResponseInterface|ResultInterface|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->pageFactory->create();
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\App\TestStubs;
|
||||
|
||||
use Magento\Framework\App\ActionInterface;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
/**
|
||||
* Stub interface only based frontend action controller for testing purposes.
|
||||
*/
|
||||
class InterfaceOnlyFrontendAction implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
private $pageFactory;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $executeWasCalled = false;
|
||||
|
||||
/**
|
||||
* @param PageFactory $pageFactory
|
||||
*/
|
||||
public function __construct(PageFactory $pageFactory)
|
||||
{
|
||||
$this->pageFactory = $pageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Page object
|
||||
*
|
||||
* @return ResponseInterface|ResultInterface|Page
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->executeWasCalled = true;
|
||||
return $this->pageFactory->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether `execute()` method was ran
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExecuted(): bool
|
||||
{
|
||||
return $this->executeWasCalled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/***
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\App\Utility;
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
class FilesTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Framework\App\Utility\Files */
|
||||
protected $model;
|
||||
|
||||
/** @var array */
|
||||
protected $moduleTests = [];
|
||||
|
||||
/** @var array */
|
||||
protected $frameworkTests = [];
|
||||
|
||||
/** @var array */
|
||||
protected $libTests = [];
|
||||
|
||||
/** @var string */
|
||||
protected $rootTestsDir = '#dev/tests/#';
|
||||
|
||||
/** @var string */
|
||||
protected $setupTestsDir = '#setup/src/Magento/Setup/Test#';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$componentRegistrar = new ComponentRegistrar();
|
||||
$dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Framework\Component\DirSearch::class);
|
||||
$themePackageList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
|
||||
$this->model = new Files($componentRegistrar, $dirSearch, $themePackageList);
|
||||
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) {
|
||||
$this->moduleTests[] = '#' . $moduleDir . '/Test#';
|
||||
}
|
||||
foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $libraryDir) {
|
||||
$this->libTests[] = '#' . $libraryDir . '/Test#';
|
||||
$this->frameworkTests[] = '#' . $libraryDir . '/[\\w]+/Test#';
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetPhpFilesExcludeTests()
|
||||
{
|
||||
$this->assertNoTestDirs(
|
||||
$this->model->getPhpFiles(
|
||||
Files::INCLUDE_APP_CODE
|
||||
| Files::INCLUDE_PUB_CODE
|
||||
| Files::INCLUDE_DEV_TOOLS
|
||||
| Files::INCLUDE_LIBS
|
||||
| Files::INCLUDE_TEMPLATES
|
||||
| Files::INCLUDE_NON_CLASSES
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetComposerExcludeTests()
|
||||
{
|
||||
$this->assertNoTestDirs(
|
||||
$this->model->getComposerFiles(ComponentRegistrar::MODULE, false)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetPhpFilesOnlyTests()
|
||||
{
|
||||
$classFiles = $this->model->getPhpFiles(Files::INCLUDE_TESTS);
|
||||
|
||||
foreach ($this->moduleTests as $moduleTest) {
|
||||
$classFiles = preg_grep($moduleTest, $classFiles, PREG_GREP_INVERT);
|
||||
}
|
||||
foreach ($this->libTests as $libraryTest) {
|
||||
$classFiles = preg_grep($libraryTest, $classFiles, PREG_GREP_INVERT);
|
||||
}
|
||||
foreach ($this->frameworkTests as $frameworkTest) {
|
||||
$classFiles = preg_grep($frameworkTest, $classFiles, PREG_GREP_INVERT);
|
||||
}
|
||||
|
||||
$classFiles = preg_grep($this->rootTestsDir, $classFiles, PREG_GREP_INVERT);
|
||||
$classFiles = preg_grep($this->setupTestsDir, $classFiles, PREG_GREP_INVERT);
|
||||
|
||||
$this->assertEmpty($classFiles);
|
||||
}
|
||||
|
||||
public function testGetConfigFiles()
|
||||
{
|
||||
$actual = $this->model->getConfigFiles('*.xml');
|
||||
$this->assertNotEmpty($actual);
|
||||
foreach ($actual as $file) {
|
||||
$this->assertStringEndsWith('.xml', $file[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetLayoutConfigFiles()
|
||||
{
|
||||
$actual = $this->model->getLayoutConfigFiles('*.xml');
|
||||
$this->assertNotEmpty($actual);
|
||||
foreach ($actual as $file) {
|
||||
$this->assertStringEndsWith('.xml', $file[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetXmlCatalogFiles()
|
||||
{
|
||||
$actual = $this->model->getXmlCatalogFiles('*.xml');
|
||||
$this->assertNotEmpty($actual);
|
||||
foreach ($actual as $file) {
|
||||
$this->assertStringEndsWith('.xml', $file[0]);
|
||||
}
|
||||
|
||||
$actual = $this->model->getXmlCatalogFiles('*.xsd');
|
||||
$this->assertNotEmpty($actual);
|
||||
foreach ($actual as $file) {
|
||||
$this->assertStringEndsWith('.xsd', $file[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the given array of files does not contain anything in test directories
|
||||
*
|
||||
* @param array $files
|
||||
*/
|
||||
protected function assertNoTestDirs($files)
|
||||
{
|
||||
foreach ($this->moduleTests as $moduleTest) {
|
||||
$this->assertEmpty(preg_grep($moduleTest, $files));
|
||||
}
|
||||
foreach ($this->frameworkTests as $frameworkTest) {
|
||||
$this->assertEmpty(preg_grep($frameworkTest, $files));
|
||||
}
|
||||
foreach ($this->libTests as $libTest) {
|
||||
$this->assertEmpty(preg_grep($libTest, $files));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoComponentsDir Magento/Framework/App/Utility/_files/fixtures
|
||||
*/
|
||||
public function testReadLists()
|
||||
{
|
||||
$fixtureDir = str_replace('\\', '/', __DIR__) . '/_files/fixtures/';
|
||||
$expected = [
|
||||
$fixtureDir . 'language/One.php',
|
||||
$fixtureDir . 'language/registration.php',
|
||||
$fixtureDir . 'library/One.php',
|
||||
$fixtureDir . 'module/One.php',
|
||||
$fixtureDir . 'module/registration.php',
|
||||
$fixtureDir . 'theme/One.php',
|
||||
];
|
||||
$actual = $this->model->readLists(__DIR__ . '/_files/patterns/paths*.txt');
|
||||
sort($actual);
|
||||
foreach ($actual as &$file) {
|
||||
$file = str_replace('\\', '/', $file);
|
||||
}
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if underscores are allowed in extended static files in theme.
|
||||
*
|
||||
* @magentoComponentsDir Magento/Framework/App/Utility/_files/design
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testAllowUnderscoreInExtendedFiles()
|
||||
{
|
||||
$this->assertNotEmpty(
|
||||
array_filter(
|
||||
$this->model->getStaticPreProcessingFiles('*.less'),
|
||||
function ($resource) {
|
||||
return $resource[3] === 'Module_Third_Party'
|
||||
&& $resource[4] === 'css/source/_module.less';
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
.a-random-css-rule {
|
||||
background: red;
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/FrameworkUtilityTest/default', __DIR__);
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
|
||||
<title>Test Default</title>
|
||||
</theme>
|
||||
|
|
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'magento_test_lang', __DIR__);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::LIBRARY, 'magento/test', __DIR__);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_Module', __DIR__);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/Test/theme', __DIR__);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user