init
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* \Magento\Framework\DataObject\Copy\Config\Reader
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\DataObject\Copy\Config;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class ReaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\DataObject\Copy\Config\Reader
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $fileResolver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->fileResolver = $this->getMockForAbstractClass(\Magento\Framework\Config\FileResolverInterface::class);
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->model = $objectManager->create(
|
||||
\Magento\Framework\DataObject\Copy\Config\Reader::class,
|
||||
['fileResolver' => $this->fileResolver]
|
||||
);
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$this->fileResolver->expects($this->once())
|
||||
->method('get')
|
||||
->with('fieldset.xml', 'global')
|
||||
->willReturn([file_get_contents(__DIR__ . '/_files/fieldset.xml')]);
|
||||
$expected = include __DIR__ . '/_files/expectedArray.php';
|
||||
$this->assertEquals($expected, $this->model->read('global'));
|
||||
}
|
||||
|
||||
public function testMergeCompleteAndPartial()
|
||||
{
|
||||
$fileList = [
|
||||
file_get_contents(__DIR__ . '/_files/partialFieldsetFirst.xml'),
|
||||
file_get_contents(__DIR__ . '/_files/partialFieldsetSecond.xml'),
|
||||
];
|
||||
$this->fileResolver->expects($this->once())
|
||||
->method('get')
|
||||
->with('fieldset.xml', 'global')
|
||||
->willReturn($fileList);
|
||||
$expected = [
|
||||
'global' => [
|
||||
'quote_convert_item' => [
|
||||
'event_id' => ['to_order_item' => "*"],
|
||||
'event_name' => ['to_order_item' => "*"],
|
||||
'event_description' => ['to_order_item' => "complexDescription"],
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $this->model->read('global'));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
return [
|
||||
'global' => [
|
||||
'sales_convert_quote_address' => [
|
||||
'company' => ['to_order_address' => '*', 'to_customer_address' => '*'],
|
||||
'street_full' => ['to_order_address' => 'street'],
|
||||
'street' => ['to_customer_address' => '*'],
|
||||
],
|
||||
]
|
||||
];
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?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:DataObject/etc/fieldset.xsd">
|
||||
<scope id="global">
|
||||
<fieldset id="sales_convert_quote_address">
|
||||
<field name="company">
|
||||
<aspect name="to_order_address" />
|
||||
<aspect name="to_customer_address" />
|
||||
</field>
|
||||
<field name="street_full">
|
||||
<aspect name="to_order_address" targetField="street" />
|
||||
</field>
|
||||
<field name="street">
|
||||
<aspect name="to_customer_address" />
|
||||
</field>
|
||||
</fieldset>
|
||||
</scope>
|
||||
</config>
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?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:DataObject/etc/fieldset.xsd">
|
||||
<scope id="global">
|
||||
<fieldset id="quote_convert_item">
|
||||
<field name="event_id">
|
||||
</field>
|
||||
<field name="event_name">
|
||||
</field>
|
||||
<field name="event_description">
|
||||
<aspect name="to_order_item" targetField="complexDescription" />
|
||||
</field>
|
||||
</fieldset>
|
||||
</scope>
|
||||
</config>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?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:DataObject/etc/fieldset_file.xsd">
|
||||
<scope id="global">
|
||||
<fieldset id="quote_convert_item">
|
||||
<field name="event_id">
|
||||
<aspect name="to_order_item" />
|
||||
</field>
|
||||
<field name="event_name">
|
||||
<aspect name="to_order_item" />
|
||||
</field>
|
||||
<field name="event_description">
|
||||
</field>
|
||||
</fieldset>
|
||||
</scope>
|
||||
</config>
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\DataObject;
|
||||
|
||||
class CopyTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\DataObject\Copy
|
||||
*/
|
||||
protected $_service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_service = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\DataObject\Copy::class);
|
||||
}
|
||||
|
||||
public function testCopyFieldset()
|
||||
{
|
||||
$fieldset = 'sales_copy_order';
|
||||
$aspect = 'to_edit';
|
||||
$data = ['customer_email' => 'admin@example.com', 'customer_group_id' => '1'];
|
||||
$source = new \Magento\Framework\DataObject($data);
|
||||
$target = new \Magento\Framework\DataObject();
|
||||
$expectedTarget = new \Magento\Framework\DataObject($data);
|
||||
|
||||
$this->assertNull($this->_service->copyFieldsetToTarget($fieldset, $aspect, 'invalid_source', []));
|
||||
$this->assertNull($this->_service->copyFieldsetToTarget($fieldset, $aspect, [], 'invalid_target'));
|
||||
$this->assertEquals(
|
||||
$target,
|
||||
$this->_service->copyFieldsetToTarget('invalid_fieldset', $aspect, $source, $target)
|
||||
);
|
||||
$this->assertSame($target, $this->_service->copyFieldsetToTarget($fieldset, $aspect, $source, $target));
|
||||
$this->assertEquals($expectedTarget, $target);
|
||||
}
|
||||
|
||||
public function testCopyFieldsetWithExtensionAttributes()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$fieldsetConfigMock = $this->getMockBuilder(\Magento\Framework\DataObject\Copy\Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getFieldSet'])
|
||||
->getMock();
|
||||
|
||||
$service = $objectManager->create(
|
||||
\Magento\Framework\DataObject\Copy::class,
|
||||
['fieldsetConfig' => $fieldsetConfigMock]
|
||||
);
|
||||
|
||||
$data = ['firstname' => ['name' => '*'], 'lastname' => ['name' => '*'], 'test_group_code' => ['name' => '*']];
|
||||
$fieldsetConfigMock
|
||||
->expects($this->once())
|
||||
->method('getFieldSet')
|
||||
->willReturn($data);
|
||||
|
||||
$fieldset = 'customer_account';
|
||||
$aspect = 'name';
|
||||
$groupCode = 'general';
|
||||
$firstName = 'First';
|
||||
$data = [
|
||||
'email' => 'customer@example.com',
|
||||
'firstname' => $firstName,
|
||||
'lastname' => 'Last',
|
||||
// see declaration in dev/tests/integration/testsuite/Magento/Framework/Api/etc/extension_attributes.xml
|
||||
'extension_attributes' => ['test_group_code' => $groupCode]
|
||||
];
|
||||
$dataWithExtraField = array_merge($data, ['undeclared_field' => 'will be omitted']);
|
||||
|
||||
/** @var \Magento\Framework\Api\DataObjectHelper $dataObjectHelper */
|
||||
$dataObjectHelper = $objectManager->get(\Magento\Framework\Api\DataObjectHelper::class);
|
||||
/** @var \Magento\TestModuleExtensionAttributes\Model\Data\FakeCustomerFactory $customerFactory */
|
||||
$customerFactory = $objectManager->get(
|
||||
\Magento\TestModuleExtensionAttributes\Model\Data\FakeCustomerFactory::class
|
||||
);
|
||||
/** @var \Magento\TestModuleExtensionAttributes\Api\Data\CustomerInterface $source */
|
||||
$source = $customerFactory->create();
|
||||
$dataObjectHelper->populateWithArray(
|
||||
$source,
|
||||
$dataWithExtraField,
|
||||
\Magento\TestModuleExtensionAttributes\Api\Data\FakeCustomerInterface::class
|
||||
);
|
||||
/** @var \Magento\TestModuleExtensionAttributes\Api\Data\CustomerInterface $target */
|
||||
$target = $customerFactory->create();
|
||||
$target = $service->copyFieldsetToTarget($fieldset, $aspect, $source, $target);
|
||||
|
||||
$this->assertInstanceOf(\Magento\TestModuleExtensionAttributes\Api\Data\FakeCustomerInterface::class, $target);
|
||||
$this->assertNull(
|
||||
$target->getEmail(),
|
||||
"Email should not be set because it is not defined in the fieldset."
|
||||
);
|
||||
$this->assertEquals(
|
||||
$firstName,
|
||||
$target->getFirstname(),
|
||||
"First name was not copied."
|
||||
);
|
||||
$this->assertEquals(
|
||||
$groupCode,
|
||||
$target->getExtensionAttributes()->getTestGroupCode(),
|
||||
"Extension attribute was not copied."
|
||||
);
|
||||
}
|
||||
|
||||
public function testCopyFieldsetWithAbstractSimpleObject()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$fieldset = 'sales_copy_order';
|
||||
$aspect = 'to_edit';
|
||||
|
||||
$fieldsetConfigMock = $this->getMockBuilder(\Magento\Framework\DataObject\Copy\Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getFieldSet'])
|
||||
->getMock();
|
||||
|
||||
$service = $objectManager->create(
|
||||
\Magento\Framework\DataObject\Copy::class,
|
||||
['fieldsetConfig' => $fieldsetConfigMock]
|
||||
);
|
||||
|
||||
$data = ['store_label' => ['to_edit' => '*'], 'frontend_label' => ['to_edit' => '*'],
|
||||
'attribute_code' => ['to_edit' => '*'], 'note' => ['to_edit' => '*']];
|
||||
$fieldsetConfigMock
|
||||
->expects($this->any())
|
||||
->method('getFieldSet')
|
||||
->willReturn($data);
|
||||
|
||||
$source = $objectManager->get(\Magento\TestModuleExtensionAttributes\Model\Data\FakeAttributeMetadata::class);
|
||||
$source->setStoreLabel('storeLabel');
|
||||
$source->setFrontendLabel('frontendLabel');
|
||||
$source->setAttributeCode('attributeCode');
|
||||
$source->setNote('note');
|
||||
|
||||
$target = $objectManager->get(\Magento\TestModuleExtensionAttributes\Model\Data\FakeAttributeMetadata::class);
|
||||
$expectedTarget = $source;
|
||||
|
||||
$this->assertEquals(
|
||||
$target,
|
||||
$service->copyFieldsetToTarget('invalid_fieldset', $aspect, $source, $target)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedTarget,
|
||||
$service->copyFieldsetToTarget($fieldset, $aspect, $source, $target)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCopyFieldsetArrayTarget()
|
||||
{
|
||||
$fieldset = 'sales_copy_order';
|
||||
$aspect = 'to_edit';
|
||||
$data = ['customer_email' => 'admin@example.com', 'customer_group_id' => '1'];
|
||||
$source = new \Magento\Framework\DataObject($data);
|
||||
$target = [];
|
||||
$expectedTarget = $data;
|
||||
|
||||
$this->assertEquals(
|
||||
$target,
|
||||
$this->_service->copyFieldsetToTarget('invalid_fieldset', $aspect, $source, $target)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedTarget,
|
||||
$this->_service->copyFieldsetToTarget($fieldset, $aspect, $source, $target)
|
||||
);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\DataObject;
|
||||
|
||||
class IdentityValidatorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const VALID_UUID = 'fe563e12-cf9d-4faf-82cd-96e011b557b7';
|
||||
const INVALID_UUID = 'abcdef';
|
||||
|
||||
/**
|
||||
* @var IdentityValidator
|
||||
*/
|
||||
protected $identityValidator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->identityValidator = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(IdentityValidator::class);
|
||||
}
|
||||
|
||||
public function testIsValid()
|
||||
{
|
||||
$isValid = $this->identityValidator->isValid(self::VALID_UUID);
|
||||
$this->assertTrue($isValid);
|
||||
}
|
||||
|
||||
public function testIsNotValid()
|
||||
{
|
||||
$isValid = $this->identityValidator->isValid(self::INVALID_UUID);
|
||||
$this->assertFalse($isValid);
|
||||
}
|
||||
|
||||
public function testEmptyValue()
|
||||
{
|
||||
$isValid = $this->identityValidator->isValid('');
|
||||
$this->assertFalse($isValid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user