From 31e30b7b1d5b7a76f8237144a89da73ec19747ed Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 30 Nov 2016 12:12:53 -0600 Subject: [PATCH 001/132] MAGETWO-61532: Remove usages of unserialize from \Magento\Framework\Model\ResourceModel\Db\AbstractDb Refactoring and updating unit test --- .../Model/ResourceModel/AbstractResource.php | 27 ++- .../ResourceModel/AbstractResourceStub.php | 6 + .../ResourceModel/AbstractResourceTest.php | 161 ++++++++++-------- 3 files changed, 123 insertions(+), 71 deletions(-) diff --git a/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php b/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php index 3d90fc781bf3a..84ab759716e27 100644 --- a/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php +++ b/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php @@ -7,6 +7,8 @@ use Magento\Framework\DataObject; use Magento\Framework\Model\CallbackPool; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\App\ObjectManager; /** * Abstract resource model @@ -14,7 +16,12 @@ abstract class AbstractResource { /** - * Main constructor + * @var Json + */ + protected $serializer; + + /** + * Constructor */ public function __construct() { @@ -116,7 +123,7 @@ protected function _serializeField(DataObject $object, $field, $defaultValue = n if (empty($value) && $unsetEmpty) { $object->unsetData($field); } else { - $object->setData($field, serialize($value ?: $defaultValue)); + $object->setData($field, $this->getSerializer()->serialize($value ?: $defaultValue)); } return $this; @@ -135,7 +142,7 @@ protected function _unserializeField(DataObject $object, $field, $defaultValue = $value = $object->getData($field); if ($value) { - $unserializedValue = @unserialize($value); + $unserializedValue = $this->getSerializer()->unserialize($value); $value = $unserializedValue !== false || $value === 'b:0;' ? $unserializedValue : $value; } @@ -228,4 +235,18 @@ protected function _getColumnsForEntityLoad(\Magento\Framework\Model\AbstractMod } return $columns; } + + /** + * Get serializer + * + * @return Json + * @deprecated + */ + private function getSerializer() + { + if (null === $this->serializer) { + $this->serializer = ObjectManager::getInstance()->get(Json::class); + } + return $this->serializer; + } } diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceStub.php b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceStub.php index 287e12e8abdf3..3a9505a79992b 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceStub.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceStub.php @@ -8,6 +8,7 @@ use Magento\Framework\DataObject; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Serialize\Serializer\Json; class AbstractResourceStub extends AbstractResource { @@ -16,6 +17,11 @@ class AbstractResourceStub extends AbstractResource */ private $connectionAdapter; + /** + * @var Json + */ + protected $serializer; + /** * Resource initialization * diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php index 217f5c8252378..5f1b1021940e2 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php @@ -7,103 +7,131 @@ use Magento\Framework\DataObject; use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\Serialize\SerializerInterface; class AbstractResourceTest extends \PHPUnit_Framework_TestCase { + /** + * @var AbstractResourceStub + */ + private $abstractResource; + + /** + * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializerMock; + + protected function setUp() + { + $objectManager = new ObjectManager($this); + $this->serializerMock = $this->getMock(SerializerInterface::class); + $this->abstractResource = $objectManager->getObject(AbstractResourceStub::class); + $objectManager->setBackwardCompatibleProperty( + $this->abstractResource, + 'serializer', + $this->serializerMock + ); + } + /** * @param array $arguments * @param string $expectation - * @dataProvider serializableFieldsDataProvider + * @param int $numSerializeCalled + * @dataProvider serializeFieldsDataProvider */ - public function testSerializeFields(array $arguments, $expectation) + public function testSerializeFields(array $arguments, $expectation, $numSerializeCalled = 1) { /** @var DataObject $dataObject */ list($dataObject, $field, $defaultValue, $unsetEmpty) = $arguments; - - $abstractResource = new AbstractResourceStub(); - - $abstractResource->_serializeField($dataObject, $field, $defaultValue, $unsetEmpty); - - static::assertEquals($expectation, $dataObject->getDataByKey($field)); + $this->serializerMock->expects($this->exactly($numSerializeCalled)) + ->method('serialize') + ->with($dataObject->getData($field)) + ->willReturn($expectation); + $this->abstractResource->_serializeField($dataObject, $field, $defaultValue, $unsetEmpty); + $this->assertEquals($expectation, $dataObject->getData($field)); } /** * @return array */ - public function serializableFieldsDataProvider() + public function serializeFieldsDataProvider() { $dataObject = new DataObject( [ - 'object' => new \stdClass(), 'array' => ['a', 'b', 'c'], 'string' => 'i am string', 'int' => 969, - 'serialized_object' => 'O:8:"stdClass":0:{}', 'empty_value' => '', 'empty_value_with_default' => '' ] ); - return [ - [[$dataObject, 'object', null, false], serialize($dataObject->getDataByKey('object'))], - [[$dataObject, 'array', null, false], serialize($dataObject->getDataByKey('array'))], - [[$dataObject, 'string', null, false], serialize($dataObject->getDataByKey('string'))], - [[$dataObject, 'int', null, false], serialize($dataObject->getDataByKey('int'))], [ - [$dataObject, 'serialized_object', null, false], - serialize($dataObject->getDataByKey('serialized_object')) + [$dataObject, 'array', null, false], + '["a","b","c"]' + ], + [ + [$dataObject, 'string', null, false], + '"i am string"' ], - [[$dataObject, 'empty_value', null, true], null], - [[$dataObject, 'empty_value_with_default', new \stdClass(), false], 'O:8:"stdClass":0:{}'], + [ + [$dataObject, 'int', null, false], + '969' + ], + [ + [$dataObject, 'empty_value', null, true], + null, + 0 + ] ]; } /** * @param array $arguments * @param mixed $expectation - * @dataProvider unserializableFieldsDataProvider + * @dataProvider unserializeFieldsDataProvider */ public function testUnserializeFields(array $arguments, $expectation) { /** @var DataObject $dataObject */ list($dataObject, $field, $defaultValue) = $arguments; - - $abstractResource = new AbstractResourceStub(); - - $abstractResource->_unserializeField($dataObject, $field, $defaultValue); - - static::assertEquals($expectation, $dataObject->getDataByKey($field)); + $this->serializerMock->expects($this->once()) + ->method('unserialize') + ->with($dataObject->getData($field)) + ->willReturn($expectation); + $this->abstractResource->_unserializeField($dataObject, $field, $defaultValue); + $this->assertEquals($expectation, $dataObject->getData($field)); } /** * @return array */ - public function unserializableFieldsDataProvider() + public function unserializeFieldsDataProvider() { $dataObject = new DataObject( [ - 'object' => serialize(new \stdClass()), - 'array' => serialize(['a', 'b', 'c']), - 'string' => serialize('i am string'), - 'int' => serialize(969), - 'serialized_object' => serialize('O:8:"stdClass":0:{}'), - 'empty_value_with_default' => serialize(''), + 'array' => '["a","b","c"]', + 'string' => '"i am string"', + 'int' => '969', + 'empty_value_with_default' => '""', 'not_serialized_string' => 'i am string', - 'serialized_boolean_false' => serialize(false) + 'serialized_boolean_false' => 'false' ] ); - - $defaultValue = new \stdClass(); - return [ - [[$dataObject, 'object', null], unserialize($dataObject->getDataByKey('object'))], - [[$dataObject, 'array', null], unserialize($dataObject->getDataByKey('array'))], - [[$dataObject, 'string', null], unserialize($dataObject->getDataByKey('string'))], - [[$dataObject, 'int', null], unserialize($dataObject->getDataByKey('int'))], - [[$dataObject, 'serialized_object', null], unserialize($dataObject->getDataByKey('serialized_object'))], - [[$dataObject, 'empty_value_with_default', $defaultValue], $defaultValue], - [[$dataObject, 'not_serialized_string', null], 'i am string'], - [[$dataObject, 'serialized_boolean_false', null], false] + [ + [$dataObject, 'array', null], + ['a', 'b', 'c'] + ], + [ + [$dataObject, 'string', null], + 'i am string' + ], + [ + [$dataObject, 'int', null], + 969 + ] ]; } @@ -116,32 +144,31 @@ public function testCommitZeroLevel() ->disableOriginalConstructor() ->getMock(); - $abstractResource = new AbstractResourceStub(); - $abstractResource->setConnection($connection); - $abstractResource->addCommitCallback( + $this->abstractResource->setConnection($connection); + $this->abstractResource->addCommitCallback( function () use ($closureExpectation) { $closureExpectation->setData(1); } ); - $abstractResource->addCommitCallback( + $this->abstractResource->addCommitCallback( function () use ($closureExpectation) { $closureExpectation->getData(); } ); - $connection->expects(static::once()) + $connection->expects($this->once()) ->method('commit'); - $connection->expects(static::once()) + $connection->expects($this->once()) ->method('getTransactionLevel') ->willReturn(0); - $closureExpectation->expects(static::once()) + $closureExpectation->expects($this->once()) ->method('setData') ->with(1); - $closureExpectation->expects(static::once()) + $closureExpectation->expects($this->once()) ->method('getData'); - $abstractResource->commit(); + $this->abstractResource->commit(); } /** @@ -152,21 +179,20 @@ public function testCommitZeroLevelCallbackException() /** @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject $connection */ $connection = $this->getMock(AdapterInterface::class); - $abstractResource = new AbstractResourceStub(); - $abstractResource->setConnection($connection); - $abstractResource->addCommitCallback( + $this->abstractResource->setConnection($connection); + $this->abstractResource->addCommitCallback( function () { throw new \Exception(); } ); - $connection->expects(static::once()) + $connection->expects($this->once()) ->method('commit'); - $connection->expects(static::once()) + $connection->expects($this->once()) ->method('getTransactionLevel') ->willReturn(0); - $abstractResource->commit(); + $this->abstractResource->commit(); } public function testCommitNotCompletedTransaction() @@ -178,24 +204,23 @@ public function testCommitNotCompletedTransaction() ->disableOriginalConstructor() ->getMock(); - $abstractResource = new AbstractResourceStub(); - $abstractResource->setConnection($connection); - $abstractResource->addCommitCallback( + $this->abstractResource->setConnection($connection); + $this->abstractResource->addCommitCallback( function () use ($closureExpectation) { $closureExpectation->setData(1); } ); - $connection->expects(static::once()) + $connection->expects($this->once()) ->method('commit'); - $connection->expects(static::once()) + $connection->expects($this->once()) ->method('getTransactionLevel') ->willReturn(1); - $closureExpectation->expects(static::never()) + $closureExpectation->expects($this->never()) ->method('setData') ->with(1); - $abstractResource->commit(); + $this->abstractResource->commit(); } } From e9f34b0b104948b7dcfc8c32233adb73241ac5ad Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 30 Nov 2016 15:02:50 -0600 Subject: [PATCH 002/132] MAGETWO-61532: Remove usages of unserialize from \Magento\Framework\Model\ResourceModel\Db\AbstractDb Refactoring and updating unit test --- .../ResourceModel/AbstractResourceStub.php | 6 -- .../ResourceModel/AbstractResourceTest.php | 74 +++++++++++++------ 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceStub.php b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceStub.php index 3a9505a79992b..287e12e8abdf3 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceStub.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceStub.php @@ -8,7 +8,6 @@ use Magento\Framework\DataObject; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\Model\ResourceModel\AbstractResource; -use Magento\Framework\Serialize\Serializer\Json; class AbstractResourceStub extends AbstractResource { @@ -17,11 +16,6 @@ class AbstractResourceStub extends AbstractResource */ private $connectionAdapter; - /** - * @var Json - */ - protected $serializer; - /** * Resource initialization * diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php index 5f1b1021940e2..84babd047bc0a 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php @@ -37,16 +37,21 @@ protected function setUp() /** * @param array $arguments * @param string $expectation + * @param array|string|int $serializeCalledWith * @param int $numSerializeCalled * @dataProvider serializeFieldsDataProvider */ - public function testSerializeFields(array $arguments, $expectation, $numSerializeCalled = 1) - { + public function testSerializeFields( + array $arguments, + $expectation, + $serializeCalledWith, + $numSerializeCalled = 1 + ) { /** @var DataObject $dataObject */ list($dataObject, $field, $defaultValue, $unsetEmpty) = $arguments; $this->serializerMock->expects($this->exactly($numSerializeCalled)) ->method('serialize') - ->with($dataObject->getData($field)) + ->with($serializeCalledWith) ->willReturn($expectation); $this->abstractResource->_serializeField($dataObject, $field, $defaultValue, $unsetEmpty); $this->assertEquals($expectation, $dataObject->getData($field)); @@ -57,46 +62,60 @@ public function testSerializeFields(array $arguments, $expectation, $numSerializ */ public function serializeFieldsDataProvider() { + $array = ['a', 'b', 'c']; + $string = 'i am string'; + $integer = 969; + $empty = ''; $dataObject = new DataObject( [ - 'array' => ['a', 'b', 'c'], - 'string' => 'i am string', - 'int' => 969, - 'empty_value' => '', - 'empty_value_with_default' => '' + 'array' => $array, + 'string' => $string, + 'integer' => $integer, + 'empty' => $empty, + 'empty_with_default' => '' ] ); return [ [ [$dataObject, 'array', null, false], - '["a","b","c"]' + '["a","b","c"]', + $array ], [ [$dataObject, 'string', null, false], - '"i am string"' + '"i am string"', + $string ], [ - [$dataObject, 'int', null, false], - '969' + [$dataObject, 'integer', null, false], + '969', + $integer ], [ - [$dataObject, 'empty_value', null, true], + [$dataObject, 'empty', null, true], null, + $empty, 0 + ], + [ + [$dataObject, 'empty_with_default', 'default', false], + '"default"', + 'default' ] ]; } /** * @param array $arguments - * @param mixed $expectation + * @param array|string|int|boolean $expectation + * @param int $numUnserializeCalled * @dataProvider unserializeFieldsDataProvider */ - public function testUnserializeFields(array $arguments, $expectation) + public function testUnserializeFields(array $arguments, $expectation, $numUnserializeCalled = 1) { /** @var DataObject $dataObject */ list($dataObject, $field, $defaultValue) = $arguments; - $this->serializerMock->expects($this->once()) + $this->serializerMock->expects($this->exactly($numUnserializeCalled)) ->method('unserialize') ->with($dataObject->getData($field)) ->willReturn($expectation); @@ -113,10 +132,10 @@ public function unserializeFieldsDataProvider() [ 'array' => '["a","b","c"]', 'string' => '"i am string"', - 'int' => '969', - 'empty_value_with_default' => '""', + 'integer' => '969', + 'empty_with_default' => '""', 'not_serialized_string' => 'i am string', - 'serialized_boolean_false' => 'false' + 'serialized_boolean_false' => false ] ); return [ @@ -129,8 +148,21 @@ public function unserializeFieldsDataProvider() 'i am string' ], [ - [$dataObject, 'int', null], + [$dataObject, 'integer', null], 969 + ], + [ + [$dataObject, 'empty_with_default', 'default', false], + 'default' + ], + [ + [$dataObject, 'not_serialized_string', null], + 'i am string' + ], + [ + [$dataObject, 'serialized_boolean_false', null], + false, + 0 ] ]; } @@ -194,7 +226,7 @@ function () { $this->abstractResource->commit(); } - + public function testCommitNotCompletedTransaction() { /** @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject $connection */ From 9cf85c9a0c79788084543d0d2b8de5d7d34929ee Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 30 Nov 2016 15:35:57 -0600 Subject: [PATCH 003/132] MAGETWO-61532: Remove usages of unserialize from \Magento\Framework\Model\ResourceModel\Db\AbstractDb Refactoring and updating unit test --- .../Model/ResourceModel/AbstractResource.php | 8 +------ .../ResourceModel/AbstractResourceTest.php | 22 +++++++++---------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php b/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php index 84ab759716e27..460c9759bb7e4 100644 --- a/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php +++ b/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php @@ -139,13 +139,7 @@ protected function _serializeField(DataObject $object, $field, $defaultValue = n */ protected function _unserializeField(DataObject $object, $field, $defaultValue = null) { - $value = $object->getData($field); - - if ($value) { - $unserializedValue = $this->getSerializer()->unserialize($value); - $value = $unserializedValue !== false || $value === 'b:0;' ? $unserializedValue : $value; - } - + $value = $this->getSerializer()->unserialize($object->getData($field)); if (empty($value)) { $object->setData($field, $defaultValue); } else { diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php index 84babd047bc0a..0f6c46b5cdeaf 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php @@ -36,14 +36,14 @@ protected function setUp() /** * @param array $arguments - * @param string $expectation + * @param string $expected * @param array|string|int $serializeCalledWith * @param int $numSerializeCalled * @dataProvider serializeFieldsDataProvider */ public function testSerializeFields( array $arguments, - $expectation, + $expected, $serializeCalledWith, $numSerializeCalled = 1 ) { @@ -52,9 +52,9 @@ public function testSerializeFields( $this->serializerMock->expects($this->exactly($numSerializeCalled)) ->method('serialize') ->with($serializeCalledWith) - ->willReturn($expectation); + ->willReturn($expected); $this->abstractResource->_serializeField($dataObject, $field, $defaultValue, $unsetEmpty); - $this->assertEquals($expectation, $dataObject->getData($field)); + $this->assertEquals($expected, $dataObject->getData($field)); } /** @@ -107,20 +107,19 @@ public function serializeFieldsDataProvider() /** * @param array $arguments - * @param array|string|int|boolean $expectation - * @param int $numUnserializeCalled + * @param array|string|int|boolean $expected * @dataProvider unserializeFieldsDataProvider */ - public function testUnserializeFields(array $arguments, $expectation, $numUnserializeCalled = 1) + public function testUnserializeFields(array $arguments, $expected) { /** @var DataObject $dataObject */ list($dataObject, $field, $defaultValue) = $arguments; - $this->serializerMock->expects($this->exactly($numUnserializeCalled)) + $this->serializerMock->expects($this->once()) ->method('unserialize') ->with($dataObject->getData($field)) - ->willReturn($expectation); + ->willReturn($expected); $this->abstractResource->_unserializeField($dataObject, $field, $defaultValue); - $this->assertEquals($expectation, $dataObject->getData($field)); + $this->assertEquals($expected, $dataObject->getData($field)); } /** @@ -135,7 +134,7 @@ public function unserializeFieldsDataProvider() 'integer' => '969', 'empty_with_default' => '""', 'not_serialized_string' => 'i am string', - 'serialized_boolean_false' => false + 'serialized_boolean_false' => 'false' ] ); return [ @@ -162,7 +161,6 @@ public function unserializeFieldsDataProvider() [ [$dataObject, 'serialized_boolean_false', null], false, - 0 ] ]; } From ba230246f6a5e7ece520444e9331b552aff831ee Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 1 Dec 2016 13:36:08 +0200 Subject: [PATCH 004/132] MAGETWO-61652: Magento/Sales/Model/Order/Config.php and unit tests --- app/code/Magento/Sales/Model/Order/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/Config.php b/app/code/Magento/Sales/Model/Order/Config.php index 535e2975ee13d..0da26bdbbe2e3 100644 --- a/app/code/Magento/Sales/Model/Order/Config.php +++ b/app/code/Magento/Sales/Model/Order/Config.php @@ -192,7 +192,7 @@ public function getStates() */ public function getStateStatuses($state, $addLabels = true) { - $key = md5(serialize([$state, $addLabels])); + $key = md5(json_encode([$state, $addLabels])); if (isset($this->stateStatuses[$key])) { return $this->stateStatuses[$key]; } From d98edc616ac6acfbf07f4143f1b5fbbd3fde83f9 Mon Sep 17 00:00:00 2001 From: Joan He Date: Thu, 1 Dec 2016 09:11:37 -0600 Subject: [PATCH 005/132] MAGETWO-61524: Create upgrade script for sales_order_item table product_options field --- app/code/Magento/Sales/Setup/UpgradeData.php | 49 +++++++++++++++++++- app/code/Magento/Sales/etc/module.xml | 2 +- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 9580dd8a667a0..c98dbaff1ea61 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -6,6 +6,7 @@ namespace Magento\Sales\Setup; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; @@ -24,16 +25,24 @@ class UpgradeData implements UpgradeDataInterface */ protected $eavConfig; + /** + * @var Json + */ + private $serializer; + /** * @param SalesSetupFactory $salesSetupFactory * @param \Magento\Eav\Model\Config $eavConfig + * @param Json $serializer */ public function __construct( SalesSetupFactory $salesSetupFactory, - \Magento\Eav\Model\Config $eavConfig + \Magento\Eav\Model\Config $eavConfig, + Json $serializer ) { $this->salesSetupFactory = $salesSetupFactory; $this->eavConfig = $eavConfig; + $this->serializer = $serializer; } /** @@ -89,7 +98,45 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface \Magento\Eav\Model\Entity\Increment\NumericValue::class ); } + + if (version_compare($context->getVersion(), '2.0.5', '<')) { + $this->upgradeVersionTwoZeroFive($setup); + } + $this->eavConfig->clear(); $setup->endSetup(); } + + /** + * Upgrade version 2.0.5 + * + * @param ModuleDataSetupInterface $setup + */ + private function upgradeVersionTwoZeroFive(ModuleDataSetupInterface $setup) + { + $orderItemTable = $setup->getTable('sales_order_item'); + + $select = $setup->getConnection()->select()->from( + $orderItemTable, + ['item_id', 'product_options'] + )->where('product_options is not null'); + + $orderItems = $setup->getConnection()->fetchAll($select); + foreach ($orderItems as $orderItem) { + $bind = ['product_options' => $this->convertData($orderItem['product_options'])]; + $where = ['item_id = ?' => (int)$orderItem['item_id']]; + $setup->getConnection()->update($orderItemTable, $bind, $where); + } + } + + /** + * Convert serialized data to json string + * + * @param string $data + * @return string + */ + private function convertData($data) + { + return $this->serializer->serialize(unserialize($data)); + } } diff --git a/app/code/Magento/Sales/etc/module.xml b/app/code/Magento/Sales/etc/module.xml index 980395e965e08..c0bef637833a1 100644 --- a/app/code/Magento/Sales/etc/module.xml +++ b/app/code/Magento/Sales/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + From b499f91a2b314c4c411ecb5bf9da5d9f54393bcc Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Thu, 1 Dec 2016 17:53:52 -0600 Subject: [PATCH 006/132] MAGETWO-61526: Create upgrade script for quote_payment table additional_information field Refactoring upgrade script --- app/code/Magento/Sales/Setup/UpgradeData.php | 155 +++++++++++-------- 1 file changed, 88 insertions(+), 67 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index c98dbaff1ea61..0ccc703734d67 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -3,13 +3,13 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Sales\Setup; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; +use Magento\Eav\Model\Config; class UpgradeData implements UpgradeDataInterface { @@ -18,12 +18,12 @@ class UpgradeData implements UpgradeDataInterface * * @var SalesSetupFactory */ - protected $salesSetupFactory; + private $salesSetupFactory; /** - * @var \Magento\Eav\Model\Config + * @var Config */ - protected $eavConfig; + private $eavConfig; /** * @var Json @@ -31,13 +31,15 @@ class UpgradeData implements UpgradeDataInterface private $serializer; /** + * Constructor + * * @param SalesSetupFactory $salesSetupFactory - * @param \Magento\Eav\Model\Config $eavConfig + * @param Config $eavConfig * @param Json $serializer */ public function __construct( SalesSetupFactory $salesSetupFactory, - \Magento\Eav\Model\Config $eavConfig, + Config $eavConfig, Json $serializer ) { $this->salesSetupFactory = $salesSetupFactory; @@ -47,90 +49,109 @@ public function __construct( /** * {@inheritdoc} - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); - - /** @var SalesSetup $salesSetup */ $salesSetup = $this->salesSetupFactory->create(['setup' => $setup]); - if (version_compare($context->getVersion(), '2.0.1', '<')) { - $salesSetup->updateEntityType( - \Magento\Sales\Model\Order::ENTITY, - 'entity_model', - \Magento\Sales\Model\ResourceModel\Order::class - ); - $salesSetup->updateEntityType( - \Magento\Sales\Model\Order::ENTITY, - 'increment_model', - \Magento\Eav\Model\Entity\Increment\NumericValue::class - ); - $salesSetup->updateEntityType( - 'invoice', - 'entity_model', - \Magento\Sales\Model\ResourceModel\Order::class - ); - $salesSetup->updateEntityType( - 'invoice', - 'increment_model', - \Magento\Eav\Model\Entity\Increment\NumericValue::class - ); - $salesSetup->updateEntityType( - 'creditmemo', - 'entity_model', - \Magento\Sales\Model\ResourceModel\Order\Creditmemo::class - ); - $salesSetup->updateEntityType( - 'creditmemo', - 'increment_model', - \Magento\Eav\Model\Entity\Increment\NumericValue::class - ); - $salesSetup->updateEntityType( - 'shipment', - 'entity_model', - \Magento\Sales\Model\ResourceModel\Order\Shipment::class - ); - $salesSetup->updateEntityType( - 'shipment', - 'increment_model', - \Magento\Eav\Model\Entity\Increment\NumericValue::class - ); + $this->upgradeToTwoZeroOne($salesSetup); } - if (version_compare($context->getVersion(), '2.0.5', '<')) { - $this->upgradeVersionTwoZeroFive($setup); + $this->upgradeToVersionTwoZeroFive($setup); } - $this->eavConfig->clear(); $setup->endSetup(); } /** - * Upgrade version 2.0.5 + * Upgrade to version 2.0.1 * - * @param ModuleDataSetupInterface $setup + * @param SalesSetup $setup + * @return void */ - private function upgradeVersionTwoZeroFive(ModuleDataSetupInterface $setup) + private function upgradeToTwoZeroOne(SalesSetup $setup) { - $orderItemTable = $setup->getTable('sales_order_item'); + $setup->updateEntityType( + \Magento\Sales\Model\Order::ENTITY, + 'entity_model', + \Magento\Sales\Model\ResourceModel\Order::class + ); + $setup->updateEntityType( + \Magento\Sales\Model\Order::ENTITY, + 'increment_model', + \Magento\Eav\Model\Entity\Increment\NumericValue::class + ); + $setup->updateEntityType( + 'invoice', + 'entity_model', + \Magento\Sales\Model\ResourceModel\Order::class + ); + $setup->updateEntityType( + 'invoice', + 'increment_model', + \Magento\Eav\Model\Entity\Increment\NumericValue::class + ); + $setup->updateEntityType( + 'creditmemo', + 'entity_model', + \Magento\Sales\Model\ResourceModel\Order\Creditmemo::class + ); + $setup->updateEntityType( + 'creditmemo', + 'increment_model', + \Magento\Eav\Model\Entity\Increment\NumericValue::class + ); + $setup->updateEntityType( + 'shipment', + 'entity_model', + \Magento\Sales\Model\ResourceModel\Order\Shipment::class + ); + $setup->updateEntityType( + 'shipment', + 'increment_model', + \Magento\Eav\Model\Entity\Increment\NumericValue::class + ); + } - $select = $setup->getConnection()->select()->from( - $orderItemTable, - ['item_id', 'product_options'] - )->where('product_options is not null'); + /** + * Upgrade to version 2.0.5 + * + * @param ModuleDataSetupInterface $setup + * @return void + */ + private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) + { + $this->changeFieldFormat($setup, 'sales_order_item', 'item_id', 'product_options'); + $this->changeFieldFormat($setup, 'quote_payment', 'payment_id', 'additional_information'); + } - $orderItems = $setup->getConnection()->fetchAll($select); - foreach ($orderItems as $orderItem) { - $bind = ['product_options' => $this->convertData($orderItem['product_options'])]; - $where = ['item_id = ?' => (int)$orderItem['item_id']]; - $setup->getConnection()->update($orderItemTable, $bind, $where); + /** + * Change format of the field for the table + * + * @param ModuleDataSetupInterface $setup + * @param string $tableName + * @param string $identifier + * @param string $field + * @return void + */ + private function changeFieldFormat(ModuleDataSetupInterface $setup, $tableName, $identifier, $field) + { + $table = $setup->getTable($tableName); + $select = $setup->getConnection() + ->select() + ->from($table, [$identifier, $field]) + ->where($field . ' IS NOT NULL'); + $items = $setup->getConnection()->fetchAll($select); + foreach ($items as $item) { + $bind = [$field => $this->convertData($item[$field])]; + $where = [$identifier . ' = ?' => (int) $item[$identifier]]; + $setup->getConnection()->update($table, $bind, $where); } } /** - * Convert serialized data to json string + * Convert from serialized to json format * * @param string $data * @return string From 511d207e3021e450cd2b9fecd0d810d4cdfc9db8 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Fri, 2 Dec 2016 10:00:44 -0600 Subject: [PATCH 007/132] MAGETWO-61532: Remove usages of unserialize from \Magento\Framework\Model\ResourceModel\Db\AbstractDb Refactoring --- .../ResourceModel/Entity/Attribute/Set.php | 33 +++++++------------ .../Model/ResourceModel/AbstractResource.php | 28 +++++----------- .../ResourceModel/AbstractResourceTest.php | 16 ++++----- 3 files changed, 29 insertions(+), 48 deletions(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php index b3e7bf2bc3925..94f5558a0110b 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php @@ -5,7 +5,8 @@ */ namespace Magento\Eav\Model\ResourceModel\Entity\Attribute; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\App\ObjectManager; class Set extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { @@ -25,26 +26,31 @@ class Set extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb protected $eavConfig; /** - * @var SerializerInterface + * @var Json */ private $serializer; /** + * Constructor + * * @param \Magento\Framework\Model\ResourceModel\Db\Context $context * @param GroupFactory $attrGroupFactory * @param \Magento\Eav\Model\Config $eavConfig - * @param string $connectionName + * @param string|null $connectionName + * @param Json|null $serializer * @codeCoverageIgnore */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Eav\Model\ResourceModel\Entity\Attribute\GroupFactory $attrGroupFactory, \Magento\Eav\Model\Config $eavConfig, - $connectionName = null + $connectionName = null, + Json $serializer = null ) { parent::__construct($context, $connectionName); $this->_attrGroupFactory = $attrGroupFactory; $this->eavConfig = $eavConfig; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** @@ -154,7 +160,7 @@ public function getSetInfo(array $attributeIds, $setId = null) $cacheKey = self::ATTRIBUTES_CACHE_ID . $setId; if ($this->eavConfig->isCacheEnabled() && ($cache = $this->eavConfig->getCache()->load($cacheKey))) { - $setInfoData = $this->getSerializer()->unserialize($cache); + $setInfoData = $this->serializer->unserialize($cache); } else { $attributeSetData = $this->fetchAttributeSetData($setId); @@ -170,7 +176,7 @@ public function getSetInfo(array $attributeIds, $setId = null) if ($this->eavConfig->isCacheEnabled()) { $this->eavConfig->getCache()->save( - $this->getSerializer()->serialize($setInfoData), + $this->serializer->serialize($setInfoData), $cacheKey, [ \Magento\Eav\Model\Cache\Type::CACHE_TAG, @@ -235,19 +241,4 @@ protected function fetchAttributeSetData($setId = null) } return $connection->fetchAll($select, $bind); } - - /** - * Get serializer - * - * @return SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (null === $this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(SerializerInterface::class); - } - return $this->serializer; - } } diff --git a/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php b/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php index 460c9759bb7e4..f82c461d3139b 100644 --- a/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php +++ b/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php @@ -18,13 +18,17 @@ abstract class AbstractResource /** * @var Json */ - protected $serializer; + private $serializer; /** * Constructor + * + * @param Json|null $serializer */ - public function __construct() - { + public function __construct( + Json $serializer = null + ) { + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); /** * Please override this one instead of overriding real __construct constructor */ @@ -123,7 +127,7 @@ protected function _serializeField(DataObject $object, $field, $defaultValue = n if (empty($value) && $unsetEmpty) { $object->unsetData($field); } else { - $object->setData($field, $this->getSerializer()->serialize($value ?: $defaultValue)); + $object->setData($field, $this->serializer->serialize($value ?: $defaultValue)); } return $this; @@ -139,7 +143,7 @@ protected function _serializeField(DataObject $object, $field, $defaultValue = n */ protected function _unserializeField(DataObject $object, $field, $defaultValue = null) { - $value = $this->getSerializer()->unserialize($object->getData($field)); + $value = $this->serializer->unserialize($object->getData($field)); if (empty($value)) { $object->setData($field, $defaultValue); } else { @@ -229,18 +233,4 @@ protected function _getColumnsForEntityLoad(\Magento\Framework\Model\AbstractMod } return $columns; } - - /** - * Get serializer - * - * @return Json - * @deprecated - */ - private function getSerializer() - { - if (null === $this->serializer) { - $this->serializer = ObjectManager::getInstance()->get(Json::class); - } - return $this->serializer; - } } diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php index 0f6c46b5cdeaf..575c8e2181206 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php @@ -8,7 +8,7 @@ use Magento\Framework\DataObject; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; class AbstractResourceTest extends \PHPUnit_Framework_TestCase { @@ -18,19 +18,19 @@ class AbstractResourceTest extends \PHPUnit_Framework_TestCase private $abstractResource; /** - * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var Json|\PHPUnit_Framework_MockObject_MockObject */ private $serializerMock; protected function setUp() { $objectManager = new ObjectManager($this); - $this->serializerMock = $this->getMock(SerializerInterface::class); - $this->abstractResource = $objectManager->getObject(AbstractResourceStub::class); - $objectManager->setBackwardCompatibleProperty( - $this->abstractResource, - 'serializer', - $this->serializerMock + $this->serializerMock = $this->getMock(Json::class); + $this->abstractResource = $objectManager->getObject( + AbstractResourceStub::class, + [ + 'serializer' => $this->serializerMock + ] ); } From 0c2fe68448c03a170b409bec4f14688608c7d2bc Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Fri, 2 Dec 2016 10:13:04 -0600 Subject: [PATCH 008/132] MAGETWO-61532: Remove usages of unserialize from \Magento\Framework\Model\ResourceModel\Db\AbstractDb Refactoring --- .../ResourceModel/Entity/Attribute/Set.php | 6 +++--- .../ResourceModel/Entity/Attribute/SetTest.php | 11 +++++------ .../Model/ResourceModel/Db/AbstractDb.php | 17 +++++++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php index 94f5558a0110b..03c53fb315d5e 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php @@ -11,7 +11,7 @@ class Set extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { /** - * EAV cache ids + * EAV cache id */ const ATTRIBUTES_CACHE_ID = 'EAV_ENTITY_ATTRIBUTES_BY_SET_ID'; @@ -47,10 +47,10 @@ public function __construct( $connectionName = null, Json $serializer = null ) { - parent::__construct($context, $connectionName); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); + parent::__construct($context, $connectionName, $serializer); $this->_attrGroupFactory = $attrGroupFactory; $this->eavConfig = $eavConfig; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** diff --git a/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/SetTest.php b/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/SetTest.php index e00a8ee97648c..6fdc9ece87f85 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/SetTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/SetTest.php @@ -7,7 +7,7 @@ use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -50,7 +50,7 @@ class SetTest extends \PHPUnit_Framework_TestCase protected $relationProcessor; /** - * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var Json|\PHPUnit_Framework_MockObject_MockObject */ private $serializerMock; @@ -88,7 +88,7 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $this->serializerMock = $this->getMock(SerializerInterface::class); + $this->serializerMock = $this->getMock(Json::class); $attributeGroupFactoryMock = $this->getMock( \Magento\Eav\Model\ResourceModel\Entity\Attribute\GroupFactory::class, @@ -103,12 +103,11 @@ protected function setUp() [ 'context' => $contextMock, 'attrGroupFactory' => $attributeGroupFactoryMock, - 'eavConfig' => $this->eavConfigMock + 'eavConfig' => $this->eavConfigMock, + 'serializer' => $this->serializerMock ] ); - $objectManager->setBackwardCompatibleProperty($this->model, 'serializer', $this->serializerMock); - $this->typeMock = $this->getMock(\Magento\Eav\Model\Entity\Type::class, [], [], '', false); $this->objectMock = $this->getMock( \Magento\Framework\Model\AbstractModel::class, diff --git a/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php b/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php index 4cd88e356e9ca..867e59dd93cc8 100644 --- a/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php +++ b/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php @@ -3,7 +3,6 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Framework\Model\ResourceModel\Db; use Magento\Framework\App\ResourceConnection; @@ -12,9 +11,11 @@ use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\DB\Adapter\DuplicateException; use Magento\Framework\Phrase; +use Magento\Framework\Serialize\Serializer\Json; /** - * Abstract resource model class + * Abstract resource model + * * @SuppressWarnings(PHPMD.NumberOfChildren) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @@ -133,20 +134,24 @@ abstract class AbstractDb extends AbstractResource protected $objectRelationProcessor; /** - * Class constructor + * Constructor * * @param \Magento\Framework\Model\ResourceModel\Db\Context $context * @param string $connectionName + * @param Json|null $serializer */ - public function __construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, $connectionName = null) - { + public function __construct( + \Magento\Framework\Model\ResourceModel\Db\Context $context, + $connectionName = null, + Json $serializer = null + ) { $this->transactionManager = $context->getTransactionManager(); $this->_resources = $context->getResources(); $this->objectRelationProcessor = $context->getObjectRelationProcessor(); if ($connectionName !== null) { $this->connectionName = $connectionName; } - parent::__construct(); + parent::__construct($serializer); } /** From be86ac52a2a4b32f0f5eb0384ab01da4b3770bd3 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Fri, 2 Dec 2016 10:24:48 -0600 Subject: [PATCH 009/132] MAGETWO-61526: Create upgrade script for quote_payment table additional_information field Refactoring upgrade script --- app/code/Magento/Sales/Setup/UpgradeData.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 0ccc703734d67..09eec6840943f 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -5,11 +5,9 @@ */ namespace Magento\Sales\Setup; -use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Eav\Model\Config; class UpgradeData implements UpgradeDataInterface { @@ -21,12 +19,12 @@ class UpgradeData implements UpgradeDataInterface private $salesSetupFactory; /** - * @var Config + * @var \Magento\Eav\Model\Config */ private $eavConfig; /** - * @var Json + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -34,13 +32,13 @@ class UpgradeData implements UpgradeDataInterface * Constructor * * @param SalesSetupFactory $salesSetupFactory - * @param Config $eavConfig - * @param Json $serializer + * @param \Magento\Eav\Model\Config $eavConfig + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( SalesSetupFactory $salesSetupFactory, - Config $eavConfig, - Json $serializer + \Magento\Eav\Model\Config $eavConfig, + \Magento\Framework\Serialize\Serializer\Json $serializer ) { $this->salesSetupFactory = $salesSetupFactory; $this->eavConfig = $eavConfig; From 7da3d3b28c8909876389e97383b8481b07c55c27 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Fri, 2 Dec 2016 10:41:23 -0600 Subject: [PATCH 010/132] MAGETWO-61532: Remove usages of unserialize from \Magento\Framework\Model\ResourceModel\Db\AbstractDb Refactoring --- .../ResourceModel/Entity/Attribute/Set.php | 16 ++--------- .../Entity/Attribute/SetTest.php | 5 ++-- .../Model/ResourceModel/AbstractResource.php | 28 +++++++++++++------ .../Model/ResourceModel/Db/AbstractDb.php | 7 ++--- .../ResourceModel/AbstractResourceTest.php | 10 +++---- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php index 03c53fb315d5e..734648015a5d9 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php @@ -5,9 +5,6 @@ */ namespace Magento\Eav\Model\ResourceModel\Entity\Attribute; -use Magento\Framework\Serialize\Serializer\Json; -use Magento\Framework\App\ObjectManager; - class Set extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { /** @@ -25,11 +22,6 @@ class Set extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb */ protected $eavConfig; - /** - * @var Json - */ - private $serializer; - /** * Constructor * @@ -37,18 +29,14 @@ class Set extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb * @param GroupFactory $attrGroupFactory * @param \Magento\Eav\Model\Config $eavConfig * @param string|null $connectionName - * @param Json|null $serializer - * @codeCoverageIgnore */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Eav\Model\ResourceModel\Entity\Attribute\GroupFactory $attrGroupFactory, \Magento\Eav\Model\Config $eavConfig, - $connectionName = null, - Json $serializer = null + $connectionName = null ) { - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); - parent::__construct($context, $connectionName, $serializer); + parent::__construct($context, $connectionName); $this->_attrGroupFactory = $attrGroupFactory; $this->eavConfig = $eavConfig; } diff --git a/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/SetTest.php b/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/SetTest.php index 6fdc9ece87f85..8a588a6cbe76c 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/SetTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/SetTest.php @@ -103,11 +103,12 @@ protected function setUp() [ 'context' => $contextMock, 'attrGroupFactory' => $attributeGroupFactoryMock, - 'eavConfig' => $this->eavConfigMock, - 'serializer' => $this->serializerMock + 'eavConfig' => $this->eavConfigMock ] ); + $objectManager->setBackwardCompatibleProperty($this->model, 'serializer', $this->serializerMock); + $this->typeMock = $this->getMock(\Magento\Eav\Model\Entity\Type::class, [], [], '', false); $this->objectMock = $this->getMock( \Magento\Framework\Model\AbstractModel::class, diff --git a/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php b/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php index f82c461d3139b..c87a07eaab37e 100644 --- a/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php +++ b/lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php @@ -18,17 +18,13 @@ abstract class AbstractResource /** * @var Json */ - private $serializer; + protected $serializer; /** * Constructor - * - * @param Json|null $serializer */ - public function __construct( - Json $serializer = null - ) { - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); + public function __construct() + { /** * Please override this one instead of overriding real __construct constructor */ @@ -127,7 +123,7 @@ protected function _serializeField(DataObject $object, $field, $defaultValue = n if (empty($value) && $unsetEmpty) { $object->unsetData($field); } else { - $object->setData($field, $this->serializer->serialize($value ?: $defaultValue)); + $object->setData($field, $this->getSerializer()->serialize($value ?: $defaultValue)); } return $this; @@ -143,7 +139,7 @@ protected function _serializeField(DataObject $object, $field, $defaultValue = n */ protected function _unserializeField(DataObject $object, $field, $defaultValue = null) { - $value = $this->serializer->unserialize($object->getData($field)); + $value = $this->getSerializer()->unserialize($object->getData($field)); if (empty($value)) { $object->setData($field, $defaultValue); } else { @@ -233,4 +229,18 @@ protected function _getColumnsForEntityLoad(\Magento\Framework\Model\AbstractMod } return $columns; } + + /** + * Get serializer + * + * @return Json + * @deprecated + */ + protected function getSerializer() + { + if (null === $this->serializer) { + $this->serializer = ObjectManager::getInstance()->get(Json::class); + } + return $this->serializer; + } } diff --git a/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php b/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php index 867e59dd93cc8..12e2da6d4ebd4 100644 --- a/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php +++ b/lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php @@ -11,7 +11,6 @@ use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\DB\Adapter\DuplicateException; use Magento\Framework\Phrase; -use Magento\Framework\Serialize\Serializer\Json; /** * Abstract resource model @@ -138,12 +137,10 @@ abstract class AbstractDb extends AbstractResource * * @param \Magento\Framework\Model\ResourceModel\Db\Context $context * @param string $connectionName - * @param Json|null $serializer */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, - $connectionName = null, - Json $serializer = null + $connectionName = null ) { $this->transactionManager = $context->getTransactionManager(); $this->_resources = $context->getResources(); @@ -151,7 +148,7 @@ public function __construct( if ($connectionName !== null) { $this->connectionName = $connectionName; } - parent::__construct($serializer); + parent::__construct(); } /** diff --git a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php index 575c8e2181206..85696221beeaf 100644 --- a/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php +++ b/lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php @@ -26,11 +26,11 @@ protected function setUp() { $objectManager = new ObjectManager($this); $this->serializerMock = $this->getMock(Json::class); - $this->abstractResource = $objectManager->getObject( - AbstractResourceStub::class, - [ - 'serializer' => $this->serializerMock - ] + $this->abstractResource = $objectManager->getObject(AbstractResourceStub::class); + $objectManager->setBackwardCompatibleProperty( + $this->abstractResource, + 'serializer', + $this->serializerMock ); } From e5ac4e40721b944800b15698df5bae4c30195722 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Fri, 2 Dec 2016 10:49:55 -0600 Subject: [PATCH 011/132] MAGETWO-61532: Remove usages of unserialize from \Magento\Framework\Model\ResourceModel\Db\AbstractDb Refactoring --- .../Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php index 734648015a5d9..9b3a4ef42fc5e 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Set.php @@ -148,7 +148,7 @@ public function getSetInfo(array $attributeIds, $setId = null) $cacheKey = self::ATTRIBUTES_CACHE_ID . $setId; if ($this->eavConfig->isCacheEnabled() && ($cache = $this->eavConfig->getCache()->load($cacheKey))) { - $setInfoData = $this->serializer->unserialize($cache); + $setInfoData = $this->getSerializer()->unserialize($cache); } else { $attributeSetData = $this->fetchAttributeSetData($setId); @@ -164,7 +164,7 @@ public function getSetInfo(array $attributeIds, $setId = null) if ($this->eavConfig->isCacheEnabled()) { $this->eavConfig->getCache()->save( - $this->serializer->serialize($setInfoData), + $this->getSerializer()->serialize($setInfoData), $cacheKey, [ \Magento\Eav\Model\Cache\Type::CACHE_TAG, From 32d079c19a1c0382e8a420d69b3a6bf775e5a5b9 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Fri, 2 Dec 2016 14:04:55 +0200 Subject: [PATCH 012/132] MAGETWO-61651: Remove uses of serialize and unserialize in Magento/Sales/Model/AdminOrder/Create.php --- .../Catalog/Helper/Product/Configuration.php | 14 ++++- .../Magento/Sales/Model/AdminOrder/Create.php | 17 +++++- ...adable_product_with_additional_options.php | 61 +++++++++++++++++++ .../Sales/Model/AdminOrder/CreateTest.php | 56 +++++++++++++++++ 4 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Downloadable/_files/order_with_downloadable_product_with_additional_options.php diff --git a/app/code/Magento/Catalog/Helper/Product/Configuration.php b/app/code/Magento/Catalog/Helper/Product/Configuration.php index eb9e84afa8402..c8b720d0f5ced 100644 --- a/app/code/Magento/Catalog/Helper/Product/Configuration.php +++ b/app/code/Magento/Catalog/Helper/Product/Configuration.php @@ -5,6 +5,8 @@ */ namespace Magento\Catalog\Helper\Product; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Catalog\Helper\Product\Configuration\ConfigurationInterface; use Magento\Framework\App\Helper\AbstractHelper; @@ -36,21 +38,29 @@ class Configuration extends AbstractHelper implements ConfigurationInterface */ protected $string; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory * @param \Magento\Framework\Filter\FilterManager $filter * @param \Magento\Framework\Stdlib\StringUtils $string + * @param SerializerInterface $serializer */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, \Magento\Framework\Filter\FilterManager $filter, - \Magento\Framework\Stdlib\StringUtils $string + \Magento\Framework\Stdlib\StringUtils $string, + SerializerInterface $serializer = null ) { $this->_productOptionFactory = $productOptionFactory; $this->filter = $filter; $this->string = $string; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct($context); } @@ -105,7 +115,7 @@ public function getCustomOptions(\Magento\Catalog\Model\Product\Configuration\It $addOptions = $item->getOptionByCode('additional_options'); if ($addOptions) { - $options = array_merge($options, unserialize($addOptions->getValue())); + $options = array_merge($options, $this->serializer->unserialize($addOptions->getValue())); } return $options; diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 3715c02357a96..a8a92ca1f268e 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -8,6 +8,7 @@ namespace Magento\Sales\Model\AdminOrder; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Customer\Api\AddressMetadataInterface; use Magento\Customer\Model\Metadata\Form as CustomerForm; use Magento\Quote\Model\Quote\Item; @@ -224,6 +225,11 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ */ protected $quoteFactory; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\ObjectManagerInterface $objectManager * @param \Magento\Framework\Event\ManagerInterface $eventManager @@ -252,6 +258,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper * @param \Magento\Sales\Api\OrderManagementInterface $orderManagement * @param \Magento\Quote\Model\QuoteFactory $quoteFactory + * @param SerializerInterface $serializer * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -283,6 +290,7 @@ public function __construct( \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Sales\Api\OrderManagementInterface $orderManagement, \Magento\Quote\Model\QuoteFactory $quoteFactory, + SerializerInterface $serializer = null, array $data = [] ) { $this->_objectManager = $objectManager; @@ -312,6 +320,7 @@ public function __construct( $this->dataObjectHelper = $dataObjectHelper; $this->orderManagement = $orderManagement; $this->quoteFactory = $quoteFactory; + $this->serializer = $serializer ?: $objectManager->get(SerializerInterface::class); parent::__construct($data); } @@ -632,7 +641,7 @@ public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $q [ 'product' => $item->getProduct(), 'code' => 'additional_options', - 'value' => serialize($additionalOptions) + 'value' => $this->serializer->serialize($additionalOptions) ] ) ); @@ -1166,6 +1175,8 @@ protected function _parseOptions(\Magento\Quote\Model\Quote\Item $item, $additio * @param \Magento\Quote\Model\Quote\Item $item * @param array $options * @return $this + * + * @deprecated */ protected function _assignOptionsToItem(\Magento\Quote\Model\Quote\Item $item, $options) { @@ -1209,7 +1220,7 @@ protected function _assignOptionsToItem(\Magento\Quote\Model\Quote\Item $item, $ [ 'product' => $item->getProduct(), 'code' => 'additional_options', - 'value' => serialize($options['additional_options']) + 'value' => $this->serializer->serialize($options['additional_options']) ] ) ); @@ -1844,7 +1855,7 @@ protected function _prepareQuoteItems() } $addOptions = $item->getOptionByCode('additional_options'); if ($addOptions) { - $options['additional_options'] = unserialize($addOptions->getValue()); + $options['additional_options'] = $this->serializer->unserialize($addOptions->getValue()); } $item->setProductOrderOptions($options); } diff --git a/dev/tests/integration/testsuite/Magento/Downloadable/_files/order_with_downloadable_product_with_additional_options.php b/dev/tests/integration/testsuite/Magento/Downloadable/_files/order_with_downloadable_product_with_additional_options.php new file mode 100644 index 0000000000000..46caf347a098b --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Downloadable/_files/order_with_downloadable_product_with_additional_options.php @@ -0,0 +1,61 @@ +create( + \Magento\Sales\Model\Order\Address::class, + [ + 'data' => [ + 'firstname' => 'guest', + 'lastname' => 'guest', + 'email' => 'customer@example.com', + 'street' => 'street', + 'city' => 'Los Angeles', + 'region' => 'CA', + 'postcode' => '1', + 'country_id' => 'US', + 'telephone' => '1', + ] + ] +); +$billingAddress->setAddressType('billing'); + +$payment = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Sales\Model\Order\Payment::class); +$payment->setMethod('checkmo'); + +$orderItem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Sales\Model\Order\Item::class); +$orderItem->setProductId( + 1 +)->setProductType( + \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE +)->setBasePrice( + 100 +)->setQtyOrdered( + 1 +); +$orderItem->setProductOptions(['additional_options' => ['additional_option_key' => 'additional_option_value']]); + +$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class); +$order->setCustomerEmail('mail@to.co') + ->addItem( + $orderItem +)->setIncrementId( + '100000001' +)->setCustomerIsGuest( + true +)->setStoreId( + 1 +)->setEmailSent( + 1 +)->setBillingAddress( + $billingAddress +)->setPayment( + $payment +); +$order->save(); diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index f8ca1929df91e..0714423cff4b1 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -52,6 +52,62 @@ public function testInitFromOrderShippingAddressSameAsBillingWhenEmpty() $this->assertNull($order->getShippingAddress()); } + /** + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php + * @magentoDataFixture Magento/Downloadable/_files/order_with_downloadable_product_with_additional_options.php + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testInitFromOrderAndCreateOrderFromQuoteWithAdditionalOptions() + { + /** @var $serializer \Magento\Framework\Serialize\SerializerInterface */ + $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\SerializerInterface::class); + + /** @var $order \Magento\Sales\Model\Order */ + $order = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class); + $order->loadByIncrementId('100000001'); + + /** @var $orderCreate \Magento\Sales\Model\AdminOrder\Create */ + $orderCreate = $this->_model->initFromOrder($order); + + $quoteItems = $orderCreate->getQuote()->getItemsCollection(); + + $this->assertEquals(1, $quoteItems->count()); + + $quoteItem = $quoteItems->getFirstItem(); + $quoteItemOptions = $quoteItem->getOptionsByCode(); + + $this->assertEquals( + $serializer->serialize(['additional_option_key' => 'additional_option_value']), + $quoteItemOptions['additional_options']->getValue() + ); + + $session = Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session\Quote::class); + $session->setCustomerId(1); + + $customer = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Customer::class); + $customer->load(1)->setDefaultBilling(null)->setDefaultShipping(null)->save(); + + $rate = Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote\Address\Rate::class); + $rate->setCode('freeshipping_freeshipping'); + + $this->_model->getQuote()->getShippingAddress()->addShippingRate($rate); + $this->_model->setShippingAsBilling(0); + $this->_model->setPaymentData(['method' => 'checkmo']); + + $newOrder = $this->_model->createOrder(); + $newOrderItems = $newOrder->getItemsCollection(); + + $this->assertEquals(1, $newOrderItems->count()); + + $newOrderItem = $newOrderItems->getFirstItem(); + + $this->assertEquals( + ['additional_option_key' => 'additional_option_value'], + $newOrderItem->getProductOptionByCode('additional_options') + ); + } /** * @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php * @magentoDataFixture Magento/Downloadable/_files/order_with_downloadable_product.php From b3085b843adad127e0f1462996c372a4e1c84664 Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Fri, 2 Dec 2016 20:33:48 +0200 Subject: [PATCH 013/132] MAGETWO-61653: Magento/Sales/Model/Order/CreditmemoFactory.php, remove \Magento\Framework\Unserialize\Unserialize and fix unit tests --- .../Sales/Model/Order/CreditmemoFactory.php | 12 +-- .../Model/Order/CreditmemoFactoryTest.php | 100 ++++++++++++++++++ .../order_with_dummy_item_and_invoiced.php | 73 +++++++++++++ 3 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Sales/Model/Order/CreditmemoFactoryTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/order_with_dummy_item_and_invoiced.php diff --git a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php index ff687074e4a66..1a78bb4f27b09 100644 --- a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php +++ b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php @@ -262,7 +262,7 @@ protected function initData($creditmemo, $data) /** * @param \Magento\Sales\Api\Data\OrderItemInterface $orderItem - * @param array $qtys + * @param int $parentQty * @return int */ private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterface $orderItem, $parentQty) @@ -270,7 +270,7 @@ private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterf $qty = $parentQty; $productOptions = $orderItem->getProductOptions(); if (isset($productOptions['bundle_selection_attributes'])) { - $bundleSelectionAttributes = $this->getUnserialize() + $bundleSelectionAttributes = $this->getSerializer() ->unserialize($productOptions['bundle_selection_attributes']); if ($bundleSelectionAttributes) { $qty = $bundleSelectionAttributes['qty'] * $parentQty; @@ -280,16 +280,16 @@ private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterf } /** - * Get Unserialize + * Get instance of Serializer. * - * @return \Magento\Framework\Unserialize\Unserialize + * @return \Magento\Framework\Serialize\SerializerInterface * @deprecated */ - private function getUnserialize() + private function getSerializer() { if (!$this->unserialize) { $this->unserialize = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Unserialize\Unserialize::class); + ->get(\Magento\Framework\Serialize\SerializerInterface::class); } return $this->unserialize; } diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/CreditmemoFactoryTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/CreditmemoFactoryTest.php new file mode 100644 index 0000000000000..64de21811dddf --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/CreditmemoFactoryTest.php @@ -0,0 +1,100 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + } + + /** + * @magentoDataFixture Magento/Sales/_files/order_with_dummy_item_and_invoiced.php + * @dataProvider createByOrderDataProvider + * @param array $creditmemoData + * @param int $expectedQty + */ + public function testCreateByOrder(array $creditmemoData, $expectedQty) + { + /** @var \Magento\Sales\Model\Order $order */ + $order = $this->objectManager->create(\Magento\Sales\Model\Order::class); + $order->loadByIncrementId('100000001'); + /** @var \Magento\Sales\Model\Order\CreditmemoFactory $creditmemoFactory */ + $creditmemoFactory = $this->objectManager->create(\Magento\Sales\Model\Order\CreditmemoFactory::class); + $creditmemoData = $this->prepareCreditMemoData($order, $creditmemoData); + $creditmemo = $creditmemoFactory->createByOrder($order, $creditmemoData); + $this->assertEquals($expectedQty, $creditmemo->getTotalQty(), 'Creditmemo has wrong total qty.'); + } + + /** + * Prepare Creditmemo data. + * + * @param \Magento\Sales\Model\Order $order + * @param array $creditmemoData + * @return array + */ + private function prepareCreditMemoData(\Magento\Sales\Model\Order $order, array $creditmemoData) + { + $result = []; + $orderItems = $order->getAllItems(); + foreach ($creditmemoData['qtys'] as $key => $item) { + $result[$orderItems[$this->prepareOrderItemKey($key)]->getId()] = $item; + } + $creditmemoData['qtys'] = $result; + + return $creditmemoData; + } + + /** + * Prepare order item key. + * + * @param string $key + * @return int + */ + private function prepareOrderItemKey($key) + { + return str_replace(self::ORDER_ITEM_ID_PLACEHOLDER, '', $key) - 1; + } + + /** + * @return array + */ + public function createByOrderDataProvider() + { + return [ + // Variation #1 + [ + //$creditmemoData + [ + 'qtys' => [ + self::ORDER_ITEM_ID_PLACEHOLDER . '1' => 1, + self::ORDER_ITEM_ID_PLACEHOLDER . '2' => 1, + ] + ], + //$expectedQty + 4 + ] + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order_with_dummy_item_and_invoiced.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order_with_dummy_item_and_invoiced.php new file mode 100644 index 0000000000000..65389e13564ce --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/order_with_dummy_item_and_invoiced.php @@ -0,0 +1,73 @@ + 2, + \Magento\Sales\Api\Data\OrderItemInterface::BASE_PRICE => 100, + \Magento\Sales\Api\Data\OrderItemInterface::ORDER_ID => $order->getId(), + \Magento\Sales\Api\Data\OrderItemInterface::QTY_ORDERED => 2, + \Magento\Sales\Api\Data\OrderItemInterface::QTY_INVOICED => 2, + \Magento\Sales\Api\Data\OrderItemInterface::PRICE => 100, + \Magento\Sales\Api\Data\OrderItemInterface::ROW_TOTAL => 102, + \Magento\Sales\Api\Data\OrderItemInterface::PRODUCT_TYPE => 'bundle', + 'children' => [ + [ + \Magento\Sales\Api\Data\OrderItemInterface::PRODUCT_ID => 13, + \Magento\Sales\Api\Data\OrderItemInterface::ORDER_ID => $order->getId(), + \Magento\Sales\Api\Data\OrderItemInterface::QTY_ORDERED => 2, + \Magento\Sales\Api\Data\OrderItemInterface::QTY_INVOICED => 2, + \Magento\Sales\Api\Data\OrderItemInterface::BASE_PRICE => 90, + \Magento\Sales\Api\Data\OrderItemInterface::PRICE => 90, + \Magento\Sales\Api\Data\OrderItemInterface::ROW_TOTAL => 92, + \Magento\Sales\Api\Data\OrderItemInterface::PRODUCT_TYPE => 'simple', + 'product_options' => [ + 'bundle_selection_attributes' => '{"qty":2}', + ], + ] + ], + ] +]; + +// Invoiced all existing order items. +foreach ($order->getAllItems() as $item) { + $item->setQtyInvoiced(1); + $item->save(); +} + +saveOrderItems($orderItems); + + +/** + * Save Order Items. + * + * @param array $orderItems + * @param \Magento\Sales\Model\Order\Item|null $parentOrderItem [optional] + * @return void + */ +function saveOrderItems(array $orderItems, $parentOrderItem = null) +{ + /** @var array $orderItemData */ + foreach ($orderItems as $orderItemData) { + /** @var $orderItem \Magento\Sales\Model\Order\Item */ + $orderItem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Sales\Model\Order\Item::class + ); + if (null !== $parentOrderItem) { + $orderItemData['parent_item'] = $parentOrderItem; + } + $orderItem + ->setData($orderItemData) + ->save(); + + if (isset($orderItemData['children'])) { + saveOrderItems($orderItemData['children'], $orderItem); + } + } +} \ No newline at end of file From 63ea11de87d0f89318c699b90f8bddfe4379835f Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Mon, 5 Dec 2016 12:17:02 +0200 Subject: [PATCH 014/132] MAGETWO-61651: Remove uses of serialize and unserialize in Magento/Sales/Model/AdminOrder/Create.php --- .../Unit/Helper/Product/ConfigurationTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php diff --git a/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php b/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php new file mode 100644 index 0000000000000..f2b57ce043198 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php @@ -0,0 +1,81 @@ +getMock(\Magento\Framework\App\Helper\Context::class, [], [], '', false); + $optionFactoryMock = $this->getMock(\Magento\Catalog\Model\Product\OptionFactory::class, [], [], '', false); + $filterManagerMock = $this->getMock(\Magento\Framework\Filter\FilterManager::class, [], [], '', false); + $stringUtilsMock = $this->getMock(\Magento\Framework\Stdlib\StringUtils::class, [], [], '', false); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class, [], [], '', false); + + $this->helper = new \Magento\Catalog\Helper\Product\Configuration( + $contextMock, + $optionFactoryMock, + $filterManagerMock, + $stringUtilsMock, + $this->serializer + ); + } + + /** + * Retrieves product additional options + */ + public function testGetAdditionalOptionOnly() + { + $additional_option_result = ['additional_option' => 1]; + + $itemMock = $this->getMock( + \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface::class, + [], + [], + '', + false + ); + $optionMock = $this->getMock( + \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface::class, + [], + [], + '', + false + ); + $additionalOptionMock = $this->getMock( + \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface::class, + [], + [], + '', + false + ); + $productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); + + $this->serializer->expects($this->once())->method('unserialize')->willReturn($additional_option_result); + $optionMock->expects($this->once())->method('getValue')->willReturn(null); + $additionalOptionMock->expects($this->once())->method('getValue'); + + $itemMock->expects($this->once())->method('getProduct')->willReturn($productMock); + $itemMock->expects($this->any())->method('getOptionByCode')->will($this->returnValueMap( + [ + ['option_ids', $optionMock], + ['additional_options', $additionalOptionMock] + ] + )); + + $this->assertEquals($additional_option_result, $this->helper->getCustomOptions($itemMock)); + } +} From 6447324bd406e811b13f7d942c6401ddddab1205 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Mon, 5 Dec 2016 12:40:03 +0200 Subject: [PATCH 015/132] MAGETWO-61652: Magento/Sales/Model/Order/Config.php and unit tests --- .../Test/Unit/Model/Order/ConfigTest.php | 112 ++++++++++++++++-- 1 file changed, 104 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php index 7ee4f745cde8f..efb43ff903293 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php @@ -4,6 +4,8 @@ * See COPYING.txt for license details. */ namespace Magento\Sales\Test\Unit\Model\Order; +use Magento\Framework\DataObject; +use Magento\Sales\Model\ResourceModel\Order\Status\Collection; /** * Class ConfigTest @@ -44,28 +46,28 @@ protected function setUp() public function testGetInvisibleOnFrontStatuses() { $statuses = [ - new \Magento\Framework\DataObject( + new DataObject( [ 'status' => 'canceled', 'is_default' => 1, 'visible_on_front' => 1, ] ), - new \Magento\Framework\DataObject( + new DataObject( [ 'status' => 'complete', 'is_default' => 1, 'visible_on_front' => 0, ] ), - new \Magento\Framework\DataObject( + new DataObject( [ 'status' => 'processing', 'is_default' => 1, 'visible_on_front' => 1, ] ), - new \Magento\Framework\DataObject( + new DataObject( [ 'status' => 'pending_payment', 'is_default' => 1, @@ -76,7 +78,7 @@ public function testGetInvisibleOnFrontStatuses() $expectedResult = ['complete', 'pending_payment']; $collectionMock = $this->getMock( - \Magento\Sales\Model\ResourceModel\Order\Status\Collection::class, + Collection::class, ['create', 'joinStates'], [], '', @@ -97,14 +99,14 @@ public function testGetInvisibleOnFrontStatuses() public function testGetStateLabelByStateAndStatus() { $statuses = [ - new \Magento\Framework\DataObject( + new DataObject( [ 'status' => 'fraud', 'state' => 'processing', 'label' => 'Suspected Fraud', ] ), - new \Magento\Framework\DataObject( + new DataObject( [ 'status' => 'processing', 'state' => 'processing', @@ -113,7 +115,7 @@ public function testGetStateLabelByStateAndStatus() ) ]; $collectionMock = $this->getMock( - \Magento\Sales\Model\ResourceModel\Order\Status\Collection::class, + Collection::class, ['create', 'joinStates'], [], '', @@ -129,4 +131,98 @@ public function testGetStateLabelByStateAndStatus() $result = $this->salesConfig->getStateLabelByStateAndStatus('processing', 'fraud'); $this->assertSame('Suspected Fraud', $result->getText()); } + + /** + * Test get statuses + * + * @dataProvider getStatusesDataProvider + * + * @param string $state + * @param bool $joinLabels + * @param DataObject[] $collectionData + * @param array $expectedResult + */ + public function testGetStatuses($state, $joinLabels, $collectionData, $expectedResult) + { + $collectionMock = $this->getMock( + Collection::class, + ['create', 'joinStates', 'addStateFilter', 'orderByLabel'], + [], + '', + false, + false + ); + $this->orderStatusCollectionFactoryMock->expects($this->any()) + ->method('create') + ->will($this->returnValue($collectionMock)); + + $collectionMock->expects($this->once()) + ->method('addStateFilter') + ->will($this->returnSelf()); + + $collectionMock->expects($this->once()) + ->method('orderByLabel') + ->will($this->returnValue($collectionData)); + + $collectionMock->expects($this->once()) + ->method('joinStates') + ->will($this->returnValue($collectionData)); + + $result = $this->salesConfig->getStateStatuses($state, $joinLabels); + $this->assertSame($expectedResult, $result); + + // checking data cached in private property + $this->assertSame($result, $this->salesConfig->getStateStatuses($state, $joinLabels)); + } + + /** + * Data provider for testGetStatuses + * + * @return array + */ + public function getStatusesDataProvider() + { + return [ + 'processing state' => [ + 'state' => 'processing', + 'joinLabels' => false, + 'collectionData' => [ + new DataObject( + [ + 'status' => 'fraud', + 'state' => 'processing', + 'store_label' => 'Suspected Fraud', + ] + ), + new DataObject( + [ + 'status' => 'processing', + 'state' => 'processing', + 'store_label' => 'Processing', + ] + ), + ], + 'expectedResult' => [ + 0 => 'fraud', + 1 => 'processing' + ], + ], + 'pending state' => [ + 'state' => 'pending', + 'joinLabels' => true, + 'collectionData' => [ + new DataObject( + [ + 'status' => 'pending_status', + 'state' => 'pending', + 'store_label' => 'Pending label', + ] + ), + ], + 'expectedResult' => [ + 'pending_status' => 'Pending label' + ], + ], + ]; + } } From cba9332f912d863913d9824e296530d2caaca6eb Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Mon, 5 Dec 2016 15:16:05 +0200 Subject: [PATCH 016/132] MAGETWO-61652: Magento/Sales/Model/Order/Config.php and unit tests - fixed satic test notices - changed hash in key preparation from md5 as it is treated as unsecure --- app/code/Magento/Sales/Model/Order/Config.php | 2 +- app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/Config.php b/app/code/Magento/Sales/Model/Order/Config.php index 0da26bdbbe2e3..48021fedc03f8 100644 --- a/app/code/Magento/Sales/Model/Order/Config.php +++ b/app/code/Magento/Sales/Model/Order/Config.php @@ -192,7 +192,7 @@ public function getStates() */ public function getStateStatuses($state, $addLabels = true) { - $key = md5(json_encode([$state, $addLabels])); + $key = sha1(json_encode([$state, $addLabels])); if (isset($this->stateStatuses[$key])) { return $this->stateStatuses[$key]; } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php index efb43ff903293..e0aae72555c03 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Sales\Test\Unit\Model\Order; + use Magento\Framework\DataObject; use Magento\Sales\Model\ResourceModel\Order\Status\Collection; From e5be730d0d156e657bc64621dad16ccff2eddfb9 Mon Sep 17 00:00:00 2001 From: Joan He Date: Mon, 5 Dec 2016 10:49:40 -0600 Subject: [PATCH 017/132] MAGETWO-61535: Create upgrade script for sales_shipment table packages field --- app/code/Magento/Sales/Setup/UpgradeData.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 09eec6840943f..f26975972a12f 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -122,6 +122,7 @@ private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) { $this->changeFieldFormat($setup, 'sales_order_item', 'item_id', 'product_options'); $this->changeFieldFormat($setup, 'quote_payment', 'payment_id', 'additional_information'); + $this->changeFieldFormat($setup, 'sales_shipment', 'entity_id', 'packages'); } /** From 87b66cc1506aec2a135d55cda40c4bc43660d540 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 5 Dec 2016 10:49:54 -0600 Subject: [PATCH 018/132] MAGETWO-61533: Create upgrade script for sales_order_payment table additional_information field Changing format from serialized to json of additional_information field in sales_order_payment table --- app/code/Magento/Sales/Setup/UpgradeData.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 09eec6840943f..395f30e508f41 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -122,6 +122,7 @@ private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) { $this->changeFieldFormat($setup, 'sales_order_item', 'item_id', 'product_options'); $this->changeFieldFormat($setup, 'quote_payment', 'payment_id', 'additional_information'); + $this->changeFieldFormat($setup, 'sales_order_payment', 'entity_id', 'additional_information'); } /** From 36f83c17fd64c02838aa2e0b019430c0851b3326 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 5 Dec 2016 11:55:39 -0600 Subject: [PATCH 019/132] MAGETWO-61537: Create upgrade script for sales_payment_transaction table additional_information field Changing format from serialized to json of additional_information field in sales_payment_transaction table --- app/code/Magento/Sales/Setup/UpgradeData.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 9322921c48284..a32c6941bee01 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -124,6 +124,7 @@ private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) $this->changeFieldFormat($setup, 'quote_payment', 'payment_id', 'additional_information'); $this->changeFieldFormat($setup, 'sales_order_payment', 'entity_id', 'additional_information'); $this->changeFieldFormat($setup, 'sales_shipment', 'entity_id', 'packages'); + $this->changeFieldFormat($setup, 'sales_payment_transaction', 'transaction_id', 'packages'); } /** From 871aa37053968fae7256765b1d2b8579d5a1fc53 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 5 Dec 2016 11:56:05 -0600 Subject: [PATCH 020/132] MAGETWO-61537: Create upgrade script for sales_payment_transaction table additional_information field Changing format from serialized to json of additional_information field in sales_payment_transaction table --- app/code/Magento/Sales/Setup/UpgradeData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index a32c6941bee01..6dedb2ea84779 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -124,7 +124,7 @@ private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) $this->changeFieldFormat($setup, 'quote_payment', 'payment_id', 'additional_information'); $this->changeFieldFormat($setup, 'sales_order_payment', 'entity_id', 'additional_information'); $this->changeFieldFormat($setup, 'sales_shipment', 'entity_id', 'packages'); - $this->changeFieldFormat($setup, 'sales_payment_transaction', 'transaction_id', 'packages'); + $this->changeFieldFormat($setup, 'sales_payment_transaction', 'transaction_id', 'additional_information'); } /** From 3cc51336b93eeca9a7045dc26459546440e9b319 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Tue, 6 Dec 2016 10:09:46 +0200 Subject: [PATCH 021/132] MAGETWO-61654: Update serialization in Magento/Sales/Model/Order/Item.php and unit tests --- app/code/Magento/Sales/Model/Order/Item.php | 22 +++++++- .../Sales/Test/Unit/Model/Order/ItemTest.php | 55 ++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index 10ba1e1662144..b48921ac7b63f 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -6,6 +6,8 @@ namespace Magento\Sales\Model\Order; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Sales\Model\AbstractModel; use Magento\Sales\Api\Data\OrderItemInterface; @@ -95,6 +97,11 @@ class Item extends AbstractModel implements OrderItemInterface */ protected $_storeManager; + /** + * @var SerializerInterface + */ + private $serializer; + /** * Initialize dependencies. * @@ -458,6 +465,19 @@ public function setProductOptions(array $options = null) return $this; } + /** + * Get serializer instance + * + * @return SerializerInterface + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = ObjectManager::getInstance()->get(SerializerInterface::class); + } + return $this->serializer; + } + /** * Get product options array * @@ -466,7 +486,7 @@ public function setProductOptions(array $options = null) public function getProductOptions() { $data = $this->_getData('product_options'); - return is_string($data) ? unserialize($data) : $data; + return is_string($data) ? $this->getSerializer()->unserialize($data) : $data; } /** diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php index 3d6ba772618c7..6006f5234b198 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php @@ -6,6 +6,7 @@ namespace Magento\Sales\Test\Unit\Model\Order; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Sales\Model\ResourceModel\OrderFactory; use \Magento\Sales\Model\Order; @@ -118,7 +119,8 @@ public function testGetStatusId( $qtyRefunded, $qtyShipped, $expectedStatus - ) { + ) + { $this->model->setQtyBackordered($qtyBackOrdered); $this->model->setQtyCanceled($qtyCanceled); $this->model->setQtyInvoiced($qtyInvoiced); @@ -173,4 +175,55 @@ public function testGetOriginalPrice() $this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::ORIGINAL_PRICE, $originalPrice); $this->assertEquals($originalPrice, $this->model->getOriginalPrice()); } + + /** + * Test get product options with serialization + * + * @param array|string $options + * @param array $expectedResult + * + * @dataProvider getProductOptionsDataProvider + */ + public function testGetProductOptions($options, $expectedResult) + { + $serializerMock = $this->getMock(SerializerInterface::class, [], ['unserialize'], '', false); + if (is_string($options)) { + $serializerMock->expects($this->once())->method('unserialize')->will($this->returnValue($expectedResult)); + } + $this->objectManager->setBackwardCompatibleProperty($this->model, 'serializer', $serializerMock); + $this->model->setData('product_options', $options); + $result = $this->model->getProductOptions(); + $this->assertSame($result, $expectedResult); + } + + /** + * Data provider for testGetProductOptions + * + * @return array + */ + public function getProductOptionsDataProvider() + { + return [ + 'array' => [ + 'options' => [ + 'option1' => 'option 1 value', + 'option2' => 'option 2 value', + ], + 'expectedResult' => [ + 'option1' => 'option 1 value', + 'option2' => 'option 2 value', + ] + ], + 'serialized' => [ + 'options' => json_encode([ + 'option1' => 'option 1 value', + 'option2' => 'option 2 value', + ]), + 'expectedResult' => [ + 'option1' => 'option 1 value', + 'option2' => 'option 2 value', + ] + ] + ]; + } } From 0ab0d2fc847c86cc29cc6f35c24bbc7db645753a Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Tue, 6 Dec 2016 10:13:05 +0200 Subject: [PATCH 022/132] MAGETWO-61654: Update serialization in Magento/Sales/Model/Order/Item.php and unit tests - added deprecation tag to deprecated method --- app/code/Magento/Sales/Model/Order/Item.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index b48921ac7b63f..757c4f673d347 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -469,6 +469,7 @@ public function setProductOptions(array $options = null) * Get serializer instance * * @return SerializerInterface + * @deprecated */ private function getSerializer() { From 2e920bd5dc703e1685bba92062aa847c8363928e Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Tue, 6 Dec 2016 16:06:56 +0200 Subject: [PATCH 023/132] MAGETWO-61651: Remove uses of serialize and unserialize in Magento/Sales/Model/AdminOrder/Create.php --- .../Catalog/Test/Unit/Helper/Product/ConfigurationTest.php | 6 +++--- .../testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php b/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php index f2b57ce043198..9a2e46776c6f5 100644 --- a/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php @@ -39,7 +39,7 @@ protected function setUp() */ public function testGetAdditionalOptionOnly() { - $additional_option_result = ['additional_option' => 1]; + $additionalOptionResult = ['additional_option' => 1]; $itemMock = $this->getMock( \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface::class, @@ -64,7 +64,7 @@ public function testGetAdditionalOptionOnly() ); $productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); - $this->serializer->expects($this->once())->method('unserialize')->willReturn($additional_option_result); + $this->serializer->expects($this->once())->method('unserialize')->willReturn($additionalOptionResult); $optionMock->expects($this->once())->method('getValue')->willReturn(null); $additionalOptionMock->expects($this->once())->method('getValue'); @@ -76,6 +76,6 @@ public function testGetAdditionalOptionOnly() ] )); - $this->assertEquals($additional_option_result, $this->helper->getCustomOptions($itemMock)); + $this->assertEquals($additionalOptionResult, $this->helper->getCustomOptions($itemMock)); } } diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index 0714423cff4b1..040ab446222a9 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -108,6 +108,7 @@ public function testInitFromOrderAndCreateOrderFromQuoteWithAdditionalOptions() $newOrderItem->getProductOptionByCode('additional_options') ); } + /** * @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php * @magentoDataFixture Magento/Downloadable/_files/order_with_downloadable_product.php From a07910d8ffaa3db9bfd511db505a1691399dabc6 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 6 Dec 2016 14:03:45 -0600 Subject: [PATCH 024/132] MAGETWO-61872: Create FieldDataConverter Implementing FieldDataConverter --- .../DataConverter/DataConverterInterface.php | 20 ++++++ .../Setup/DataConverter/SerializedToJson.php | 50 +++++++++++++ .../Framework/Setup/FieldDataConverter.php | 72 +++++++++++++++++++ .../Setup/FieldDataConverterFactory.php | 55 ++++++++++++++ .../DataConverter/SerializedToJsonTest.php | 59 +++++++++++++++ 5 files changed, 256 insertions(+) create mode 100644 lib/internal/Magento/Framework/Setup/DataConverter/DataConverterInterface.php create mode 100644 lib/internal/Magento/Framework/Setup/DataConverter/SerializedToJson.php create mode 100644 lib/internal/Magento/Framework/Setup/FieldDataConverter.php create mode 100644 lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php create mode 100644 lib/internal/Magento/Framework/Setup/Test/Unit/DataConverter/SerializedToJsonTest.php diff --git a/lib/internal/Magento/Framework/Setup/DataConverter/DataConverterInterface.php b/lib/internal/Magento/Framework/Setup/DataConverter/DataConverterInterface.php new file mode 100644 index 0000000000000..0ddab69cb9c89 --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/DataConverter/DataConverterInterface.php @@ -0,0 +1,20 @@ +serialize = $serialize; + $this->json = $json; + } + + /** + * Convert from serialized to JSON format + * + * @param string $string + * @return string + */ + public function convert($string) + { + return $this->json->serialize($this->serialize->unserialize($string)); + } +} diff --git a/lib/internal/Magento/Framework/Setup/FieldDataConverter.php b/lib/internal/Magento/Framework/Setup/FieldDataConverter.php new file mode 100644 index 0000000000000..c14fefad7353f --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/FieldDataConverter.php @@ -0,0 +1,72 @@ +connection = $connection; + $this->queryGenerator = $queryGenerator; + $this->dataConverter = $dataConverter; + } + + /** + * Convert field data from one representation to another + * + * @param string $table + * @param string $identifier + * @param string $field + * @return void + */ + public function convert($table, $identifier, $field) + { + $select = $this->connection->select() + ->from($table, [$identifier, $field]) + ->where($field . ' IS NOT NULL'); + $iterator = $this->queryGenerator->generate($identifier, $select); + foreach ($iterator as $selectByRange) { + $rows = $this->connection->fetchAll($selectByRange); + foreach ($rows as $row) { + $bind = [$field => $this->dataConverter->convert($row[$field])]; + $where = [$identifier . ' = ?' => (int) $row[$identifier]]; + $this->connection->update($table, $bind, $where); + } + } + } +} diff --git a/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php b/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php new file mode 100644 index 0000000000000..e57765501514d --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php @@ -0,0 +1,55 @@ +objectManager = $objectManager; + } + + /** + * Create instance of FieldDataConverter + * + * @param AdapterInterface $connection + * @param DataConverterInterface $dataConverterClassName + * @return FieldDataConverter + */ + public function create(AdapterInterface $connection, DataConverterInterface $dataConverterClassName) + { + return $this->objectManager->create( + self::CLASS_NAME, + [ + 'connection' => $connection, + 'dataConverter' => $this->objectManager->get($dataConverterClassName) + ] + ); + } +} diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/DataConverter/SerializedToJsonTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/DataConverter/SerializedToJsonTest.php new file mode 100644 index 0000000000000..e7119040e02b9 --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/DataConverter/SerializedToJsonTest.php @@ -0,0 +1,59 @@ +serializeMock = $this->getMock(Serialize::class, [], [], '', false); + $this->jsonMock = $this->getMock(Json::class, [], [], '', false); + $this->serializedToJson = $objectManager->getObject( + SerializedToJson::class, + [ + 'serialize' => $this->serializeMock, + 'json' => $this->jsonMock + ] + ); + } + + public function testConvert() + { + $serializedData = 'serialized data'; + $jsonData = 'json data'; + $unserializedData = 'unserialized data'; + $this->serializeMock->expects($this->once()) + ->method('unserialize') + ->with($serializedData) + ->willReturn($unserializedData); + $this->jsonMock->expects($this->once()) + ->method('serialize') + ->with($unserializedData) + ->willReturn($jsonData); + $this->assertEquals($jsonData, $this->serializedToJson->convert($serializedData)); + } +} From d3ee7fc9a4f1a9f6f24abd98ded544de600c8864 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 6 Dec 2016 14:17:11 -0600 Subject: [PATCH 025/132] MAGETWO-61537: Create upgrade script for sales_payment_transaction table additional_information field Refactoring to use FieldDataConverter --- app/code/Magento/Sales/Setup/UpgradeData.php | 74 ++++++++------------ 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 6dedb2ea84779..912c891079e37 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -24,25 +24,25 @@ class UpgradeData implements UpgradeDataInterface private $eavConfig; /** - * @var \Magento\Framework\Serialize\Serializer\Json + * @var \Magento\Framework\Setup\FieldDataConverterFactory */ - private $serializer; + private $fieldDataConverterFactory; /** * Constructor * * @param SalesSetupFactory $salesSetupFactory * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\Serialize\Serializer\Json $serializer + * @param \Magento\Framework\Setup\FieldDataConverterFactory $fieldDataConverterFactory */ public function __construct( SalesSetupFactory $salesSetupFactory, \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\Serialize\Serializer\Json $serializer + \Magento\Framework\Setup\FieldDataConverterFactory $fieldDataConverterFactory ) { $this->salesSetupFactory = $salesSetupFactory; $this->eavConfig = $eavConfig; - $this->serializer = $serializer; + $this->fieldDataConverterFactory = $fieldDataConverterFactory; } /** @@ -120,45 +120,29 @@ private function upgradeToTwoZeroOne(SalesSetup $setup) */ private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) { - $this->changeFieldFormat($setup, 'sales_order_item', 'item_id', 'product_options'); - $this->changeFieldFormat($setup, 'quote_payment', 'payment_id', 'additional_information'); - $this->changeFieldFormat($setup, 'sales_order_payment', 'entity_id', 'additional_information'); - $this->changeFieldFormat($setup, 'sales_shipment', 'entity_id', 'packages'); - $this->changeFieldFormat($setup, 'sales_payment_transaction', 'transaction_id', 'additional_information'); - } - - /** - * Change format of the field for the table - * - * @param ModuleDataSetupInterface $setup - * @param string $tableName - * @param string $identifier - * @param string $field - * @return void - */ - private function changeFieldFormat(ModuleDataSetupInterface $setup, $tableName, $identifier, $field) - { - $table = $setup->getTable($tableName); - $select = $setup->getConnection() - ->select() - ->from($table, [$identifier, $field]) - ->where($field . ' IS NOT NULL'); - $items = $setup->getConnection()->fetchAll($select); - foreach ($items as $item) { - $bind = [$field => $this->convertData($item[$field])]; - $where = [$identifier . ' = ?' => (int) $item[$identifier]]; - $setup->getConnection()->update($table, $bind, $where); - } - } - - /** - * Convert from serialized to json format - * - * @param string $data - * @return string - */ - private function convertData($data) - { - return $this->serializer->serialize(unserialize($data)); + $fieldDataConverter = $this->fieldDataConverterFactory->create( + $setup->getConnection(), + \Magento\Framework\Setup\DataConverter\SerializedToJson::class + ); + $fieldDataConverter->convert( + $setup->getTable('quote_payment'), + 'payment_id', + 'additional_information' + ); + $fieldDataConverter->convert( + $setup->getTable('sales_order_payment'), + 'entity_id', + 'additional_information' + ); + $fieldDataConverter->convert( + $setup->getTable('sales_shipment'), + 'entity_id', + 'packages' + ); + $fieldDataConverter->convert( + $setup->getTable('sales_payment_transaction'), + 'transaction_id', + 'additional_information' + ); } } From b3e81eab3945f64df17bea7a06fea4bdeee2eaf2 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 6 Dec 2016 15:08:45 -0600 Subject: [PATCH 026/132] MAGETWO-61537: Create upgrade script for sales_payment_transaction table additional_information field Refactoring to use FieldDataConverter --- app/code/Magento/Sales/Setup/UpgradeData.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 912c891079e37..ea40a4d7624c8 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -125,19 +125,19 @@ private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) \Magento\Framework\Setup\DataConverter\SerializedToJson::class ); $fieldDataConverter->convert( - $setup->getTable('quote_payment'), - 'payment_id', - 'additional_information' + $setup->getTable('sales_order_item'), + 'item_id', + 'product_options' ); $fieldDataConverter->convert( - $setup->getTable('sales_order_payment'), + $setup->getTable('sales_shipment'), 'entity_id', - 'additional_information' + 'packages' ); $fieldDataConverter->convert( - $setup->getTable('sales_shipment'), + $setup->getTable('sales_order_payment'), 'entity_id', - 'packages' + 'additional_information' ); $fieldDataConverter->convert( $setup->getTable('sales_payment_transaction'), From 3dd81a20071237fb2abaf2f49c616c5547f3a880 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 6 Dec 2016 15:24:15 -0600 Subject: [PATCH 027/132] MAGETWO-61526: Create upgrade script for quote_payment table additional_information field Changing format from serialized to json of additional_information field in quote_payment table --- app/code/Magento/Quote/Setup/UpgradeData.php | 69 ++++++++++++++++++++ app/code/Magento/Quote/etc/module.xml | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Quote/Setup/UpgradeData.php diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php new file mode 100644 index 0000000000000..e93ed2bb055b8 --- /dev/null +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -0,0 +1,69 @@ +eavConfig = $eavConfig; + $this->fieldDataConverterFactory = $fieldDataConverterFactory; + } + + /** + * {@inheritdoc} + */ + public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + { + $setup->startSetup(); + if (version_compare($context->getVersion(), '2.0.4', '<')) { + $this->upgradeToVersionTwoZeroFour($setup); + } + $this->eavConfig->clear(); + $setup->endSetup(); + } + + /** + * Upgrade to version 2.0.4 + * + * @param ModuleDataSetupInterface $setup + * @return void + */ + private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) + { + $fieldDataConverter = $this->fieldDataConverterFactory->create( + $setup->getConnection(), + \Magento\Framework\Setup\DataConverter\SerializedToJson::class + ); + $fieldDataConverter->convert( + $setup->getTable('quote_payment'), + 'payment_id', + 'additional_information' + ); + } +} diff --git a/app/code/Magento/Quote/etc/module.xml b/app/code/Magento/Quote/etc/module.xml index 281cde9eeb9d1..52c92cf2d912a 100644 --- a/app/code/Magento/Quote/etc/module.xml +++ b/app/code/Magento/Quote/etc/module.xml @@ -6,6 +6,6 @@ */ --> - + From a552b2f90f2a40df08a22d85e3e8a31e355bd1ae Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 6 Dec 2016 16:23:13 -0600 Subject: [PATCH 028/132] MAGETWO-61872: Create FieldDataConverter Implementing FieldDataConverter --- .../Setup/FieldDataConverterFactory.php | 11 +- .../Unit/FieldDataConverterFactoryTest.php | 74 ++++++++++++ .../Test/Unit/FieldDataConverterTest.php | 108 ++++++++++++++++++ 3 files changed, 185 insertions(+), 8 deletions(-) create mode 100644 lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterFactoryTest.php create mode 100644 lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterTest.php diff --git a/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php b/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php index e57765501514d..911ec637066bf 100644 --- a/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php +++ b/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php @@ -14,11 +14,6 @@ */ class FieldDataConverterFactory { - /** - * FieldDataConverter class name - */ - const CLASS_NAME = FieldDataConverter::class; - /** * @var ObjectManagerInterface */ @@ -39,13 +34,13 @@ public function __construct( * Create instance of FieldDataConverter * * @param AdapterInterface $connection - * @param DataConverterInterface $dataConverterClassName + * @param string $dataConverterClassName * @return FieldDataConverter */ - public function create(AdapterInterface $connection, DataConverterInterface $dataConverterClassName) + public function create(AdapterInterface $connection, $dataConverterClassName) { return $this->objectManager->create( - self::CLASS_NAME, + FieldDataConverter::class, [ 'connection' => $connection, 'dataConverter' => $this->objectManager->get($dataConverterClassName) diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterFactoryTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterFactoryTest.php new file mode 100644 index 0000000000000..e08e1ee749666 --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterFactoryTest.php @@ -0,0 +1,74 @@ +objectManagerMock = $this->getMock(ObjectManagerInterface::class); + $this->connectionMock = $this->getMock(AdapterInterface::class); + $this->dataConverterMock = $this->getMock(DataConverterInterface::class); + $this->fieldDataConverterFactory = $objectManager->getObject( + FieldDataConverterFactory::class, + [ + 'objectManager' => $this->objectManagerMock + ] + ); + } + + public function testCreate() + { + $dataConverterClassName = 'ClassName'; + $fieldDataConverterInstance = 'field data converter instance'; + $this->objectManagerMock->expects($this->once()) + ->method('get') + ->with($dataConverterClassName) + ->willReturn($this->dataConverterMock); + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with( + FieldDataConverter::class, + [ + 'connection' => $this->connectionMock, + 'dataConverter' => $this->dataConverterMock + ] + ) + ->willReturn($fieldDataConverterInstance); + $this->assertEquals( + $fieldDataConverterInstance, + $this->fieldDataConverterFactory->create($this->connectionMock, $dataConverterClassName) + ); + } +} diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterTest.php new file mode 100644 index 0000000000000..9c16d1ea0123c --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterTest.php @@ -0,0 +1,108 @@ +connectionMock = $this->getMock(AdapterInterface::class); + $this->queryGeneratorMock = $this->getMock(Generator::class, [], [], '', false); + $this->dataConverterMock = $this->getMock(DataConverterInterface::class); + $this->selectMock = $this->getMock(Select::class, [], [], '', false); + $this->fieldDataConverter = $objectManager->getObject( + FieldDataConverter::class, + [ + 'connection' => $this->connectionMock, + 'queryGenerator' => $this->queryGeneratorMock, + 'dataConverter' => $this->dataConverterMock + ] + ); + } + + public function testConvert() + { + $table = 'table'; + $identifier = 'id'; + $field = 'field'; + $where = $field . ' IS NOT NULL'; + $iterator = ['query 1']; + $rows = [ + [ + $identifier => 1, + $field => 'value' + ] + ]; + $convertedValue = 'converted value'; + $this->connectionMock->expects($this->once()) + ->method('select') + ->willReturn($this->selectMock); + $this->selectMock->expects($this->once()) + ->method('from') + ->with( + $table, + [$identifier, $field] + ) + ->willReturnSelf(); + $this->selectMock->expects($this->once()) + ->method('where') + ->with($where) + ->willReturnSelf(); + $this->queryGeneratorMock->expects($this->once()) + ->method('generate') + ->with($identifier, $this->selectMock) + ->willReturn($iterator); + $this->connectionMock->expects($this->once()) + ->method('fetchAll') + ->with($iterator[0]) + ->willReturn($rows); + $this->dataConverterMock->expects($this->once()) + ->method('convert') + ->with($rows[0][$field]) + ->willReturn($convertedValue); + $this->connectionMock->expects($this->once()) + ->method('update') + ->with( + $table, + [$field => $convertedValue], + [$identifier . ' = ?' => $rows[0][$identifier]] + ); + $this->fieldDataConverter->convert($table, $identifier, $field); + } +} From d1c056a9655ed663f21e9d87558520edbf93cb35 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 7 Dec 2016 11:44:35 +0200 Subject: [PATCH 029/132] MAGETWO-61674: Fix seralization in Module Downloadable --- .../Downloadable/Model/Product/Type.php | 30 +++- .../Test/Unit/Model/Product/TypeTest.php | 137 +++++++++++++++++- 2 files changed, 159 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Downloadable/Model/Product/Type.php b/app/code/Magento/Downloadable/Model/Product/Type.php index 64c00d208b86f..f5e63153f2a7e 100644 --- a/app/code/Magento/Downloadable/Model/Product/Type.php +++ b/app/code/Magento/Downloadable/Model/Product/Type.php @@ -7,6 +7,8 @@ use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\SerializerInterface; /** * Downloadable product type model @@ -65,6 +67,11 @@ class Type extends \Magento\Catalog\Model\Product\Type\Virtual */ private $extensionAttributesJoinProcessor; + /** + * @var SerializerInterface + */ + private $serializer; + /** * Construct * @@ -249,14 +256,19 @@ public function checkProductBuyState($product) parent::checkProductBuyState($product); $option = $product->getCustomOption('info_buyRequest'); if ($option instanceof \Magento\Quote\Model\Quote\Item\Option) { - $buyRequest = new \Magento\Framework\DataObject(unserialize($option->getValue())); + $buyRequest = new \Magento\Framework\DataObject( + $this->getSerializer()->unserialize($option->getValue()) + ); if (!$buyRequest->hasLinks()) { if (!$product->getLinksPurchasedSeparately()) { $allLinksIds = $this->_linksFactory->create()->addProductToFilter( $product->getEntityId() )->getAllIds(); $buyRequest->setLinks($allLinksIds); - $product->addCustomOption('info_buyRequest', serialize($buyRequest->getData())); + $product->addCustomOption( + 'info_buyRequest', + $this->getSerializer()->serialize($buyRequest->getData()) + ); } else { throw new \Magento\Framework\Exception\LocalizedException(__('Please specify product link(s).')); } @@ -265,6 +277,20 @@ public function checkProductBuyState($product) return $this; } + /** + * Get serializer instance + * + * @return SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = ObjectManager::getInstance()->get(SerializerInterface::class); + } + return $this->serializer; + } + /** * Prepare additional options/information for order item which will be * created from this product diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php index 61d66d47bc281..6cc2e4dafdc6e 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php @@ -6,6 +6,8 @@ namespace Magento\Downloadable\Test\Unit\Model\Product; use Magento\Downloadable\Model\Product\TypeHandler\TypeHandlerInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; /** * Class TypeTest @@ -30,12 +32,27 @@ class TypeTest extends \PHPUnit_Framework_TestCase */ private $product; + /** + * @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializerMock; + + /** + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + private $objectManager; + + /** + * @var \Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $linksFactory; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { - $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $eventManager = $this->getMock(\Magento\Framework\Event\ManagerInterface::class, [], [], '', false); $fileStorageDb = $this->getMockBuilder( \Magento\MediaStorage\Helper\File\Storage\Database::class @@ -54,7 +71,7 @@ protected function setUp() false ); $linkResource = $this->getMock(\Magento\Downloadable\Model\ResourceModel\Link::class, [], [], '', false); - $linksFactory = $this->getMock( + $this->linksFactory = $this->getMock( \Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory::class, [], [], @@ -94,6 +111,9 @@ protected function setUp() 'setLinksExist', 'getDownloadableLinks', '__wakeup', + 'getCustomOption', + 'addCustomOption', + 'getEntityId' ], [], '', @@ -109,8 +129,7 @@ protected function setUp() $this->product->expects($this->any())->method('setTypeHasOptions')->with($this->equalTo(false)); $this->product->expects($this->any())->method('setLinksExist')->with($this->equalTo(false)); $this->product->expects($this->any())->method('canAffectOptions')->with($this->equalTo(true)); - $this->product->expects($this->any())->method('getLinksPurchasedSeparately')->will($this->returnValue(true)); - $this->product->expects($this->any())->method('getLinksPurchasedSeparately')->will($this->returnValue(true)); + $eavConfigMock = $this->getMock(\Magento\Eav\Model\Config::class, ['getEntityAttributeCodes'], [], '', false); $eavConfigMock->expects($this->any()) @@ -123,7 +142,7 @@ protected function setUp() ->setMethods(['save']) ->getMock(); - $this->target = $objectHelper->getObject( + $this->target = $this->objectManager->getObject( \Magento\Downloadable\Model\Product\Type::class, [ 'eventManager' => $eventManager, @@ -134,7 +153,7 @@ protected function setUp() 'productFactory' => $productFactoryMock, 'sampleResFactory' => $sampleResFactory, 'linkResource' => $linkResource, - 'linksFactory' => $linksFactory, + 'linksFactory' => $this->linksFactory, 'samplesFactory' => $samplesFactory, 'sampleFactory' => $sampleFactory, 'linkFactory' => $linkFactory, @@ -157,9 +176,115 @@ public function testBeforeSave() public function testHasLinks() { + $this->product->expects($this->any())->method('getLinksPurchasedSeparately')->will($this->returnValue(true)); $this->product->expects($this->exactly(2)) ->method('getDownloadableLinks') ->willReturn(['link1', 'link2']); $this->assertTrue($this->target->hasLinks($this->product)); } + + public function testCheckProductBuyState() + { + $optionMock = $this->getMock(\Magento\Quote\Model\Quote\Item\Option::class, [], ['getValue'], '', false); + + $optionMock->expects($this->any())->method('getValue')->will($this->returnValue('{}')); + + $this->product->expects($this->any()) + ->method('getCustomOption') + ->with('info_buyRequest') + ->will($this->returnValue($optionMock)); + + $this->product->expects($this->any()) + ->method('getLinksPurchasedSeparately') + ->will($this->returnValue(false)); + + $this->product->expects($this->any()) + ->method('getEntityId') + ->will($this->returnValue(123)); + + $this->initSerializerMock(); + + $linksCollectionMock = $this->getMock( + \Magento\Downloadable\Model\ResourceModel\Link\Collection::class, + [], + ['addProductToFilter', 'getAllIds'], + '', + false + ); + + $linksCollectionMock->expects($this->once()) + ->method('addProductToFilter') + ->with(123) + ->will($this->returnSelf()); + + $linksCollectionMock->expects($this->once()) + ->method('getAllIds') + ->will($this->returnValue([1, 2, 3])); + + $this->linksFactory->expects($this->any()) + ->method('create') + ->will($this->returnValue($linksCollectionMock)); + + $this->product->expects($this->once()) + ->method('addCustomOption') + ->with('info_buyRequest', '{"links":[1,2,3]}'); + + $this->target->checkProductBuyState($this->product); + } + + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Please specify product link(s). + */ + public function testCheckProductBuyStateException() + { + $optionMock = $this->getMock(\Magento\Quote\Model\Quote\Item\Option::class, [], ['getValue'], '', false); + + $optionMock->expects($this->any())->method('getValue')->will($this->returnValue('{}')); + + $this->product->expects($this->any()) + ->method('getCustomOption') + ->with('info_buyRequest') + ->will($this->returnValue($optionMock)); + + $this->product->expects($this->any()) + ->method('getLinksPurchasedSeparately') + ->will($this->returnValue(true)); + + $this->initSerializerMock(); + + $this->target->checkProductBuyState($this->product); + } + + /** + * Initialize serializer mock + */ + private function initSerializerMock() + { + $this->serializerMock = $this->getMock( + SerializerInterface::class, + [], + ['serialize', 'unserialize'], + '', + false + ); + + $this->serializerMock->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); + + $this->serializerMock->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + + $this->objectManager->setBackwardCompatibleProperty($this->target, 'serializer', $this->serializerMock); + } } From 6be316b9e96e76b40b1d821a66bff559015dcc5e Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Tue, 6 Dec 2016 16:00:04 +0200 Subject: [PATCH 030/132] MAGETWO-61673: Remove uses of serialize and unserialize in ConfigurableProduct --- .../Model/Product/Type/Configurable.php | 61 +-- .../Model/Product/Type/ConfigurableTest.php | 517 +++++++----------- 2 files changed, 220 insertions(+), 358 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php index 0bd2f23418221..7e426eee139a5 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php @@ -5,6 +5,7 @@ */ namespace Magento\ConfigurableProduct\Model\Product\Type; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\ProductRepositoryInterface; @@ -163,6 +164,11 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType */ private $customerSession; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @codingStandardsIgnoreStart/End * @@ -183,6 +189,7 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType * @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $catalogProductTypeConfigurable * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor + * @param SerializerInterface $serializer * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -205,7 +212,8 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor, \Magento\Framework\Cache\FrontendInterface $cache = null, - \Magento\Customer\Model\Session $customerSession = null + \Magento\Customer\Model\Session $customerSession = null, + SerializerInterface $serializer = null ) { $this->typeConfigurableFactory = $typeConfigurableFactory; $this->_eavAttributeFactory = $eavAttributeFactory; @@ -217,6 +225,7 @@ public function __construct( $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; $this->cache = $cache; $this->customerSession = $customerSession; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct( $catalogProductOption, $eavConfig, @@ -414,47 +423,15 @@ public function getConfigurableAttributes($product) ['group' => 'CONFIGURABLE', 'method' => __METHOD__] ); if (!$product->hasData($this->_configurableAttributes)) { - $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class); - $productId = $product->getData($metadata->getLinkField()); - $cacheId = __CLASS__ . $productId . '_' . $product->getStoreId(); - $configurableAttributes = $this->getCache()->load($cacheId); - $configurableAttributes = $this->hasCacheData($configurableAttributes); - if ($configurableAttributes) { - $configurableAttributes->setProductFilter($product); - } else { - $configurableAttributes = $this->getConfigurableAttributeCollection($product); - $this->extensionAttributesJoinProcessor->process($configurableAttributes); - $configurableAttributes->orderByPosition()->load(); - $this->getCache()->save( - serialize($configurableAttributes), - $cacheId, - array_merge($product->getIdentities(), [self::TYPE_CODE . '_' . $productId]) - ); - } + $configurableAttributes = $this->getConfigurableAttributeCollection($product); + $this->extensionAttributesJoinProcessor->process($configurableAttributes); + $configurableAttributes->orderByPosition()->load(); $product->setData($this->_configurableAttributes, $configurableAttributes); } \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__); return $product->getData($this->_configurableAttributes); } - /** - * @param mixed $configurableAttributes - * @return bool - */ - protected function hasCacheData($configurableAttributes) - { - $configurableAttributes = $configurableAttributes ?: unserialize($configurableAttributes); - if (is_array($configurableAttributes) && count($configurableAttributes)) { - foreach ($configurableAttributes as $attribute) { - /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $attribute */ - if ($attribute->getData('options')) { - return $configurableAttributes; - } - } - } - return false; - } - /** * Reset the cached configurable attributes of a product * @@ -463,13 +440,7 @@ protected function hasCacheData($configurableAttributes) */ public function resetConfigurableAttributes($product) { - $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class); - $productId = $product->getData($metadata->getLinkField()); $product->unsetData($this->_configurableAttributes); - $cacheId = __CLASS__ . $productId . '_' . $product->getStoreId(); - $this->getCache()->remove($cacheId); - $this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [self::TYPE_CODE . '_' . $productId]); - return $this; } @@ -566,7 +537,7 @@ public function getUsedProducts($product, $requiredAttributeIds = null) ) ); $collection = $this->getUsedProductCollection($product); - $data = unserialize($this->getCache()->load($key)); + $data = $this->serializer->unserialize($this->getCache()->load($key)); if (!empty($data)) { $usedProducts = []; foreach ($data as $item) { @@ -592,7 +563,7 @@ public function getUsedProducts($product, $requiredAttributeIds = null) $usedProducts = $collection->getItems(); $this->getCache()->save( - serialize(array_map( + $this->serializer->serialize(array_map( function ($item) { return $item->getData(); }, @@ -906,7 +877,7 @@ public function getSelectedAttributesInfo($product) 'value' => $value, 'option_id' => $attributeId, 'option_value' => $attributeValue - ]; + ]; } } } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php index 4f7ae98cc11ce..cd36c03e7e99b 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php @@ -15,7 +15,15 @@ use Magento\Framework\EntityManager\EntityMetadata; use Magento\Framework\EntityManager\MetadataPool; use Magento\Customer\Model\Session; -use Magento\Framework\Cache\FrontendInterface; +use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\CollectionFactory; +use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection; +use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface; +use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; +use Magento\ConfigurableProduct\Model\Product\Type\Configurable\AttributeFactory; +use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\ConfigurableFactory; +use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend; +use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource; +use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection as ProductCollection; /** * Class \Magento\ConfigurableProduct\Test\Unit\Model\Product\Type\ConfigurableTest @@ -94,6 +102,9 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase /** @var \PHPUnit_Framework_MockObject_MockObject */ private $cache; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + private $serializer; + /** * @var Config */ @@ -105,76 +116,67 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->_objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $eventManager = $this->getMock(\Magento\Framework\Event\ManagerInterface::class, [], [], '', false); - $fileStorageDbMock = $this->getMock( - \Magento\MediaStorage\Helper\File\Storage\Database::class, - [], - [], - '', - false - ); + $eventManager = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $fileStorageDbMock = $this->getMockBuilder(\Magento\MediaStorage\Helper\File\Storage\Database::class) + ->disableOriginalConstructor() + ->getMock(); $filesystem = $this->getMockBuilder(\Magento\Framework\Filesystem::class) ->disableOriginalConstructor() ->getMock(); - $coreRegistry = $this->getMock(\Magento\Framework\Registry::class, [], [], '', false); + $coreRegistry = $this->getMockBuilder(\Magento\Framework\Registry::class) + ->disableOriginalConstructor() + ->getMock(); $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class) ->disableOriginalConstructor() - ->setMethods([]) - ->getMockForAbstractClass(); - $this->_typeConfigurableFactory = $this->getMock( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\ConfigurableFactory::class, - ['create', 'saveProducts'], - [], - '', - false - ); - $this->_configurableAttributeFactoryMock = $this->getMock( - \Magento\ConfigurableProduct\Model\Product\Type\Configurable\AttributeFactory::class, - ['create'], - [], - '', - false - ); - $this->_productCollectionFactory = $this->getMock( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory::class, - ['create'], - [], - '', - false - ); - $this->_attributeCollectionFactory = $this->getMock( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\CollectionFactory::class, - ['create'], - [], - '', - false - ); - $this->productRepository = $this->getMock(\Magento\Catalog\Api\ProductRepositoryInterface::class); - $this->extensionAttributesJoinProcessorMock = $this->getMock( - \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface::class, - [], - [], - '', - false - ); + ->getMock(); + $this->_typeConfigurableFactory = $this->getMockBuilder(ConfigurableFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create', 'saveProducts']) + ->getMock(); + $this->_configurableAttributeFactoryMock = $this->getMockBuilder(AttributeFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->_productCollectionFactory = $this->getMockBuilder( + \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->_attributeCollectionFactory = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->productRepository = $this->getMockBuilder(\Magento\Catalog\Api\ProductRepositoryInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->extensionAttributesJoinProcessorMock = $this->getMockBuilder(JoinProcessorInterface::class) + ->disableOriginalConstructor() + ->getMock(); $this->entityMetadata = $this->getMockBuilder(EntityMetadata::class) ->disableOriginalConstructor() ->getMock(); $this->metadataPool = $this->getMockBuilder(MetadataPool::class) ->disableOriginalConstructor() ->getMock(); - $this->metadataPool->expects($this->any()) - ->method('getMetadata') - ->with(ProductInterface::class) - ->willReturn($this->entityMetadata); $this->cache = $this->getMockBuilder(\Magento\Framework\Cache\FrontendInterface::class) - ->getMockForAbstractClass(); + ->disableOriginalConstructor() + ->getMock(); $this->catalogConfig = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->getMock(); - - $this->eavConfig = $this->getMockBuilder(\Magento\Eav\Model\Config::class)->disableOriginalConstructor() + $this->eavConfig = $this->getMockBuilder(\Magento\Eav\Model\Config::class) + ->disableOriginalConstructor() ->getMock(); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->metadataPool->expects($this->any()) + ->method('getMetadata') + ->with(ProductInterface::class) + ->willReturn($this->entityMetadata); $this->_model = $this->_objectHelper->getObject( Configurable::class, @@ -194,6 +196,7 @@ protected function setUp() 'customerSession' => $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(), 'cache' => $this->cache, 'catalogConfig' => $this->catalogConfig, + 'serializer' => $this->serializer, ] ); $refClass = new \ReflectionClass(Configurable::class); @@ -223,19 +226,20 @@ public function testSave() 'getData', 'hasData', 'getAssociatedProductIds', - '__wakeup', - '__sleep', ] )->disableOriginalConstructor() ->getMock(); - $product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue('false')); - $product->expects($this->any())->method('getConfigurableAttributesData') - ->will($this->returnValue($this->attributeData)); - $product->expects($this->once())->method('getIsDuplicate')->will($this->returnValue(true)); - $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1)); - $product->expects($this->any())->method('getAssociatedProductIds')->will($this->returnValue([2])); - $product->expects($this->any())->method('hasData')->with('_cache_instance_used_product_attribute_ids') - ->will($this->returnValue(true)); + $product->expects($this->once())->method('dataHasChangedFor')->willReturn('false'); + $product->expects($this->once()) + ->method('getConfigurableAttributesData') + ->willReturn($this->attributeData); + $product->expects($this->once())->method('getIsDuplicate')->willReturn(true); + $product->expects($this->atLeastOnce())->method('getStoreId')->willReturn(1); + $product->expects($this->once())->method('getAssociatedProductIds')->willReturn([2]); + $product->expects($this->once()) + ->method('hasData') + ->with('_cache_instance_used_product_attribute_ids') + ->willReturn(true); $extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class) ->setMethods([ 'getConfigurableProductOptions', @@ -250,7 +254,7 @@ public function testSave() ['_cache_instance_used_product_attribute_ids', null, 1], ['link', null, 1], ]; - $product->expects($this->any()) + $product->expects($this->atLeastOnce()) ->method('getData') ->willReturnMap($dataMap); $attribute = $this->getMockBuilder( @@ -260,24 +264,26 @@ public function testSave() ->getMock(); $expectedAttributeData = $this->attributeData[1]; unset($expectedAttributeData['id']); - $attribute->expects($this->once())->method('addData')->with($expectedAttributeData)->will($this->returnSelf()); - $attribute->expects($this->once())->method('setStoreId')->with(1)->will($this->returnSelf()); - $attribute->expects($this->once())->method('setProductId')->with(1)->will($this->returnSelf()); - $attribute->expects($this->once())->method('save')->will($this->returnSelf()); - - $this->_configurableAttributeFactoryMock->expects($this->any())->method('create') - ->will($this->returnValue($attribute)); - - $attributeCollection = $this->getMockBuilder( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::class - )->setMethods(['setProductFilter', 'addFieldToFilter', 'walk'])->disableOriginalConstructor() - ->getMock(); - $this->_attributeCollectionFactory->expects($this->any())->method('create') - ->will($this->returnValue($attributeCollection)); - - $this->_typeConfigurableFactory->expects($this->once())->method('create')->will($this->returnSelf()); - $this->_typeConfigurableFactory->expects($this->once())->method('saveProducts')->withAnyParameters() - ->will($this->returnSelf()); + $attribute->expects($this->once())->method('addData')->with($expectedAttributeData)->willReturnSelf(); + $attribute->expects($this->once())->method('setStoreId')->with(1)->willReturnSelf(); + $attribute->expects($this->once())->method('setProductId')->with(1)->willReturnSelf(); + $attribute->expects($this->once())->method('save')->willReturnSelf(); + + $this->_configurableAttributeFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($attribute); + $attributeCollection = $this->getMockBuilder(Collection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->_attributeCollectionFactory->expects($this->once()) + ->method('create') + ->willReturn($attributeCollection); + $this->_typeConfigurableFactory->expects($this->once()) + ->method('create') + ->willReturnSelf(); + $this->_typeConfigurableFactory->expects($this->once()) + ->method('saveProducts') + ->willReturnSelf(); $this->_model->save($product); } @@ -293,174 +299,117 @@ public function testGetRelationInfo() public function testCanUseAttribute() { - $attribute = $this->getMock( - \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class, - [ - 'getIsGlobal', - 'getIsVisible', - 'usesSource', - 'getIsUserDefined', - '__wakeup', - '__sleep' - ], - [], - '', - false - ); + $attribute = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class) + ->disableOriginalConstructor() + ->getMock(); $attribute->expects($this->once()) ->method('getIsGlobal') - ->will($this->returnValue(1)); + ->willReturn(1); $attribute->expects($this->once()) ->method('getIsVisible') - ->will($this->returnValue(1)); + ->willReturn(1); $attribute->expects($this->once()) ->method('usesSource') - ->will($this->returnValue(1)); + ->willReturn(1); $attribute->expects($this->once()) ->method('getIsUserDefined') - ->will($this->returnValue(1)); + ->willReturn(1); $this->assertTrue($this->_model->canUseAttribute($attribute)); } public function testGetUsedProducts() { - $attributeCollection = $this->getMockBuilder( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::class - )->setMethods(['setProductFilter', 'addFieldToFilter', 'walk'])->disableOriginalConstructor() + $productCollectionItemData = ['array']; + + $productCollectionItem = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $attributeCollection = $this->getMockBuilder(Collection::class) + ->disableOriginalConstructor() ->getMock(); - $attributeCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); - $this->_attributeCollectionFactory->expects($this->any())->method('create') - ->will($this->returnValue($attributeCollection)); $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'dataHasChangedFor', - 'getConfigurableAttributesData', - 'getStoreId', - 'getId', - 'getData', - 'hasData', - 'getAssociatedProductIds', - 'getIdentities', - '__wakeup', - '__sleep', - ] - )->disableOriginalConstructor() + ->disableOriginalConstructor() + ->getMock(); + $productCollection = $this->getMockBuilder(ProductCollection::class) + ->disableOriginalConstructor() ->getMock(); - $product->expects($this->any())->method('getConfigurableAttributesData') - ->will($this->returnValue($this->attributeData)); - $product->expects($this->any())->method('getStoreId')->will($this->returnValue(5)); - $product->expects($this->any())->method('getId')->will($this->returnValue(1)); - $product->expects($this->any())->method('getIdentities')->willReturn(['123']); - $product->expects($this->any())->method('getAssociatedProductIds')->will($this->returnValue([2])); - $product->expects($this->any())->method('hasData') - ->will( - $this->returnValueMap( - [ - ['_cache_instance_used_product_attribute_ids', 1], - ['_cache_instance_products', 0], - ['_cache_instance_configurable_attributes', 1], - ['_cache_instance_used_product_attributes', 1], - ] - ) + $productCollectionItem->expects($this->once())->method('getData')->willReturn($productCollectionItemData); + $attributeCollection->expects($this->any())->method('setProductFilter')->willReturnSelf(); + $product->expects($this->atLeastOnce())->method('getStoreId')->willReturn(5); + $product->expects($this->once())->method('getIdentities')->willReturn(['123']); + + $product->expects($this->exactly(2)) + ->method('hasData') + ->willReturnMap( + [ + ['_cache_instance_products', null], + ['_cache_instance_used_product_attributes', 1], + ] ); - $product->expects($this->any())->method('getData') - ->will($this->returnValueMap( + $product->expects($this->any()) + ->method('getData') + ->willReturnMap( [ - ['_cache_instance_used_product_attributes', null, []], + ['_cache_instance_used_product_attributes', null, []] ] - )); - - - $productCollection = $this->getMockBuilder( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection::class - )->setMethods( - [ - 'setFlag', - 'setProductFilter', - 'addStoreFilter', - 'addAttributeToSelect', - 'addFilterByRequiredOptions', - 'setStoreId', - 'addTierPriceData', - 'getIterator', - 'load', - ] - )->disableOriginalConstructor() - ->getMock(); - $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('addTierPriceData')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('addFilterByRequiredOptions')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('setStoreId')->with(5)->will($this->returnValue([])); - $productCollection->expects($this->any())->method('getIterator')->willReturn( - new \ArrayIterator([]) - ); - + ); - $this->_productCollectionFactory->expects($this->any())->method('create') - ->will($this->returnValue($productCollection)); + $productCollection->expects($this->atLeastOnce())->method('addAttributeToSelect')->willReturnSelf(); + $productCollection->expects($this->once())->method('setProductFilter')->willReturnSelf(); + $productCollection->expects($this->atLeastOnce())->method('setFlag')->willReturnSelf(); + $productCollection->expects($this->once())->method('addTierPriceData')->willReturnSelf(); + $productCollection->expects($this->once())->method('addFilterByRequiredOptions')->willReturnSelf(); + $productCollection->expects($this->once())->method('setStoreId')->with(5)->willReturn([]); + $productCollection->expects($this->once())->method('getItems')->willReturn([$productCollectionItem]); + + $this->serializer->expects($this->once())->method('unserialize')->willReturn([]); + $this->serializer->expects($this->once()) + ->method('serialize') + ->with([$productCollectionItemData]) + ->willReturn('result'); + + $this->_productCollectionFactory->expects($this->any())->method('create')->willReturn($productCollection); $this->_model->getUsedProducts($product); } /** * @param int $productStore - * @param int $attributeStore * * @dataProvider getConfigurableAttributesAsArrayDataProvider */ - public function testGetConfigurableAttributesAsArray($productStore, $attributeStore) + public function testGetConfigurableAttributesAsArray($productStore) { - $attributeSource = $this->getMockForAbstractClass( - \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::class, - [], - '', - false, - true, - true, - ['getAllOptions'] - ); - $attributeSource->expects($this->any())->method('getAllOptions')->will($this->returnValue([])); - - $attributeFrontend = $this->getMockForAbstractClass( - \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend::class, - [], - '', - false, - true, - true, - ['getLabel'] - ); - $attributeFrontend->expects($this->any())->method('getLabel')->will($this->returnValue('Label')); - - $eavAttribute = $this->getMock( - \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class, - ['getFrontend', 'getSource', 'getStoreLabel', '__wakeup', 'setStoreId', '__sleep'], - [], - '', - false - ); - $eavAttribute->expects($this->any())->method('getFrontend')->will($this->returnValue($attributeFrontend)); - $eavAttribute->expects($this->any())->method('getSource')->will($this->returnValue($attributeSource)); - $eavAttribute->expects($this->any())->method('getStoreLabel')->will($this->returnValue('Store Label')); - $eavAttribute->expects($this->any())->method('setStoreId')->with($attributeStore); + $attributeSource = $this->getMockBuilder(AbstractSource::class) + ->disableOriginalConstructor() + ->getMock(); + $attributeFrontend = $this->getMockBuilder(AbstractFrontend::class) + ->disableOriginalConstructor() + ->getMock(); + $eavAttribute = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class) + ->disableOriginalConstructor() + ->getMock(); + + $attributeSource->expects($this->once())->method('getAllOptions')->willReturn([]); + $attributeFrontend->expects($this->once())->method('getLabel')->willReturn('Label'); + $eavAttribute->expects($this->once())->method('getFrontend')->willReturn($attributeFrontend); + $eavAttribute->expects($this->once())->method('getSource')->willReturn($attributeSource); + $eavAttribute->expects($this->atLeastOnce())->method('getStoreLabel')->willReturn('Store Label'); $attribute = $this->getMockBuilder( \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class) ->disableOriginalConstructor() ->setMethods(['getProductAttribute', '__wakeup', '__sleep']) ->getMock(); - $attribute->expects($this->any())->method('getProductAttribute')->will($this->returnValue($eavAttribute)); + $attribute->expects($this->any())->method('getProductAttribute')->willReturn($eavAttribute); $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->setMethods(['getStoreId', 'getData', 'hasData', '__wakeup', '__sleep']) ->disableOriginalConstructor() ->getMock(); - $product->expects($this->any())->method('getStoreId')->will($this->returnValue($productStore)); - $product->expects($this->any())->method('hasData') + $product->expects($this->atLeastOnce())->method('getStoreId')->willReturn($productStore); + $product->expects($this->atLeastOnce())->method('hasData') ->will( $this->returnValueMap( [ @@ -487,69 +436,56 @@ public function testGetConfigurableAttributesAsArray($productStore, $attributeSt public function getConfigurableAttributesAsArrayDataProvider() { return [ - [5, 5], - [null, 0], + [5], + [null], ]; } public function testGetConfigurableAttributes() { - $expectedData = [1]; $configurableAttributes = '_cache_instance_configurable_attributes'; /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */ $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['getData', 'hasData', 'setData', 'getIdentities', 'getId', 'getStoreId']) + ->setMethods(['getData', 'hasData', 'setData']) ->disableOriginalConstructor() ->getMock(); - $product->expects($this->once())->method('hasData')->with($configurableAttributes)->willReturn(false); - $product->expects($this->once())->method('getStoreId')->willReturn(0); - $product->expects($this->any())->method('getId')->willReturn(0); - $product->expects($this->any())->method('getIdentities')->willReturn(['123']); - $product->expects($this->once())->method('setData')->willReturnSelf(); - $product->expects($this->exactly(2)) - ->method('getData') - ->willReturnMap( - [ - [$configurableAttributes, null, $expectedData], - ['link', null, 1], - ] - ); - $product->expects($this->once())->method('getIdentities')->willReturn([1,2,3]); - $this->entityMetadata->expects($this->once()) - ->method('getLinkField') - ->willReturn('link'); + $product->expects($this->once())->method('hasData')->with($configurableAttributes)->willReturn(false); - $attributeCollection = $this->getMockBuilder( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::class - ) + $attributeCollection = $this->getMockBuilder(Collection::class) ->setMethods(['setProductFilter', 'orderByPosition', 'load']) ->disableOriginalConstructor() ->getMock(); - $attributeCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); - $attributeCollection->expects($this->any())->method('orderByPosition')->will($this->returnSelf()); - $this->_attributeCollectionFactory->expects($this->any())->method('create')->willReturn($attributeCollection); + $attributeCollection->expects($this->once())->method('setProductFilter')->willReturnSelf(); + $attributeCollection->expects($this->once())->method('orderByPosition')->willReturnSelf(); + $attributeCollection->expects($this->once())->method('load')->willReturnSelf(); - $this->extensionAttributesJoinProcessorMock->expects($this->once()) - ->method('process') - ->with( - $this->isInstanceOf(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::class - ) - ); + $this->_attributeCollectionFactory->expects($this->once())->method('create')->willReturn($attributeCollection); - $this->assertEquals($expectedData, $this->_model->getConfigurableAttributes($product)); + $product->expects($this->once()) + ->method('setData') + ->with($configurableAttributes, $attributeCollection) + ->willReturnSelf(); + + $product->expects($this->once()) + ->method('getData') + ->with($configurableAttributes) + ->willReturn($attributeCollection); + + $this->assertEquals($attributeCollection, $this->_model->getConfigurableAttributes($product)); } public function testResetConfigurableAttributes() { $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['unsetData', '__wakeup', '__sleep', 'getStoreId', 'getId']) + ->setMethods(['unsetData']) ->disableOriginalConstructor() ->getMock(); - $product->expects($this->any())->method('unsetData') + $product->expects($this->once()) + ->method('unsetData') ->with('_cache_instance_configurable_attributes') - ->will($this->returnSelf()); + ->willReturnSelf(); $this->assertEquals($this->_model, $this->_model->resetConfigurableAttributes($product)); } @@ -630,12 +566,9 @@ public function testIsSalable() public function testGetSelectedAttributesInfo() { $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getCustomOption', 'hasData', 'getData']) ->disableOriginalConstructor() ->getMock(); - $optionMock = $this->getMockBuilder( - \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface::class) - ->setMethods(['getValue']) + $optionMock = $this->getMockBuilder(OptionInterface::class) ->disableOriginalConstructor() ->getMock(); $usedAttributeMock = $this->getMockBuilder( @@ -645,7 +578,6 @@ public function testGetSelectedAttributesInfo() ->disableOriginalConstructor() ->getMock(); $attributeMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class) - ->setMethods(['getStoreLabel', 'getSourceModel']) ->disableOriginalConstructor() ->getMock(); @@ -662,10 +594,10 @@ public function testGetSelectedAttributesInfo() $this->_model->getSelectedAttributesInfo($productMock), [ [ - 'label' => 'attr_store_label', - 'value' => '', - 'option_id' => 1, - 'option_value' => '' + 'label' => 'attr_store_label', + 'value' => '', + 'option_id' => 1, + 'option_value' => '' ] ] ); @@ -675,11 +607,9 @@ public function testCheckProductBuyState() { $this->markTestIncomplete('checkProductBuyState() method is not complete in parent class'); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getCustomOption', 'getSkipCheckRequiredOption']) ->disableOriginalConstructor() ->getMock(); $optionMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Option::class) - ->setMethods(['getValue']) ->disableOriginalConstructor() ->getMock(); @@ -703,11 +633,9 @@ public function testCheckProductBuyStateException() { $this->markTestIncomplete('checkProductBuyState() method is not complete in parent class'); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getCustomOption', 'getSkipCheckRequiredOption']) ->disableOriginalConstructor() ->getMock(); $optionMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Option::class) - ->setMethods(['getValue']) ->disableOriginalConstructor() ->getMock(); @@ -724,47 +652,29 @@ public function testCheckProductBuyStateException() public function testGetProductByAttributesReturnUsedProduct() { $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'hasData', 'getData', 'getResource', 'getAttributeSetId']) ->disableOriginalConstructor() ->getMock(); $firstItemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getId']) ->disableOriginalConstructor() ->getMock(); $usedProductMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getData']) ->disableOriginalConstructor() ->getMock(); $eavAttributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class) - ->setMethods(['__wakeup', 'getId', 'getAttributeCode']) ->disableOriginalConstructor() ->getMock(); - $productCollection = $this->getMockBuilder( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection::class - ) - ->setMethods( - [ - 'setFlag', - 'setProductFilter', - 'addStoreFilter', - 'addAttributeToSelect', - 'addAttributeToFilter', - 'getFirstItem', - 'getIterator' - ] - ) + $productCollection = $this->getMockBuilder(ProductCollection::class) ->disableOriginalConstructor() ->getMock(); - $this->_productCollectionFactory->expects($this->any())->method('create') - ->will($this->returnValue($productCollection)); - $productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('addAttributeToFilter')->will($this->returnSelf()); + $this->_productCollectionFactory->expects($this->once())->method('create')->willReturn($productCollection); + $productCollection->expects($this->once())->method('setProductFilter')->willReturnSelf(); + $productCollection->expects($this->once())->method('setFlag')->willReturnSelf(); + $productCollection->expects($this->once())->method('addAttributeToSelect')->willReturnSelf(); + $productCollection->expects($this->once())->method('addAttributeToFilter')->willReturnSelf(); $productCollection->expects($this->once())->method('getFirstItem')->willReturn($firstItemMock); - $productCollection->expects($this->any())->method('getIterator')->willReturn( - new \ArrayIterator([$usedProductMock]) + $productCollection->expects($this->once())->method('getIterator')->willReturn( + new \ArrayIterator([$usedProductMock]) ); $firstItemMock->expects($this->once())->method('getId')->willReturn(false); @@ -789,42 +699,24 @@ public function testGetProductByAttributesReturnUsedProduct() public function testGetProductByAttributesReturnFirstItem() { $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'hasData', 'getData', 'getResource', 'getAttributeSetId']) ->disableOriginalConstructor() ->getMock(); $firstItemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getId']) ->disableOriginalConstructor() ->getMock(); - $productCollection = $this->getMockBuilder( - \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection::class - ) - ->setMethods( - [ - 'setFlag', - 'setProductFilter', - 'addStoreFilter', - 'addAttributeToSelect', - 'addAttributeToFilter', - 'getFirstItem', - ] - ) + $productCollection = $this->getMockBuilder(ProductCollection::class) ->disableOriginalConstructor() ->getMock(); - $this->_productCollectionFactory->expects($this->any())->method('create') - ->will($this->returnValue($productCollection)); - $productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf()); - $productCollection->expects($this->any())->method('addAttributeToFilter')->will($this->returnSelf()); + $this->_productCollectionFactory->expects($this->any())->method('create')->willReturn($productCollection); + $productCollection->expects($this->once())->method('setProductFilter')->willReturnSelf(); + $productCollection->expects($this->once())->method('setFlag')->willReturnSelf(); + $productCollection->expects($this->once())->method('addAttributeToSelect')->willReturnSelf(); + $productCollection->expects($this->once())->method('addAttributeToFilter')->willReturnSelf(); $productCollection->expects($this->once())->method('getFirstItem')->willReturn($firstItemMock); - $firstItemMock->expects(static::once()) - ->method('getId') - ->willReturn(3); + $firstItemMock->expects($this->once())->method('getId')->willReturn(3); $this->productRepository->expects($this->once())->method('getById')->with(3)->willReturn($firstItemMock); - $this->assertEquals( $firstItemMock, $this->_model->getProductByAttributes($this->attributeData, $productMock) @@ -834,11 +726,10 @@ public function testGetProductByAttributesReturnFirstItem() public function testSetImageFromChildProduct() { $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'hasData', 'getData', 'setImage']) + ->setMethods(['hasData', 'getData', 'setImage']) ->disableOriginalConstructor() ->getMock(); $childProductMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getData']) ->disableOriginalConstructor() ->getMock(); From 92b98ac544382f8ee8190bb6832127ba0e8aff71 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 09:56:32 -0600 Subject: [PATCH 031/132] MAGETWO-61872: Create FieldDataConverter Implementing FieldDataConverter --- .../DataConverter/DataConverterInterface.php | 6 +++--- .../{Setup => DB}/DataConverter/SerializedToJson.php | 2 +- .../Framework/{Setup => DB}/FieldDataConverter.php | 4 ++-- .../Framework/{Setup => DB}/FieldDataConverterFactory.php | 4 ++-- .../Test/Unit/DataConverter/SerializedToJsonTest.php | 2 +- .../Test/Unit/FieldDataConverterFactoryTest.php | 8 ++++---- .../{Setup => DB}/Test/Unit/FieldDataConverterTest.php | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) rename lib/internal/Magento/Framework/{Setup => DB}/DataConverter/DataConverterInterface.php (70%) rename lib/internal/Magento/Framework/{Setup => DB}/DataConverter/SerializedToJson.php (95%) rename lib/internal/Magento/Framework/{Setup => DB}/FieldDataConverter.php (94%) rename lib/internal/Magento/Framework/{Setup => DB}/FieldDataConverterFactory.php (92%) rename lib/internal/Magento/Framework/{Setup => DB}/Test/Unit/DataConverter/SerializedToJsonTest.php (96%) rename lib/internal/Magento/Framework/{Setup => DB}/Test/Unit/FieldDataConverterFactoryTest.php (91%) rename lib/internal/Magento/Framework/{Setup => DB}/Test/Unit/FieldDataConverterTest.php (95%) diff --git a/lib/internal/Magento/Framework/Setup/DataConverter/DataConverterInterface.php b/lib/internal/Magento/Framework/DB/DataConverter/DataConverterInterface.php similarity index 70% rename from lib/internal/Magento/Framework/Setup/DataConverter/DataConverterInterface.php rename to lib/internal/Magento/Framework/DB/DataConverter/DataConverterInterface.php index 0ddab69cb9c89..a2ca45ea638de 100644 --- a/lib/internal/Magento/Framework/Setup/DataConverter/DataConverterInterface.php +++ b/lib/internal/Magento/Framework/DB/DataConverter/DataConverterInterface.php @@ -3,7 +3,7 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\DataConverter; +namespace Magento\Framework\DB\DataConverter; /** * Convert from one format to another @@ -13,8 +13,8 @@ interface DataConverterInterface /** * Convert from one format to another * - * @param string $string + * @param string $value * @return string */ - public function convert($string); + public function convert($value); } diff --git a/lib/internal/Magento/Framework/Setup/DataConverter/SerializedToJson.php b/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php similarity index 95% rename from lib/internal/Magento/Framework/Setup/DataConverter/SerializedToJson.php rename to lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php index 08b076be94414..05416a49ff817 100644 --- a/lib/internal/Magento/Framework/Setup/DataConverter/SerializedToJson.php +++ b/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php @@ -3,7 +3,7 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\DataConverter; +namespace Magento\Framework\DB\DataConverter; use Magento\Framework\Serialize\Serializer\Serialize; use Magento\Framework\Serialize\Serializer\Json; diff --git a/lib/internal/Magento/Framework/Setup/FieldDataConverter.php b/lib/internal/Magento/Framework/DB/FieldDataConverter.php similarity index 94% rename from lib/internal/Magento/Framework/Setup/FieldDataConverter.php rename to lib/internal/Magento/Framework/DB/FieldDataConverter.php index c14fefad7353f..b9841a3cc90a7 100644 --- a/lib/internal/Magento/Framework/Setup/FieldDataConverter.php +++ b/lib/internal/Magento/Framework/DB/FieldDataConverter.php @@ -3,11 +3,11 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\DB; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Query\Generator; -use Magento\Framework\Setup\DataConverter\DataConverterInterface; +use Magento\Framework\DB\DataConverter\DataConverterInterface; /** * Convert field data from one representation to another diff --git a/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php b/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php similarity index 92% rename from lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php rename to lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php index 911ec637066bf..0c7c339e76e58 100644 --- a/lib/internal/Magento/Framework/Setup/FieldDataConverterFactory.php +++ b/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php @@ -3,11 +3,11 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup; +namespace Magento\Framework\DB; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\DB\Adapter\AdapterInterface; -use Magento\Framework\Setup\DataConverter\DataConverterInterface; +use Magento\Framework\DB\DataConverter\DataConverterInterface; /** * Create instance of FieldDataConverter with concrete implementation of DataConverterInterface diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/DataConverter/SerializedToJsonTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/DataConverter/SerializedToJsonTest.php similarity index 96% rename from lib/internal/Magento/Framework/Setup/Test/Unit/DataConverter/SerializedToJsonTest.php rename to lib/internal/Magento/Framework/DB/Test/Unit/DataConverter/SerializedToJsonTest.php index e7119040e02b9..bd7a163210125 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/DataConverter/SerializedToJsonTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/DataConverter/SerializedToJsonTest.php @@ -7,7 +7,7 @@ use Magento\Framework\Serialize\Serializer\Serialize; use Magento\Framework\Serialize\Serializer\Json; -use Magento\Framework\Setup\DataConverter\SerializedToJson; +use Magento\Framework\DB\DataConverter\SerializedToJson; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; class SerializedToJsonTest extends \PHPUnit_Framework_TestCase diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterFactoryTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterFactoryTest.php similarity index 91% rename from lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterFactoryTest.php rename to lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterFactoryTest.php index e08e1ee749666..9518bddeff6fa 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterFactoryTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterFactoryTest.php @@ -3,14 +3,14 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\Test\Unit; +namespace Magento\Framework\DB\Test\Unit; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Framework\Setup\FieldDataConverterFactory; +use Magento\Framework\DB\FieldDataConverterFactory; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\DB\Adapter\AdapterInterface; -use Magento\Framework\Setup\FieldDataConverter; -use Magento\Framework\Setup\DataConverter\DataConverterInterface; +use Magento\Framework\DB\FieldDataConverter; +use Magento\Framework\DB\DataConverter\DataConverterInterface; class FieldDataConverterFactoryTest extends \PHPUnit_Framework_TestCase { diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php similarity index 95% rename from lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterTest.php rename to lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php index 9c16d1ea0123c..b2fd4e987fb85 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/FieldDataConverterTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php @@ -3,13 +3,13 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\Test\Unit; +namespace Magento\Framework\DB\Test\Unit; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\DB\Query\Generator; use Magento\Framework\DB\Adapter\AdapterInterface; -use Magento\Framework\Setup\FieldDataConverter; -use Magento\Framework\Setup\DataConverter\DataConverterInterface; +use Magento\Framework\DB\FieldDataConverter; +use Magento\Framework\DB\DataConverter\DataConverterInterface; use Magento\Framework\DB\Select; class FieldDataConverterTest extends \PHPUnit_Framework_TestCase From 357882074567a096305e44359c8c5d385160d43d Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 10:25:06 -0600 Subject: [PATCH 032/132] MAGETWO-61872: Create FieldDataConverter Removing dependency on connection from constructor --- .../Magento/Framework/DB/FieldDataConverter.php | 17 +++++------------ .../Framework/DB/FieldDataConverterFactory.php | 5 +---- .../Test/Unit/FieldDataConverterFactoryTest.php | 10 +--------- .../DB/Test/Unit/FieldDataConverterTest.php | 3 +-- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/lib/internal/Magento/Framework/DB/FieldDataConverter.php b/lib/internal/Magento/Framework/DB/FieldDataConverter.php index b9841a3cc90a7..55bd6ae0d1805 100644 --- a/lib/internal/Magento/Framework/DB/FieldDataConverter.php +++ b/lib/internal/Magento/Framework/DB/FieldDataConverter.php @@ -14,11 +14,6 @@ */ class FieldDataConverter { - /** - * @var AdapterInterface - */ - private $connection; - /** * @var Generator */ @@ -32,16 +27,13 @@ class FieldDataConverter /** * Constructor * - * @param AdapterInterface $connection * @param Generator $queryGenerator * @param DataConverterInterface $dataConverter */ public function __construct( - AdapterInterface $connection, Generator $queryGenerator, DataConverterInterface $dataConverter ) { - $this->connection = $connection; $this->queryGenerator = $queryGenerator; $this->dataConverter = $dataConverter; } @@ -49,23 +41,24 @@ public function __construct( /** * Convert field data from one representation to another * + * @param AdapterInterface $connection * @param string $table * @param string $identifier * @param string $field * @return void */ - public function convert($table, $identifier, $field) + public function convert(AdapterInterface $connection, $table, $identifier, $field) { - $select = $this->connection->select() + $select = $connection->select() ->from($table, [$identifier, $field]) ->where($field . ' IS NOT NULL'); $iterator = $this->queryGenerator->generate($identifier, $select); foreach ($iterator as $selectByRange) { - $rows = $this->connection->fetchAll($selectByRange); + $rows = $connection->fetchAll($selectByRange); foreach ($rows as $row) { $bind = [$field => $this->dataConverter->convert($row[$field])]; $where = [$identifier . ' = ?' => (int) $row[$identifier]]; - $this->connection->update($table, $bind, $where); + $connection->update($table, $bind, $where); } } } diff --git a/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php b/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php index 0c7c339e76e58..cff9cd8d04a93 100644 --- a/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php +++ b/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php @@ -6,7 +6,6 @@ namespace Magento\Framework\DB; use Magento\Framework\ObjectManagerInterface; -use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\DataConverter\DataConverterInterface; /** @@ -33,16 +32,14 @@ public function __construct( /** * Create instance of FieldDataConverter * - * @param AdapterInterface $connection * @param string $dataConverterClassName * @return FieldDataConverter */ - public function create(AdapterInterface $connection, $dataConverterClassName) + public function create($dataConverterClassName) { return $this->objectManager->create( FieldDataConverter::class, [ - 'connection' => $connection, 'dataConverter' => $this->objectManager->get($dataConverterClassName) ] ); diff --git a/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterFactoryTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterFactoryTest.php index 9518bddeff6fa..266f9e9ceceae 100644 --- a/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterFactoryTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterFactoryTest.php @@ -8,7 +8,6 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\DB\FieldDataConverterFactory; use Magento\Framework\ObjectManagerInterface; -use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\FieldDataConverter; use Magento\Framework\DB\DataConverter\DataConverterInterface; @@ -19,11 +18,6 @@ class FieldDataConverterFactoryTest extends \PHPUnit_Framework_TestCase */ private $objectManagerMock; - /** - * @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $connectionMock; - /** * @var DataConverterInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -38,7 +32,6 @@ protected function setUp() { $objectManager = new ObjectManager($this); $this->objectManagerMock = $this->getMock(ObjectManagerInterface::class); - $this->connectionMock = $this->getMock(AdapterInterface::class); $this->dataConverterMock = $this->getMock(DataConverterInterface::class); $this->fieldDataConverterFactory = $objectManager->getObject( FieldDataConverterFactory::class, @@ -61,14 +54,13 @@ public function testCreate() ->with( FieldDataConverter::class, [ - 'connection' => $this->connectionMock, 'dataConverter' => $this->dataConverterMock ] ) ->willReturn($fieldDataConverterInstance); $this->assertEquals( $fieldDataConverterInstance, - $this->fieldDataConverterFactory->create($this->connectionMock, $dataConverterClassName) + $this->fieldDataConverterFactory->create($dataConverterClassName) ); } } diff --git a/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php index b2fd4e987fb85..f30dc4d1a3828 100644 --- a/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php @@ -49,7 +49,6 @@ protected function setUp() $this->fieldDataConverter = $objectManager->getObject( FieldDataConverter::class, [ - 'connection' => $this->connectionMock, 'queryGenerator' => $this->queryGeneratorMock, 'dataConverter' => $this->dataConverterMock ] @@ -103,6 +102,6 @@ public function testConvert() [$field => $convertedValue], [$identifier . ' = ?' => $rows[0][$identifier]] ); - $this->fieldDataConverter->convert($table, $identifier, $field); + $this->fieldDataConverter->convert($this->connectionMock, $table, $identifier, $field); } } From 539c5f62b6e8db4e90980dcba69339f89c857848 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 10:36:17 -0600 Subject: [PATCH 033/132] MAGETWO-61537: Create upgrade script for sales_payment_transaction table additional_information field Refactoring after changes to FieldDataConverter --- app/code/Magento/Sales/Setup/UpgradeData.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index ea40a4d7624c8..081c713a78541 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -24,7 +24,7 @@ class UpgradeData implements UpgradeDataInterface private $eavConfig; /** - * @var \Magento\Framework\Setup\FieldDataConverterFactory + * @var \Magento\Framework\DB\FieldDataConverterFactory */ private $fieldDataConverterFactory; @@ -33,12 +33,12 @@ class UpgradeData implements UpgradeDataInterface * * @param SalesSetupFactory $salesSetupFactory * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\Setup\FieldDataConverterFactory $fieldDataConverterFactory + * @param \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory */ public function __construct( SalesSetupFactory $salesSetupFactory, \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\Setup\FieldDataConverterFactory $fieldDataConverterFactory + \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory ) { $this->salesSetupFactory = $salesSetupFactory; $this->eavConfig = $eavConfig; @@ -121,25 +121,28 @@ private function upgradeToTwoZeroOne(SalesSetup $setup) private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) { $fieldDataConverter = $this->fieldDataConverterFactory->create( - $setup->getConnection(), - \Magento\Framework\Setup\DataConverter\SerializedToJson::class + \Magento\Framework\DB\DataConverter\SerializedToJson::class ); $fieldDataConverter->convert( + $setup->getConnection(), $setup->getTable('sales_order_item'), 'item_id', 'product_options' ); $fieldDataConverter->convert( + $setup->getConnection(), $setup->getTable('sales_shipment'), 'entity_id', 'packages' ); $fieldDataConverter->convert( + $setup->getConnection(), $setup->getTable('sales_order_payment'), 'entity_id', 'additional_information' ); $fieldDataConverter->convert( + $setup->getConnection(), $setup->getTable('sales_payment_transaction'), 'transaction_id', 'additional_information' From e946717cdcf987a3df37edbd9468dcc319f8b601 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 10:45:33 -0600 Subject: [PATCH 034/132] MAGETWO-61526: Create upgrade script for quote_payment table additional_information field Refactoring after changes to FieldDataConverter --- app/code/Magento/Quote/Setup/UpgradeData.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index e93ed2bb055b8..5442355e6c3b9 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -17,7 +17,7 @@ class UpgradeData implements UpgradeDataInterface private $eavConfig; /** - * @var \Magento\Framework\Setup\FieldDataConverterFactory + * @var \Magento\Framework\DB\FieldDataConverterFactory */ private $fieldDataConverterFactory; @@ -25,11 +25,11 @@ class UpgradeData implements UpgradeDataInterface * Constructor * * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\Setup\FieldDataConverterFactory $fieldDataConverterFactory + * @param \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory */ public function __construct( \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\Setup\FieldDataConverterFactory $fieldDataConverterFactory + \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory ) { $this->eavConfig = $eavConfig; $this->fieldDataConverterFactory = $fieldDataConverterFactory; @@ -57,10 +57,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) { $fieldDataConverter = $this->fieldDataConverterFactory->create( - $setup->getConnection(), - \Magento\Framework\Setup\DataConverter\SerializedToJson::class + \Magento\Framework\DB\DataConverter\SerializedToJson::class ); $fieldDataConverter->convert( + $setup->getConnection(), $setup->getTable('quote_payment'), 'payment_id', 'additional_information' From e94d2af5cf8c4c20e16d605435f5d6be34319b2b Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 10:55:05 -0600 Subject: [PATCH 035/132] MAGETWO-61872: Create FieldDataConverter Renaming variable --- .../Magento/Framework/DB/DataConverter/SerializedToJson.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php b/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php index 05416a49ff817..ae675784021d4 100644 --- a/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php +++ b/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php @@ -40,11 +40,11 @@ public function __construct( /** * Convert from serialized to JSON format * - * @param string $string + * @param string $value * @return string */ - public function convert($string) + public function convert($value) { - return $this->json->serialize($this->serialize->unserialize($string)); + return $this->json->serialize($this->serialize->unserialize($value)); } } From 1179992f35239cd1070ecf2cfc3776a7bf2e758f Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 11:36:01 -0600 Subject: [PATCH 036/132] MAGETWO-61872: Create FieldDataConverter Fixing namespace --- .../DB/Test/Unit/DataConverter/SerializedToJsonTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/DB/Test/Unit/DataConverter/SerializedToJsonTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/DataConverter/SerializedToJsonTest.php index bd7a163210125..c84929f90c25c 100644 --- a/lib/internal/Magento/Framework/DB/Test/Unit/DataConverter/SerializedToJsonTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/DataConverter/SerializedToJsonTest.php @@ -3,7 +3,7 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\Setup\Test\Unit\DataConverter; +namespace Magento\Framework\DB\Test\Unit\DataConverter; use Magento\Framework\Serialize\Serializer\Serialize; use Magento\Framework\Serialize\Serializer\Json; From 4f148b660855f105794515b9eba05c347326b7a5 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 13:50:59 -0600 Subject: [PATCH 037/132] MAGETWO-61537: Create upgrade script for sales_payment_transaction table additional_information field Refactoring to use fully qualified names --- app/code/Magento/Sales/Setup/UpgradeData.php | 26 +++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 081c713a78541..9a42d07c588f9 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -5,16 +5,12 @@ */ namespace Magento\Sales\Setup; -use Magento\Framework\Setup\UpgradeDataInterface; -use Magento\Framework\Setup\ModuleContextInterface; -use Magento\Framework\Setup\ModuleDataSetupInterface; - -class UpgradeData implements UpgradeDataInterface +class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface { /** * Sales setup factory * - * @var SalesSetupFactory + * @var \Magento\Sales\Setup\SalesSetupFactory */ private $salesSetupFactory; @@ -31,12 +27,12 @@ class UpgradeData implements UpgradeDataInterface /** * Constructor * - * @param SalesSetupFactory $salesSetupFactory + * @param \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory */ public function __construct( - SalesSetupFactory $salesSetupFactory, + \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory ) { @@ -48,8 +44,10 @@ public function __construct( /** * {@inheritdoc} */ - public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { + public function upgrade( + \Magento\Framework\Setup\ModuleDataSetupInterface $setup, + \Magento\Framework\Setup\ModuleContextInterface $context + ) { $setup->startSetup(); $salesSetup = $this->salesSetupFactory->create(['setup' => $setup]); if (version_compare($context->getVersion(), '2.0.1', '<')) { @@ -65,10 +63,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface /** * Upgrade to version 2.0.1 * - * @param SalesSetup $setup + * @param \Magento\Sales\Setup\SalesSetup $setup * @return void */ - private function upgradeToTwoZeroOne(SalesSetup $setup) + private function upgradeToTwoZeroOne(\Magento\Sales\Setup\SalesSetup $setup) { $setup->updateEntityType( \Magento\Sales\Model\Order::ENTITY, @@ -115,10 +113,10 @@ private function upgradeToTwoZeroOne(SalesSetup $setup) /** * Upgrade to version 2.0.5 * - * @param ModuleDataSetupInterface $setup + * @param \Magento\Framework\Setup\ModuleDataSetupInterface $setup * @return void */ - private function upgradeToVersionTwoZeroFive(ModuleDataSetupInterface $setup) + private function upgradeToVersionTwoZeroFive(\Magento\Framework\Setup\ModuleDataSetupInterface $setup) { $fieldDataConverter = $this->fieldDataConverterFactory->create( \Magento\Framework\DB\DataConverter\SerializedToJson::class From d40256427033f8e409696d8f9d1354b129a9a6ac Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 14:23:57 -0600 Subject: [PATCH 038/132] MAGETWO-61526: Create upgrade script for quote_payment table additional_information field Removing unnecessary code --- app/code/Magento/Quote/Setup/UpgradeData.php | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 5442355e6c3b9..e6b8f9eba8b76 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -8,28 +8,31 @@ use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; +use Magento\Eav\Model\Config; +use Magento\Framework\DB\FieldDataConverterFactory; +use Magento\Framework\DB\DataConverter\SerializedToJson; class UpgradeData implements UpgradeDataInterface { /** - * @var \Magento\Eav\Model\Config + * @var Config */ private $eavConfig; /** - * @var \Magento\Framework\DB\FieldDataConverterFactory + * @var FieldDataConverterFactory */ private $fieldDataConverterFactory; /** * Constructor * - * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory + * @param Config $eavConfig + * @param FieldDataConverterFactory $fieldDataConverterFactory */ public function __construct( - \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory + Config $eavConfig, + FieldDataConverterFactory $fieldDataConverterFactory ) { $this->eavConfig = $eavConfig; $this->fieldDataConverterFactory = $fieldDataConverterFactory; @@ -40,25 +43,21 @@ public function __construct( */ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { - $setup->startSetup(); if (version_compare($context->getVersion(), '2.0.4', '<')) { $this->upgradeToVersionTwoZeroFour($setup); } $this->eavConfig->clear(); - $setup->endSetup(); } /** - * Upgrade to version 2.0.4 + * Convert data for additional_information field in quote_payment table from serialized to JSON format * * @param ModuleDataSetupInterface $setup * @return void */ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) { - $fieldDataConverter = $this->fieldDataConverterFactory->create( - \Magento\Framework\DB\DataConverter\SerializedToJson::class - ); + $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class); $fieldDataConverter->convert( $setup->getConnection(), $setup->getTable('quote_payment'), From 8f82cf5f24dddf4506f14c436da1b5a5abe4c0b5 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 14:44:41 -0600 Subject: [PATCH 039/132] MAGETWO-61526: Create upgrade script for quote_payment table additional_information field Changing method description --- app/code/Magento/Quote/Setup/UpgradeData.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index e6b8f9eba8b76..1a4245686d239 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -50,7 +50,8 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface } /** - * Convert data for additional_information field in quote_payment table from serialized to JSON format + * Upgrade to version 2.0.4, convert data for additional_information field in quote_payment table from serialized + * to JSON format * * @param ModuleDataSetupInterface $setup * @return void From 003d19b2e0e77fc327a3af12d8dcb14833d7dc5a Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 14:49:57 -0600 Subject: [PATCH 040/132] MAGETWO-61872: Create FieldDataConverter Whitelisting SerializedToJson data converter --- .../Test/Legacy/_files/restricted_classes.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php index 683449d4e5e34..c22e51647fc25 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php @@ -45,11 +45,6 @@ 'Magento\Framework\Serialize\Serializer\Serialize' => [ 'replacement' => 'Magento\Framework\Serialize\SerializerInterface', 'exclude' => [ - [ - 'type' => 'library', - 'name' => 'magento/framework', - 'path' => 'DB/Adapter/Pdo/Mysql.php' - ], [ 'type' => 'library', 'name' => 'magento/framework', @@ -69,6 +64,16 @@ 'name' => 'magento/framework', 'path' => 'App/ObjectManager/ConfigLoader.php' ], + [ + 'type' => 'library', + 'name' => 'magento/framework', + 'path' => 'DB/Adapter/Pdo/Mysql.php' + ], + [ + 'type' => 'library', + 'name' => 'magento/framework', + 'path' => 'DB/DataConverter/SerializedToJson.php' + ], [ 'type' => 'library', 'name' => 'magento/framework', From 81284fd24263532c0b4188ff93d7558bb2e10264 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 15:19:03 -0600 Subject: [PATCH 041/132] MAGETWO-61526: Create upgrade script for quote_payment table additional_information field Removing unnecessary code --- app/code/Magento/Quote/Setup/UpgradeData.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 1a4245686d239..19873352c33be 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -14,11 +14,6 @@ class UpgradeData implements UpgradeDataInterface { - /** - * @var Config - */ - private $eavConfig; - /** * @var FieldDataConverterFactory */ @@ -27,14 +22,11 @@ class UpgradeData implements UpgradeDataInterface /** * Constructor * - * @param Config $eavConfig * @param FieldDataConverterFactory $fieldDataConverterFactory */ public function __construct( - Config $eavConfig, FieldDataConverterFactory $fieldDataConverterFactory ) { - $this->eavConfig = $eavConfig; $this->fieldDataConverterFactory = $fieldDataConverterFactory; } @@ -46,7 +38,6 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface if (version_compare($context->getVersion(), '2.0.4', '<')) { $this->upgradeToVersionTwoZeroFour($setup); } - $this->eavConfig->clear(); } /** From 8267343ef386de0502cfbd70a263db241e3fd94e Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 15:31:11 -0600 Subject: [PATCH 042/132] MAGETWO-61537: Create upgrade script for sales_payment_transaction table additional_information field Removing unnecessary code --- app/code/Magento/Sales/Setup/UpgradeData.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 9a42d07c588f9..0c33dff5b5d7e 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -48,7 +48,6 @@ public function upgrade( \Magento\Framework\Setup\ModuleDataSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context ) { - $setup->startSetup(); $salesSetup = $this->salesSetupFactory->create(['setup' => $setup]); if (version_compare($context->getVersion(), '2.0.1', '<')) { $this->upgradeToTwoZeroOne($salesSetup); @@ -57,7 +56,6 @@ public function upgrade( $this->upgradeToVersionTwoZeroFive($setup); } $this->eavConfig->clear(); - $setup->endSetup(); } /** From 11b754e7865edb5a5646a2f384dfbf93c8f25875 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 15:38:13 -0600 Subject: [PATCH 043/132] MAGETWO-61537: Create upgrade script for sales_payment_transaction table additional_information field Changing method description --- app/code/Magento/Sales/Setup/UpgradeData.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 0c33dff5b5d7e..a4a38f5cdcbab 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -109,7 +109,11 @@ private function upgradeToTwoZeroOne(\Magento\Sales\Setup\SalesSetup $setup) } /** - * Upgrade to version 2.0.5 + * Upgrade to version 2.0.5, convert data for the following fields from serialized to JSON format: + * sales_order_item.product_options + * sales_shipment.packages + * sales_order_payment.additional_information + * sales_payment_transaction.additional_information * * @param \Magento\Framework\Setup\ModuleDataSetupInterface $setup * @return void From f44c92c4b4fde86266d67640913c7f56d7e5e364 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 7 Dec 2016 16:34:19 -0600 Subject: [PATCH 044/132] MAGETWO-61872: Create FieldDataConverter Whitelisting SerializedToJsonTest --- .../Magento/Test/Legacy/_files/restricted_classes.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php index c22e51647fc25..196112e437989 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php @@ -74,6 +74,11 @@ 'name' => 'magento/framework', 'path' => 'DB/DataConverter/SerializedToJson.php' ], + [ + 'type' => 'library', + 'name' => 'magento/framework', + 'path' => 'DB/Test/Unit/DataConverter/SerializedToJsonTest.php' + ], [ 'type' => 'library', 'name' => 'magento/framework', From 7365ffae2df4979b0f31650f0c54a83bcbaa051f Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 8 Dec 2016 10:01:25 +0200 Subject: [PATCH 045/132] MAGETWO-61654: Update serialization in Magento/Sales/Model/Order/Item.php and unit tests - CR changes --- app/code/Magento/Sales/Model/Order/Item.php | 21 +++++-------------- .../Sales/Test/Unit/Model/Order/ItemTest.php | 15 ++++++++----- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index 757c4f673d347..ae1d9042ea676 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -115,6 +115,7 @@ class Item extends AbstractModel implements OrderItemInterface * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param SerializerInterface $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -127,7 +128,8 @@ public function __construct( \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + SerializerInterface $serializer ) { parent::__construct( $context, @@ -141,6 +143,7 @@ public function __construct( $this->_orderFactory = $orderFactory; $this->_storeManager = $storeManager; $this->productRepository = $productRepository; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** @@ -465,20 +468,6 @@ public function setProductOptions(array $options = null) return $this; } - /** - * Get serializer instance - * - * @return SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = ObjectManager::getInstance()->get(SerializerInterface::class); - } - return $this->serializer; - } - /** * Get product options array * @@ -487,7 +476,7 @@ private function getSerializer() public function getProductOptions() { $data = $this->_getData('product_options'); - return is_string($data) ? $this->getSerializer()->unserialize($data) : $data; + return is_string($data) ? $this->serializer->unserialize($data) : $data; } /** diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php index 6006f5234b198..a9b965a6e83b2 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php @@ -32,14 +32,22 @@ class ItemTest extends \PHPUnit_Framework_TestCase */ protected $orderFactory; + /** + * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializerMock; + protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->orderFactory = $this->getMock(\Magento\Sales\Model\OrderFactory::class, ['create'], [], '', false); + $this->serializerMock = $this->getMock(SerializerInterface::class, [], ['unserialize'], '', false); + $arguments = [ 'orderFactory' => $this->orderFactory, + 'serializer' => $this->serializerMock ]; $this->model = $this->objectManager->getObject(\Magento\Sales\Model\Order\Item::class, $arguments); } @@ -119,8 +127,7 @@ public function testGetStatusId( $qtyRefunded, $qtyShipped, $expectedStatus - ) - { + ) { $this->model->setQtyBackordered($qtyBackOrdered); $this->model->setQtyCanceled($qtyCanceled); $this->model->setQtyInvoiced($qtyInvoiced); @@ -186,11 +193,9 @@ public function testGetOriginalPrice() */ public function testGetProductOptions($options, $expectedResult) { - $serializerMock = $this->getMock(SerializerInterface::class, [], ['unserialize'], '', false); if (is_string($options)) { - $serializerMock->expects($this->once())->method('unserialize')->will($this->returnValue($expectedResult)); + $this->serializerMock->expects($this->once())->method('unserialize')->will($this->returnValue($expectedResult)); } - $this->objectManager->setBackwardCompatibleProperty($this->model, 'serializer', $serializerMock); $this->model->setData('product_options', $options); $result = $this->model->getProductOptions(); $this->assertSame($result, $expectedResult); From a29777b9d4e81e6d2e46b2432cec03b2a6e12243 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 8 Dec 2016 10:06:19 +0200 Subject: [PATCH 046/132] MAGETWO-61654: Update serialization in Magento/Sales/Model/Order/Item.php and unit tests - CR changes --- app/code/Magento/Sales/Model/Order/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index ae1d9042ea676..ec0d30d121496 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -129,7 +129,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - SerializerInterface $serializer + SerializerInterface $serializer = null ) { parent::__construct( $context, From 87b396dcf8da47862d623e40a55f85fb013d3847 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 8 Dec 2016 10:07:17 +0200 Subject: [PATCH 047/132] MAGETWO-61654: Update serialization in Magento/Sales/Model/Order/Item.php and unit tests - CR changes --- app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php index a9b965a6e83b2..78e0127b9a4f0 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php @@ -194,7 +194,9 @@ public function testGetOriginalPrice() public function testGetProductOptions($options, $expectedResult) { if (is_string($options)) { - $this->serializerMock->expects($this->once())->method('unserialize')->will($this->returnValue($expectedResult)); + $this->serializerMock->expects($this->once()) + ->method('unserialize') + ->will($this->returnValue($expectedResult)); } $this->model->setData('product_options', $options); $result = $this->model->getProductOptions(); From bfd7e060e2f5c592b76cda3c3c946782dbe06bb9 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 8 Dec 2016 10:20:02 +0200 Subject: [PATCH 048/132] MAGETWO-61674: Fix seralization in Module Downloadable --- .../Downloadable/Model/Product/Type.php | 22 ++----- .../Test/Unit/Model/Product/TypeTest.php | 62 ++++++++----------- 2 files changed, 30 insertions(+), 54 deletions(-) diff --git a/app/code/Magento/Downloadable/Model/Product/Type.php b/app/code/Magento/Downloadable/Model/Product/Type.php index f5e63153f2a7e..8b37777f79c2d 100644 --- a/app/code/Magento/Downloadable/Model/Product/Type.php +++ b/app/code/Magento/Downloadable/Model/Product/Type.php @@ -111,7 +111,8 @@ public function __construct( \Magento\Downloadable\Model\SampleFactory $sampleFactory, \Magento\Downloadable\Model\LinkFactory $linkFactory, \Magento\Downloadable\Model\Product\TypeHandler\TypeHandlerInterface $typeHandler, - JoinProcessorInterface $extensionAttributesJoinProcessor + JoinProcessorInterface $extensionAttributesJoinProcessor, + SerializerInterface $serializer = null ) { $this->_sampleResFactory = $sampleResFactory; $this->_linkResource = $linkResource; @@ -121,6 +122,7 @@ public function __construct( $this->_linkFactory = $linkFactory; $this->typeHandler = $typeHandler; $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct( $catalogProductOption, $eavConfig, @@ -257,7 +259,7 @@ public function checkProductBuyState($product) $option = $product->getCustomOption('info_buyRequest'); if ($option instanceof \Magento\Quote\Model\Quote\Item\Option) { $buyRequest = new \Magento\Framework\DataObject( - $this->getSerializer()->unserialize($option->getValue()) + $this->serializer->unserialize($option->getValue()) ); if (!$buyRequest->hasLinks()) { if (!$product->getLinksPurchasedSeparately()) { @@ -267,7 +269,7 @@ public function checkProductBuyState($product) $buyRequest->setLinks($allLinksIds); $product->addCustomOption( 'info_buyRequest', - $this->getSerializer()->serialize($buyRequest->getData()) + $this->serializer->serialize($buyRequest->getData()) ); } else { throw new \Magento\Framework\Exception\LocalizedException(__('Please specify product link(s).')); @@ -277,20 +279,6 @@ public function checkProductBuyState($product) return $this; } - /** - * Get serializer instance - * - * @return SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = ObjectManager::getInstance()->get(SerializerInterface::class); - } - return $this->serializer; - } - /** * Prepare additional options/information for order item which will be * created from this product diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php index 6cc2e4dafdc6e..a8c4cda54d2a8 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php @@ -98,6 +98,30 @@ protected function setUp() ); $resourceProductMock->expects($this->any())->method('getEntityType')->will($this->returnValue($entityTypeMock)); + $this->serializerMock = $this->getMock( + SerializerInterface::class, + [], + ['serialize', 'unserialize'], + '', + false + ); + + $this->serializerMock->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); + + $this->serializerMock->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + $this->product = $this->getMock( \Magento\Catalog\Model\Product::class, [ @@ -159,7 +183,7 @@ protected function setUp() 'linkFactory' => $linkFactory, 'eavConfig' => $eavConfigMock, 'typeHandler' => $this->typeHandler, - + 'serializer' => $this->serializerMock ] ); } @@ -202,8 +226,6 @@ public function testCheckProductBuyState() ->method('getEntityId') ->will($this->returnValue(123)); - $this->initSerializerMock(); - $linksCollectionMock = $this->getMock( \Magento\Downloadable\Model\ResourceModel\Link\Collection::class, [], @@ -251,40 +273,6 @@ public function testCheckProductBuyStateException() ->method('getLinksPurchasedSeparately') ->will($this->returnValue(true)); - $this->initSerializerMock(); - $this->target->checkProductBuyState($this->product); } - - /** - * Initialize serializer mock - */ - private function initSerializerMock() - { - $this->serializerMock = $this->getMock( - SerializerInterface::class, - [], - ['serialize', 'unserialize'], - '', - false - ); - - $this->serializerMock->expects($this->any()) - ->method('serialize') - ->willReturnCallback( - function ($value) { - return json_encode($value); - } - ); - - $this->serializerMock->expects($this->any()) - ->method('unserialize') - ->willReturnCallback( - function ($value) { - return json_decode($value, true); - } - ); - - $this->objectManager->setBackwardCompatibleProperty($this->target, 'serializer', $this->serializerMock); - } } From 18b9a66df59f268a0b277655861be0ba494c565d Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 8 Dec 2016 10:25:15 +0200 Subject: [PATCH 049/132] MAGETWO-61674: Fix seralization in Module Downloadable - CR changes --- app/code/Magento/Downloadable/Model/Product/Type.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Downloadable/Model/Product/Type.php b/app/code/Magento/Downloadable/Model/Product/Type.php index 8b37777f79c2d..c88e93f0a9f7c 100644 --- a/app/code/Magento/Downloadable/Model/Product/Type.php +++ b/app/code/Magento/Downloadable/Model/Product/Type.php @@ -92,6 +92,7 @@ class Type extends \Magento\Catalog\Model\Product\Type\Virtual * @param \Magento\Downloadable\Model\LinkFactory $linkFactory * @param TypeHandler\TypeHandlerInterface $typeHandler * @param JoinProcessorInterface $extensionAttributesJoinProcessor + * @param SerializerInterface $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( From 16a8920339883f34712231343051cd7ef60f95ab Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Thu, 8 Dec 2016 13:55:44 +0200 Subject: [PATCH 050/132] MAGETWO-61647: Detailed investigation for info_buyrequest field and extension points for its modifications --- .../CustomOptions/CustomOptionProcessor.php | 25 +++- .../Model/Product/Option/Type/Date.php | 25 +++- .../Model/Product/Type/AbstractType.php | 28 ++++- .../CustomOptionProcessorTest.php | 15 ++- .../Model/Product/Type/Configurable.php | 4 +- .../Model/Product/Type/ConfigurableTest.php | 36 +++++- .../Downloadable/Model/Product/Type.php | 7 +- .../Model/Product/Type/Grouped.php | 4 +- app/code/Magento/Quote/Model/Quote/Item.php | 26 +++- .../Quote/Model/Quote/Item/Updater.php | 27 ++++- .../Unit/Model/Quote/Item/UpdaterTest.php | 27 ++++- .../Quote/Test/Unit/Model/Quote/ItemTest.php | 11 +- .../Magento/Sales/Model/AdminOrder/Create.php | 27 ++++- app/code/Magento/Sales/Model/Order/Item.php | 25 +++- app/code/Magento/Wishlist/Model/Item.php | 29 ++++- .../Model/Product/Option/Type/DateTest.php | 112 ++++++++++++++++++ .../Downloadable/Model/Product/TypeTest.php | 41 ++++++- .../Model/Product/Type/GroupedTest.php | 48 ++++++++ .../Sales/Model/AdminOrder/CreateTest.php | 27 +++++ .../Magento/Sales/Model/Order/ItemTest.php | 56 +++++++++ .../Magento/Wishlist/Model/ItemTest.php | 84 +++++++++++++ 21 files changed, 652 insertions(+), 32 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/DateTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php diff --git a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php index 5b55f9cb66cfe..cd4db2bb3353d 100644 --- a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php +++ b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php @@ -28,6 +28,13 @@ class CustomOptionProcessor implements CartItemProcessorInterface /** @var \Magento\Catalog\Model\Product\Option\UrlBuilder */ private $urlBuilder; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param DataObject\Factory $objectFactory * @param ProductOptionFactory $productOptionFactory @@ -99,13 +106,29 @@ public function processOptions(CartItemInterface $cartItem) protected function getOptions(CartItemInterface $cartItem) { $buyRequest = !empty($cartItem->getOptionByCode('info_buyRequest')) - ? unserialize($cartItem->getOptionByCode('info_buyRequest')->getValue()) + ? $this->getSerializer()->unserialize($cartItem->getOptionByCode('info_buyRequest')->getValue()) : null; return is_array($buyRequest) && isset($buyRequest['options']) ? $buyRequest['options'] : []; } + /** + * Get Serializer interface. + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + + return $this->serializer; + } + /** * Update options values * diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php index afa44c42d87b8..9b7ff1dff290e 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php @@ -22,6 +22,13 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType */ protected $_localeDate; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig @@ -269,7 +276,7 @@ public function prepareOptionValueForRequest($optionValue) $confItem = $this->getConfigurationItem(); $infoBuyRequest = $confItem->getOptionByCode('info_buyRequest'); try { - $value = unserialize($infoBuyRequest->getValue()); + $value = $this->getSerializer()->unserialize($infoBuyRequest->getValue()); if (is_array($value) && isset($value['options']) && isset($value['options'][$this->getOption()->getId()]) ) { return $value['options'][$this->getOption()->getId()]; @@ -281,6 +288,22 @@ public function prepareOptionValueForRequest($optionValue) } } + /** + * Get Serializer interface. + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + + return $this->serializer; + } + /** * Use Calendar on frontend or not * diff --git a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php index 11b8d03fc7ee5..aaceedbe076ca 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php +++ b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php @@ -161,6 +161,13 @@ abstract public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $ */ protected $productRepository; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + protected $serializer; + /** * Construct * @@ -394,8 +401,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p $product->prepareCustomOptions(); $buyRequest->unsetData('_processing_params'); // One-time params only - $product->addCustomOption('info_buyRequest', serialize($buyRequest->getData())); - + $product->addCustomOption('info_buyRequest', $this->getSerializer()->serialize($buyRequest->getData())); if ($options) { $optionIds = array_keys($options); $product->addCustomOption('option_ids', implode(',', $optionIds)); @@ -413,6 +419,22 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p return [$product]; } + /** + * Get Serializer interface. + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + protected function getSerializer() + { + if (!$this->serializer) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + + return $this->serializer; + } + /** * Process product configuration * @@ -645,7 +667,7 @@ public function getOrderOptions($product) $optionArr = []; $info = $product->getCustomOption('info_buyRequest'); if ($info) { - $optionArr['info_buyRequest'] = unserialize($info->getValue()); + $optionArr['info_buyRequest'] = $this->getSerializer()->unserialize($info->getValue()); } $optionIds = $product->getCustomOption('option_ids'); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php index e3bdffbf5aefc..f302f569431c6 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php @@ -126,6 +126,9 @@ public function testConvertToBuyRequest() $this->assertSame($this->buyRequest, $this->processor->convertToBuyRequest($this->cartItem)); } + /** + * @covers \Magento\Catalog\Model\CustomOptions\CustomOptionProcessor::getOptions() + */ public function testProcessCustomOptions() { $optionId = 23; @@ -136,9 +139,17 @@ public function testProcessCustomOptions() ->method('getOptionByCode') ->with('info_buyRequest') ->willReturn($quoteItemOption); - $quoteItemOption->expects($this->once()) + $quoteItemOption->expects($this->any()) ->method('getValue') - ->willReturn('a:1:{s:7:"options";a:1:{i:' . $optionId . ';a:2:{i:0;s:1:"5";i:1;s:1:"6";}}} '); + ->willReturn('{"options":{"' . $optionId . '":["5","6"]}}'); + $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['unserialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturn(json_decode($quoteItemOption->getValue(), true)); + $objectHelper->setBackwardCompatibleProperty($this->processor, 'serializer', $serializer); $this->customOptionFactory->expects($this->once()) ->method('create') ->willReturn($this->customOption); diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php index 0bd2f23418221..79bfa1c343430 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php @@ -883,7 +883,7 @@ public function getSelectedAttributesInfo($product) ['group' => 'CONFIGURABLE', 'method' => __METHOD__] ); if ($attributesOption = $product->getCustomOption('attributes')) { - $data = unserialize($attributesOption->getValue()); + $data = $this->getSerializer()->unserialize($attributesOption->getValue()); $this->getUsedProductAttributeIds($product); $usedAttributes = $product->getData($this->_usedAttributes); @@ -1026,7 +1026,7 @@ public function checkProductBuyState($product) parent::checkProductBuyState($product); $option = $product->getCustomOption('info_buyRequest'); if ($option instanceof \Magento\Quote\Model\Quote\Item\Option) { - $buyRequest = new \Magento\Framework\DataObject(unserialize($option->getValue())); + $buyRequest = new \Magento\Framework\DataObject($this->getSerializer()->unserialize($option->getValue())); $attributes = $buyRequest->getSuperAttribute(); if (is_array($attributes)) { foreach ($attributes as $key => $val) { diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php index 4f7ae98cc11ce..9e27966ff8c7c 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php @@ -649,7 +649,14 @@ public function testGetSelectedAttributesInfo() ->disableOriginalConstructor() ->getMock(); - $optionMock->expects($this->once())->method('getValue')->willReturn(serialize($this->attributeData)); + $optionMock->expects($this->any())->method('getValue')->willReturn(json_encode($this->attributeData, true)); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['unserialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturn(json_decode($optionMock->getValue(), true)); + $this->_objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); $productMock->expects($this->once())->method('getCustomOption')->with('attributes')->willReturn($optionMock); $productMock->expects($this->once())->method('hasData')->willReturn(true); $productMock->expects($this->at(2))->method('getData')->willReturn(true); @@ -671,9 +678,11 @@ public function testGetSelectedAttributesInfo() ); } + /** + * @covers \Magento\ConfigurableProduct\Model\Product\Type\Configurable::checkProductBuyState() + */ public function testCheckProductBuyState() { - $this->markTestIncomplete('checkProductBuyState() method is not complete in parent class'); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->setMethods(['__wakeup', 'getCustomOption', 'getSkipCheckRequiredOption']) ->disableOriginalConstructor() @@ -688,20 +697,28 @@ public function testCheckProductBuyState() ->method('getCustomOption') ->with('info_buyRequest') ->willReturn($optionMock); - $optionMock->expects($this->once()) + $optionMock->expects($this->any()) ->method('getValue') - ->willReturn(serialize(['super_attribute' => ['test_key' => 'test_value', 'empty_key' => '']])); + ->willReturn(json_encode(['super_attribute' => ['test_key' => 'test_value', 'empty_key' => '']], true)); + + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['unserialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturn(json_decode($optionMock->getValue(), true)); + $this->_objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); $this->assertEquals($this->_model, $this->_model->checkProductBuyState($productMock)); } /** + * @covers \Magento\ConfigurableProduct\Model\Product\Type\Configurable::checkProductBuyState() * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage You need to choose options for your item. */ public function testCheckProductBuyStateException() { - $this->markTestIncomplete('checkProductBuyState() method is not complete in parent class'); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->setMethods(['__wakeup', 'getCustomOption', 'getSkipCheckRequiredOption']) ->disableOriginalConstructor() @@ -716,7 +733,14 @@ public function testCheckProductBuyStateException() ->method('getCustomOption') ->with('info_buyRequest') ->willReturn($optionMock); - $optionMock->expects($this->once())->method('getValue')->willReturn(serialize([])); + $optionMock->expects($this->any())->method('getValue')->willReturn('{}'); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['unserialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturn(json_decode($optionMock->getValue(), true)); + $this->_objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); $this->_model->checkProductBuyState($productMock); } diff --git a/app/code/Magento/Downloadable/Model/Product/Type.php b/app/code/Magento/Downloadable/Model/Product/Type.php index 64c00d208b86f..66ca9c82b002c 100644 --- a/app/code/Magento/Downloadable/Model/Product/Type.php +++ b/app/code/Magento/Downloadable/Model/Product/Type.php @@ -249,14 +249,17 @@ public function checkProductBuyState($product) parent::checkProductBuyState($product); $option = $product->getCustomOption('info_buyRequest'); if ($option instanceof \Magento\Quote\Model\Quote\Item\Option) { - $buyRequest = new \Magento\Framework\DataObject(unserialize($option->getValue())); + $buyRequest = new \Magento\Framework\DataObject($this->getSerializer()->unserialize($option->getValue())); if (!$buyRequest->hasLinks()) { if (!$product->getLinksPurchasedSeparately()) { $allLinksIds = $this->_linksFactory->create()->addProductToFilter( $product->getEntityId() )->getAllIds(); $buyRequest->setLinks($allLinksIds); - $product->addCustomOption('info_buyRequest', serialize($buyRequest->getData())); + $product->addCustomOption( + 'info_buyRequest', + $this->getSerializer()->serialize($buyRequest->getData()) + ); } else { throw new \Magento\Framework\Exception\LocalizedException(__('Please specify product link(s).')); } diff --git a/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php b/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php index 02ff894df7c1f..f131977512366 100644 --- a/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php @@ -384,7 +384,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p $_result[0]->addCustomOption('product_type', self::TYPE_CODE, $product); $_result[0]->addCustomOption( 'info_buyRequest', - serialize( + $this->getSerializer()->serialize( [ 'super_product_config' => [ 'product_type' => self::TYPE_CODE, @@ -402,7 +402,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p if (!$isStrictProcessMode || count($associatedProductsInfo)) { $product->addCustomOption('product_type', self::TYPE_CODE, $product); - $product->addCustomOption('info_buyRequest', serialize($buyRequest->getData())); + $product->addCustomOption('info_buyRequest', $this->getSerializer()->serialize($buyRequest->getData())); $products[] = $product; } diff --git a/app/code/Magento/Quote/Model/Quote/Item.php b/app/code/Magento/Quote/Model/Quote/Item.php index ac3a1109d7172..6e69ce841312b 100644 --- a/app/code/Magento/Quote/Model/Quote/Item.php +++ b/app/code/Magento/Quote/Model/Quote/Item.php @@ -175,6 +175,13 @@ class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem implements \Mage */ protected $stockRegistry; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -808,7 +815,8 @@ public function __clone() public function getBuyRequest() { $option = $this->getOptionByCode('info_buyRequest'); - $buyRequest = new \Magento\Framework\DataObject($option ? unserialize($option->getValue()) : []); + $data = $option ? $this->getSerializer()->unserialize($option->getValue()) : []; + $buyRequest = new \Magento\Framework\DataObject($data); // Overwrite standard buy request qty, because item qty could have changed since adding to quote $buyRequest->setOriginalQty($buyRequest->getQty())->setQty($this->getQty() * 1); @@ -816,6 +824,22 @@ public function getBuyRequest() return $buyRequest; } + /** + * Get Serializer interface. + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + + return $this->serializer; + } + /** * Sets flag, whether this quote item has some error associated with it. * diff --git a/app/code/Magento/Quote/Model/Quote/Item/Updater.php b/app/code/Magento/Quote/Model/Quote/Item/Updater.php index 45f9d3d90e39e..103dd8acfb920 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Updater.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Updater.php @@ -32,6 +32,13 @@ class Updater */ protected $objectFactory; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param ProductFactory $productFactory * @param FormatInterface $localeFormat @@ -104,7 +111,7 @@ protected function setCustomPrice(array $info, Item $item) if ($infoBuyRequest) { $infoBuyRequest->setCustomPrice($itemPrice); - $infoBuyRequest->setValue(serialize($infoBuyRequest->getData())); + $infoBuyRequest->setValue($this->getSerializer()->serialize($infoBuyRequest->getData())); $infoBuyRequest->setCode('info_buyRequest'); $infoBuyRequest->setProduct($item->getProduct()); @@ -128,7 +135,7 @@ protected function unsetCustomPrice(Item $item) if ($infoBuyRequest->hasData('custom_price')) { $infoBuyRequest->unsetData('custom_price'); - $infoBuyRequest->setValue(serialize($infoBuyRequest->getData())); + $infoBuyRequest->setValue($this->getSerializer()->serialize($infoBuyRequest->getData())); $infoBuyRequest->setCode('info_buyRequest'); $infoBuyRequest->setProduct($item->getProduct()); $item->addOption($infoBuyRequest); @@ -138,6 +145,22 @@ protected function unsetCustomPrice(Item $item) $item->unsetData('original_custom_price'); } + /** + * Get Serializer interface. + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + + return $this->serializer; + } + /** * Return formatted price * diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php index fc86df0819e68..1d817ccfbe818 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php @@ -226,6 +226,9 @@ public function testUpdateQtyDecimalWithConfiguredOption() $this->object->update($this->itemMock, ['qty' => 3, 'use_discount' => true]); } + /** + * @covers \Magento\Quote\Model\Quote\Item\Updater::setCustomPrice() + */ public function testUpdateCustomPrice() { $customPrice = 9.99; @@ -250,9 +253,18 @@ public function testUpdateCustomPrice() ->method('getData') ->will($this->returnValue(['custom_price' => $customPrice])); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['serialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('serialize') + ->willReturn(json_encode($buyRequestMock->getData())); + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManagerHelper->setBackwardCompatibleProperty($this->object, 'serializer', $serializer); + $buyRequestMock->expects($this->any()) ->method('setValue') - ->with($this->equalTo(serialize(['custom_price' => $customPrice]))); + ->with($this->equalTo('{"custom_price":' . $customPrice . '}')); $buyRequestMock->expects($this->any()) ->method('setCode') ->with($this->equalTo('info_buyRequest')); @@ -293,6 +305,9 @@ public function testUpdateCustomPrice() $this->object->update($this->itemMock, ['qty' => $qty, 'custom_price' => $customPrice]); } + /** + * @covers \Magento\Quote\Model\Quote\Item\Updater::unsetCustomPrice() + */ public function testUpdateUnsetCustomPrice() { $qty = 3; @@ -313,6 +328,14 @@ public function testUpdateUnsetCustomPrice() ); $buyRequestMock->expects($this->never())->method('setCustomPrice'); $buyRequestMock->expects($this->once())->method('getData')->will($this->returnValue([])); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['serialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('serialize') + ->willReturn('{}'); + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $objectManagerHelper->setBackwardCompatibleProperty($this->object, 'serializer', $serializer); $buyRequestMock->expects($this->once())->method('unsetData')->with($this->equalTo('custom_price')); $buyRequestMock->expects($this->once()) ->method('hasData') @@ -321,7 +344,7 @@ public function testUpdateUnsetCustomPrice() $buyRequestMock->expects($this->any()) ->method('setValue') - ->with($this->equalTo(serialize([]))); + ->with($this->equalTo('{}')); $buyRequestMock->expects($this->any()) ->method('setCode') ->with($this->equalTo('info_buyRequest')); diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php index 7e07fcddf4aba..ec5ff92982fd2 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php @@ -1058,9 +1058,9 @@ public function testGetBuyRequestOptionByCode() $optionMock->expects($this->exactly(3)) ->method('getCode') ->will($this->returnValue($optionCode)); - $optionMock->expects($this->once()) + $optionMock->expects($this->any()) ->method('getValue') - ->will($this->returnValue(serialize(['qty' => $buyRequestQuantity]))); + ->will($this->returnValue('{"qty":23}')); $this->model->addOption($optionMock); @@ -1071,6 +1071,13 @@ public function testGetBuyRequestOptionByCode() ->will($this->returnValue($quantity)); $this->model->setQty($quantity); $this->assertEquals($quantity, $this->model->getQty()); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['unserialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturn(json_decode($optionMock->getValue(), true)); + $this->objectManagerHelper->setBackwardCompatibleProperty($this->model, 'serializer', $serializer); $buyRequest = $this->model->getBuyRequest(); $this->assertEquals($buyRequestQuantity, $buyRequest->getOriginalQty()); $this->assertEquals($quantity, $buyRequest->getQty()); diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 3715c02357a96..767c35f3a07eb 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -224,6 +224,13 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ */ protected $quoteFactory; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\ObjectManagerInterface $objectManager * @param \Magento\Framework\Event\ManagerInterface $eventManager @@ -794,7 +801,9 @@ public function moveQuoteItem($item, $moveTo, $qty) $info = $item->getOptionByCode('info_buyRequest'); if ($info) { - $info = new \Magento\Framework\DataObject(unserialize($info->getValue())); + $info = new \Magento\Framework\DataObject( + $this->getSerializer()->unserialize($info->getValue()) + ); $info->setQty($qty); $info->setOptions($this->_prepareOptionsForRequest($item)); } else { @@ -872,6 +881,22 @@ public function moveQuoteItem($item, $moveTo, $qty) return $this; } + /** + * Get Serializer interface. + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + + return $this->serializer; + } + /** * Handle data sent from sidebar * diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index 10ba1e1662144..2492ce1980ac2 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -95,6 +95,13 @@ class Item extends AbstractModel implements OrderItemInterface */ protected $_storeManager; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * Initialize dependencies. * @@ -466,7 +473,23 @@ public function setProductOptions(array $options = null) public function getProductOptions() { $data = $this->_getData('product_options'); - return is_string($data) ? unserialize($data) : $data; + return is_string($data) ? $this->getSerializer()->unserialize($data) : $data; + } + + /** + * Get Serializer interface. + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + + return $this->serializer; } /** diff --git a/app/code/Magento/Wishlist/Model/Item.php b/app/code/Magento/Wishlist/Model/Item.php index c68eb5572cf59..f9cba6712ebd7 100644 --- a/app/code/Magento/Wishlist/Model/Item.php +++ b/app/code/Magento/Wishlist/Model/Item.php @@ -120,6 +120,13 @@ class Item extends AbstractModel implements ItemInterface */ protected $productRepository; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -472,7 +479,7 @@ public function getProductUrl() public function getBuyRequest() { $option = $this->getOptionByCode('info_buyRequest'); - $initialData = $option ? unserialize($option->getValue()) : null; + $initialData = $option ? $this->getSerializer()->unserialize($option->getValue()) : null; if ($initialData instanceof \Magento\Framework\DataObject) { $initialData = $initialData->getData(); @@ -500,7 +507,7 @@ public function mergeBuyRequest($buyRequest) } $oldBuyRequest = $this->getBuyRequest()->getData(); - $sBuyRequest = serialize($buyRequest + $oldBuyRequest); + $sBuyRequest = $this->getSerializer()->serialize($buyRequest + $oldBuyRequest); $option = $this->getOptionByCode('info_buyRequest'); if ($option) { @@ -523,11 +530,27 @@ public function setBuyRequest($buyRequest) { $buyRequest->setId($this->getId()); - $_buyRequest = serialize($buyRequest->getData()); + $_buyRequest = $this->getSerializer()->serialize($buyRequest->getData()); $this->setData('buy_request', $_buyRequest); return $this; } + /** + * Get Serializer interface. + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if (!$this->serializer) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + + return $this->serializer; + } + /** * Check product representation in item * diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/DateTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/DateTest.php new file mode 100644 index 0000000000000..93af50480c880 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/DateTest.php @@ -0,0 +1,112 @@ +objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->model = $this->objectManager->create( + \Magento\Catalog\Model\Product\Option\Type\Date::class + ); + } + + /** + * @covers \Magento\Catalog\Model\Product\Option\Type\Date::prepareOptionValueForRequest() + * @dataProvider prepareOptionValueForRequestDataProvider + * @param array $optionValue + * @param array $infoBuyRequest + * @param array $expectedOptionValueForRequest + * @param array $productOptionData + */ + public function testPrepareOptionValueForRequest( + array $optionValue, + array $infoBuyRequest, + array $productOptionData, + array $expectedOptionValueForRequest + ) { + /** @var \Magento\Quote\Model\Quote\Item\Option $option */ + $option = $this->objectManager->create( + \Magento\Quote\Model\Quote\Item\Option::class, + ['data' => $infoBuyRequest] + ); + /** @var \Magento\Quote\Model\Quote\Item $item */ + $item = $this->objectManager->create(\Magento\Quote\Model\Quote\Item::class); + $item->addOption($option); + /** @var \Magento\Catalog\Model\Product\Option|null $productOption */ + $productOption = $productOptionData + ? $this->objectManager->create( + \Magento\Catalog\Model\Product\Option::class, + ['data' => $productOptionData] + ) + : null; + $this->model->setData('quote_item', $item); + $this->model->setOption($productOption); + + $actualOptionValueForRequest = $this->model->prepareOptionValueForRequest($optionValue); + $this->assertSame($expectedOptionValueForRequest, $actualOptionValueForRequest); + } + + /** + * @return array + */ + public function prepareOptionValueForRequestDataProvider() + { + return [ + // Variation 1 + [ + // $optionValue + ['field1' => 'value1', 'field2' => 'value2'], + // $infoBuyRequest + ['code' => 'info_buyRequest', 'value' => '{"qty":23}'], + // $productOptionData + ['id' => '11', 'value' => '{"qty":12}'], + // $expectedOptionValueForRequest + ['date_internal' => ['field1' => 'value1', 'field2' => 'value2']] + ], + // Variation 2 + [ + // $optionValue + ['field1' => 'value1', 'field2' => 'value2'], + // $infoBuyRequest + ['code' => 'info_buyRequest', 'value' => '{"options":{"11":{"qty":23}}}'], + // $productOptionData + ['id' => '11', 'value' => '{"qty":12}'], + // $expectedOptionValueForRequest + ['qty' => 23] + ], + // Variation 3 + [ + // $optionValue + ['field1' => 'value1', 'field2' => 'value2'], + // $infoBuyRequest + ['code' => 'info_buyRequest', 'value' => '{"options":{"11":{"qty":23}}}'], + // $productOptionData + [], + // $expectedOptionValueForRequest + ['date_internal' => ['field1' => 'value1', 'field2' => 'value2']] + ], + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Downloadable/Model/Product/TypeTest.php b/dev/tests/integration/testsuite/Magento/Downloadable/Model/Product/TypeTest.php index c9c9109ac95df..c3b6d668fdad1 100644 --- a/dev/tests/integration/testsuite/Magento/Downloadable/Model/Product/TypeTest.php +++ b/dev/tests/integration/testsuite/Magento/Downloadable/Model/Product/TypeTest.php @@ -19,9 +19,15 @@ class TypeTest extends \PHPUnit_Framework_TestCase */ protected $_model; + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + private $objectManager; + protected function setUp() { - $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->_model = $this->objectManager->create( \Magento\Downloadable\Model\Product\Type::class ); } @@ -216,4 +222,37 @@ public function testSaveTypeSpecificData() $this->assertEquals($value, $sample[$key]); } } + + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + * @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php + * @covers \Magento\Downloadable\Model\Product\Type::checkProductBuyState() + */ + public function testCheckProductBuyState() + { + /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ + $productRepository =$this->objectManager->create( + \Magento\Catalog\Api\ProductRepositoryInterface::class + ); + $product = $productRepository->get('downloadable-product'); + $product->setLinksPurchasedSeparately(false); + $productRepository->save($product); + /** @var \Magento\Quote\Model\Quote\Item\Option $option */ + $option = $this->objectManager->create( + \Magento\Quote\Model\Quote\Item\Option::class, + ['data' => ['code' => 'info_buyRequest', 'value' => '{"qty":23}']] + ); + $option->setProduct($product); + $product->setCustomOptions(['info_buyRequest' => $option]); + + $this->_model->checkProductBuyState($product); + $linksFactory = $this->objectManager + ->get(\Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory::class); + $allLinksIds = $linksFactory->create()->addProductToFilter($product->getEntityId())->getAllIds(); + $this->assertEquals( + '{"qty":23,"links":["' . implode('","', $allLinksIds). '"]}', + $product->getCustomOption('info_buyRequest')->getValue() + ); + } } diff --git a/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php b/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php index dfff15995ecf4..87e015a0a5215 100644 --- a/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php +++ b/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php @@ -80,4 +80,52 @@ private function assertProductInfo($product) $this->assertEquals($data[$productId]['qty'], $product->getQty()); $this->assertEquals($data[$productId]['position'], $product->getPosition()); } + + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation disabled + * @covers \Magento\GroupedProduct\Model\Product\Type\Grouped::_prepareProduct() + * @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php + */ + public function testPrepareProduct() + { + $buyRequest = $this->objectManager->create( + \Magento\Framework\DataObject::class, + ['data' => ['value' => ['qty' => 2]]] + ); + /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ + $productRepository = $this->objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); + $product = $productRepository->get('grouped-product'); + + /** @var \Magento\GroupedProduct\Model\Product\Type\Grouped $type */ + $type = $this->objectManager->get(\Magento\GroupedProduct\Model\Product\Type\Grouped::class); + + $processModes = [ + \Magento\GroupedProduct\Model\Product\Type\Grouped::PROCESS_MODE_FULL, + \Magento\GroupedProduct\Model\Product\Type\Grouped::PROCESS_MODE_LITE + ]; + $expectedData = [ + \Magento\GroupedProduct\Model\Product\Type\Grouped::PROCESS_MODE_FULL => [ + 1 => '{"super_product_config":{"product_type":"grouped","product_id":"' + . $product->getId() . '"}}', + 21 => '{"super_product_config":{"product_type":"grouped","product_id":"' + . $product->getId() . '"}}', + ], + \Magento\GroupedProduct\Model\Product\Type\Grouped::PROCESS_MODE_LITE => [ + $product->getId() => '{"value":{"qty":2}}', + ] + ]; + + foreach ($processModes as $processMode) { + $products = $type->processConfiguration($buyRequest, $product, $processMode); + foreach ($products as $item) { + $productId = $item->getId(); + $this->assertEquals( + $expectedData[$processMode][$productId], + $item->getCustomOptions()['info_buyRequest']->getValue(), + "Wrong info_buyRequest data for product with id: $productId" + ); + } + } + } } diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index f8ca1929df91e..687532cc5bf2d 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -477,6 +477,33 @@ public function testGetCustomerCartExistingCart() $this->assertSame($customerQuote, $customerQuoteFromCache, 'Customer quote caching does not work correctly.'); } + /** + * @covers \Magento\Sales\Model\AdminOrder\Create::moveQuoteItem() + * @magentoAppIsolation enabled + * @magentoDataFixture Magento/Sales/_files/quote.php + * @magentoDataFixture Magento/Customer/_files/customer.php + */ + public function testMoveQuoteItemToCart() + { + $fixtureCustomerId = 1; + + /** Preconditions */ + /** @var \Magento\Backend\Model\Session\Quote $session */ + $session = Bootstrap::getObjectManager()->create(\Magento\Backend\Model\Session\Quote::class); + $session->setCustomerId($fixtureCustomerId); + /** @var $quoteFixture \Magento\Quote\Model\Quote */ + $quoteFixture = Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class); + $quoteFixture->load('test01', 'reserved_order_id'); + $quoteFixture->setCustomerIsGuest(false)->setCustomerId($fixtureCustomerId)->save(); + + $customerQuote = $this->_model->getCustomerCart(); + $item = $customerQuote->getAllVisibleItems()[0]; + + $this->_model->moveQuoteItem($item, 'cart', 3); + $this->assertEquals(4, $item->getQty(), 'Number of Qty isn\'t correct for Quote item.'); + $this->assertEquals(3, $item->getQtyToAdd(), 'Number of added qty isn\'t correct for Quote item.'); + } + /** * @magentoAppIsolation enabled * @magentoDbIsolation enabled diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php new file mode 100644 index 0000000000000..c05d0747973d8 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php @@ -0,0 +1,56 @@ +get(\Magento\Sales\Model\Order\Item::class); + $model->setData('product_options', $options); + $this->assertEquals($expectedData, $model->getProductOptions()); + } + + /** + * @return array + */ + public function getProductOptionsDataProvider() + { + return [ + // Variation #1 + [ + // $options + '{"option1":1,"option2":2}', + //$expectedData + ["option1" => 1, "option2" => 2] + ], + // Variation #2 + [ + // $options + 'a:2:{s:7:"option1";i:1;s:7:"option2";i:2;}', + //$expectedData + null + ], + // Variation #3 + [ + // $options + ["option1" => 1, "option2" => 2], + //$expectedData + ["option1" => 1, "option2" => 2] + ], + ]; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php b/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php new file mode 100644 index 0000000000000..411ac4421f888 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php @@ -0,0 +1,84 @@ +objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $this->model = $this->objectManager->get(\Magento\Wishlist\Model\Item::class); + } + + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + * @magentoDataFixture Magento/Catalog/_files/product_simple.php + * @covers \Magento\Wishlist\Model\Item::getBuyRequest() + * @covers \Magento\Wishlist\Model\Item::mergeBuyRequest() + */ + public function testBuyRequest() + { + /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ + $productRepository = $this->objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); + $product = $productRepository->getById(1); + + /** @var \Magento\Wishlist\Model\Item\Option $option */ + $option = $this->objectManager->create( + \Magento\Wishlist\Model\Item\Option::class, + ['data' => ['code' => 'info_buyRequest', 'value' => '{"qty":23}']] + ); + $option->setProduct($product); + $this->model->addOption($option); + + // Assert getBuyRequest method + $buyRequest = $this->model->getBuyRequest(); + $this->assertEquals($buyRequest->getOriginalQty(), 23); + + // Assert mergeBuyRequest method + $this->model->mergeBuyRequest(['qty' => 11, 'additional_data' => 'some value']); + $buyRequest = $this->model->getBuyRequest(); + $this->assertEquals( + ['additional_data' => 'some value', 'qty' => 0, 'original_qty' => 11], + $buyRequest->getData() + ); + } + + /** + * @covers \Magento\Wishlist\Model\Item::setBuyRequest() + */ + public function testSetBuyRequest() + { + $buyRequest = $this->objectManager->create( + \Magento\Framework\DataObject::class, + ['data' => ['field_1' => 'some data', 'field_2' => 234]] + ); + + $this->model->setBuyRequest($buyRequest); + + $this->assertEquals( + '{"field_1":"some data","field_2":234,"id":null}', + $this->model->getData('buy_request') + ); + } +} From 9082053bd5cd4154dc5618341f5d0cf6aa3325a0 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Thu, 8 Dec 2016 14:27:54 +0200 Subject: [PATCH 051/132] MAGETWO-62041: Remove uses of attributes serialize and unserialize in ConfigurableProduct --- .../Model/Product/Type/Configurable.php | 4 +-- .../Model/Quote/Item/CartItemProcessor.php | 14 ++++++-- .../Model/Product/Type/ConfigurableTest.php | 22 ++++++++++-- .../Quote/Item/CartItemProcessorTest.php | 34 +++++++++++++++++-- 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php index 7e426eee139a5..4d9a7f582d33e 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php @@ -854,7 +854,7 @@ public function getSelectedAttributesInfo($product) ['group' => 'CONFIGURABLE', 'method' => __METHOD__] ); if ($attributesOption = $product->getCustomOption('attributes')) { - $data = unserialize($attributesOption->getValue()); + $data = $this->serializer->unserialize($attributesOption->getValue()); $this->getUsedProductAttributeIds($product); $usedAttributes = $product->getData($this->_usedAttributes); @@ -936,7 +936,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p if ($subProduct) { $subProductLinkFieldId = $subProduct->getId(); - $product->addCustomOption('attributes', serialize($attributes)); + $product->addCustomOption('attributes', $this->serializer->serialize($attributes)); $product->addCustomOption('product_qty_' . $subProductLinkFieldId, 1, $subProduct); $product->addCustomOption('simple_product', $subProductLinkFieldId, $subProduct); diff --git a/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php b/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php index 8e661f99c5238..6e9d439ade646 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php +++ b/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php @@ -7,6 +7,8 @@ use Magento\Quote\Model\Quote\Item\CartItemProcessorInterface; use Magento\Quote\Api\Data\CartItemInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; class CartItemProcessor implements CartItemProcessorInterface { @@ -30,22 +32,30 @@ class CartItemProcessor implements CartItemProcessorInterface */ protected $itemOptionValueFactory; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\DataObject\Factory $objectFactory * @param \Magento\Quote\Model\Quote\ProductOptionFactory $productOptionFactory * @param \Magento\Quote\Api\Data\ProductOptionExtensionFactory $extensionFactory * @param \Magento\ConfigurableProduct\Model\Quote\Item\ConfigurableItemOptionValueFactory $itemOptionValueFactory + * @param SerializerInterface $serializer */ public function __construct( \Magento\Framework\DataObject\Factory $objectFactory, \Magento\Quote\Model\Quote\ProductOptionFactory $productOptionFactory, \Magento\Quote\Api\Data\ProductOptionExtensionFactory $extensionFactory, - \Magento\ConfigurableProduct\Model\Quote\Item\ConfigurableItemOptionValueFactory $itemOptionValueFactory + \Magento\ConfigurableProduct\Model\Quote\Item\ConfigurableItemOptionValueFactory $itemOptionValueFactory, + SerializerInterface $serializer = null ) { $this->objectFactory = $objectFactory; $this->productOptionFactory = $productOptionFactory; $this->extensionFactory = $extensionFactory; $this->itemOptionValueFactory = $itemOptionValueFactory; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** @@ -73,7 +83,7 @@ public function convertToBuyRequest(CartItemInterface $cartItem) public function processOptions(CartItemInterface $cartItem) { $attributesOption = $cartItem->getProduct()->getCustomOption('attributes'); - $selectedConfigurableOptions = unserialize($attributesOption->getValue()); + $selectedConfigurableOptions = $this->serializer->unserialize($attributesOption->getValue()); if (is_array($selectedConfigurableOptions)) { $configurableOptions = []; diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php index cd36c03e7e99b..6231bfdee8d24 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php @@ -565,6 +565,22 @@ public function testIsSalable() public function testGetSelectedAttributesInfo() { + $this->serializer->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); + + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->disableOriginalConstructor() ->getMock(); @@ -581,7 +597,7 @@ public function testGetSelectedAttributesInfo() ->disableOriginalConstructor() ->getMock(); - $optionMock->expects($this->once())->method('getValue')->willReturn(serialize($this->attributeData)); + $optionMock->expects($this->once())->method('getValue')->willReturn(json_encode($this->attributeData)); $productMock->expects($this->once())->method('getCustomOption')->with('attributes')->willReturn($optionMock); $productMock->expects($this->once())->method('hasData')->willReturn(true); $productMock->expects($this->at(2))->method('getData')->willReturn(true); @@ -620,7 +636,7 @@ public function testCheckProductBuyState() ->willReturn($optionMock); $optionMock->expects($this->once()) ->method('getValue') - ->willReturn(serialize(['super_attribute' => ['test_key' => 'test_value', 'empty_key' => '']])); + ->willReturn(json_encode(['super_attribute' => ['test_key' => 'test_value', 'empty_key' => '']])); $this->assertEquals($this->_model, $this->_model->checkProductBuyState($productMock)); } @@ -644,7 +660,7 @@ public function testCheckProductBuyStateException() ->method('getCustomOption') ->with('info_buyRequest') ->willReturn($optionMock); - $optionMock->expects($this->once())->method('getValue')->willReturn(serialize([])); + $optionMock->expects($this->once())->method('getValue')->willReturn(json_encode([])); $this->_model->checkProductBuyState($productMock); } diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php index ab4f5e3be7cfa..271787eead256 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php @@ -43,6 +43,9 @@ class CartItemProcessorTest extends \PHPUnit_Framework_TestCase */ private $productOptionExtensionAttributes; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + private $serializer; + protected function setUp() { $this->objectFactoryMock = $this->getMock( @@ -84,11 +87,36 @@ protected function setUp() ['setConfigurableItemOptions'] ); + $this->serializer = $this->getMock( + \Magento\Framework\Serialize\SerializerInterface::class, + [], + [], + '', + false + ); + + $this->serializer->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); + + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + $this->model = new \Magento\ConfigurableProduct\Model\Quote\Item\CartItemProcessor( $this->objectFactoryMock, $this->optionFactoryMock, $this->optionExtensionFactoryMock, - $this->optionValueFactoryMock + $this->optionValueFactoryMock, + $this->serializer ); } @@ -174,7 +202,7 @@ public function testProcessProductOptions() '', false ); - $customOption->expects($this->once())->method('getValue')->willReturn(serialize([$optionId => $optionValue])); + $customOption->expects($this->once())->method('getValue')->willReturn(json_encode([$optionId => $optionValue])); $productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); $productMock->expects($this->once())->method('getCustomOption')->with('attributes')->willReturn($customOption); @@ -227,7 +255,7 @@ public function testProcessProductOptionsIfOptionsExist() '', false ); - $customOption->expects($this->once())->method('getValue')->willReturn(serialize([$optionId => $optionValue])); + $customOption->expects($this->once())->method('getValue')->willReturn(json_encode([$optionId => $optionValue])); $productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); $productMock->expects($this->once())->method('getCustomOption')->with('attributes')->willReturn($customOption); From 6e4b6258822b472e6028150eea845b8308f9a110 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Thu, 8 Dec 2016 14:36:05 +0200 Subject: [PATCH 052/132] MAGETWO-61651: Remove uses of serialize and unserialize in Magento/Sales/Model/AdminOrder/Create.php --- app/code/Magento/Sales/Model/AdminOrder/Create.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index a8a92ca1f268e..6bfc2cd866416 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -258,8 +258,8 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper * @param \Magento\Sales\Api\OrderManagementInterface $orderManagement * @param \Magento\Quote\Model\QuoteFactory $quoteFactory - * @param SerializerInterface $serializer * @param array $data + * @param SerializerInterface $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -290,8 +290,8 @@ public function __construct( \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Sales\Api\OrderManagementInterface $orderManagement, \Magento\Quote\Model\QuoteFactory $quoteFactory, - SerializerInterface $serializer = null, - array $data = [] + array $data = [], + SerializerInterface $serializer = null ) { $this->_objectManager = $objectManager; $this->_eventManager = $eventManager; From acf59dd72fdd239d530b9b54e01b6b5cd182bd05 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Thu, 8 Dec 2016 14:52:21 +0200 Subject: [PATCH 053/132] MAGETWO-62041: Remove uses of attributes serialize and unserialize in ConfigurableProduct --- .../Model/Product/Type/ConfigurableTest.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php index 59d828baa2d5c..b559fb846289c 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php @@ -294,12 +294,18 @@ public function testGetProductByAttributes() */ public function testGetSelectedAttributesInfo() { + /** @var $serializer \Magento\Framework\Serialize\SerializerInterface */ + $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\SerializerInterface::class); + $product = $this->productRepository->getById(1, true); $attributes = $this->model->getConfigurableAttributesAsArray($product); $attribute = reset($attributes); $optionValueId = $attribute['values'][0]['value_index']; - $product->addCustomOption('attributes', serialize([$attribute['attribute_id'] => $optionValueId])); + $product->addCustomOption('attributes', + $serializer->serialize([$attribute['attribute_id'] => $optionValueId]) + ); + $info = $this->model->getSelectedAttributesInfo($product); $this->assertEquals('Test Configurable', $info[0]['label']); $this->assertEquals('Option 1', $info[0]['value']); @@ -311,12 +317,18 @@ public function testGetSelectedAttributesInfo() */ public function testGetSelectedAttributesInfoForStore() { + /** @var $serializer \Magento\Framework\Serialize\SerializerInterface */ + $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\SerializerInterface::class); + $attributes = $this->model->getConfigurableAttributesAsArray($this->product); $attribute = reset($attributes); $optionValueId = $attribute['values'][0]['value_index']; - $this->product->addCustomOption('attributes', serialize([$attribute['attribute_id'] => $optionValueId])); + $this->product->addCustomOption( + 'attributes', + $serializer->serialize([$attribute['attribute_id'] => $optionValueId]) + ); $configurableAttr = $this->model->getConfigurableAttributes($this->product); $attribute = $configurableAttr->getFirstItem(); From 8c60f93789c468939d0cf2b8d8bb58c3bad23eba Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 8 Dec 2016 15:08:12 +0200 Subject: [PATCH 054/132] MAGETWO-61674: Fix seralization in Module Downloadable --- .../Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php index a8c4cda54d2a8..6c8d817a9004a 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php @@ -7,7 +7,6 @@ use Magento\Downloadable\Model\Product\TypeHandler\TypeHandlerInterface; use Magento\Framework\Serialize\SerializerInterface; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; /** * Class TypeTest @@ -73,7 +72,7 @@ protected function setUp() $linkResource = $this->getMock(\Magento\Downloadable\Model\ResourceModel\Link::class, [], [], '', false); $this->linksFactory = $this->getMock( \Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory::class, - [], + ['create'], [], '', false From c2dd85dbbeb98d291da2e13fe8b87f9d808e4f87 Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Thu, 8 Dec 2016 15:17:26 +0200 Subject: [PATCH 055/132] MAGETWO-61653: Magento/Sales/Model/Order/CreditmemoFactory.php, remove \Magento\Framework\Unserialize\Unserialize and fix unit tests - changes after CR --- app/code/Magento/Sales/Model/Order/CreditmemoFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php index 1a78bb4f27b09..e222d3de5bd94 100644 --- a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php +++ b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php @@ -23,7 +23,7 @@ class CreditmemoFactory protected $taxConfig; /** - * @var \Magento\Framework\Unserialize\Unserialize + * @var \Magento\Framework\Serialize\SerializerInterface */ protected $unserialize; From 77cf5ea71fcb84a111dd8a37727df0964edf03cb Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Thu, 8 Dec 2016 07:55:52 -0600 Subject: [PATCH 056/132] MAGETWO-61872: Create FieldDataConverter Removing unnecessary code --- lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php b/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php index cff9cd8d04a93..c5caca06b283a 100644 --- a/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php +++ b/lib/internal/Magento/Framework/DB/FieldDataConverterFactory.php @@ -6,7 +6,6 @@ namespace Magento\Framework\DB; use Magento\Framework\ObjectManagerInterface; -use Magento\Framework\DB\DataConverter\DataConverterInterface; /** * Create instance of FieldDataConverter with concrete implementation of DataConverterInterface From 3b155cccdc70a1792fee50087230e7ae5ed1c0cd Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 8 Dec 2016 17:30:15 +0200 Subject: [PATCH 057/132] MAGETWO-61670: Fix serialization in module Sales (other) and unit tests --- .../Controller/Download/DownloadCustomOption.php | 15 +++++++++++++-- .../Download/DownloadCustomOptionTest.php | 15 +++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php index a2dcebe8440b1..1e034228fec1d 100644 --- a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php +++ b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php @@ -6,6 +6,8 @@ */ namespace Magento\Sales\Controller\Download; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\SerializerInterface; use Magento\Sales\Model\Download; use Magento\Framework\App\Action\Context; use Magento\Catalog\Model\Product\Type\AbstractType; @@ -26,25 +28,34 @@ class DownloadCustomOption extends \Magento\Framework\App\Action\Action /** * @var Unserialize + * @deprecated */ protected $unserialize; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param Context $context * @param ForwardFactory $resultForwardFactory * @param Download $download * @param Unserialize $unserialize + * @param SerializerInterface $serializer */ public function __construct( Context $context, ForwardFactory $resultForwardFactory, Download $download, - Unserialize $unserialize + Unserialize $unserialize, + SerializerInterface $serializer = null ) { parent::__construct($context); $this->resultForwardFactory = $resultForwardFactory; $this->download = $download; $this->unserialize = $unserialize; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** @@ -88,7 +99,7 @@ public function execute() } try { - $info = $this->unserialize->unserialize($option->getValue()); + $info = $this->serializer->unserialize($option->getValue()); if ($this->getRequest()->getParam('key') != $info['secret_key']) { return $resultForward->forward('noroute'); } diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php index 387fc3b782b10..cbb4adce24a02 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Sales\Test\Unit\Controller\Download; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Unserialize\Unserialize; /** * Class DownloadCustomOptionTest @@ -55,7 +57,7 @@ class DownloadCustomOptionTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Framework\Unserialize\Unserialize|\PHPUnit_Framework_MockObject_MockObject */ - protected $unserializeMock; + protected $serializerMock; /** * @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject @@ -89,9 +91,9 @@ protected function setUp() ->setMethods(['downloadFile']) ->getMock(); - $this->unserializeMock = $this->getMockBuilder(\Magento\Framework\Unserialize\Unserialize::class) + $this->serializerMock = $this->getMockBuilder(SerializerInterface::class) ->disableOriginalConstructor() - ->setMethods(['unserialize']) + ->setMethods(['serialize', 'unserialize']) ->getMock(); $requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) @@ -151,7 +153,8 @@ protected function setUp() 'context' => $contextMock, 'resultForwardFactory' => $resultForwardFactoryMock, 'download' => $this->downloadMock, - 'unserialize' => $this->unserializeMock + 'unserialize' => $this->getMock(Unserialize::class, [], [], '', false), + 'serializer' => $this->serializerMock ] ) ->getMock(); @@ -197,7 +200,7 @@ public function testExecute($itemOptionValues, $productOptionValues, $noRouteOcc } else { $unserializeResult = [self::SECRET_KEY => self::SECRET_KEY]; - $this->unserializeMock->expects($this->once()) + $this->serializerMock->expects($this->once()) ->method('unserialize') ->with($itemOptionValues[self::OPTION_VALUE]) ->willReturn($unserializeResult); @@ -321,7 +324,7 @@ public function testExecuteBadSecretKey() $this->productOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID); $this->productOptionMock->expects($this->any())->method('getType')->willReturn(self::OPTION_TYPE); - $this->unserializeMock->expects($this->once()) + $this->serializerMock->expects($this->once()) ->method('unserialize') ->with(self::OPTION_VALUE) ->willReturn([self::SECRET_KEY => 'bad_test_secret_key']); From b4c4e762353b8ae3007b2c0289b8598538cc8970 Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Thu, 8 Dec 2016 19:21:41 +0200 Subject: [PATCH 058/132] MAGETWO-61647: Detailed investigation for info_buyrequest field and extension points for its modifications - stabilization bamboo builds --- .../Magento/Bundle/Model/Product/Type.php | 8 +++--- .../CustomOptions/CustomOptionProcessor.php | 23 ++++------------- .../Attribute/Source/Countryofmanufacture.php | 24 +++++------------- .../Model/Product/Type/AbstractType.php | 25 +++++-------------- .../Model/Product/Type/Configurable.php | 16 +++++++----- .../Downloadable/Model/Product/Type.php | 11 +++++--- .../Model/Product/Type/Grouped.php | 14 ++++++----- .../Unit/Model/Product/Type/GroupedTest.php | 23 +++++++++++++++++ .../Quote/Model/Quote/Item/Updater.php | 25 +++++-------------- .../Model/Product/Option/Type/DateTest.php | 2 +- .../Model/Product/Type/AbstractTypeTest.php | 2 +- .../Model/Product/Type/ConfigurableTest.php | 5 ++-- 12 files changed, 81 insertions(+), 97 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index 4cfdf27fd0e6a..ff66bd6d32a6e 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -168,7 +168,7 @@ class Type extends \Magento\Catalog\Model\Product\Type\AbstractType * @param PriceCurrencyInterface $priceCurrency * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry * @param \Magento\CatalogInventory\Api\StockStateInterface $stockState - * + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -192,7 +192,8 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, PriceCurrencyInterface $priceCurrency, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, - \Magento\CatalogInventory\Api\StockStateInterface $stockState + \Magento\CatalogInventory\Api\StockStateInterface $stockState, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->_catalogProduct = $catalogProduct; $this->_catalogData = $catalogData; @@ -215,7 +216,8 @@ public function __construct( $filesystem, $coreRegistry, $logger, - $productRepository + $productRepository, + $serializer ); } diff --git a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php index cd4db2bb3353d..e127aa0970ea2 100644 --- a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php +++ b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php @@ -40,17 +40,20 @@ class CustomOptionProcessor implements CartItemProcessorInterface * @param ProductOptionFactory $productOptionFactory * @param ProductOptionExtensionFactory $extensionFactory * @param CustomOptionFactory $customOptionFactory + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] */ public function __construct( \Magento\Framework\DataObject\Factory $objectFactory, \Magento\Quote\Model\Quote\ProductOptionFactory $productOptionFactory, \Magento\Quote\Api\Data\ProductOptionExtensionFactory $extensionFactory, - \Magento\Catalog\Model\CustomOptions\CustomOptionFactory $customOptionFactory + \Magento\Catalog\Model\CustomOptions\CustomOptionFactory $customOptionFactory, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->objectFactory = $objectFactory; $this->productOptionFactory = $productOptionFactory; $this->extensionFactory = $extensionFactory; $this->customOptionFactory = $customOptionFactory; + $this->serializer = $serializer; } /** @@ -106,29 +109,13 @@ public function processOptions(CartItemInterface $cartItem) protected function getOptions(CartItemInterface $cartItem) { $buyRequest = !empty($cartItem->getOptionByCode('info_buyRequest')) - ? $this->getSerializer()->unserialize($cartItem->getOptionByCode('info_buyRequest')->getValue()) + ? $this->serializer->unserialize($cartItem->getOptionByCode('info_buyRequest')->getValue()) : null; return is_array($buyRequest) && isset($buyRequest['options']) ? $buyRequest['options'] : []; } - /** - * Get Serializer interface. - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - - return $this->serializer; - } - /** * Update options values * diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php b/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php index 8bcf01ba3db38..2e21a6d88902b 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php @@ -46,15 +46,18 @@ class Countryofmanufacture extends AbstractSource implements OptionSourceInterfa * @param \Magento\Directory\Model\CountryFactory $countryFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\App\Cache\Type\Config $configCacheType + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] */ public function __construct( \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\App\Cache\Type\Config $configCacheType + \Magento\Framework\App\Cache\Type\Config $configCacheType, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->_countryFactory = $countryFactory; $this->_storeManager = $storeManager; $this->_configCacheType = $configCacheType; + $this->serializer = $serializer; } /** @@ -66,30 +69,15 @@ public function getAllOptions() { $cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); if ($cache = $this->_configCacheType->load($cacheKey)) { - $options = $this->getSerializer()->unserialize($cache); + $options = $this->serializer->unserialize($cache); } else { /** @var \Magento\Directory\Model\Country $country */ $country = $this->_countryFactory->create(); /** @var \Magento\Directory\Model\ResourceModel\Country\Collection $collection */ $collection = $country->getResourceCollection(); $options = $collection->load()->toOptionArray(); - $this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey); + $this->_configCacheType->save($this->serializer->serialize($options), $cacheKey); } return $options; } - - /** - * Get serializer - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if ($this->serializer === null) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - return $this->serializer; - } } diff --git a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php index aaceedbe076ca..6f2cb2ccf140c 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php +++ b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php @@ -180,6 +180,7 @@ abstract public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $ * @param \Magento\Framework\Registry $coreRegistry * @param \Psr\Log\LoggerInterface $logger * @param ProductRepositoryInterface $productRepository + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -191,7 +192,8 @@ public function __construct( \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Registry $coreRegistry, \Psr\Log\LoggerInterface $logger, - ProductRepositoryInterface $productRepository + ProductRepositoryInterface $productRepository, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->_catalogProductOption = $catalogProductOption; $this->_eavConfig = $eavConfig; @@ -202,6 +204,7 @@ public function __construct( $this->_filesystem = $filesystem; $this->_logger = $logger; $this->productRepository = $productRepository; + $this->serializer = $serializer; } /** @@ -401,7 +404,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p $product->prepareCustomOptions(); $buyRequest->unsetData('_processing_params'); // One-time params only - $product->addCustomOption('info_buyRequest', $this->getSerializer()->serialize($buyRequest->getData())); + $product->addCustomOption('info_buyRequest', $this->serializer->serialize($buyRequest->getData())); if ($options) { $optionIds = array_keys($options); $product->addCustomOption('option_ids', implode(',', $optionIds)); @@ -419,22 +422,6 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p return [$product]; } - /** - * Get Serializer interface. - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - protected function getSerializer() - { - if (!$this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - - return $this->serializer; - } - /** * Process product configuration * @@ -667,7 +654,7 @@ public function getOrderOptions($product) $optionArr = []; $info = $product->getCustomOption('info_buyRequest'); if ($info) { - $optionArr['info_buyRequest'] = $this->getSerializer()->unserialize($info->getValue()); + $optionArr['info_buyRequest'] = $this->serializer->unserialize($info->getValue()); } $optionIds = $product->getCustomOption('option_ids'); diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php index 79bfa1c343430..6d0351b373d9e 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php @@ -183,7 +183,9 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType * @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $catalogProductTypeConfigurable * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor - * + * @param \Magento\Framework\Cache\FrontendInterface $cache [optional] + * @param \Magento\Customer\Model\Session $customerSession [optional] + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -205,7 +207,8 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor, \Magento\Framework\Cache\FrontendInterface $cache = null, - \Magento\Customer\Model\Session $customerSession = null + \Magento\Customer\Model\Session $customerSession = null, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->typeConfigurableFactory = $typeConfigurableFactory; $this->_eavAttributeFactory = $eavAttributeFactory; @@ -226,7 +229,8 @@ public function __construct( $filesystem, $coreRegistry, $logger, - $productRepository + $productRepository, + $serializer ); } @@ -883,7 +887,7 @@ public function getSelectedAttributesInfo($product) ['group' => 'CONFIGURABLE', 'method' => __METHOD__] ); if ($attributesOption = $product->getCustomOption('attributes')) { - $data = $this->getSerializer()->unserialize($attributesOption->getValue()); + $data = $this->serializer->unserialize($attributesOption->getValue()); $this->getUsedProductAttributeIds($product); $usedAttributes = $product->getData($this->_usedAttributes); @@ -965,7 +969,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p if ($subProduct) { $subProductLinkFieldId = $subProduct->getId(); - $product->addCustomOption('attributes', serialize($attributes)); + $product->addCustomOption('attributes', $this->serializer->serialize($attributes)); $product->addCustomOption('product_qty_' . $subProductLinkFieldId, 1, $subProduct); $product->addCustomOption('simple_product', $subProductLinkFieldId, $subProduct); @@ -1026,7 +1030,7 @@ public function checkProductBuyState($product) parent::checkProductBuyState($product); $option = $product->getCustomOption('info_buyRequest'); if ($option instanceof \Magento\Quote\Model\Quote\Item\Option) { - $buyRequest = new \Magento\Framework\DataObject($this->getSerializer()->unserialize($option->getValue())); + $buyRequest = new \Magento\Framework\DataObject($this->serializer->unserialize($option->getValue())); $attributes = $buyRequest->getSuperAttribute(); if (is_array($attributes)) { foreach ($attributes as $key => $val) { diff --git a/app/code/Magento/Downloadable/Model/Product/Type.php b/app/code/Magento/Downloadable/Model/Product/Type.php index 66ca9c82b002c..5c5807f66b205 100644 --- a/app/code/Magento/Downloadable/Model/Product/Type.php +++ b/app/code/Magento/Downloadable/Model/Product/Type.php @@ -85,6 +85,7 @@ class Type extends \Magento\Catalog\Model\Product\Type\Virtual * @param \Magento\Downloadable\Model\LinkFactory $linkFactory * @param TypeHandler\TypeHandlerInterface $typeHandler * @param JoinProcessorInterface $extensionAttributesJoinProcessor + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -104,7 +105,8 @@ public function __construct( \Magento\Downloadable\Model\SampleFactory $sampleFactory, \Magento\Downloadable\Model\LinkFactory $linkFactory, \Magento\Downloadable\Model\Product\TypeHandler\TypeHandlerInterface $typeHandler, - JoinProcessorInterface $extensionAttributesJoinProcessor + JoinProcessorInterface $extensionAttributesJoinProcessor, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->_sampleResFactory = $sampleResFactory; $this->_linkResource = $linkResource; @@ -123,7 +125,8 @@ public function __construct( $filesystem, $coreRegistry, $logger, - $productRepository + $productRepository, + $serializer ); } @@ -249,7 +252,7 @@ public function checkProductBuyState($product) parent::checkProductBuyState($product); $option = $product->getCustomOption('info_buyRequest'); if ($option instanceof \Magento\Quote\Model\Quote\Item\Option) { - $buyRequest = new \Magento\Framework\DataObject($this->getSerializer()->unserialize($option->getValue())); + $buyRequest = new \Magento\Framework\DataObject($this->serializer->unserialize($option->getValue())); if (!$buyRequest->hasLinks()) { if (!$product->getLinksPurchasedSeparately()) { $allLinksIds = $this->_linksFactory->create()->addProductToFilter( @@ -258,7 +261,7 @@ public function checkProductBuyState($product) $buyRequest->setLinks($allLinksIds); $product->addCustomOption( 'info_buyRequest', - $this->getSerializer()->serialize($buyRequest->getData()) + $this->serializer->serialize($buyRequest->getData()) ); } else { throw new \Magento\Framework\Exception\LocalizedException(__('Please specify product link(s).')); diff --git a/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php b/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php index f131977512366..83983cecb4ac3 100644 --- a/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php @@ -95,7 +95,7 @@ class Grouped extends \Magento\Catalog\Model\Product\Type\AbstractType * @param \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus * @param \Magento\Framework\App\State $appState * @param \Magento\Msrp\Helper\Data $msrpData - * + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -112,7 +112,8 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus, \Magento\Framework\App\State $appState, - \Magento\Msrp\Helper\Data $msrpData + \Magento\Msrp\Helper\Data $msrpData, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->productLinks = $catalogProductLink; $this->_storeManager = $storeManager; @@ -128,7 +129,8 @@ public function __construct( $filesystem, $coreRegistry, $logger, - $productRepository + $productRepository, + $serializer ); } @@ -202,7 +204,7 @@ public function getAssociatedProducts($product) $collection = $this->getAssociatedProductCollection( $product )->addAttributeToSelect( - ['name', 'price', 'special_price', 'special_from_date', 'special_to_date'] + ['name', 'price', 'special_price', 'special_from_date', 'special_to_date'] )->addFilterByRequiredOptions()->setPositionOrder()->addStoreFilter( $this->getStoreFilter($product) )->addAttributeToFilter( @@ -384,7 +386,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p $_result[0]->addCustomOption('product_type', self::TYPE_CODE, $product); $_result[0]->addCustomOption( 'info_buyRequest', - $this->getSerializer()->serialize( + $this->serializer->serialize( [ 'super_product_config' => [ 'product_type' => self::TYPE_CODE, @@ -402,7 +404,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p if (!$isStrictProcessMode || count($associatedProductsInfo)) { $product->addCustomOption('product_type', self::TYPE_CODE, $product); - $product->addCustomOption('info_buyRequest', $this->getSerializer()->serialize($buyRequest->getData())); + $product->addCustomOption('info_buyRequest', $this->serializer->serialize($buyRequest->getData())); $products[] = $product; } diff --git a/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php b/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php index 3efc0b7058be1..803165fe6c836 100644 --- a/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php +++ b/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php @@ -429,6 +429,13 @@ public function testPrepareForCartAdvancedNoProductsStrictFalse() ->expects($this->atLeastOnce()) ->method('getData') ->will($this->returnValue($associatedProducts)); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['serialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('serialize') + ->willReturn(json_encode($buyRequest->getData())); + $this->objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); $this->assertEquals( [0 => $this->product], @@ -540,6 +547,14 @@ public function testPrepareForCartAdvancedWithProductsStrictFalse() $buyRequest = new \Magento\Framework\DataObject(); $buyRequest->setSuperGroup([$associatedId => 1]); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['serialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('serialize') + ->willReturn(json_encode($buyRequest->getData())); + $this->objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); + $cached = true; $this->product ->expects($this->atLeastOnce()) @@ -583,6 +598,14 @@ public function testPrepareForCartAdvancedWithProductsStrictTrue() $buyRequest = new \Magento\Framework\DataObject(); $buyRequest->setSuperGroup([$associatedId => 1]); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['serialize']) + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('serialize') + ->willReturn(json_encode($buyRequest->getData())); + $this->objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); + $cached = true; $this->product ->expects($this->atLeastOnce()) diff --git a/app/code/Magento/Quote/Model/Quote/Item/Updater.php b/app/code/Magento/Quote/Model/Quote/Item/Updater.php index 103dd8acfb920..556ec5035e3ac 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Updater.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Updater.php @@ -43,15 +43,18 @@ class Updater * @param ProductFactory $productFactory * @param FormatInterface $localeFormat * @param ObjectFactory $objectFactory + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] */ public function __construct( ProductFactory $productFactory, FormatInterface $localeFormat, - ObjectFactory $objectFactory + ObjectFactory $objectFactory, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->productFactory = $productFactory; $this->localeFormat = $localeFormat; $this->objectFactory = $objectFactory; + $this->serializer = $serializer; } /** @@ -111,7 +114,7 @@ protected function setCustomPrice(array $info, Item $item) if ($infoBuyRequest) { $infoBuyRequest->setCustomPrice($itemPrice); - $infoBuyRequest->setValue($this->getSerializer()->serialize($infoBuyRequest->getData())); + $infoBuyRequest->setValue($this->serializer->serialize($infoBuyRequest->getData())); $infoBuyRequest->setCode('info_buyRequest'); $infoBuyRequest->setProduct($item->getProduct()); @@ -135,7 +138,7 @@ protected function unsetCustomPrice(Item $item) if ($infoBuyRequest->hasData('custom_price')) { $infoBuyRequest->unsetData('custom_price'); - $infoBuyRequest->setValue($this->getSerializer()->serialize($infoBuyRequest->getData())); + $infoBuyRequest->setValue($this->serializer->serialize($infoBuyRequest->getData())); $infoBuyRequest->setCode('info_buyRequest'); $infoBuyRequest->setProduct($item->getProduct()); $item->addOption($infoBuyRequest); @@ -145,22 +148,6 @@ protected function unsetCustomPrice(Item $item) $item->unsetData('original_custom_price'); } - /** - * Get Serializer interface. - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - - return $this->serializer; - } - /** * Return formatted price * diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/DateTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/DateTest.php index 93af50480c880..280996a81d7f6 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/DateTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/DateTest.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Catalog\Model\Product; +namespace Magento\Catalog\Model\Product\Option\Type; /** * Test for \Magento\Catalog\Model\Product\Option\Type\Date diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php index 6f98f0f413bf2..20d40abd61821 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php @@ -186,7 +186,7 @@ public function testPrepareForCart() $this->assertInstanceOf(\Magento\Framework\DataObject::class, $buyRequest); $this->assertEquals($product->getId(), $buyRequest->getProductId()); $this->assertSame($product, $buyRequest->getProduct()); - $this->assertEquals(serialize($requestData), $buyRequest->getValue()); + $this->assertEquals(json_encode($requestData), $buyRequest->getValue()); } /** diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php index 59d828baa2d5c..a3f84ab95abac 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php @@ -299,13 +299,14 @@ public function testGetSelectedAttributesInfo() $attribute = reset($attributes); $optionValueId = $attribute['values'][0]['value_index']; - $product->addCustomOption('attributes', serialize([$attribute['attribute_id'] => $optionValueId])); + $product->addCustomOption('attributes', json_encode([$attribute['attribute_id'] => $optionValueId])); $info = $this->model->getSelectedAttributesInfo($product); $this->assertEquals('Test Configurable', $info[0]['label']); $this->assertEquals('Option 1', $info[0]['value']); } /** + * @covers \Magento\ConfigurableProduct\Model\Product\Type\Configurable::getConfigurableAttributes() * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php * @magentoAppIsolation enabled */ @@ -316,7 +317,7 @@ public function testGetSelectedAttributesInfoForStore() $attribute = reset($attributes); $optionValueId = $attribute['values'][0]['value_index']; - $this->product->addCustomOption('attributes', serialize([$attribute['attribute_id'] => $optionValueId])); + $this->product->addCustomOption('attributes', json_encode([$attribute['attribute_id'] => $optionValueId])); $configurableAttr = $this->model->getConfigurableAttributes($this->product); $attribute = $configurableAttr->getFirstItem(); From 10bf550dae0fcaba726476113149126c45449959 Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Thu, 8 Dec 2016 19:28:20 +0200 Subject: [PATCH 059/132] MAGETWO-61653: Magento/Sales/Model/Order/CreditmemoFactory.php, remove \Magento\Framework\Unserialize\Unserialize and fix unit tests - stabilization bamboo builds --- .../Magento/Sales/_files/order_with_dummy_item_and_invoiced.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order_with_dummy_item_and_invoiced.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order_with_dummy_item_and_invoiced.php index 65389e13564ce..49671242a6793 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/order_with_dummy_item_and_invoiced.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/order_with_dummy_item_and_invoiced.php @@ -70,4 +70,4 @@ function saveOrderItems(array $orderItems, $parentOrderItem = null) saveOrderItems($orderItemData['children'], $orderItem); } } -} \ No newline at end of file +} From 6709b3cfff2973168d9255a41f4caf04886fe0e1 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Thu, 8 Dec 2016 18:44:16 +0200 Subject: [PATCH 060/132] MAGETWO-61647: Detailed investigation for info_buyrequest field and extension points for its modifications Conflicts: app/code/Magento/Bundle/Model/Product/Type.php --- .../Magento/Bundle/Model/Product/Type.php | 7 +- .../Test/Unit/Model/Product/TypeTest.php | 2500 +---------------- 2 files changed, 139 insertions(+), 2368 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index ff66bd6d32a6e..fcf61a967255b 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -11,6 +11,7 @@ use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Framework\Serialize\SerializerInterface; /** * Bundle Type Model @@ -169,6 +170,7 @@ class Type extends \Magento\Catalog\Model\Product\Type\AbstractType * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry * @param \Magento\CatalogInventory\Api\StockStateInterface $stockState * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -207,6 +209,7 @@ public function __construct( $this->priceCurrency = $priceCurrency; $this->_stockRegistry = $stockRegistry; $this->_stockState = $stockState; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct( $catalogProductOption, $eavConfig, @@ -1011,9 +1014,9 @@ public function checkProductBuyState($product) $productOptionIds = $this->getOptionsIds($product); $productSelections = $this->getSelectionsCollection($productOptionIds, $product); $selectionIds = $product->getCustomOption('bundle_selection_ids'); - $selectionIds = unserialize($selectionIds->getValue()); + $selectionIds = $this->serializer->unserialize($selectionIds->getValue()); $buyRequest = $product->getCustomOption('info_buyRequest'); - $buyRequest = new \Magento\Framework\DataObject(unserialize($buyRequest->getValue())); + $buyRequest = new \Magento\Framework\DataObject($this->serializer->unserialize($buyRequest->getValue())); $bundleOption = $buyRequest->getBundleOption(); if (empty($bundleOption)) { diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php index 2be68359909ef..4084813c7cd85 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php @@ -9,6 +9,10 @@ use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection; use Magento\Catalog\Model\Product\Option\Type\DefaultType; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\DataObject; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Bundle\Model\Selection; +use Magento\Catalog\Model\Product; /** * Class TypeTest @@ -78,7 +82,19 @@ protected function setUp() { $this->bundleCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory::class) - ->setMethods(['create']) + ->setMethods( + [ + 'create', + 'addAttributeToSelect', + 'setFlag', + 'setPositionOrder', + 'addStoreFilter', + 'setStoreId', + 'addFilterByRequiredOptions', + 'setOptionIdsFilter', + 'getItemById' + ] + ) ->disableOriginalConstructor() ->getMock(); $this->catalogData = $this->getMockBuilder(\Magento\Catalog\Helper\Data::class) @@ -135,2420 +151,172 @@ protected function setUp() 'stockState' => $this->stockState, 'catalogProduct' => $this->catalogProduct, 'priceCurrency' => $this->priceCurrency, - + 'serializer' => new Json() ] ); } /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * Bundle product without options should not be possible to buy. + * + * @expectedException \Magento\Framework\Exception\LocalizedException + * @expectedExceptionMessage Please specify product option */ - public function testPrepareForCartAdvancedWithoutOptions() + public function testCheckProductBuyStateEmptyOptionsException() { - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ - $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->setMethods(['getItems']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption', - 'getTypeInstance', - 'getStoreId', - 'hasData', - 'getData' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ - $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) - ->setMethods(['setStoreFilter', 'getOptionsCollection', 'getOptionsIds', 'getSelectionsCollection']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems', 'getItemById', 'appendSelections']) - ->disableOriginalConstructor() - ->getMock(); - - $this->parentClass($group, $option, $buyRequest, $product); + $this->mockBundleCollection(); + $product = $this->getProductMock(); + $product->method('getCustomOption')->willReturnMap([ + ['bundle_selection_ids', new DataObject(['value' => ''])], + ['info_buyRequest', new DataObject(['value' => json_encode(['bundle_option' => ''])])], + ]); + $product->setCustomOption(json_encode([])); - $product->expects($this->any()) - ->method('getSkipCheckRequiredOption') - ->willReturn(true); - $product->expects($this->any()) - ->method('getTypeInstance') - ->willReturn($productType); - $optionCollection->expects($this->any()) - ->method('appendSelections') - ->willReturn([$option]); - $productType->expects($this->once()) - ->method('setStoreFilter'); - $productType->expects($this->once()) - ->method('getOptionsCollection') - ->willReturn($optionCollection); - $productType->expects($this->once()) - ->method('getOptionsIds') - ->willReturn([1, 2, 3]); - $productType->expects($this->once()) - ->method('getSelectionsCollection') - ->willReturn($selectionCollection); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn('options'); - $option->expects($this->at(3)) - ->method('getId') - ->willReturn(3); - $option->expects($this->once()) - ->method('getRequired') - ->willReturn(true); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - $this->assertEquals('Please specify product option(s).', $result); + $this->model->checkProductBuyState($product); } /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * Previously selected options are not more available for buying. + * + * @param object $element + * @param string $expectedMessage + * @param bool $check + * + * @throws LocalizedException + * + * @expectedException \Magento\Framework\Exception\LocalizedException + * @dataProvider notAvailableOptionProvider */ - public function testPrepareForCartAdvancedWithShoppingCart() + public function testCheckProductBuyStateMissedOptionException($element, $expectedMessage, $check) { - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Type\Price $priceModel */ - $priceModel = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\Price::class) - ->setMethods(['getSelectionFinalTotalPrice']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - [ - '__wakeup', - 'getOptions', - 'getSuperProductConfig', - 'unsetData', - 'getData', - 'getQty', - 'getBundleOption', - 'getBundleOptionQty' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods( - [ - 'groupFactory', - 'getType', - 'getId', - 'getRequired', - 'isMultiSelection', - 'getProduct', - 'getValue', - 'getTitle' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ - $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->setMethods(['getItems']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - [ - '__wakeup', - 'isSalable', - 'getOptionId', - 'getSelectionCanChangeQty', - 'getSelectionId', - 'addCustomOption', - 'getId', - 'getOption', - 'getTypeInstance' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption', - 'getTypeInstance', - 'getStoreId', - 'hasData', - 'getData', - 'getId', - 'getCustomOption', - 'getPriceModel' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ - $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) - ->setMethods( - [ - 'setStoreFilter', - 'prepareForCart', - 'setParentProductId', - 'addCustomOption', - 'setCartQty', - 'getSelectionId' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems', 'getItemById', 'appendSelections']) - ->disableOriginalConstructor() - ->getMock(); + $this->mockBundleCollection(); + $product = $this->getProductMock(); + $product->method('getCustomOption')->willReturnMap([ + ['bundle_selection_ids', new DataObject(['value' => json_encode([1])])], + ['info_buyRequest', new DataObject(['value' => json_encode(['bundle_option' => [1]])])], + ]); + $product->setCustomOption(json_encode([])); - $this->parentClass($group, $option, $buyRequest, $product); + $this->bundleCollection->method('getItemById')->willReturn($element); + $this->catalogProduct->setSkipSaleableCheck($check); - $product->expects($this->any()) - ->method('getSkipCheckRequiredOption') - ->willReturn(true); - $product->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $product->expects($this->once()) - ->method('hasData') - ->willReturn(true); - $product->expects($this->any()) - ->method('getData') - ->willReturnCallback( - function ($key) use ($optionCollection, $selectionCollection) { - $resultValue = null; - switch ($key) { - case '_cache_instance_options_collection': - $resultValue = $optionCollection; - break; - case '_cache_instance_used_selections': - $resultValue = $selectionCollection; - break; - case '_cache_instance_used_selections_ids': - $resultValue = [5]; - break; - } - - return $resultValue; - } + try { + $this->model->checkProductBuyState($product); + } catch (LocalizedException $e) { + $this->assertContains( + $expectedMessage, + $e->getMessage() ); - $product->expects($this->any()) - ->method('getId') - ->willReturn(333); - $product->expects($this->once()) - ->method('getCustomOption') - ->willReturn($option); - $product->expects($this->once()) - ->method('getPriceModel') - ->willReturn($priceModel); - $optionCollection->expects($this->once()) - ->method('getItemById') - ->willReturn($option); - $optionCollection->expects($this->once()) - ->method('appendSelections'); - $productType->expects($this->once()) - ->method('setStoreFilter'); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn([3 => 5]); - $selectionCollection->expects($this->any()) - ->method('getItems') - ->willReturn([$selection]); - $selection->expects($this->once()) - ->method('isSalable') - ->willReturn(false); - $selection->expects($this->any()) - ->method('getOptionId') - ->willReturn(3); - $selection->expects($this->any()) - ->method('getOption') - ->willReturn($option); - $selection->expects($this->once()) - ->method('getSelectionCanChangeQty') - ->willReturn(true); - $selection->expects($this->once()) - ->method('getSelectionId'); - $selection->expects($this->once()) - ->method('addCustomOption') - ->willReturnSelf(); - $selection->expects($this->any()) - ->method('getId') - ->willReturn(333); - $selection->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $option->expects($this->at(3)) - ->method('getId') - ->willReturn(3); - $option->expects($this->at(9)) - ->method('getId') - ->willReturn(3); - $option->expects($this->once()) - ->method('getRequired') - ->willReturn(false); - $option->expects($this->once()) - ->method('isMultiSelection') - ->willReturn(true); - $option->expects($this->once()) - ->method('getProduct') - ->willReturn($product); - $option->expects($this->once()) - ->method('getValue') - ->willReturn(4); - $option->expects($this->once()) - ->method('getTitle') - ->willReturn('Title for option'); - $buyRequest->expects($this->once()) - ->method('getBundleOptionQty') - ->willReturn([3 => 5]); - $priceModel->expects($this->once()) - ->method('getSelectionFinalTotalPrice') - ->willReturnSelf(); - $productType->expects($this->once()) - ->method('prepareForCart') - ->willReturn([$productType]); - $productType->expects($this->once()) - ->method('setParentProductId') - ->willReturnSelf(); - $productType->expects($this->any()) - ->method('addCustomOption') - ->willReturnSelf(); - $productType->expects($this->once()) - ->method('setCartQty') - ->willReturnSelf(); - $productType->expects($this->once()) - ->method('getSelectionId') - ->willReturn(314); - - $this->priceCurrency->expects($this->once()) - ->method('convert') - ->willReturn(3.14); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - $this->assertEquals([$product, $productType], $result); + throw $e; + } } /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * In case of missed selection for required options, bundle product should be not able to buy. + * + * @expectedException \Magento\Framework\Exception\LocalizedException */ - public function testPrepareForCartAdvancedEmptyShoppingCart() + public function testCheckProductBuyStateRequiredOptionException() { - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Type\Price $priceModel */ - $priceModel = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\Price::class) - ->setMethods(['getSelectionFinalTotalPrice']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - [ - '__wakeup', - 'getOptions', - 'getSuperProductConfig', - 'unsetData', - 'getData', - 'getQty', - 'getBundleOption', - 'getBundleOptionQty' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods( - [ - 'groupFactory', - 'getType', - 'getId', - 'getRequired', - 'isMultiSelection', - 'getProduct', - 'getValue', - 'getTitle' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ - $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->setMethods(['getItems']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - [ - '__wakeup', - 'isSalable', - 'getOptionId', - 'getSelectionCanChangeQty', - 'getSelectionId', - 'addCustomOption', - 'getId', - 'getOption', - 'getTypeInstance' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption', - 'getTypeInstance', - 'getStoreId', - 'hasData', - 'getData', - 'getId', - 'getCustomOption', - 'getPriceModel' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ - $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) - ->setMethods(['setStoreFilter', 'prepareForCart']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems', 'getItemById', 'appendSelections']) - ->disableOriginalConstructor() - ->getMock(); - - $this->parentClass($group, $option, $buyRequest, $product); + $this->mockBundleCollection(); + $product = $this->getProductMock(); + $product->method('getCustomOption')->willReturnMap([ + ['bundle_selection_ids', new DataObject(['value' => json_encode([])])], + ['info_buyRequest', new DataObject(['value' => json_encode(['bundle_option' => [1]])])], + ]); + $product->setCustomOption(json_encode([])); - $product->expects($this->any()) - ->method('getSkipCheckRequiredOption') - ->willReturn(true); - $product->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $product->expects($this->once()) - ->method('hasData') - ->willReturn(true); - $product->expects($this->any()) - ->method('getData') - ->willReturnCallback( - function ($key) use ($optionCollection, $selectionCollection) { - $resultValue = null; - switch ($key) { - case '_cache_instance_options_collection': - $resultValue = $optionCollection; - break; - case '_cache_instance_used_selections': - $resultValue = $selectionCollection; - break; - case '_cache_instance_used_selections_ids': - $resultValue = [5]; - break; - } - - return $resultValue; - } - ); - $product->expects($this->any()) - ->method('getId') - ->willReturn(333); - $product->expects($this->once()) - ->method('getCustomOption') - ->willReturn($option); - $product->expects($this->once()) - ->method('getPriceModel') - ->willReturn($priceModel); - $optionCollection->expects($this->once()) - ->method('getItemById') - ->willReturn($option); - $optionCollection->expects($this->once()) - ->method('appendSelections'); - $productType->expects($this->once()) - ->method('setStoreFilter'); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn([3 => 5]); - $selectionCollection->expects($this->any()) - ->method('getItems') - ->willReturn([$selection]); - $selection->expects($this->once()) - ->method('isSalable') - ->willReturn(false); - $selection->expects($this->any()) - ->method('getOptionId') - ->willReturn(3); - $selection->expects($this->any()) - ->method('getOption') - ->willReturn($option); - $selection->expects($this->once()) - ->method('getSelectionCanChangeQty') - ->willReturn(true); - $selection->expects($this->once()) - ->method('getSelectionId'); - $selection->expects($this->once()) - ->method('addCustomOption') - ->willReturnSelf(); - $selection->expects($this->any()) - ->method('getId') - ->willReturn(333); - $selection->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $option->expects($this->at(3)) - ->method('getId') - ->willReturn(3); - $option->expects($this->at(9)) - ->method('getId') - ->willReturn(3); - $option->expects($this->once()) - ->method('getRequired') - ->willReturn(false); - $option->expects($this->once()) - ->method('isMultiSelection') - ->willReturn(true); - $option->expects($this->once()) - ->method('getProduct') - ->willReturn($product); - $option->expects($this->once()) - ->method('getValue') - ->willReturn(4); - $option->expects($this->once()) - ->method('getTitle') - ->willReturn('Title for option'); - $buyRequest->expects($this->once()) - ->method('getBundleOptionQty') - ->willReturn([3 => 5]); - $priceModel->expects($this->once()) - ->method('getSelectionFinalTotalPrice') - ->willReturnSelf(); - $productType->expects($this->once()) - ->method('prepareForCart') - ->willReturn([]); - - $this->priceCurrency->expects($this->once()) - ->method('convert') - ->willReturn(3.14); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - $this->assertEquals('We can\'t add this item to your shopping cart right now.', $result); - } - - /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function testPrepareForCartAdvancedStringInResult() - { - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Type\Price $priceModel */ - $priceModel = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\Price::class) - ->setMethods(['getSelectionFinalTotalPrice']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - [ - '__wakeup', - 'getOptions', - 'getSuperProductConfig', - 'unsetData', - 'getData', - 'getQty', - 'getBundleOption', - 'getBundleOptionQty' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods( - [ - 'groupFactory', - 'getType', - 'getId', - 'getRequired', - 'isMultiSelection', - 'getProduct', - 'getValue', - 'getTitle' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ - $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->setMethods(['getItems']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - [ - '__wakeup', - 'isSalable', - 'getOptionId', - 'getSelectionCanChangeQty', - 'getSelectionId', - 'addCustomOption', - 'getId', - 'getOption', - 'getTypeInstance' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption', - 'getTypeInstance', - 'getStoreId', - 'hasData', - 'getData', - 'getId', - 'getCustomOption', - 'getPriceModel' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ - $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) - ->setMethods(['setStoreFilter', 'prepareForCart']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems', 'getItemById', 'appendSelections']) + $falseSelection = $this->getMockBuilder(Selection::class) ->disableOriginalConstructor() + ->setMethods(['isSalable']) ->getMock(); + $falseSelection->method('isSalable')->willReturn(false); - $this->parentClass($group, $option, $buyRequest, $product); + $this->bundleCollection->method('getItemById')->willReturn($falseSelection); + $this->catalogProduct->setSkipSaleableCheck(false); - $product->expects($this->any()) - ->method('getSkipCheckRequiredOption') - ->willReturn(true); - $product->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $product->expects($this->once()) - ->method('hasData') - ->willReturn(true); - $product->expects($this->any()) - ->method('getData') - ->willReturnCallback( - function ($key) use ($optionCollection, $selectionCollection) { - $resultValue = null; - switch ($key) { - case '_cache_instance_options_collection': - $resultValue = $optionCollection; - break; - case '_cache_instance_used_selections': - $resultValue = $selectionCollection; - break; - case '_cache_instance_used_selections_ids': - $resultValue = [5]; - break; - } - - return $resultValue; - } + try { + $this->model->checkProductBuyState($product); + } catch (LocalizedException $e) { + $this->assertContains( + 'Please select all required options', + $e->getMessage() ); - $product->expects($this->any()) - ->method('getId') - ->willReturn(333); - $product->expects($this->once()) - ->method('getCustomOption') - ->willReturn($option); - $product->expects($this->once()) - ->method('getPriceModel') - ->willReturn($priceModel); - $optionCollection->expects($this->once()) - ->method('getItemById') - ->willReturn($option); - $optionCollection->expects($this->once()) - ->method('appendSelections'); - $productType->expects($this->once()) - ->method('setStoreFilter'); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn([3 => 5]); - $selectionCollection->expects($this->any()) - ->method('getItems') - ->willReturn([$selection]); - $selection->expects($this->once()) - ->method('isSalable') - ->willReturn(false); - $selection->expects($this->any()) - ->method('getOptionId') - ->willReturn(3); - $selection->expects($this->any()) - ->method('getOption') - ->willReturn($option); - $selection->expects($this->once()) - ->method('getSelectionCanChangeQty') - ->willReturn(true); - $selection->expects($this->once()) - ->method('getSelectionId'); - $selection->expects($this->once()) - ->method('addCustomOption') - ->willReturnSelf(); - $selection->expects($this->any()) - ->method('getId') - ->willReturn(333); - $selection->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $option->expects($this->at(3)) - ->method('getId') - ->willReturn(3); - $option->expects($this->at(9)) - ->method('getId') - ->willReturn(3); - $option->expects($this->once()) - ->method('getRequired') - ->willReturn(false); - $option->expects($this->once()) - ->method('isMultiSelection') - ->willReturn(true); - $option->expects($this->once()) - ->method('getProduct') - ->willReturn($product); - $option->expects($this->once()) - ->method('getValue') - ->willReturn(4); - $option->expects($this->once()) - ->method('getTitle') - ->willReturn('Title for option'); - $buyRequest->expects($this->once()) - ->method('getBundleOptionQty') - ->willReturn([3 => 5]); - $priceModel->expects($this->once()) - ->method('getSelectionFinalTotalPrice') - ->willReturnSelf(); - $productType->expects($this->once()) - ->method('prepareForCart') - ->willReturn('string'); - - $this->priceCurrency->expects($this->once()) - ->method('convert') - ->willReturn(3.14); - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - $this->assertEquals('string', $result); + throw $e; + } } /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * Prepare product mock for testing. + * + * @return \PHPUnit_Framework_MockObject_MockObject */ - public function testPrepareForCartAdvancedWithoutSelections() + public function getProductMock() { - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - [ - '__wakeup', - 'getOptions', - 'getSuperProductConfig', - 'unsetData', - 'getData', - 'getQty', - 'getBundleOption', - 'getBundleOptionQty' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) - ->disableOriginalConstructor() - ->getMock(); - - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption', - 'getTypeInstance', - 'getStoreId', - 'hasData', - 'getData', - 'getId' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ - $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) - ->setMethods(['setStoreFilter']) + $product = $this->getMockBuilder(Product::class) ->disableOriginalConstructor() + ->setMethods([ + '_wakeup', + 'getHasOptions', + 'getId', + 'getStoreId', + 'getCustomOption', + 'getTypeInstance', + 'setStoreFilter', + ]) ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems', 'getItemById', 'appendSelections']) - ->disableOriginalConstructor() - ->getMock(); - - $this->parentClass($group, $option, $buyRequest, $product); - - $product->expects($this->any()) - ->method('getSkipCheckRequiredOption') - ->willReturn(true); - $product->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $product->expects($this->once()) - ->method('hasData') - ->willReturn(true); - $product->expects($this->any()) - ->method('getData') - ->willReturnCallback( - function ($key) use ($optionCollection) { - $resultValue = null; - switch ($key) { - case '_cache_instance_options_collection': - $resultValue = $optionCollection; - break; - } - - return $resultValue; - } - ); - $product->expects($this->once()) - ->method('getId') - ->willReturn(333); - $productType->expects($this->once()) - ->method('setStoreFilter'); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn([]); - $buyRequest->expects($this->once()) - ->method('getBundleOptionQty') - ->willReturn([3 => 5]); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product, 'single'); - $this->assertEquals([$product], $result); + $product->method('getTypeInstance')->willReturn($product); + $product->method('setStoreFilter')->willReturn($product); + $optionCollectionCache = new DataObject(); + $optionCollectionCache->setAllIds([]); + $optionCollectionCache->setItems([ + new DataObject([ + 'required' => true, + 'id' => 1 + ]), + ]); + $product->setData('_cache_instance_options_collection', $optionCollectionCache); + return $product; } /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * Preparation mocks for checkProductsBuyState. */ - public function testPrepareForCartAdvancedSelectionsSelectionIdsExists() + public function mockBundleCollection() { - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ - $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->setMethods(['getItems']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods(['__wakeup', 'isSalable', 'getOptionId']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption', - 'getTypeInstance', - 'getStoreId', - 'hasData', - 'getData' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ - $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) - ->setMethods(['setStoreFilter']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems', 'getItemById', 'appendSelections']) - ->disableOriginalConstructor() - ->getMock(); - - $this->parentClass($group, $option, $buyRequest, $product); - - $product->expects($this->any()) - ->method('getSkipCheckRequiredOption') - ->willReturn(true); - $product->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $product->expects($this->once()) - ->method('hasData') - ->willReturn(true); - $product->expects($this->any()) - ->method('getData') - ->willReturnCallback( - function ($key) use ($optionCollection, $selectionCollection) { - $resultValue = null; - switch ($key) { - case '_cache_instance_options_collection': - $resultValue = $optionCollection; - break; - case '_cache_instance_used_selections': - $resultValue = $selectionCollection; - break; - case '_cache_instance_used_selections_ids': - $resultValue = [5]; - break; - } - - return $resultValue; - } - ); - $optionCollection->expects($this->once()) - ->method('appendSelections'); - $productType->expects($this->once()) - ->method('setStoreFilter'); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn([3 => 5]); - $selectionCollection->expects($this->at(0)) - ->method('getItems') - ->willReturn([$selection]); - $selectionCollection->expects($this->at(1)) - ->method('getItems') - ->willReturn([]); - $option->expects($this->any()) - ->method('getId') - ->willReturn(3); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - $this->assertEquals('Please specify product option(s).', $result); + $this->bundleCollection->method('create')->willReturn($this->bundleCollection); + $this->bundleCollection->method('addAttributeToSelect')->willReturn($this->bundleCollection); + $this->bundleCollection->method('setFlag')->willReturn($this->bundleCollection); + $this->bundleCollection->method('setPositionOrder')->willReturn($this->bundleCollection); + $this->bundleCollection->method('addStoreFilter')->willReturn($this->bundleCollection); + $this->bundleCollection->method('setStoreId')->willReturn($this->bundleCollection); + $this->bundleCollection->method('addFilterByRequiredOptions')->willReturn($this->bundleCollection); + $this->bundleCollection->method('setOptionIdsFilter')->willReturn($this->bundleCollection); } /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * Data provider for not available option. + * @return array */ - public function testPrepareForCartAdvancedSelectRequiredOptions() + public function notAvailableOptionProvider() { - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ - $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->setMethods(['getItems']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods(['__wakeup', 'isSalable', 'getOptionId']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption', - 'getTypeInstance', - 'getStoreId', - 'hasData', - 'getData' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ - $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) - ->setMethods(['setStoreFilter']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems', 'getItemById']) + $falseSelection = $this->getMockBuilder(Selection::class) ->disableOriginalConstructor() + ->setMethods(['isSalable']) ->getMock(); - - $this->parentClass($group, $option, $buyRequest, $product); - - $product->expects($this->any()) - ->method('getSkipCheckRequiredOption') - ->willReturn(true); - $product->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $product->expects($this->once()) - ->method('hasData') - ->willReturn(true); - $product->expects($this->any()) - ->method('getData') - ->willReturnCallback( - function ($key) use ($optionCollection, $selectionCollection) { - $resultValue = null; - switch ($key) { - case '_cache_instance_options_collection': - $resultValue = $optionCollection; - break; - case '_cache_instance_used_selections': - $resultValue = $selectionCollection; - break; - case '_cache_instance_used_selections_ids': - $resultValue = [0 => 5]; - break; - } - - return $resultValue; - } - ); - $optionCollection->expects($this->once()) - ->method('getItemById') - ->willReturn($option); - $productType->expects($this->once()) - ->method('setStoreFilter'); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn([3 => 5]); - $selectionCollection->expects($this->any()) - ->method('getItems') - ->willReturn([$selection]); - $selection->expects($this->once()) - ->method('isSalable') - ->willReturn(false); - $option->expects($this->at(3)) - ->method('getId') - ->willReturn(3); - $option->expects($this->once()) - ->method('getRequired') - ->willReturn(true); - $option->expects($this->once()) - ->method('isMultiSelection') - ->willReturn(true); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - $this->assertEquals('The required options you selected are not available.', $result); - } - - /** - * @return void - */ - public function testPrepareForCartAdvancedParentClassReturnString() - { - $exceptedResult = 'String message'; - - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods(['getItems', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - $product->expects($this->any()) - ->method('getOptions') - ->willThrowException(new LocalizedException(__($exceptedResult))); - $product->expects($this->once()) - ->method('getHasOptions') - ->willReturn(true); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - - $this->assertEquals($exceptedResult, $result); - } - - /** - * @return void - */ - public function testPrepareForCartAdvancedAllrequiredOption() - { - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption', - 'getTypeInstance', - 'getStoreId', - 'hasData', - 'getData' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ - $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) - ->setMethods(['setStoreFilter']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems']) - ->disableOriginalConstructor() - ->getMock(); - - $this->parentClass($group, $option, $buyRequest, $product); - - $product->expects($this->any()) - ->method('getSkipCheckRequiredOption') - ->willReturn(false); - $product->expects($this->once()) - ->method('getTypeInstance') - ->willReturn($productType); - $product->expects($this->once()) - ->method('hasData') - ->willReturn(true); - $product->expects($this->any()) - ->method('getData') - ->willReturnCallback( - function ($key) use ($optionCollection) { - $resultValue = null; - switch ($key) { - case '_cache_instance_options_collection': - $resultValue = $optionCollection; - break; - case '_cache_instance_used_selections_ids': - $resultValue = [0 => 5]; - break; - } - - return $resultValue; - } - ); - $optionCollection->expects($this->once()) - ->method('getItems') - ->willReturn([$option]); - $productType->expects($this->once()) - ->method('setStoreFilter'); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn([3 => 5]); - $option->expects($this->at(3)) - ->method('getId') - ->willReturn(3); - $option->expects($this->once()) - ->method('getRequired') - ->willReturn(true); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - $this->assertEquals('Please select all required options.', $result); - } - - /** - * @return void - */ - public function testPrepareForCartAdvancedSpecifyProductOptions() - { - /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ - $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) - ->setMethods( - ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] - ) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods( - ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] - ) - ->disableOriginalConstructor() - ->getMock(); - /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ - $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) - ->setMethods(['groupFactory', 'getType', 'getId']) - ->disableOriginalConstructor() - ->getMock(); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods( - [ - 'getOptions', - 'getHasOptions', - 'prepareCustomOptions', - 'addCustomOption', - 'setCartQty', - 'setQty', - 'getSkipCheckRequiredOption' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - - $this->parentClass($group, $option, $buyRequest, $product); - - $product->expects($this->once()) - ->method('getSkipCheckRequiredOption') - ->willReturn(true); - $buyRequest->expects($this->once()) - ->method('getBundleOption') - ->willReturn([0, '', 'str']); - - $result = $this->model->prepareForCartAdvanced($buyRequest, $product); - $this->assertEquals('Please specify product option(s).', $result); - } - - /** - * @return void - */ - public function testHasWeightTrue() - { - $this->assertTrue($this->model->hasWeight(), 'This product has no weight, but it should'); - } - - /** - * @return void - */ - public function testGetIdentities() - { - $identities = ['id1', 'id2']; - $productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); - $optionMock = $this->getMock( - \Magento\Bundle\Model\Option::class, - ['getSelections', '__wakeup'], - [], - '', - false - ); - $optionCollectionMock = $this->getMock( - \Magento\Bundle\Model\ResourceModel\Option\Collection::class, - [], - [], - '', - false - ); - $cacheKey = '_cache_instance_options_collection'; - $productMock->expects($this->once()) - ->method('getIdentities') - ->will($this->returnValue($identities)); - $productMock->expects($this->once()) - ->method('hasData') - ->with($cacheKey) - ->will($this->returnValue(true)); - $productMock->expects($this->once()) - ->method('getData') - ->with($cacheKey) - ->will($this->returnValue($optionCollectionMock)); - $optionCollectionMock - ->expects($this->once()) - ->method('getItems') - ->will($this->returnValue([$optionMock])); - $optionMock - ->expects($this->exactly(2)) - ->method('getSelections') - ->will($this->returnValue([$productMock])); - $this->assertEquals($identities, $this->model->getIdentities($productMock)); - } - - /** - * @return void - */ - public function testGetSkuWithType() - { - $sku = 'sku'; - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->getMock(); - $productMock->expects($this->at(0)) - ->method('getData') - ->with('sku') - ->will($this->returnValue($sku)); - $productMock->expects($this->at(2)) - ->method('getData') - ->with('sku_type') - ->will($this->returnValue('some_data')); - - $this->assertEquals($sku, $this->model->getSku($productMock)); - } - - /** - * @return void - */ - public function testGetSkuWithoutType() - { - $sku = 'sku'; - $itemSku = 'item'; - $selectionIds = [1, 2, 3]; - $serializeIds = serialize($selectionIds); - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) - ->disableOriginalConstructor() - ->getMock(); - $customOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) - ->setMethods(['getValue', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - $selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods(['getSku', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - - $productMock->expects($this->at(0)) - ->method('getData') - ->with('sku') - ->will($this->returnValue($sku)); - $productMock->expects($this->at(1)) - ->method('getCustomOption') - ->with('option_ids') - ->will($this->returnValue(false)); - $productMock->expects($this->at(2)) - ->method('getData') - ->with('sku_type') - ->will($this->returnValue(null)); - $productMock->expects($this->once()) - ->method('hasCustomOptions') - ->will($this->returnValue(true)); - $productMock->expects($this->at(4)) - ->method('getCustomOption') - ->with('bundle_selection_ids') - ->will($this->returnValue($customOptionMock)); - $customOptionMock->expects($this->any()) - ->method('getValue') - ->will($this->returnValue($serializeIds)); - $selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6); - $selectionMock->expects(($this->any())) - ->method('getItems') - ->will($this->returnValue([$selectionItemMock])); - $selectionItemMock->expects($this->any()) - ->method('getSku') - ->will($this->returnValue($itemSku)); - - $this->assertEquals($sku . '-' . $itemSku, $this->model->getSku($productMock)); - } - - /** - * @return void - */ - public function testGetWeightWithoutCustomOption() - { - $weight = 5; - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getData']) - ->disableOriginalConstructor() - ->getMock(); - - $productMock->expects($this->at(0)) - ->method('getData') - ->with('weight_type') - ->will($this->returnValue(true)); - $productMock->expects($this->at(1)) - ->method('getData') - ->with('weight') - ->will($this->returnValue($weight)); - - $this->assertEquals($weight, $this->model->getWeight($productMock)); - } - - /** - * @return void - */ - public function testGetWeightWithCustomOption() - { - $weight = 5; - $selectionIds = [1, 2, 3]; - $serializeIds = serialize($selectionIds); - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) - ->disableOriginalConstructor() - ->getMock(); - $customOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) - ->setMethods(['getValue', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - $selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods(['getSelectionId', 'getWeight', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - - $productMock->expects($this->at(0)) - ->method('getData') - ->with('weight_type') - ->will($this->returnValue(false)); - $productMock->expects($this->once()) - ->method('hasCustomOptions') - ->will($this->returnValue(true)); - $productMock->expects($this->at(2)) - ->method('getCustomOption') - ->with('bundle_selection_ids') - ->will($this->returnValue($customOptionMock)); - $customOptionMock->expects($this->once()) - ->method('getValue') - ->will($this->returnValue($serializeIds)); - $selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 3, 4); - $selectionMock->expects($this->once()) - ->method('getItems') - ->will($this->returnValue([$selectionItemMock])); - $selectionItemMock->expects($this->any()) - ->method('getSelectionId') - ->will($this->returnValue('id')); - $productMock->expects($this->at(5)) - ->method('getCustomOption') - ->with('selection_qty_' . 'id') - ->will($this->returnValue(null)); - $selectionItemMock->expects($this->once()) - ->method('getWeight') - ->will($this->returnValue($weight)); - - $this->assertEquals($weight, $this->model->getWeight($productMock)); - } - - /** - * @return void - */ - public function testGetWeightWithSeveralCustomOption() - { - $weight = 5; - $qtyOption = 5; - $selectionIds = [1, 2, 3]; - $serializeIds = serialize($selectionIds); - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) - ->disableOriginalConstructor() - ->getMock(); - $customOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) - ->setMethods(['getValue', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - $qtyOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) - ->setMethods(['getValue', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - $selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods(['getSelectionId', 'getWeight', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - - $productMock->expects($this->at(0)) - ->method('getData') - ->with('weight_type') - ->will($this->returnValue(false)); - $productMock->expects($this->once()) - ->method('hasCustomOptions') - ->will($this->returnValue(true)); - $productMock->expects($this->at(2)) - ->method('getCustomOption') - ->with('bundle_selection_ids') - ->will($this->returnValue($customOptionMock)); - $customOptionMock->expects($this->once()) - ->method('getValue') - ->will($this->returnValue($serializeIds)); - $selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 3, 4); - $selectionMock->expects($this->once()) - ->method('getItems') - ->will($this->returnValue([$selectionItemMock])); - $selectionItemMock->expects($this->any()) - ->method('getSelectionId') - ->will($this->returnValue('id')); - $productMock->expects($this->at(5)) - ->method('getCustomOption') - ->with('selection_qty_' . 'id') - ->will($this->returnValue($qtyOptionMock)); - $qtyOptionMock->expects($this->once()) - ->method('getValue') - ->will($this->returnValue($qtyOption)); - $selectionItemMock->expects($this->once()) - ->method('getWeight') - ->will($this->returnValue($weight)); - - $this->assertEquals($weight * $qtyOption, $this->model->getWeight($productMock)); - } - - /** - * @return void - */ - public function testIsVirtualWithoutCustomOption() - { - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->getMock(); - - $productMock->expects($this->once()) - ->method('hasCustomOptions') - ->will($this->returnValue(false)); - - $this->assertFalse($this->model->isVirtual($productMock)); - } - - /** - * @return void - */ - public function testIsVirtual() - { - $selectionIds = [1, 2, 3]; - $serializeIds = serialize($selectionIds); - - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->getMock(); - $customOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) - ->setMethods(['getValue', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - $selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->setMethods(['isVirtual', 'getItems', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - - $productMock->expects($this->once()) - ->method('hasCustomOptions') - ->will($this->returnValue(true)); - $productMock->expects($this->once()) - ->method('getCustomOption') - ->with('bundle_selection_ids') - ->will($this->returnValue($customOptionMock)); - $customOptionMock->expects($this->once()) - ->method('getValue') - ->will($this->returnValue($serializeIds)); - $selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 2, 3); - $selectionMock->expects($this->once()) - ->method('getItems') - ->will($this->returnValue([$selectionItemMock])); - $selectionItemMock->expects($this->once()) - ->method('isVirtual') - ->will($this->returnValue(true)); - $selectionItemMock->expects($this->once()) - ->method('isVirtual') - ->will($this->returnValue(true)); - $selectionMock->expects($this->once()) - ->method('count') - ->will($this->returnValue(1)); - - $this->assertTrue($this->model->isVirtual($productMock)); - } - - /** - * @param array $selectionIds - * @param \PHPUnit_Framework_MockObject_MockObject $productMock - * @param int $getSelectionsIndex - * @param int $getSelectionsIdsIndex - * @return \PHPUnit_Framework_MockObject_MockObject - */ - - protected function getSelectionsByIdsMock($selectionIds, $productMock, $getSelectionsIndex, $getSelectionsIdsIndex) - { - $usedSelectionsMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->disableOriginalConstructor() - ->getMock(); - - $productMock->expects($this->at($getSelectionsIndex)) - ->method('getData') - ->with('_cache_instance_used_selections') - ->will($this->returnValue($usedSelectionsMock)); - $productMock->expects($this->at($getSelectionsIdsIndex)) - ->method('getData') - ->with('_cache_instance_used_selections_ids') - ->will($this->returnValue($selectionIds)); - - return $usedSelectionsMock; - } - - /** - * @param int $expected - * @param int $firstId - * @param int $secondId - * @return void - * @dataProvider shakeSelectionsDataProvider - */ - public function testShakeSelections($expected, $firstId, $secondId) - { - $firstItemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getOption', 'getOptionId', 'getPosition', 'getSelectionId']) - ->disableOriginalConstructor() - ->getMock(); - $secondItemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->setMethods(['__wakeup', 'getOption', 'getOptionId', 'getPosition', 'getSelectionId']) - ->disableOriginalConstructor() - ->getMock(); - $optionFirstMock = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) - ->setMethods(['getPosition', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - $optionSecondMock = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) - ->setMethods(['getPosition', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - - $firstItemMock->expects($this->once()) - ->method('getOption') - ->will($this->returnValue($optionFirstMock)); - $optionFirstMock->expects($this->once()) - ->method('getPosition') - ->will($this->returnValue('option_position')); - $firstItemMock->expects($this->once()) - ->method('getOptionId') - ->will($this->returnValue('option_id')); - $firstItemMock->expects($this->once()) - ->method('getPosition') - ->will($this->returnValue('position')); - $firstItemMock->expects($this->once()) - ->method('getSelectionId') - ->will($this->returnValue($firstId)); - $secondItemMock->expects($this->once()) - ->method('getOption') - ->will($this->returnValue($optionSecondMock)); - $optionSecondMock->expects($this->any()) - ->method('getPosition') - ->will($this->returnValue('option_position')); - $secondItemMock->expects($this->once()) - ->method('getOptionId') - ->will($this->returnValue('option_id')); - $secondItemMock->expects($this->once()) - ->method('getPosition') - ->will($this->returnValue('position')); - $secondItemMock->expects($this->once()) - ->method('getSelectionId') - ->will($this->returnValue($secondId)); - - $this->assertEquals($expected, $this->model->shakeSelections($firstItemMock, $secondItemMock)); - } - - /** - * @return array - */ - public function shakeSelectionsDataProvider() - { + $falseSelection->method('isSalable')->willReturn(false); return [ - [0, 0, 0], - [1, 1, 0], - [-1, 0, 1] - ]; - } - - /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function testGetSelectionsByIds() - { - $selectionIds = [1, 2, 3]; - $usedSelectionsIds = [4, 5, 6]; - $storeId = 2; - $websiteId = 1; - $storeFilter = 'store_filter'; - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->getMock(); - $usedSelectionsMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->setMethods( - [ - 'addAttributeToSelect', - 'setFlag', - 'addStoreFilter', - 'setStoreId', - 'setPositionOrder', - 'addFilterByRequiredOptions', - 'setSelectionIdsFilter', - 'joinPrices' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - $productGetMap = [ - ['_cache_instance_used_selections', null, null], - ['_cache_instance_used_selections_ids', null, $usedSelectionsIds], - ['_cache_instance_store_filter', null, $storeFilter], - ]; - $productMock->expects($this->any()) - ->method('getData') - ->will($this->returnValueMap($productGetMap)); - $productSetMap = [ - ['_cache_instance_used_selections', $usedSelectionsMock, $productMock], - ['_cache_instance_used_selections_ids', $selectionIds, $productMock], - ]; - $productMock->expects($this->any()) - ->method('setData') - ->will($this->returnValueMap($productSetMap)); - $productMock->expects($this->once()) - ->method('getStoreId') - ->will($this->returnValue($storeId)); - - $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) - ->setMethods(['getWebsiteId', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - $this->storeManager->expects($this->once()) - ->method('getStore') - ->with($storeId) - ->will($this->returnValue($storeMock)); - $storeMock->expects($this->once()) - ->method('getWebsiteId') - ->will($this->returnValue($websiteId)); - - $this->bundleCollection->expects($this->once()) - ->method('create') - ->will($this->returnValue($usedSelectionsMock)); - - $usedSelectionsMock->expects($this->once()) - ->method('addAttributeToSelect') - ->with('*') - ->will($this->returnSelf()); - $flagMap = [ - ['product_children', true, $usedSelectionsMock], - ]; - $usedSelectionsMock->expects($this->any()) - ->method('setFlag') - ->will($this->returnValueMap($flagMap)); - $usedSelectionsMock->expects($this->once()) - ->method('addStoreFilter') - ->with($storeFilter) - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('setStoreId') - ->with($storeId) - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('setPositionOrder') - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('addFilterByRequiredOptions') - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('setSelectionIdsFilter') - ->with($selectionIds) - ->will($this->returnSelf()); - - $usedSelectionsMock->expects($this->once()) - ->method('joinPrices') - ->with($websiteId) - ->will($this->returnSelf()); - - $this->catalogData->expects($this->once()) - ->method('isPriceGlobal') - ->will($this->returnValue(false)); - - $this->model->getSelectionsByIds($selectionIds, $productMock); - } - - /** - * @return void - */ - public function testGetOptionsByIds() - { - $optionsIds = [1, 2, 3]; - $usedOptionsIds = [4, 5, 6]; - $productId = 3; - $storeId = 2; - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->getMock(); - $usedOptionsMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getResourceCollection']) - ->disableOriginalConstructor() - ->getMock(); - $resourceClassName = \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::class; - $dbResourceMock = $this->getMockBuilder($resourceClassName) - ->setMethods(['setProductIdFilter', 'setPositionOrder', 'joinValues', 'setIdFilter']) - ->disableOriginalConstructor() - ->getMock(); - $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) - ->setMethods(['getId', '__wakeup']) - ->disableOriginalConstructor() - ->getMock(); - - $productMock->expects($this->at(0)) - ->method('getData') - ->with('_cache_instance_used_options') - ->will($this->returnValue(null)); - $productMock->expects($this->at(1)) - ->method('getData') - ->with('_cache_instance_used_options_ids') - ->will($this->returnValue($usedOptionsIds)); - $productMock->expects($this->once()) - ->method('getId') - ->will($this->returnValue($productId)); - $this->bundleOptionFactory->expects($this->once()) - ->method('create') - ->will($this->returnValue($usedOptionsMock)); - $usedOptionsMock->expects($this->once()) - ->method('getResourceCollection') - ->will($this->returnValue($dbResourceMock)); - $dbResourceMock->expects($this->once()) - ->method('setProductIdFilter') - ->with($productId) - ->will($this->returnSelf()); - $dbResourceMock->expects($this->once()) - ->method('setPositionOrder') - ->will($this->returnSelf()); - $this->storeManager->expects($this->once()) - ->method('getStore') - ->will($this->returnValue($storeMock)); - $storeMock->expects($this->once()) - ->method('getId') - ->will($this->returnValue($storeId)); - $dbResourceMock->expects($this->once()) - ->method('joinValues') - ->will($this->returnSelf()); - $dbResourceMock->expects($this->once()) - ->method('setIdFilter') - ->with($optionsIds) - ->will($this->returnSelf()); - $productMock->expects($this->at(3)) - ->method('setData') - ->with('_cache_instance_used_options', $dbResourceMock) - ->will($this->returnSelf()); - $productMock->expects($this->at(4)) - ->method('setData') - ->with('_cache_instance_used_options_ids', $optionsIds) - ->will($this->returnSelf()); - - $this->model->getOptionsByIds($optionsIds, $productMock); - } - - /** - * @return void - */ - public function testIsSalableFalse() - { - $product = new \Magento\Framework\DataObject( [ - 'is_salable' => false, - 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED - ] - ); - - $this->assertFalse($this->model->isSalable($product)); - } - - /** - * @return void - */ - public function testIsSalableWithoutOptions() - { - $optionCollectionMock = $this->getOptionCollectionMock([]); - $product = new \Magento\Framework\DataObject( + false, + 'The required options you selected are not available', + false, + ], [ - 'is_salable' => true, - '_cache_instance_options_collection' => $optionCollectionMock, - 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED - ] - ); - - $this->assertFalse($this->model->isSalable($product)); - } - - /** - * @return void - */ - public function testIsSalableWithRequiredOptionsTrue() - { - $option1 = $this->getRequiredOptionMock(10, 10); - $option2 = $this->getRequiredOptionMock(20, 10); - - $option3 = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) - ->setMethods(['getRequired', 'getOptionId', 'getId']) - ->disableOriginalConstructor() - ->getMock(); - $option3->method('getRequired') - ->willReturn(false); - $option3->method('getOptionId') - ->willReturn(30); - $option3->method('getId') - ->willReturn(30); - - $optionCollectionMock = $this->getOptionCollectionMock([$option1, $option2, $option3]); - $selectionCollectionMock = $this->getSelectionCollectionMock([$option1, $option2]); - $this->bundleCollection->expects($this->atLeastOnce()) - ->method('create') - ->will($this->returnValue($selectionCollectionMock)); - - $product = new \Magento\Framework\DataObject( - [ - 'is_salable' => true, - '_cache_instance_options_collection' => $optionCollectionMock, - 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, - ] - ); - - $this->assertTrue($this->model->isSalable($product)); - } - - /** - * @return void - */ - public function testIsSalableCache() - { - $product = new \Magento\Framework\DataObject( - [ - 'is_salable' => true, - 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, - 'all_items_salable' => true - ] - ); - - $this->assertTrue($this->model->isSalable($product)); - } - - /** - * @return void - */ - public function testIsSalableWithEmptySelectionsCollection() - { - $option = $this->getRequiredOptionMock(1, 10); - $optionCollectionMock = $this->getOptionCollectionMock([$option]); - $selectionCollectionMock = $this->getSelectionCollectionMock([]); - - $this->bundleCollection->expects($this->once()) - ->method('create') - ->will($this->returnValue($selectionCollectionMock)); - - $product = new \Magento\Framework\DataObject( - [ - 'is_salable' => true, - '_cache_instance_options_collection' => $optionCollectionMock, - 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, - ] - ); - - $this->assertFalse($this->model->isSalable($product)); - } - - /** - * @return void - */ - public function nottestIsSalableWithRequiredOptionsOutOfStock() - { - $option1 = $this->getRequiredOptionMock(10, 10); - $option1 - ->expects($this->atLeastOnce()) - ->method('getSelectionCanChangeQty') - ->willReturn(false); - - $option2 = $this->getRequiredOptionMock(20, 10); - $option2 - ->expects($this->atLeastOnce()) - ->method('getSelectionCanChangeQty') - ->willReturn(false); - - $this->stockRegistry->method('getStockItem') - ->willReturn($this->getStockItem(true)); - $this->stockState - ->method('getStockQty') - ->will( - $this->returnValueMap( - [ - [10, 10], - [20, 5] - ] - ) - ); - - $optionCollectionMock = $this->getOptionCollectionMock([$option1, $option2]); - $selectionCollectionMock = $this->getSelectionCollectionMock([$option1, $option2]); - $this->bundleCollection->expects($this->once()) - ->method('create') - ->will($this->returnValue($selectionCollectionMock)); - - $product = new \Magento\Framework\DataObject( - [ - 'is_salable' => true, - '_cache_instance_options_collection' => $optionCollectionMock, - 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, - ] - ); - - $this->assertFalse($this->model->isSalable($product)); - } - - /** - * @param int $id - * @param int $selectionQty - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getRequiredOptionMock($id, $selectionQty) - { - $option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) - ->setMethods( - [ - 'getRequired', - 'isSalable', - 'hasSelectionQty', - 'getSelectionQty', - 'getOptionId', - 'getId', - 'getSelectionCanChangeQty' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - $option->method('getRequired') - ->willReturn(true); - $option->method('isSalable') - ->willReturn(true); - $option->method('hasSelectionQty') - ->willReturn(true); - $option->method('getSelectionQty') - ->willReturn($selectionQty); - $option->method('getOptionId') - ->willReturn($id); - $option->method('getSelectionCanChangeQty') - ->willReturn(false); - $option->method('getId') - ->willReturn($id); - - return $option; - } - - /** - * @param array $selectedOptions - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getSelectionCollectionMock(array $selectedOptions) - { - $selectionCollectionMock = $this->getMockBuilder( - \Magento\Bundle\Model\ResourceModel\Selection\Collection::class - ) - ->disableOriginalConstructor() - ->getMock(); - - $selectionCollectionMock - ->expects($this->any()) - ->method('getItems') - ->willReturn($selectedOptions); - - $selectionCollectionMock - ->expects($this->any()) - ->method('getIterator') - ->willReturn(new \ArrayIterator($selectedOptions)); - - return $selectionCollectionMock; - } - - /** - * @param array $options - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getOptionCollectionMock(array $options) - { - $ids = []; - foreach ($options as $option) { - $ids[] = $option->getId(); - } - - $optionCollectionMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->setMethods(['getItems', 'getAllIds']) - ->disableOriginalConstructor() - ->getMock(); - - $optionCollectionMock - ->expects($this->any()) - ->method('getItems') - ->willReturn($options); - - $optionCollectionMock - ->expects($this->any()) - ->method('getAllIds') - ->willReturn($ids); - - return $optionCollectionMock; - } - - /** - * @param bool $isManageStock - * @return \Magento\CatalogInventory\Api\Data\StockItemInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected function getStockItem($isManageStock) - { - $result = $this->getMockBuilder(\Magento\CatalogInventory\Api\Data\StockItemInterface::class) - ->getMock(); - $result->method('getManageStock') - ->willReturn($isManageStock); - - return $result; - } - - /** - * @param \PHPUnit_Framework_MockObject_MockObject|DefaultType $group - * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option $option - * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest - * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product - * @return void - */ - protected function parentClass($group, $option, $buyRequest, $product) - { - $group->expects($this->once()) - ->method('setOption') - ->willReturnSelf(); - $group->expects($this->once()) - ->method('setProduct') - ->willReturnSelf(); - $group->expects($this->once()) - ->method('setRequest') - ->willReturnSelf(); - $group->expects($this->once()) - ->method('setProcessMode') - ->willReturnSelf(); - $group->expects($this->once()) - ->method('validateUserValue') - ->willReturnSelf(); - $group->expects($this->once()) - ->method('prepareForCart') - ->willReturn('someString'); - - $option->expects($this->once()) - ->method('getType'); - $option->expects($this->once()) - ->method('groupFactory') - ->willReturn($group); - $option->expects($this->at(0)) - ->method('getId') - ->willReturn(333); - - $buyRequest->expects($this->once()) - ->method('getData'); - $buyRequest->expects($this->once()) - ->method('getOptions'); - $buyRequest->expects($this->once()) - ->method('getSuperProductConfig') - ->willReturn([]); - $buyRequest->expects($this->any()) - ->method('unsetData') - ->willReturnSelf(); - $buyRequest->expects($this->any()) - ->method('getQty'); - - $product->expects($this->once()) - ->method('getOptions') - ->willReturn([$option]); - $product->expects($this->once()) - ->method('getHasOptions') - ->willReturn(true); - $product->expects($this->once()) - ->method('prepareCustomOptions'); - $product->expects($this->any()) - ->method('addCustomOption') - ->willReturnSelf(); - $product->expects($this->any()) - ->method('setCartQty') - ->willReturnSelf(); - $product->expects($this->once()) - ->method('setQty'); - - $this->catalogProduct->expects($this->once()) - ->method('getSkipSaleableCheck') - ->willReturn(false); - } - - public function testGetSelectionsCollection() - { - $optionIds = [1, 2, 3]; - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->setMethods( - [ - '_wakeup', - 'getStoreId', - 'getData', - 'hasData', - 'setData', - 'getId' - ] - ) - ->getMock(); - $store = $this->getMockBuilder(\Magento\Store\Model\Store::class) - ->disableOriginalConstructor() - ->setMethods(['getWebsiteId']) - ->getMock(); - - $product->expects($this->once())->method('getStoreId')->willReturn('store_id'); - $selectionCollection = $this->getSelectionCollection(); - $this->bundleCollection->expects($this->once())->method('create')->willReturn($selectionCollection); - $this->storeManager->expects($this->once())->method('getStore')->willReturn($store); - $store->expects($this->once())->method('getWebsiteId')->willReturn('website_id'); - $selectionCollection->expects($this->any())->method('joinPrices')->with('website_id')->willReturnSelf(); - - $this->assertEquals($selectionCollection, $this->model->getSelectionsCollection($optionIds, $product)); - } - - /** - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function getSelectionCollection() - { - $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) - ->disableOriginalConstructor() - ->getMock(); - $selectionCollection->expects($this->any())->method('addAttributeToSelect')->willReturnSelf(); - $selectionCollection->expects($this->any())->method('setFlag')->willReturnSelf(); - $selectionCollection->expects($this->any())->method('setPositionOrder')->willReturnSelf(); - $selectionCollection->expects($this->any())->method('addStoreFilter')->willReturnSelf(); - $selectionCollection->expects($this->any())->method('setStoreId')->willReturnSelf(); - $selectionCollection->expects($this->any())->method('addFilterByRequiredOptions')->willReturnSelf(); - $selectionCollection->expects($this->any())->method('setOptionIdsFilter')->willReturnSelf(); - $selectionCollection->expects($this->any())->method('addPriceData')->willReturnSelf(); - $selectionCollection->expects($this->any())->method('addTierPriceData')->willReturnSelf(); - - return $selectionCollection; - } - - public function testProcessBuyRequest() - { - $result = ['bundle_option' => [], 'bundle_option_qty' => []]; - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->getMock(); - $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->disableOriginalConstructor() - ->setMethods(['getBundleOption', 'getBundleOptionQty']) - ->getMock(); - - $buyRequest->expects($this->once())->method('getBundleOption')->willReturn('bundleOption'); - $buyRequest->expects($this->once())->method('getBundleOptionQty')->willReturn('optionId'); - - $this->assertEquals($result, $this->model->processBuyRequest($product, $buyRequest)); - } - - public function testGetProductsToPurchaseByReqGroups() - { - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->getMock(); - $resourceClassName = \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::class; - $dbResourceMock = $this->getMockBuilder($resourceClassName) - ->setMethods(['getItems']) - ->disableOriginalConstructor() - ->getMock(); - $item = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->disableOriginalConstructor() - ->setMethods(['getId', 'getRequired']) - ->getMock(); - $selectionCollection = $this->getSelectionCollection(); - $this->bundleCollection->expects($this->once())->method('create')->willReturn($selectionCollection); - - $selectionItem = $this->getMockBuilder(\Magento\Framework\DataObject::class) - ->disableOriginalConstructor() - ->getMock(); - - $product->expects($this->any())->method('hasData')->willReturn(true); - $product->expects($this->at(1)) - ->method('getData') - ->with('_cache_instance_options_collection') - ->willReturn($dbResourceMock); - $dbResourceMock->expects($this->once())->method('getItems')->willReturn([$item]); - $item->expects($this->once())->method('getId')->willReturn('itemId'); - $item->expects($this->once())->method('getRequired')->willReturn(true); - - $selectionCollection - ->expects($this->any()) - ->method('getIterator') - ->willReturn(new \ArrayIterator([$selectionItem])); - $this->assertEquals([[$selectionItem]], $this->model->getProductsToPurchaseByReqGroups($product)); - } - - public function testGetSearchableData() - { - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->setMethods(['_wakeup', 'getHasOptions', 'getId', 'getStoreId']) - ->getMock(); - $option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) - ->disableOriginalConstructor() - ->setMethods(['getSearchableData']) - ->getMock(); - - $product->expects($this->once())->method('getHasOptions')->willReturn(false); - $product->expects($this->once())->method('getId')->willReturn('productId'); - $product->expects($this->once())->method('getStoreId')->willReturn('storeId'); - $this->bundleOptionFactory->expects($this->once())->method('create')->willReturn($option); - $option->expects($this->once())->method('getSearchableData')->willReturn(['optionSearchdata']); - - $this->assertEquals(['optionSearchdata'], $this->model->getSearchableData($product)); - } - - public function testHasOptions() - { - $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->setMethods(['_wakeup', 'hasData', 'getData', 'setData', 'getId', 'getStoreId']) - ->getMock(); - $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) - ->disableOriginalConstructor() - ->setMethods(['getAllIds']) - ->getMock(); - $selectionCollection = $this->getSelectionCollection(); - $selectionCollection - ->expects($this->any()) - ->method('count') - ->willReturn(1); - $this->bundleCollection->expects($this->once())->method('create')->willReturn($selectionCollection); - - $product->expects($this->any())->method('getStoreId')->willReturn(0); - $product->expects($this->once()) - ->method('setData') - ->with('_cache_instance_store_filter', 0) - ->willReturnSelf(); - $product->expects($this->any())->method('hasData')->willReturn(true); - $product->expects($this->at(3)) - ->method('getData') - ->with('_cache_instance_options_collection') - ->willReturn($optionCollection); - $optionCollection->expects($this->once())->method('getAllIds')->willReturn(['ids']); - - $this->assertTrue($this->model->hasOptions($product)); + $falseSelection, + 'The required options you selected are not available', + false + ], + ]; } } From 3b04edb5c1e4ef09f86efd5846762a973b748e91 Mon Sep 17 00:00:00 2001 From: Andrey Konosov Date: Wed, 7 Dec 2016 18:24:18 +0200 Subject: [PATCH 061/132] MAGETWO-61655: Magento/Sales/Model/Order/ShipmentFactory.php and unit tests - Bundle additional options are converted to json --- .../Adminhtml/Sales/Order/Items/Renderer.php | 32 +++++++++- .../Sales/Order/View/Items/Renderer.php | 36 ++++++++++- .../Block/Sales/Order/Items/Renderer.php | 30 +++++++++- .../Magento/Bundle/Model/Product/Type.php | 16 ++++- .../Sales/Order/Pdf/Items/AbstractItems.php | 60 ++++++++++++++++++- .../Sales/Order/Items/RendererTest.php | 36 +++++++---- .../Sales/Order/View/Items/RendererTest.php | 33 +++++++--- .../Block/Sales/Order/Items/RendererTest.php | 35 +++++++---- .../Order/Pdf/Items/AbstractItemsTest.php | 37 ++++++++---- .../Sales/Model/Order/ShipmentFactory.php | 16 ++++- 10 files changed, 279 insertions(+), 52 deletions(-) diff --git a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php index ad9a0b9bbbebf..9b095867d31ad 100644 --- a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php @@ -6,12 +6,42 @@ namespace Magento\Bundle\Block\Adminhtml\Sales\Order\Items; use Magento\Catalog\Model\Product\Type\AbstractType; +use Magento\Framework\Serialize\SerializerInterface; /** * Adminhtml sales order item renderer */ class Renderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer { + /** + * Serializer + * + * @var SerializerInterface + */ + private $serializer; + + /** + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry + * @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration + * @param \Magento\Framework\Registry $registry + * @param array $data + * @param \Magento\Framework\Serialize\SerializerInterface $serializer + */ + public function __construct( + \Magento\Backend\Block\Template\Context $context, + \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, + \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration, + \Magento\Framework\Registry $registry, + array $data = [], + SerializerInterface $serializer = null + ) { + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(SerializerInterface::class); + + parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data); + } + /** * Truncate string * @@ -153,7 +183,7 @@ public function getSelectionAttributes($item) $options = $item->getOrderItem()->getProductOptions(); } if (isset($options['bundle_selection_attributes'])) { - return unserialize($options['bundle_selection_attributes']); + return $this->serializer->unserialize($options['bundle_selection_attributes']); } return null; } diff --git a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php index 01e122a56b52d..ffd850556a99e 100644 --- a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php @@ -6,12 +6,46 @@ namespace Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items; use Magento\Catalog\Model\Product\Type\AbstractType; +use Magento\Framework\Serialize\SerializerInterface; /** * Adminhtml sales order item renderer */ class Renderer extends \Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer { + /** + * Serializer + * + * @var SerializerInterface + */ + private $serializer; + + /** + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry + * @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration + * @param \Magento\Framework\Registry $registry + * @param \Magento\GiftMessage\Helper\Message $messageHelper + * @param \Magento\Checkout\Helper\Data $checkoutHelper + * @param array $data + * @param \Magento\Framework\Serialize\SerializerInterface $serializer + */ + public function __construct( + \Magento\Backend\Block\Template\Context $context, + \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, + \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration, + \Magento\Framework\Registry $registry, + \Magento\GiftMessage\Helper\Message $messageHelper, + \Magento\Checkout\Helper\Data $checkoutHelper, + array $data = [], + SerializerInterface $serializer = null + ) { + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(SerializerInterface::class); + + parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $messageHelper, $checkoutHelper, $data); + } + /** * Truncate string * @@ -110,7 +144,7 @@ public function getSelectionAttributes($item) $options = $item->getOrderItem()->getProductOptions(); } if (isset($options['bundle_selection_attributes'])) { - return unserialize($options['bundle_selection_attributes']); + return $this->serializer->unserialize($options['bundle_selection_attributes']); } return null; } diff --git a/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php b/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php index f8b243c84c058..46dc764291a4b 100644 --- a/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php @@ -6,6 +6,7 @@ namespace Magento\Bundle\Block\Sales\Order\Items; use Magento\Catalog\Model\Product\Type\AbstractType; +use Magento\Framework\Serialize\SerializerInterface; /** * Order item render block @@ -14,6 +15,33 @@ */ class Renderer extends \Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer { + /** + * Serializer + * + * @var SerializerInterface + */ + private $serializer; + + /** + * @param \Magento\Framework\View\Element\Template\Context $context + * @param \Magento\Framework\Stdlib\StringUtils $string + * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory + * @param array $data + * @param \Magento\Framework\Serialize\SerializerInterface $serializer + */ + public function __construct( + \Magento\Framework\View\Element\Template\Context $context, + \Magento\Framework\Stdlib\StringUtils $string, + \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, + array $data = [], + SerializerInterface $serializer = null + ) { + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(SerializerInterface::class); + + parent::__construct($context, $string, $productOptionFactory, $data); + } + /** * @param mixed $item * @return bool @@ -100,7 +128,7 @@ public function getSelectionAttributes($item) $options = $item->getOrderItem()->getProductOptions(); } if (isset($options['bundle_selection_attributes'])) { - return unserialize($options['bundle_selection_attributes']); + return $this->serializer->unserialize($options['bundle_selection_attributes']); } return null; } diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index 4cfdf27fd0e6a..b7f21d9b6f139 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -11,6 +11,7 @@ use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Framework\Serialize\SerializerInterface; /** * Bundle Type Model @@ -146,6 +147,13 @@ class Type extends \Magento\Catalog\Model\Product\Type\AbstractType */ protected $_stockState; + /** + * Serializer + * + * @var SerializerInterface + */ + private $serializer; + /** * @param \Magento\Catalog\Model\Product\Option $catalogProductOption * @param \Magento\Eav\Model\Config $eavConfig @@ -168,6 +176,7 @@ class Type extends \Magento\Catalog\Model\Product\Type\AbstractType * @param PriceCurrencyInterface $priceCurrency * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry * @param \Magento\CatalogInventory\Api\StockStateInterface $stockState + * @param \Magento\Framework\Serialize\SerializerInterface $serializer * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -192,7 +201,8 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, PriceCurrencyInterface $priceCurrency, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, - \Magento\CatalogInventory\Api\StockStateInterface $stockState + \Magento\CatalogInventory\Api\StockStateInterface $stockState, + SerializerInterface $serializer = null ) { $this->_catalogProduct = $catalogProduct; $this->_catalogData = $catalogData; @@ -206,6 +216,8 @@ public function __construct( $this->priceCurrency = $priceCurrency; $this->_stockRegistry = $stockRegistry; $this->_stockState = $stockState; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + parent::__construct( $catalogProductOption, $eavConfig, @@ -697,7 +709,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p $result[] = $_result[0]->setParentProductId($product->getId()) ->addCustomOption('bundle_option_ids', serialize(array_map('intval', $optionIds))) - ->addCustomOption('bundle_selection_attributes', serialize($attributes)); + ->addCustomOption('bundle_selection_attributes', $this->serializer->serialize($attributes)); if ($isStrictProcessMode) { $_result[0]->setCartQty($qty); diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index 2b479b4a2506e..4ae62543e212f 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -6,12 +6,55 @@ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; use Magento\Catalog\Model\Product\Type\AbstractType; +use Magento\Framework\Serialize\SerializerInterface; /** * Sales Order Pdf Items renderer */ abstract class AbstractItems extends \Magento\Sales\Model\Order\Pdf\Items\AbstractItems { + /** + * Serializer + * + * @var SerializerInterface + */ + private $serializer; + + /** + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Tax\Helper\Data $taxData + * @param \Magento\Framework\Filesystem $filesystem , + * @param \Magento\Framework\Filter\FilterManager $filterManager + * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource + * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param array $data + * @param \Magento\Framework\Serialize\SerializerInterface $serializer + */ + public function __construct( + \Magento\Framework\Model\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Tax\Helper\Data $taxData, + \Magento\Framework\Filesystem $filesystem, + \Magento\Framework\Filter\FilterManager $filterManager, + \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, + \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + array $data = [], + SerializerInterface $serializer = null + ) { + $this->serializer = $serializer; + + parent::__construct($context, + $registry, + $taxData, + $filesystem, + $filterManager, + $resource, + $resourceCollection, + $data + ); + } + /** * Getting all available children for Invoice, Shipment or CreditMemo item * @@ -157,7 +200,7 @@ public function getSelectionAttributes($item) $options = $item->getOrderItem()->getProductOptions(); } if (isset($options['bundle_selection_attributes'])) { - return unserialize($options['bundle_selection_attributes']); + return $this->getSerializer()->unserialize($options['bundle_selection_attributes']); } return null; } @@ -242,4 +285,19 @@ public function canShowPriceInfo($item) } return false; } + + /** + * The getter function to get serializer + * + * @return SerializerInterface + * + * @deprecated + */ + private function getSerializer() + { + if ($this->serializer === null) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(SerializerInterface::class); + } + return $this->serializer; + } } diff --git a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php index aee7b81edc1c4..816dcba4c0c07 100644 --- a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php @@ -13,6 +13,9 @@ class RendererTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer $model */ protected $model; + /** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject $serializer */ + protected $serializer; + protected function setUp() { $this->orderItem = $this->getMock( @@ -22,9 +25,12 @@ protected function setUp() '', false ); - + $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->model = $objectManager->getObject(\Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer::class); + $this->model = $objectManager->getObject( + \Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer::class, + ['serializer' => $this->serializer] + ); } /** @@ -221,21 +227,25 @@ public function isChildCalculatedWithItemDataProvider() ]; } - /** - * @dataProvider getSelectionAttributesDataProvider - */ - public function testGetSelectionAttributes($productOptions, $result) + public function testGetSelectionAttributes() { - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); - $this->assertSame($result, $this->model->getSelectionAttributes($this->orderItem)); + $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue([])); + $this->assertNull($this->model->getSelectionAttributes($this->orderItem)); } - public function getSelectionAttributesDataProvider() + public function testGetSelectionAttributesWithBundle() { - return [ - [[], null], - [['bundle_selection_attributes' => 'a:1:{i:0;i:1;}'], [0 => 1]], - ]; + $bundleAttributes = 'Serialized value'; + $options = ['bundle_selection_attributes' => $bundleAttributes]; + $unserializedResult = 'result of "bundle_selection_attributes" unserialization'; + + $this->serializer->expects($this->any()) + ->method('unserialize') + ->with($bundleAttributes) + ->will($this->returnValue($unserializedResult)); + $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($options)); + + $this->assertEquals($unserializedResult, $this->model->getSelectionAttributes($this->orderItem)); } public function testGetOrderOptions() diff --git a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php index 72c4a40fbbb54..1c0c7df002ece 100644 --- a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php @@ -13,6 +13,9 @@ class RendererTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items\Renderer $model */ protected $model; + /** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject $serializer */ + protected $serializer; + protected function setUp() { $this->orderItem = $this->getMock( @@ -22,10 +25,11 @@ protected function setUp() '', false ); - + $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject( - \Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items\Renderer::class + \Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items\Renderer::class, + ['serializer' => $this->serializer] ); } @@ -141,13 +145,26 @@ public function isChildCalculatedWithItemDataProvider() ]; } - /** - * @dataProvider getSelectionAttributesDataProvider - */ - public function testGetSelectionAttributes($productOptions, $result) + + public function testGetSelectionAttributes() { - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); - $this->assertSame($result, $this->model->getSelectionAttributes($this->orderItem)); + $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue([])); + $this->assertNull($this->model->getSelectionAttributes($this->orderItem)); + } + + public function testGetSelectionAttributesWithBundle() + { + $bundleAttributes = 'Serialized value'; + $options = ['bundle_selection_attributes' => $bundleAttributes]; + $unserializedResult = 'result of "bundle_selection_attributes" unserialization'; + + $this->serializer->expects($this->any()) + ->method('unserialize') + ->with($bundleAttributes) + ->will($this->returnValue($unserializedResult)); + + $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($options)); + $this->assertEquals($unserializedResult, $this->model->getSelectionAttributes($this->orderItem)); } public function getSelectionAttributesDataProvider() diff --git a/app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php b/app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php index d81908bd62506..fc37687625b83 100644 --- a/app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php @@ -13,6 +13,9 @@ class RendererTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Block\Sales\Order\Items\Renderer $model */ protected $model; + /** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject $serializer */ + protected $serializer; + protected function setUp() { $this->orderItem = $this->getMock( @@ -23,8 +26,12 @@ protected function setUp() false ); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->model = $objectManager->getObject(\Magento\Bundle\Block\Sales\Order\Items\Renderer::class); + $this->model = $objectManager->getObject( + \Magento\Bundle\Block\Sales\Order\Items\Renderer::class, + ['serializer' => $this->serializer] + ); } /** @@ -221,21 +228,25 @@ public function isChildCalculatedWithItemDataProvider() ]; } - /** - * @dataProvider getSelectionAttributesDataProvider - */ - public function testGetSelectionAttributes($productOptions, $result) + public function testGetSelectionAttributes() { - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); - $this->assertSame($result, $this->model->getSelectionAttributes($this->orderItem)); + $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue([])); + $this->assertNull($this->model->getSelectionAttributes($this->orderItem)); } - public function getSelectionAttributesDataProvider() + public function testGetSelectionAttributesWithBundle() { - return [ - [[], null], - [['bundle_selection_attributes' => 'a:1:{i:0;i:1;}'], [0 => 1]], - ]; + $bundleAttributes = 'Serialized value'; + $options = ['bundle_selection_attributes' => $bundleAttributes]; + $unserializedResult = 'result of "bundle_selection_attributes" unserialization'; + + $this->serializer->expects($this->any()) + ->method('unserialize') + ->with($bundleAttributes) + ->will($this->returnValue($unserializedResult)); + $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($options)); + + $this->assertEquals($unserializedResult, $this->model->getSelectionAttributes($this->orderItem)); } /** diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php index 83c38d8d9ad32..5ee7479e78491 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php @@ -13,6 +13,9 @@ class AbstractItemsTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment $model */ protected $model; + /** @var \Magento\Framework\Serialize\SerializerInterface $serializer */ + protected $serializer; + protected function setUp() { $this->orderItem = $this->getMock( @@ -25,6 +28,13 @@ protected function setUp() $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject(\Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class); + + $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); + $reflection = new \ReflectionClass(\Magento\Bundle\Model\Sales\Order\Pdf\Items\AbstractItems::class); + $reflectionProperty = $reflection->getProperty('serializer'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->model, $this->serializer); + } /** @@ -234,21 +244,26 @@ public function getBundleOptionsDataProvider() ]; } - /** - * @dataProvider getSelectionAttributesDataProvider - */ - public function testGetSelectionAttributes($productOptions, $result) + + public function testGetSelectionAttributes() { - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); - $this->assertSame($result, $this->model->getSelectionAttributes($this->orderItem)); + $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue([])); + $this->assertNull($this->model->getSelectionAttributes($this->orderItem)); } - public function getSelectionAttributesDataProvider() + public function testGetSelectionAttributesWithBundle() { - return [ - [[], null], - [['bundle_selection_attributes' => 'a:1:{i:0;i:1;}'], [0 => 1]], - ]; + $bundleAttributes = 'Serialized value'; + $options = ['bundle_selection_attributes' => $bundleAttributes]; + $unserializedResult = 'result of "bundle_selection_attributes" unserialization'; + + $this->serializer->expects($this->any()) + ->method('unserialize') + ->with($bundleAttributes) + ->will($this->returnValue($unserializedResult)); + $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($options)); + + $this->assertEquals($unserializedResult, $this->model->getSelectionAttributes($this->orderItem)); } public function testGetOrderOptions() diff --git a/app/code/Magento/Sales/Model/Order/ShipmentFactory.php b/app/code/Magento/Sales/Model/Order/ShipmentFactory.php index a8839c7537587..73331b203d996 100644 --- a/app/code/Magento/Sales/Model/Order/ShipmentFactory.php +++ b/app/code/Magento/Sales/Model/Order/ShipmentFactory.php @@ -8,6 +8,7 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface; +use Magento\Framework\Serialize\SerializerInterface; /** * Factory class for @see \Magento\Sales\Api\Data\ShipmentInterface @@ -35,19 +36,30 @@ class ShipmentFactory */ protected $instanceName; + /** + * Serializer + * + * @var SerializerInterface + */ + private $serializer; + /** * Factory constructor. * * @param \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory * @param \Magento\Sales\Model\Order\Shipment\TrackFactory $trackFactory + * @param \Magento\Framework\Serialize\SerializerInterface $serializer */ public function __construct( \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory, - \Magento\Sales\Model\Order\Shipment\TrackFactory $trackFactory + \Magento\Sales\Model\Order\Shipment\TrackFactory $trackFactory, + SerializerInterface $serializer = null ) { $this->converter = $convertOrderFactory->create(); $this->trackFactory = $trackFactory; $this->instanceName = \Magento\Sales\Api\Data\ShipmentInterface::class; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(SerializerInterface::class); } /** @@ -100,7 +112,7 @@ protected function prepareItems( $productOptions = $orderItem->getProductOptions(); if (isset($productOptions['bundle_selection_attributes'])) { - $bundleSelectionAttributes = unserialize( + $bundleSelectionAttributes = $this->serializer->unserialize( $productOptions['bundle_selection_attributes'] ); From ccd8785a620d84f4fc10fa7c0b1a0cd95580f394 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 9 Dec 2016 12:53:45 +0200 Subject: [PATCH 062/132] MAGETWO-61647: Detailed investigation for info_buyrequest field and extension points for its modifications --- .../Test/Unit/Model/Product/TypeTest.php | 2425 ++++++++++++++++- 1 file changed, 2424 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php index 4084813c7cd85..da340dbbfadcf 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php @@ -75,6 +75,11 @@ class TypeTest extends \PHPUnit_Framework_TestCase */ private $priceCurrency; + /** + * @var Json + */ + private $serializer; + /** * @return void */ @@ -137,6 +142,12 @@ protected function setUp() ) ->disableOriginalConstructor() ->getMock(); + + $this->serializer = $this->getMockBuilder(Json::class) + ->setMethods(null) + ->disableOriginalConstructor() + ->getMock(); + $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectHelper->getObject( \Magento\Bundle\Model\Product\Type::class, @@ -151,11 +162,2423 @@ protected function setUp() 'stockState' => $this->stockState, 'catalogProduct' => $this->catalogProduct, 'priceCurrency' => $this->priceCurrency, - 'serializer' => new Json() + 'serializer' => $this->serializer ] ); } + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPrepareForCartAdvancedWithoutOptions() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ + $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption', + 'getTypeInstance', + 'getStoreId', + 'hasData', + 'getData' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ + $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) + ->setMethods(['setStoreFilter', 'getOptionsCollection', 'getOptionsIds', 'getSelectionsCollection']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems', 'getItemById', 'appendSelections']) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->any()) + ->method('getSkipCheckRequiredOption') + ->willReturn(true); + $product->expects($this->any()) + ->method('getTypeInstance') + ->willReturn($productType); + $optionCollection->expects($this->any()) + ->method('appendSelections') + ->willReturn([$option]); + $productType->expects($this->once()) + ->method('setStoreFilter'); + $productType->expects($this->once()) + ->method('getOptionsCollection') + ->willReturn($optionCollection); + $productType->expects($this->once()) + ->method('getOptionsIds') + ->willReturn([1, 2, 3]); + $productType->expects($this->once()) + ->method('getSelectionsCollection') + ->willReturn($selectionCollection); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn('options'); + $option->expects($this->at(3)) + ->method('getId') + ->willReturn(3); + $option->expects($this->once()) + ->method('getRequired') + ->willReturn(true); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + $this->assertEquals('Please specify product option(s).', $result); + } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPrepareForCartAdvancedWithShoppingCart() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Type\Price $priceModel */ + $priceModel = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\Price::class) + ->setMethods(['getSelectionFinalTotalPrice']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + [ + '__wakeup', + 'getOptions', + 'getSuperProductConfig', + 'unsetData', + 'getData', + 'getQty', + 'getBundleOption', + 'getBundleOptionQty' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods( + [ + 'groupFactory', + 'getType', + 'getId', + 'getRequired', + 'isMultiSelection', + 'getProduct', + 'getValue', + 'getTitle' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ + $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + [ + '__wakeup', + 'isSalable', + 'getOptionId', + 'getSelectionCanChangeQty', + 'getSelectionId', + 'addCustomOption', + 'getId', + 'getOption', + 'getTypeInstance' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption', + 'getTypeInstance', + 'getStoreId', + 'hasData', + 'getData', + 'getId', + 'getCustomOption', + 'getPriceModel' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ + $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) + ->setMethods( + [ + 'setStoreFilter', + 'prepareForCart', + 'setParentProductId', + 'addCustomOption', + 'setCartQty', + 'getSelectionId' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems', 'getItemById', 'appendSelections']) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->any()) + ->method('getSkipCheckRequiredOption') + ->willReturn(true); + $product->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $product->expects($this->once()) + ->method('hasData') + ->willReturn(true); + $product->expects($this->any()) + ->method('getData') + ->willReturnCallback( + function ($key) use ($optionCollection, $selectionCollection) { + $resultValue = null; + switch ($key) { + case '_cache_instance_options_collection': + $resultValue = $optionCollection; + break; + case '_cache_instance_used_selections': + $resultValue = $selectionCollection; + break; + case '_cache_instance_used_selections_ids': + $resultValue = [5]; + break; + } + + return $resultValue; + } + ); + $product->expects($this->any()) + ->method('getId') + ->willReturn(333); + $product->expects($this->once()) + ->method('getCustomOption') + ->willReturn($option); + $product->expects($this->once()) + ->method('getPriceModel') + ->willReturn($priceModel); + $optionCollection->expects($this->once()) + ->method('getItemById') + ->willReturn($option); + $optionCollection->expects($this->once()) + ->method('appendSelections'); + $productType->expects($this->once()) + ->method('setStoreFilter'); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn([3 => 5]); + $selectionCollection->expects($this->any()) + ->method('getItems') + ->willReturn([$selection]); + $selection->expects($this->once()) + ->method('isSalable') + ->willReturn(false); + $selection->expects($this->any()) + ->method('getOptionId') + ->willReturn(3); + $selection->expects($this->any()) + ->method('getOption') + ->willReturn($option); + $selection->expects($this->once()) + ->method('getSelectionCanChangeQty') + ->willReturn(true); + $selection->expects($this->once()) + ->method('getSelectionId'); + $selection->expects($this->once()) + ->method('addCustomOption') + ->willReturnSelf(); + $selection->expects($this->any()) + ->method('getId') + ->willReturn(333); + $selection->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $option->expects($this->at(3)) + ->method('getId') + ->willReturn(3); + $option->expects($this->at(9)) + ->method('getId') + ->willReturn(3); + $option->expects($this->once()) + ->method('getRequired') + ->willReturn(false); + $option->expects($this->once()) + ->method('isMultiSelection') + ->willReturn(true); + $option->expects($this->once()) + ->method('getProduct') + ->willReturn($product); + $option->expects($this->once()) + ->method('getValue') + ->willReturn(4); + $option->expects($this->once()) + ->method('getTitle') + ->willReturn('Title for option'); + $buyRequest->expects($this->once()) + ->method('getBundleOptionQty') + ->willReturn([3 => 5]); + $priceModel->expects($this->once()) + ->method('getSelectionFinalTotalPrice') + ->willReturnSelf(); + $productType->expects($this->once()) + ->method('prepareForCart') + ->willReturn([$productType]); + $productType->expects($this->once()) + ->method('setParentProductId') + ->willReturnSelf(); + $productType->expects($this->any()) + ->method('addCustomOption') + ->willReturnSelf(); + $productType->expects($this->once()) + ->method('setCartQty') + ->willReturnSelf(); + $productType->expects($this->once()) + ->method('getSelectionId') + ->willReturn(314); + + $this->priceCurrency->expects($this->once()) + ->method('convert') + ->willReturn(3.14); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + $this->assertEquals([$product, $productType], $result); + } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPrepareForCartAdvancedEmptyShoppingCart() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Type\Price $priceModel */ + $priceModel = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\Price::class) + ->setMethods(['getSelectionFinalTotalPrice']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + [ + '__wakeup', + 'getOptions', + 'getSuperProductConfig', + 'unsetData', + 'getData', + 'getQty', + 'getBundleOption', + 'getBundleOptionQty' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods( + [ + 'groupFactory', + 'getType', + 'getId', + 'getRequired', + 'isMultiSelection', + 'getProduct', + 'getValue', + 'getTitle' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ + $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + [ + '__wakeup', + 'isSalable', + 'getOptionId', + 'getSelectionCanChangeQty', + 'getSelectionId', + 'addCustomOption', + 'getId', + 'getOption', + 'getTypeInstance' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption', + 'getTypeInstance', + 'getStoreId', + 'hasData', + 'getData', + 'getId', + 'getCustomOption', + 'getPriceModel' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ + $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) + ->setMethods(['setStoreFilter', 'prepareForCart']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems', 'getItemById', 'appendSelections']) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->any()) + ->method('getSkipCheckRequiredOption') + ->willReturn(true); + $product->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $product->expects($this->once()) + ->method('hasData') + ->willReturn(true); + $product->expects($this->any()) + ->method('getData') + ->willReturnCallback( + function ($key) use ($optionCollection, $selectionCollection) { + $resultValue = null; + switch ($key) { + case '_cache_instance_options_collection': + $resultValue = $optionCollection; + break; + case '_cache_instance_used_selections': + $resultValue = $selectionCollection; + break; + case '_cache_instance_used_selections_ids': + $resultValue = [5]; + break; + } + + return $resultValue; + } + ); + $product->expects($this->any()) + ->method('getId') + ->willReturn(333); + $product->expects($this->once()) + ->method('getCustomOption') + ->willReturn($option); + $product->expects($this->once()) + ->method('getPriceModel') + ->willReturn($priceModel); + $optionCollection->expects($this->once()) + ->method('getItemById') + ->willReturn($option); + $optionCollection->expects($this->once()) + ->method('appendSelections'); + $productType->expects($this->once()) + ->method('setStoreFilter'); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn([3 => 5]); + $selectionCollection->expects($this->any()) + ->method('getItems') + ->willReturn([$selection]); + $selection->expects($this->once()) + ->method('isSalable') + ->willReturn(false); + $selection->expects($this->any()) + ->method('getOptionId') + ->willReturn(3); + $selection->expects($this->any()) + ->method('getOption') + ->willReturn($option); + $selection->expects($this->once()) + ->method('getSelectionCanChangeQty') + ->willReturn(true); + $selection->expects($this->once()) + ->method('getSelectionId'); + $selection->expects($this->once()) + ->method('addCustomOption') + ->willReturnSelf(); + $selection->expects($this->any()) + ->method('getId') + ->willReturn(333); + $selection->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $option->expects($this->at(3)) + ->method('getId') + ->willReturn(3); + $option->expects($this->at(9)) + ->method('getId') + ->willReturn(3); + $option->expects($this->once()) + ->method('getRequired') + ->willReturn(false); + $option->expects($this->once()) + ->method('isMultiSelection') + ->willReturn(true); + $option->expects($this->once()) + ->method('getProduct') + ->willReturn($product); + $option->expects($this->once()) + ->method('getValue') + ->willReturn(4); + $option->expects($this->once()) + ->method('getTitle') + ->willReturn('Title for option'); + $buyRequest->expects($this->once()) + ->method('getBundleOptionQty') + ->willReturn([3 => 5]); + $priceModel->expects($this->once()) + ->method('getSelectionFinalTotalPrice') + ->willReturnSelf(); + $productType->expects($this->once()) + ->method('prepareForCart') + ->willReturn([]); + + $this->priceCurrency->expects($this->once()) + ->method('convert') + ->willReturn(3.14); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + $this->assertEquals('We can\'t add this item to your shopping cart right now.', $result); + } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPrepareForCartAdvancedStringInResult() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Type\Price $priceModel */ + $priceModel = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\Price::class) + ->setMethods(['getSelectionFinalTotalPrice']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + [ + '__wakeup', + 'getOptions', + 'getSuperProductConfig', + 'unsetData', + 'getData', + 'getQty', + 'getBundleOption', + 'getBundleOptionQty' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods( + [ + 'groupFactory', + 'getType', + 'getId', + 'getRequired', + 'isMultiSelection', + 'getProduct', + 'getValue', + 'getTitle' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ + $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + [ + '__wakeup', + 'isSalable', + 'getOptionId', + 'getSelectionCanChangeQty', + 'getSelectionId', + 'addCustomOption', + 'getId', + 'getOption', + 'getTypeInstance' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption', + 'getTypeInstance', + 'getStoreId', + 'hasData', + 'getData', + 'getId', + 'getCustomOption', + 'getPriceModel' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ + $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) + ->setMethods(['setStoreFilter', 'prepareForCart']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems', 'getItemById', 'appendSelections']) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->any()) + ->method('getSkipCheckRequiredOption') + ->willReturn(true); + $product->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $product->expects($this->once()) + ->method('hasData') + ->willReturn(true); + $product->expects($this->any()) + ->method('getData') + ->willReturnCallback( + function ($key) use ($optionCollection, $selectionCollection) { + $resultValue = null; + switch ($key) { + case '_cache_instance_options_collection': + $resultValue = $optionCollection; + break; + case '_cache_instance_used_selections': + $resultValue = $selectionCollection; + break; + case '_cache_instance_used_selections_ids': + $resultValue = [5]; + break; + } + + return $resultValue; + } + ); + $product->expects($this->any()) + ->method('getId') + ->willReturn(333); + $product->expects($this->once()) + ->method('getCustomOption') + ->willReturn($option); + $product->expects($this->once()) + ->method('getPriceModel') + ->willReturn($priceModel); + $optionCollection->expects($this->once()) + ->method('getItemById') + ->willReturn($option); + $optionCollection->expects($this->once()) + ->method('appendSelections'); + $productType->expects($this->once()) + ->method('setStoreFilter'); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn([3 => 5]); + $selectionCollection->expects($this->any()) + ->method('getItems') + ->willReturn([$selection]); + $selection->expects($this->once()) + ->method('isSalable') + ->willReturn(false); + $selection->expects($this->any()) + ->method('getOptionId') + ->willReturn(3); + $selection->expects($this->any()) + ->method('getOption') + ->willReturn($option); + $selection->expects($this->once()) + ->method('getSelectionCanChangeQty') + ->willReturn(true); + $selection->expects($this->once()) + ->method('getSelectionId'); + $selection->expects($this->once()) + ->method('addCustomOption') + ->willReturnSelf(); + $selection->expects($this->any()) + ->method('getId') + ->willReturn(333); + $selection->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $option->expects($this->at(3)) + ->method('getId') + ->willReturn(3); + $option->expects($this->at(9)) + ->method('getId') + ->willReturn(3); + $option->expects($this->once()) + ->method('getRequired') + ->willReturn(false); + $option->expects($this->once()) + ->method('isMultiSelection') + ->willReturn(true); + $option->expects($this->once()) + ->method('getProduct') + ->willReturn($product); + $option->expects($this->once()) + ->method('getValue') + ->willReturn(4); + $option->expects($this->once()) + ->method('getTitle') + ->willReturn('Title for option'); + $buyRequest->expects($this->once()) + ->method('getBundleOptionQty') + ->willReturn([3 => 5]); + $priceModel->expects($this->once()) + ->method('getSelectionFinalTotalPrice') + ->willReturnSelf(); + $productType->expects($this->once()) + ->method('prepareForCart') + ->willReturn('string'); + + $this->priceCurrency->expects($this->once()) + ->method('convert') + ->willReturn(3.14); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + $this->assertEquals('string', $result); + } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPrepareForCartAdvancedWithoutSelections() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + [ + '__wakeup', + 'getOptions', + 'getSuperProductConfig', + 'unsetData', + 'getData', + 'getQty', + 'getBundleOption', + 'getBundleOptionQty' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) + ->disableOriginalConstructor() + ->getMock(); + + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption', + 'getTypeInstance', + 'getStoreId', + 'hasData', + 'getData', + 'getId' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ + $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) + ->setMethods(['setStoreFilter']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems', 'getItemById', 'appendSelections']) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->any()) + ->method('getSkipCheckRequiredOption') + ->willReturn(true); + $product->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $product->expects($this->once()) + ->method('hasData') + ->willReturn(true); + $product->expects($this->any()) + ->method('getData') + ->willReturnCallback( + function ($key) use ($optionCollection) { + $resultValue = null; + switch ($key) { + case '_cache_instance_options_collection': + $resultValue = $optionCollection; + break; + } + + return $resultValue; + } + ); + $product->expects($this->once()) + ->method('getId') + ->willReturn(333); + $productType->expects($this->once()) + ->method('setStoreFilter'); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn([]); + $buyRequest->expects($this->once()) + ->method('getBundleOptionQty') + ->willReturn([3 => 5]); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product, 'single'); + $this->assertEquals([$product], $result); + } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPrepareForCartAdvancedSelectionsSelectionIdsExists() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ + $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods(['__wakeup', 'isSalable', 'getOptionId']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption', + 'getTypeInstance', + 'getStoreId', + 'hasData', + 'getData' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ + $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) + ->setMethods(['setStoreFilter']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems', 'getItemById', 'appendSelections']) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->any()) + ->method('getSkipCheckRequiredOption') + ->willReturn(true); + $product->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $product->expects($this->once()) + ->method('hasData') + ->willReturn(true); + $product->expects($this->any()) + ->method('getData') + ->willReturnCallback( + function ($key) use ($optionCollection, $selectionCollection) { + $resultValue = null; + switch ($key) { + case '_cache_instance_options_collection': + $resultValue = $optionCollection; + break; + case '_cache_instance_used_selections': + $resultValue = $selectionCollection; + break; + case '_cache_instance_used_selections_ids': + $resultValue = [5]; + break; + } + + return $resultValue; + } + ); + $optionCollection->expects($this->once()) + ->method('appendSelections'); + $productType->expects($this->once()) + ->method('setStoreFilter'); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn([3 => 5]); + $selectionCollection->expects($this->at(0)) + ->method('getItems') + ->willReturn([$selection]); + $selectionCollection->expects($this->at(1)) + ->method('getItems') + ->willReturn([]); + $option->expects($this->any()) + ->method('getId') + ->willReturn(3); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + $this->assertEquals('Please specify product option(s).', $result); + } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPrepareForCartAdvancedSelectRequiredOptions() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired', 'isMultiSelection']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|SelectionCollection $selectionCollection */ + $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $selection = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods(['__wakeup', 'isSalable', 'getOptionId']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption', + 'getTypeInstance', + 'getStoreId', + 'hasData', + 'getData' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ + $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) + ->setMethods(['setStoreFilter']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems', 'getItemById']) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->any()) + ->method('getSkipCheckRequiredOption') + ->willReturn(true); + $product->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $product->expects($this->once()) + ->method('hasData') + ->willReturn(true); + $product->expects($this->any()) + ->method('getData') + ->willReturnCallback( + function ($key) use ($optionCollection, $selectionCollection) { + $resultValue = null; + switch ($key) { + case '_cache_instance_options_collection': + $resultValue = $optionCollection; + break; + case '_cache_instance_used_selections': + $resultValue = $selectionCollection; + break; + case '_cache_instance_used_selections_ids': + $resultValue = [0 => 5]; + break; + } + + return $resultValue; + } + ); + $optionCollection->expects($this->once()) + ->method('getItemById') + ->willReturn($option); + $productType->expects($this->once()) + ->method('setStoreFilter'); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn([3 => 5]); + $selectionCollection->expects($this->any()) + ->method('getItems') + ->willReturn([$selection]); + $selection->expects($this->once()) + ->method('isSalable') + ->willReturn(false); + $option->expects($this->at(3)) + ->method('getId') + ->willReturn(3); + $option->expects($this->once()) + ->method('getRequired') + ->willReturn(true); + $option->expects($this->once()) + ->method('isMultiSelection') + ->willReturn(true); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + $this->assertEquals('The required options you selected are not available.', $result); + } + + /** + * @return void + */ + public function testPrepareForCartAdvancedParentClassReturnString() + { + $exceptedResult = 'String message'; + + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods(['getItems', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + $product->expects($this->any()) + ->method('getOptions') + ->willThrowException(new LocalizedException(__($exceptedResult))); + $product->expects($this->once()) + ->method('getHasOptions') + ->willReturn(true); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + + $this->assertEquals($exceptedResult, $result); + } + + /** + * @return void + */ + public function testPrepareForCartAdvancedAllrequiredOption() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods(['groupFactory', 'getType', 'getId', 'getRequired']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption', + 'getTypeInstance', + 'getStoreId', + 'hasData', + 'getData' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Bundle\Model\Product\Type $productType */ + $productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) + ->setMethods(['setStoreFilter']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|Collection $optionCollection */ + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->any()) + ->method('getSkipCheckRequiredOption') + ->willReturn(false); + $product->expects($this->once()) + ->method('getTypeInstance') + ->willReturn($productType); + $product->expects($this->once()) + ->method('hasData') + ->willReturn(true); + $product->expects($this->any()) + ->method('getData') + ->willReturnCallback( + function ($key) use ($optionCollection) { + $resultValue = null; + switch ($key) { + case '_cache_instance_options_collection': + $resultValue = $optionCollection; + break; + case '_cache_instance_used_selections_ids': + $resultValue = [0 => 5]; + break; + } + + return $resultValue; + } + ); + $optionCollection->expects($this->once()) + ->method('getItems') + ->willReturn([$option]); + $productType->expects($this->once()) + ->method('setStoreFilter'); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn([3 => 5]); + $option->expects($this->at(3)) + ->method('getId') + ->willReturn(3); + $option->expects($this->once()) + ->method('getRequired') + ->willReturn(true); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + $this->assertEquals('Please select all required options.', $result); + } + + /** + * @return void + */ + public function testPrepareForCartAdvancedSpecifyProductOptions() + { + /** @var \PHPUnit_Framework_MockObject_MockObject|DefaultType $group */ + $group = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\Type\DefaultType::class) + ->setMethods( + ['setOption', 'setProduct', 'setRequest', 'setProcessMode', 'validateUserValue', 'prepareForCart'] + ) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest */ + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods( + ['__wakeup', 'getOptions', 'getSuperProductConfig', 'unsetData', 'getData', 'getQty', 'getBundleOption'] + ) + ->disableOriginalConstructor() + ->getMock(); + /* @var $option \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option */ + $option = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option::class) + ->setMethods(['groupFactory', 'getType', 'getId']) + ->disableOriginalConstructor() + ->getMock(); + /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product */ + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods( + [ + 'getOptions', + 'getHasOptions', + 'prepareCustomOptions', + 'addCustomOption', + 'setCartQty', + 'setQty', + 'getSkipCheckRequiredOption' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + + $this->parentClass($group, $option, $buyRequest, $product); + + $product->expects($this->once()) + ->method('getSkipCheckRequiredOption') + ->willReturn(true); + $buyRequest->expects($this->once()) + ->method('getBundleOption') + ->willReturn([0, '', 'str']); + + $result = $this->model->prepareForCartAdvanced($buyRequest, $product); + $this->assertEquals('Please specify product option(s).', $result); + } + + /** + * @return void + */ + public function testHasWeightTrue() + { + $this->assertTrue($this->model->hasWeight(), 'This product has no weight, but it should'); + } + + /** + * @return void + */ + public function testGetIdentities() + { + $identities = ['id1', 'id2']; + $productMock = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false); + $optionMock = $this->getMock( + \Magento\Bundle\Model\Option::class, + ['getSelections', '__wakeup'], + [], + '', + false + ); + $optionCollectionMock = $this->getMock( + \Magento\Bundle\Model\ResourceModel\Option\Collection::class, + [], + [], + '', + false + ); + $cacheKey = '_cache_instance_options_collection'; + $productMock->expects($this->once()) + ->method('getIdentities') + ->will($this->returnValue($identities)); + $productMock->expects($this->once()) + ->method('hasData') + ->with($cacheKey) + ->will($this->returnValue(true)); + $productMock->expects($this->once()) + ->method('getData') + ->with($cacheKey) + ->will($this->returnValue($optionCollectionMock)); + $optionCollectionMock + ->expects($this->once()) + ->method('getItems') + ->will($this->returnValue([$optionMock])); + $optionMock + ->expects($this->exactly(2)) + ->method('getSelections') + ->will($this->returnValue([$productMock])); + $this->assertEquals($identities, $this->model->getIdentities($productMock)); + } + + /** + * @return void + */ + public function testGetSkuWithType() + { + $sku = 'sku'; + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $productMock->expects($this->at(0)) + ->method('getData') + ->with('sku') + ->will($this->returnValue($sku)); + $productMock->expects($this->at(2)) + ->method('getData') + ->with('sku_type') + ->will($this->returnValue('some_data')); + + $this->assertEquals($sku, $this->model->getSku($productMock)); + } + + /** + * @return void + */ + public function testGetSkuWithoutType() + { + $sku = 'sku'; + $itemSku = 'item'; + $selectionIds = [1, 2, 3]; + $serializeIds = serialize($selectionIds); + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) + ->disableOriginalConstructor() + ->getMock(); + $customOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) + ->setMethods(['getValue', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + $selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods(['getSku', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + + $productMock->expects($this->at(0)) + ->method('getData') + ->with('sku') + ->will($this->returnValue($sku)); + $productMock->expects($this->at(1)) + ->method('getCustomOption') + ->with('option_ids') + ->will($this->returnValue(false)); + $productMock->expects($this->at(2)) + ->method('getData') + ->with('sku_type') + ->will($this->returnValue(null)); + $productMock->expects($this->once()) + ->method('hasCustomOptions') + ->will($this->returnValue(true)); + $productMock->expects($this->at(4)) + ->method('getCustomOption') + ->with('bundle_selection_ids') + ->will($this->returnValue($customOptionMock)); + $customOptionMock->expects($this->any()) + ->method('getValue') + ->will($this->returnValue($serializeIds)); + $selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6); + $selectionMock->expects(($this->any())) + ->method('getItems') + ->will($this->returnValue([$selectionItemMock])); + $selectionItemMock->expects($this->any()) + ->method('getSku') + ->will($this->returnValue($itemSku)); + + $this->assertEquals($sku . '-' . $itemSku, $this->model->getSku($productMock)); + } + + /** + * @return void + */ + public function testGetWeightWithoutCustomOption() + { + $weight = 5; + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['__wakeup', 'getData']) + ->disableOriginalConstructor() + ->getMock(); + + $productMock->expects($this->at(0)) + ->method('getData') + ->with('weight_type') + ->will($this->returnValue(true)); + $productMock->expects($this->at(1)) + ->method('getData') + ->with('weight') + ->will($this->returnValue($weight)); + + $this->assertEquals($weight, $this->model->getWeight($productMock)); + } + + /** + * @return void + */ + public function testGetWeightWithCustomOption() + { + $weight = 5; + $selectionIds = [1, 2, 3]; + $serializeIds = serialize($selectionIds); + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) + ->disableOriginalConstructor() + ->getMock(); + $customOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) + ->setMethods(['getValue', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + $selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods(['getSelectionId', 'getWeight', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + + $productMock->expects($this->at(0)) + ->method('getData') + ->with('weight_type') + ->will($this->returnValue(false)); + $productMock->expects($this->once()) + ->method('hasCustomOptions') + ->will($this->returnValue(true)); + $productMock->expects($this->at(2)) + ->method('getCustomOption') + ->with('bundle_selection_ids') + ->will($this->returnValue($customOptionMock)); + $customOptionMock->expects($this->once()) + ->method('getValue') + ->will($this->returnValue($serializeIds)); + $selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 3, 4); + $selectionMock->expects($this->once()) + ->method('getItems') + ->will($this->returnValue([$selectionItemMock])); + $selectionItemMock->expects($this->any()) + ->method('getSelectionId') + ->will($this->returnValue('id')); + $productMock->expects($this->at(5)) + ->method('getCustomOption') + ->with('selection_qty_' . 'id') + ->will($this->returnValue(null)); + $selectionItemMock->expects($this->once()) + ->method('getWeight') + ->will($this->returnValue($weight)); + + $this->assertEquals($weight, $this->model->getWeight($productMock)); + } + + /** + * @return void + */ + public function testGetWeightWithSeveralCustomOption() + { + $weight = 5; + $qtyOption = 5; + $selectionIds = [1, 2, 3]; + $serializeIds = serialize($selectionIds); + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) + ->disableOriginalConstructor() + ->getMock(); + $customOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) + ->setMethods(['getValue', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + $qtyOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) + ->setMethods(['getValue', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + $selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods(['getSelectionId', 'getWeight', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + + $productMock->expects($this->at(0)) + ->method('getData') + ->with('weight_type') + ->will($this->returnValue(false)); + $productMock->expects($this->once()) + ->method('hasCustomOptions') + ->will($this->returnValue(true)); + $productMock->expects($this->at(2)) + ->method('getCustomOption') + ->with('bundle_selection_ids') + ->will($this->returnValue($customOptionMock)); + $customOptionMock->expects($this->once()) + ->method('getValue') + ->will($this->returnValue($serializeIds)); + $selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 3, 4); + $selectionMock->expects($this->once()) + ->method('getItems') + ->will($this->returnValue([$selectionItemMock])); + $selectionItemMock->expects($this->any()) + ->method('getSelectionId') + ->will($this->returnValue('id')); + $productMock->expects($this->at(5)) + ->method('getCustomOption') + ->with('selection_qty_' . 'id') + ->will($this->returnValue($qtyOptionMock)); + $qtyOptionMock->expects($this->once()) + ->method('getValue') + ->will($this->returnValue($qtyOption)); + $selectionItemMock->expects($this->once()) + ->method('getWeight') + ->will($this->returnValue($weight)); + + $this->assertEquals($weight * $qtyOption, $this->model->getWeight($productMock)); + } + + /** + * @return void + */ + public function testIsVirtualWithoutCustomOption() + { + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + + $productMock->expects($this->once()) + ->method('hasCustomOptions') + ->will($this->returnValue(false)); + + $this->assertFalse($this->model->isVirtual($productMock)); + } + + /** + * @return void + */ + public function testIsVirtual() + { + $selectionIds = [1, 2, 3]; + $serializeIds = serialize($selectionIds); + + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $customOptionMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Configuration\Item\Option::class) + ->setMethods(['getValue', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + $selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->setMethods(['isVirtual', 'getItems', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + + $productMock->expects($this->once()) + ->method('hasCustomOptions') + ->will($this->returnValue(true)); + $productMock->expects($this->once()) + ->method('getCustomOption') + ->with('bundle_selection_ids') + ->will($this->returnValue($customOptionMock)); + $customOptionMock->expects($this->once()) + ->method('getValue') + ->will($this->returnValue($serializeIds)); + $selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 2, 3); + $selectionMock->expects($this->once()) + ->method('getItems') + ->will($this->returnValue([$selectionItemMock])); + $selectionItemMock->expects($this->once()) + ->method('isVirtual') + ->will($this->returnValue(true)); + $selectionItemMock->expects($this->once()) + ->method('isVirtual') + ->will($this->returnValue(true)); + $selectionMock->expects($this->once()) + ->method('count') + ->will($this->returnValue(1)); + + $this->assertTrue($this->model->isVirtual($productMock)); + } + + /** + * @param array $selectionIds + * @param \PHPUnit_Framework_MockObject_MockObject $productMock + * @param int $getSelectionsIndex + * @param int $getSelectionsIdsIndex + * @return \PHPUnit_Framework_MockObject_MockObject + */ + + protected function getSelectionsByIdsMock($selectionIds, $productMock, $getSelectionsIndex, $getSelectionsIdsIndex) + { + $usedSelectionsMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->disableOriginalConstructor() + ->getMock(); + + $productMock->expects($this->at($getSelectionsIndex)) + ->method('getData') + ->with('_cache_instance_used_selections') + ->will($this->returnValue($usedSelectionsMock)); + $productMock->expects($this->at($getSelectionsIdsIndex)) + ->method('getData') + ->with('_cache_instance_used_selections_ids') + ->will($this->returnValue($selectionIds)); + + return $usedSelectionsMock; + } + + /** + * @param int $expected + * @param int $firstId + * @param int $secondId + * @return void + * @dataProvider shakeSelectionsDataProvider + */ + public function testShakeSelections($expected, $firstId, $secondId) + { + $firstItemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['__wakeup', 'getOption', 'getOptionId', 'getPosition', 'getSelectionId']) + ->disableOriginalConstructor() + ->getMock(); + $secondItemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['__wakeup', 'getOption', 'getOptionId', 'getPosition', 'getSelectionId']) + ->disableOriginalConstructor() + ->getMock(); + $optionFirstMock = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) + ->setMethods(['getPosition', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + $optionSecondMock = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) + ->setMethods(['getPosition', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + + $firstItemMock->expects($this->once()) + ->method('getOption') + ->will($this->returnValue($optionFirstMock)); + $optionFirstMock->expects($this->once()) + ->method('getPosition') + ->will($this->returnValue('option_position')); + $firstItemMock->expects($this->once()) + ->method('getOptionId') + ->will($this->returnValue('option_id')); + $firstItemMock->expects($this->once()) + ->method('getPosition') + ->will($this->returnValue('position')); + $firstItemMock->expects($this->once()) + ->method('getSelectionId') + ->will($this->returnValue($firstId)); + $secondItemMock->expects($this->once()) + ->method('getOption') + ->will($this->returnValue($optionSecondMock)); + $optionSecondMock->expects($this->any()) + ->method('getPosition') + ->will($this->returnValue('option_position')); + $secondItemMock->expects($this->once()) + ->method('getOptionId') + ->will($this->returnValue('option_id')); + $secondItemMock->expects($this->once()) + ->method('getPosition') + ->will($this->returnValue('position')); + $secondItemMock->expects($this->once()) + ->method('getSelectionId') + ->will($this->returnValue($secondId)); + + $this->assertEquals($expected, $this->model->shakeSelections($firstItemMock, $secondItemMock)); + } + + /** + * @return array + */ + public function shakeSelectionsDataProvider() + { + return [ + [0, 0, 0], + [1, 1, 0], + [-1, 0, 1] + ]; + } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testGetSelectionsByIds() + { + $selectionIds = [1, 2, 3]; + $usedSelectionsIds = [4, 5, 6]; + $storeId = 2; + $websiteId = 1; + $storeFilter = 'store_filter'; + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $usedSelectionsMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->setMethods( + [ + 'addAttributeToSelect', + 'setFlag', + 'addStoreFilter', + 'setStoreId', + 'setPositionOrder', + 'addFilterByRequiredOptions', + 'setSelectionIdsFilter', + 'joinPrices' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + $productGetMap = [ + ['_cache_instance_used_selections', null, null], + ['_cache_instance_used_selections_ids', null, $usedSelectionsIds], + ['_cache_instance_store_filter', null, $storeFilter], + ]; + $productMock->expects($this->any()) + ->method('getData') + ->will($this->returnValueMap($productGetMap)); + $productSetMap = [ + ['_cache_instance_used_selections', $usedSelectionsMock, $productMock], + ['_cache_instance_used_selections_ids', $selectionIds, $productMock], + ]; + $productMock->expects($this->any()) + ->method('setData') + ->will($this->returnValueMap($productSetMap)); + $productMock->expects($this->once()) + ->method('getStoreId') + ->will($this->returnValue($storeId)); + + $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) + ->setMethods(['getWebsiteId', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + $this->storeManager->expects($this->once()) + ->method('getStore') + ->with($storeId) + ->will($this->returnValue($storeMock)); + $storeMock->expects($this->once()) + ->method('getWebsiteId') + ->will($this->returnValue($websiteId)); + + $this->bundleCollection->expects($this->once()) + ->method('create') + ->will($this->returnValue($usedSelectionsMock)); + + $usedSelectionsMock->expects($this->once()) + ->method('addAttributeToSelect') + ->with('*') + ->will($this->returnSelf()); + $flagMap = [ + ['product_children', true, $usedSelectionsMock], + ]; + $usedSelectionsMock->expects($this->any()) + ->method('setFlag') + ->will($this->returnValueMap($flagMap)); + $usedSelectionsMock->expects($this->once()) + ->method('addStoreFilter') + ->with($storeFilter) + ->will($this->returnSelf()); + $usedSelectionsMock->expects($this->once()) + ->method('setStoreId') + ->with($storeId) + ->will($this->returnSelf()); + $usedSelectionsMock->expects($this->once()) + ->method('setPositionOrder') + ->will($this->returnSelf()); + $usedSelectionsMock->expects($this->once()) + ->method('addFilterByRequiredOptions') + ->will($this->returnSelf()); + $usedSelectionsMock->expects($this->once()) + ->method('setSelectionIdsFilter') + ->with($selectionIds) + ->will($this->returnSelf()); + + $usedSelectionsMock->expects($this->once()) + ->method('joinPrices') + ->with($websiteId) + ->will($this->returnSelf()); + + $this->catalogData->expects($this->once()) + ->method('isPriceGlobal') + ->will($this->returnValue(false)); + + $this->model->getSelectionsByIds($selectionIds, $productMock); + } + + /** + * @return void + */ + public function testGetOptionsByIds() + { + $optionsIds = [1, 2, 3]; + $usedOptionsIds = [4, 5, 6]; + $productId = 3; + $storeId = 2; + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $usedOptionsMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getResourceCollection']) + ->disableOriginalConstructor() + ->getMock(); + $resourceClassName = \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::class; + $dbResourceMock = $this->getMockBuilder($resourceClassName) + ->setMethods(['setProductIdFilter', 'setPositionOrder', 'joinValues', 'setIdFilter']) + ->disableOriginalConstructor() + ->getMock(); + $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) + ->setMethods(['getId', '__wakeup']) + ->disableOriginalConstructor() + ->getMock(); + + $productMock->expects($this->at(0)) + ->method('getData') + ->with('_cache_instance_used_options') + ->will($this->returnValue(null)); + $productMock->expects($this->at(1)) + ->method('getData') + ->with('_cache_instance_used_options_ids') + ->will($this->returnValue($usedOptionsIds)); + $productMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($productId)); + $this->bundleOptionFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($usedOptionsMock)); + $usedOptionsMock->expects($this->once()) + ->method('getResourceCollection') + ->will($this->returnValue($dbResourceMock)); + $dbResourceMock->expects($this->once()) + ->method('setProductIdFilter') + ->with($productId) + ->will($this->returnSelf()); + $dbResourceMock->expects($this->once()) + ->method('setPositionOrder') + ->will($this->returnSelf()); + $this->storeManager->expects($this->once()) + ->method('getStore') + ->will($this->returnValue($storeMock)); + $storeMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($storeId)); + $dbResourceMock->expects($this->once()) + ->method('joinValues') + ->will($this->returnSelf()); + $dbResourceMock->expects($this->once()) + ->method('setIdFilter') + ->with($optionsIds) + ->will($this->returnSelf()); + $productMock->expects($this->at(3)) + ->method('setData') + ->with('_cache_instance_used_options', $dbResourceMock) + ->will($this->returnSelf()); + $productMock->expects($this->at(4)) + ->method('setData') + ->with('_cache_instance_used_options_ids', $optionsIds) + ->will($this->returnSelf()); + + $this->model->getOptionsByIds($optionsIds, $productMock); + } + + /** + * @return void + */ + public function testIsSalableFalse() + { + $product = new \Magento\Framework\DataObject( + [ + 'is_salable' => false, + 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED + ] + ); + + $this->assertFalse($this->model->isSalable($product)); + } + + /** + * @return void + */ + public function testIsSalableWithoutOptions() + { + $optionCollectionMock = $this->getOptionCollectionMock([]); + $product = new \Magento\Framework\DataObject( + [ + 'is_salable' => true, + '_cache_instance_options_collection' => $optionCollectionMock, + 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED + ] + ); + + $this->assertFalse($this->model->isSalable($product)); + } + + /** + * @return void + */ + public function testIsSalableWithRequiredOptionsTrue() + { + $option1 = $this->getRequiredOptionMock(10, 10); + $option2 = $this->getRequiredOptionMock(20, 10); + + $option3 = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) + ->setMethods(['getRequired', 'getOptionId', 'getId']) + ->disableOriginalConstructor() + ->getMock(); + $option3->method('getRequired') + ->willReturn(false); + $option3->method('getOptionId') + ->willReturn(30); + $option3->method('getId') + ->willReturn(30); + + $optionCollectionMock = $this->getOptionCollectionMock([$option1, $option2, $option3]); + $selectionCollectionMock = $this->getSelectionCollectionMock([$option1, $option2]); + $this->bundleCollection->expects($this->atLeastOnce()) + ->method('create') + ->will($this->returnValue($selectionCollectionMock)); + + $product = new \Magento\Framework\DataObject( + [ + 'is_salable' => true, + '_cache_instance_options_collection' => $optionCollectionMock, + 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, + ] + ); + + $this->assertTrue($this->model->isSalable($product)); + } + + /** + * @return void + */ + public function testIsSalableCache() + { + $product = new \Magento\Framework\DataObject( + [ + 'is_salable' => true, + 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, + 'all_items_salable' => true + ] + ); + + $this->assertTrue($this->model->isSalable($product)); + } + + /** + * @return void + */ + public function testIsSalableWithEmptySelectionsCollection() + { + $option = $this->getRequiredOptionMock(1, 10); + $optionCollectionMock = $this->getOptionCollectionMock([$option]); + $selectionCollectionMock = $this->getSelectionCollectionMock([]); + + $this->bundleCollection->expects($this->once()) + ->method('create') + ->will($this->returnValue($selectionCollectionMock)); + + $product = new \Magento\Framework\DataObject( + [ + 'is_salable' => true, + '_cache_instance_options_collection' => $optionCollectionMock, + 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, + ] + ); + + $this->assertFalse($this->model->isSalable($product)); + } + + /** + * @return void + */ + public function nottestIsSalableWithRequiredOptionsOutOfStock() + { + $option1 = $this->getRequiredOptionMock(10, 10); + $option1 + ->expects($this->atLeastOnce()) + ->method('getSelectionCanChangeQty') + ->willReturn(false); + + $option2 = $this->getRequiredOptionMock(20, 10); + $option2 + ->expects($this->atLeastOnce()) + ->method('getSelectionCanChangeQty') + ->willReturn(false); + + $this->stockRegistry->method('getStockItem') + ->willReturn($this->getStockItem(true)); + $this->stockState + ->method('getStockQty') + ->will( + $this->returnValueMap( + [ + [10, 10], + [20, 5] + ] + ) + ); + + $optionCollectionMock = $this->getOptionCollectionMock([$option1, $option2]); + $selectionCollectionMock = $this->getSelectionCollectionMock([$option1, $option2]); + $this->bundleCollection->expects($this->once()) + ->method('create') + ->will($this->returnValue($selectionCollectionMock)); + + $product = new \Magento\Framework\DataObject( + [ + 'is_salable' => true, + '_cache_instance_options_collection' => $optionCollectionMock, + 'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED, + ] + ); + + $this->assertFalse($this->model->isSalable($product)); + } + + /** + * @param int $id + * @param int $selectionQty + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function getRequiredOptionMock($id, $selectionQty) + { + $option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) + ->setMethods( + [ + 'getRequired', + 'isSalable', + 'hasSelectionQty', + 'getSelectionQty', + 'getOptionId', + 'getId', + 'getSelectionCanChangeQty' + ] + ) + ->disableOriginalConstructor() + ->getMock(); + $option->method('getRequired') + ->willReturn(true); + $option->method('isSalable') + ->willReturn(true); + $option->method('hasSelectionQty') + ->willReturn(true); + $option->method('getSelectionQty') + ->willReturn($selectionQty); + $option->method('getOptionId') + ->willReturn($id); + $option->method('getSelectionCanChangeQty') + ->willReturn(false); + $option->method('getId') + ->willReturn($id); + + return $option; + } + + /** + * @param array $selectedOptions + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function getSelectionCollectionMock(array $selectedOptions) + { + $selectionCollectionMock = $this->getMockBuilder( + \Magento\Bundle\Model\ResourceModel\Selection\Collection::class + ) + ->disableOriginalConstructor() + ->getMock(); + + $selectionCollectionMock + ->expects($this->any()) + ->method('getItems') + ->willReturn($selectedOptions); + + $selectionCollectionMock + ->expects($this->any()) + ->method('getIterator') + ->willReturn(new \ArrayIterator($selectedOptions)); + + return $selectionCollectionMock; + } + + /** + * @param array $options + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function getOptionCollectionMock(array $options) + { + $ids = []; + foreach ($options as $option) { + $ids[] = $option->getId(); + } + + $optionCollectionMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->setMethods(['getItems', 'getAllIds']) + ->disableOriginalConstructor() + ->getMock(); + + $optionCollectionMock + ->expects($this->any()) + ->method('getItems') + ->willReturn($options); + + $optionCollectionMock + ->expects($this->any()) + ->method('getAllIds') + ->willReturn($ids); + + return $optionCollectionMock; + } + + /** + * @param bool $isManageStock + * @return \Magento\CatalogInventory\Api\Data\StockItemInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected function getStockItem($isManageStock) + { + $result = $this->getMockBuilder(\Magento\CatalogInventory\Api\Data\StockItemInterface::class) + ->getMock(); + $result->method('getManageStock') + ->willReturn($isManageStock); + + return $result; + } + + /** + * @param \PHPUnit_Framework_MockObject_MockObject|DefaultType $group + * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product\Option $option + * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DataObject $buyRequest + * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product $product + * @return void + */ + protected function parentClass($group, $option, $buyRequest, $product) + { + $group->expects($this->once()) + ->method('setOption') + ->willReturnSelf(); + $group->expects($this->once()) + ->method('setProduct') + ->willReturnSelf(); + $group->expects($this->once()) + ->method('setRequest') + ->willReturnSelf(); + $group->expects($this->once()) + ->method('setProcessMode') + ->willReturnSelf(); + $group->expects($this->once()) + ->method('validateUserValue') + ->willReturnSelf(); + $group->expects($this->once()) + ->method('prepareForCart') + ->willReturn('someString'); + + $option->expects($this->once()) + ->method('getType'); + $option->expects($this->once()) + ->method('groupFactory') + ->willReturn($group); + $option->expects($this->at(0)) + ->method('getId') + ->willReturn(333); + + $buyRequest->expects($this->once()) + ->method('getData'); + $buyRequest->expects($this->once()) + ->method('getOptions'); + $buyRequest->expects($this->once()) + ->method('getSuperProductConfig') + ->willReturn([]); + $buyRequest->expects($this->any()) + ->method('unsetData') + ->willReturnSelf(); + $buyRequest->expects($this->any()) + ->method('getQty'); + + $product->expects($this->once()) + ->method('getOptions') + ->willReturn([$option]); + $product->expects($this->once()) + ->method('getHasOptions') + ->willReturn(true); + $product->expects($this->once()) + ->method('prepareCustomOptions'); + $product->expects($this->any()) + ->method('addCustomOption') + ->willReturnSelf(); + $product->expects($this->any()) + ->method('setCartQty') + ->willReturnSelf(); + $product->expects($this->once()) + ->method('setQty'); + + $this->catalogProduct->expects($this->once()) + ->method('getSkipSaleableCheck') + ->willReturn(false); + } + + public function testGetSelectionsCollection() + { + $optionIds = [1, 2, 3]; + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->setMethods( + [ + '_wakeup', + 'getStoreId', + 'getData', + 'hasData', + 'setData', + 'getId' + ] + ) + ->getMock(); + $store = $this->getMockBuilder(\Magento\Store\Model\Store::class) + ->disableOriginalConstructor() + ->setMethods(['getWebsiteId']) + ->getMock(); + + $product->expects($this->once())->method('getStoreId')->willReturn('store_id'); + $selectionCollection = $this->getSelectionCollection(); + $this->bundleCollection->expects($this->once())->method('create')->willReturn($selectionCollection); + $this->storeManager->expects($this->once())->method('getStore')->willReturn($store); + $store->expects($this->once())->method('getWebsiteId')->willReturn('website_id'); + $selectionCollection->expects($this->any())->method('joinPrices')->with('website_id')->willReturnSelf(); + + $this->assertEquals($selectionCollection, $this->model->getSelectionsCollection($optionIds, $product)); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function getSelectionCollection() + { + $selectionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class) + ->disableOriginalConstructor() + ->getMock(); + $selectionCollection->expects($this->any())->method('addAttributeToSelect')->willReturnSelf(); + $selectionCollection->expects($this->any())->method('setFlag')->willReturnSelf(); + $selectionCollection->expects($this->any())->method('setPositionOrder')->willReturnSelf(); + $selectionCollection->expects($this->any())->method('addStoreFilter')->willReturnSelf(); + $selectionCollection->expects($this->any())->method('setStoreId')->willReturnSelf(); + $selectionCollection->expects($this->any())->method('addFilterByRequiredOptions')->willReturnSelf(); + $selectionCollection->expects($this->any())->method('setOptionIdsFilter')->willReturnSelf(); + $selectionCollection->expects($this->any())->method('addPriceData')->willReturnSelf(); + $selectionCollection->expects($this->any())->method('addTierPriceData')->willReturnSelf(); + + return $selectionCollection; + } + + public function testProcessBuyRequest() + { + $result = ['bundle_option' => [], 'bundle_option_qty' => []]; + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->disableOriginalConstructor() + ->setMethods(['getBundleOption', 'getBundleOptionQty']) + ->getMock(); + + $buyRequest->expects($this->once())->method('getBundleOption')->willReturn('bundleOption'); + $buyRequest->expects($this->once())->method('getBundleOptionQty')->willReturn('optionId'); + + $this->assertEquals($result, $this->model->processBuyRequest($product, $buyRequest)); + } + + public function testGetProductsToPurchaseByReqGroups() + { + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $resourceClassName = \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::class; + $dbResourceMock = $this->getMockBuilder($resourceClassName) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMock(); + $item = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->disableOriginalConstructor() + ->setMethods(['getId', 'getRequired']) + ->getMock(); + $selectionCollection = $this->getSelectionCollection(); + $this->bundleCollection->expects($this->once())->method('create')->willReturn($selectionCollection); + + $selectionItem = $this->getMockBuilder(\Magento\Framework\DataObject::class) + ->disableOriginalConstructor() + ->getMock(); + + $product->expects($this->any())->method('hasData')->willReturn(true); + $product->expects($this->at(1)) + ->method('getData') + ->with('_cache_instance_options_collection') + ->willReturn($dbResourceMock); + $dbResourceMock->expects($this->once())->method('getItems')->willReturn([$item]); + $item->expects($this->once())->method('getId')->willReturn('itemId'); + $item->expects($this->once())->method('getRequired')->willReturn(true); + + $selectionCollection + ->expects($this->any()) + ->method('getIterator') + ->willReturn(new \ArrayIterator([$selectionItem])); + $this->assertEquals([[$selectionItem]], $this->model->getProductsToPurchaseByReqGroups($product)); + } + + public function testGetSearchableData() + { + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->setMethods(['_wakeup', 'getHasOptions', 'getId', 'getStoreId']) + ->getMock(); + $option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) + ->disableOriginalConstructor() + ->setMethods(['getSearchableData']) + ->getMock(); + + $product->expects($this->once())->method('getHasOptions')->willReturn(false); + $product->expects($this->once())->method('getId')->willReturn('productId'); + $product->expects($this->once())->method('getStoreId')->willReturn('storeId'); + $this->bundleOptionFactory->expects($this->once())->method('create')->willReturn($option); + $option->expects($this->once())->method('getSearchableData')->willReturn(['optionSearchdata']); + + $this->assertEquals(['optionSearchdata'], $this->model->getSearchableData($product)); + } + + public function testHasOptions() + { + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->setMethods(['_wakeup', 'hasData', 'getData', 'setData', 'getId', 'getStoreId']) + ->getMock(); + $optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + ->disableOriginalConstructor() + ->setMethods(['getAllIds']) + ->getMock(); + $selectionCollection = $this->getSelectionCollection(); + $selectionCollection + ->expects($this->any()) + ->method('count') + ->willReturn(1); + $this->bundleCollection->expects($this->once())->method('create')->willReturn($selectionCollection); + + $product->expects($this->any())->method('getStoreId')->willReturn(0); + $product->expects($this->once()) + ->method('setData') + ->with('_cache_instance_store_filter', 0) + ->willReturnSelf(); + $product->expects($this->any())->method('hasData')->willReturn(true); + $product->expects($this->at(3)) + ->method('getData') + ->with('_cache_instance_options_collection') + ->willReturn($optionCollection); + $optionCollection->expects($this->once())->method('getAllIds')->willReturn(['ids']); + + $this->assertTrue($this->model->hasOptions($product)); + } + /** * Bundle product without options should not be possible to buy. * From b415bac2c52f69582d2a2e64a97ee7b768ceabad Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Fri, 9 Dec 2016 13:16:31 +0200 Subject: [PATCH 063/132] MAGETWO-61647: Detailed investigation for info_buyrequest field and extension points for its modifications - stabilization bamboo builds - changes after CR --- .../Magento/Bundle/Model/Product/Type.php | 3 -- .../CustomOptions/CustomOptionProcessor.php | 3 +- .../Attribute/Source/Countryofmanufacture.php | 24 +++++++++++---- .../Model/Product/Option/Type/Date.php | 24 ++++----------- .../Model/Product/Type/AbstractType.php | 3 +- .../CustomOptionProcessorTest.php | 16 +++++----- .../Model/Product/Type/ConfigurableTest.php | 15 ++++++---- .../Test/Unit/Model/Product/TypeTest.php | 10 ++++++- .../Unit/Model/Product/Type/GroupedTest.php | 30 +++++++++---------- app/code/Magento/Quote/Model/Quote/Item.php | 24 ++++----------- .../Quote/Model/Quote/Item/Updater.php | 3 +- .../Unit/Model/Quote/Item/UpdaterTest.php | 20 +++++++------ .../Quote/Test/Unit/Model/Quote/ItemTest.php | 18 +++++++---- .../Magento/Sales/Model/AdminOrder/Create.php | 24 ++++----------- app/code/Magento/Sales/Model/Order/Item.php | 24 ++++----------- app/code/Magento/Wishlist/Model/Item.php | 28 +++++------------ .../Model/Product/Type/AbstractTypeTest.php | 6 +++- .../Magento/Wishlist/Model/ItemTest.php | 6 ++-- 18 files changed, 129 insertions(+), 152 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index fcf61a967255b..418d7081ffe69 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -9,9 +9,7 @@ namespace Magento\Bundle\Model\Product; use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\Framework\App\ObjectManager; use Magento\Framework\Pricing\PriceCurrencyInterface; -use Magento\Framework\Serialize\SerializerInterface; /** * Bundle Type Model @@ -209,7 +207,6 @@ public function __construct( $this->priceCurrency = $priceCurrency; $this->_stockRegistry = $stockRegistry; $this->_stockState = $stockState; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct( $catalogProductOption, $eavConfig, diff --git a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php index e127aa0970ea2..252c0bcb796b5 100644 --- a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php +++ b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php @@ -53,7 +53,8 @@ public function __construct( $this->productOptionFactory = $productOptionFactory; $this->extensionFactory = $extensionFactory; $this->customOptionFactory = $customOptionFactory; - $this->serializer = $serializer; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); } /** diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php b/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php index 2e21a6d88902b..8bcf01ba3db38 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php @@ -46,18 +46,15 @@ class Countryofmanufacture extends AbstractSource implements OptionSourceInterfa * @param \Magento\Directory\Model\CountryFactory $countryFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\App\Cache\Type\Config $configCacheType - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] */ public function __construct( \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\App\Cache\Type\Config $configCacheType, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\App\Cache\Type\Config $configCacheType ) { $this->_countryFactory = $countryFactory; $this->_storeManager = $storeManager; $this->_configCacheType = $configCacheType; - $this->serializer = $serializer; } /** @@ -69,15 +66,30 @@ public function getAllOptions() { $cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); if ($cache = $this->_configCacheType->load($cacheKey)) { - $options = $this->serializer->unserialize($cache); + $options = $this->getSerializer()->unserialize($cache); } else { /** @var \Magento\Directory\Model\Country $country */ $country = $this->_countryFactory->create(); /** @var \Magento\Directory\Model\ResourceModel\Country\Collection $collection */ $collection = $country->getResourceCollection(); $options = $collection->load()->toOptionArray(); - $this->_configCacheType->save($this->serializer->serialize($options), $cacheKey); + $this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey); } return $options; } + + /** + * Get serializer + * + * @return \Magento\Framework\Serialize\SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if ($this->serializer === null) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + return $this->serializer; + } } diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php index 9b7ff1dff290e..205cf420f5c9f 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php @@ -34,14 +34,18 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param array $data + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, - array $data = [] + array $data = [], + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->_localeDate = $localeDate; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); parent::__construct($checkoutSession, $scopeConfig, $data); } @@ -276,7 +280,7 @@ public function prepareOptionValueForRequest($optionValue) $confItem = $this->getConfigurationItem(); $infoBuyRequest = $confItem->getOptionByCode('info_buyRequest'); try { - $value = $this->getSerializer()->unserialize($infoBuyRequest->getValue()); + $value = $this->serializer->unserialize($infoBuyRequest->getValue()); if (is_array($value) && isset($value['options']) && isset($value['options'][$this->getOption()->getId()]) ) { return $value['options'][$this->getOption()->getId()]; @@ -288,22 +292,6 @@ public function prepareOptionValueForRequest($optionValue) } } - /** - * Get Serializer interface. - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - - return $this->serializer; - } - /** * Use Calendar on frontend or not * diff --git a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php index 6f2cb2ccf140c..f0e8d37921ca0 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php +++ b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php @@ -204,7 +204,8 @@ public function __construct( $this->_filesystem = $filesystem; $this->_logger = $logger; $this->productRepository = $productRepository; - $this->serializer = $serializer; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); } /** diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php index f302f569431c6..7e41275c5908e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php @@ -51,6 +51,9 @@ class CustomOptionProcessorTest extends \PHPUnit_Framework_TestCase /** @var CustomOptionProcessor */ protected $processor; + /** @var \Magento\Framework\Serialize\SerializerInterface */ + private $serializer; + protected function setUp() { $this->objectFactory = $this->getMockBuilder(\Magento\Framework\DataObject\Factory::class) @@ -90,12 +93,16 @@ protected function setUp() $this->buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) ->disableOriginalConstructor() ->getMock(); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['unserialize']) + ->getMockForAbstractClass(); $this->processor = new CustomOptionProcessor( $this->objectFactory, $this->productOptionFactory, $this->extensionFactory, - $this->customOptionFactory + $this->customOptionFactory, + $this->serializer ); } @@ -142,14 +149,9 @@ public function testProcessCustomOptions() $quoteItemOption->expects($this->any()) ->method('getValue') ->willReturn('{"options":{"' . $optionId . '":["5","6"]}}'); - $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) - ->setMethods(['unserialize']) - ->getMockForAbstractClass(); - $serializer->expects($this->any()) + $this->serializer->expects($this->any()) ->method('unserialize') ->willReturn(json_decode($quoteItemOption->getValue(), true)); - $objectHelper->setBackwardCompatibleProperty($this->processor, 'serializer', $serializer); $this->customOptionFactory->expects($this->once()) ->method('create') ->willReturn($this->customOption); diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php index 9e27966ff8c7c..1e5b3a316083e 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php @@ -99,6 +99,11 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase */ protected $catalogConfig; + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -175,6 +180,9 @@ protected function setUp() $this->eavConfig = $this->getMockBuilder(\Magento\Eav\Model\Config::class)->disableOriginalConstructor() ->getMock(); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['unserialize']) + ->getMockForAbstractClass(); $this->_model = $this->_objectHelper->getObject( Configurable::class, @@ -194,6 +202,7 @@ protected function setUp() 'customerSession' => $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(), 'cache' => $this->cache, 'catalogConfig' => $this->catalogConfig, + 'serializer' => $this->serializer ] ); $refClass = new \ReflectionClass(Configurable::class); @@ -650,13 +659,9 @@ public function testGetSelectedAttributesInfo() ->getMock(); $optionMock->expects($this->any())->method('getValue')->willReturn(json_encode($this->attributeData, true)); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) - ->setMethods(['unserialize']) - ->getMockForAbstractClass(); - $serializer->expects($this->any()) + $this->serializer->expects($this->any()) ->method('unserialize') ->willReturn(json_decode($optionMock->getValue(), true)); - $this->_objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); $productMock->expects($this->once())->method('getCustomOption')->with('attributes')->willReturn($optionMock); $productMock->expects($this->once())->method('hasData')->willReturn(true); $productMock->expects($this->at(2))->method('getData')->willReturn(true); diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php index 61d66d47bc281..0b81b76ef340d 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php @@ -30,6 +30,11 @@ class TypeTest extends \PHPUnit_Framework_TestCase */ private $product; + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -123,6 +128,9 @@ protected function setUp() ->setMethods(['save']) ->getMock(); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->getMockForAbstractClass(); + $this->target = $objectHelper->getObject( \Magento\Downloadable\Model\Product\Type::class, [ @@ -140,7 +148,7 @@ protected function setUp() 'linkFactory' => $linkFactory, 'eavConfig' => $eavConfigMock, 'typeHandler' => $this->typeHandler, - + 'serializer' => $this->serializer ] ); } diff --git a/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php b/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php index 803165fe6c836..b02cd7d2e385f 100644 --- a/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php +++ b/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php @@ -37,6 +37,11 @@ class GroupedTest extends \PHPUnit_Framework_TestCase */ protected $objectHelper; + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + protected function setUp() { $this->objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -67,6 +72,10 @@ protected function setUp() '', false ); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['serialize']) + ->getMockForAbstractClass(); + $this->_model = $this->objectHelper->getObject( \Magento\GroupedProduct\Model\Product\Type\Grouped::class, [ @@ -77,7 +86,8 @@ protected function setUp() 'logger' => $logger, 'productFactory' => $productFactoryMock, 'catalogProductLink' => $this->catalogProductLink, - 'catalogProductStatus' => $this->productStatusMock + 'catalogProductStatus' => $this->productStatusMock, + 'serializer' => $this->serializer ] ); } @@ -429,13 +439,9 @@ public function testPrepareForCartAdvancedNoProductsStrictFalse() ->expects($this->atLeastOnce()) ->method('getData') ->will($this->returnValue($associatedProducts)); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) - ->setMethods(['serialize']) - ->getMockForAbstractClass(); - $serializer->expects($this->any()) + $this->serializer->expects($this->any()) ->method('serialize') ->willReturn(json_encode($buyRequest->getData())); - $this->objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); $this->assertEquals( [0 => $this->product], @@ -547,13 +553,9 @@ public function testPrepareForCartAdvancedWithProductsStrictFalse() $buyRequest = new \Magento\Framework\DataObject(); $buyRequest->setSuperGroup([$associatedId => 1]); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) - ->setMethods(['serialize']) - ->getMockForAbstractClass(); - $serializer->expects($this->any()) + $this->serializer->expects($this->any()) ->method('serialize') ->willReturn(json_encode($buyRequest->getData())); - $this->objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); $cached = true; $this->product @@ -598,13 +600,9 @@ public function testPrepareForCartAdvancedWithProductsStrictTrue() $buyRequest = new \Magento\Framework\DataObject(); $buyRequest->setSuperGroup([$associatedId => 1]); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) - ->setMethods(['serialize']) - ->getMockForAbstractClass(); - $serializer->expects($this->any()) + $this->serializer->expects($this->any()) ->method('serialize') ->willReturn(json_encode($buyRequest->getData())); - $this->objectHelper->setBackwardCompatibleProperty($this->_model, 'serializer', $serializer); $cached = true; $this->product diff --git a/app/code/Magento/Quote/Model/Quote/Item.php b/app/code/Magento/Quote/Model/Quote/Item.php index 6e69ce841312b..1e6a6e1e5ace8 100644 --- a/app/code/Magento/Quote/Model/Quote/Item.php +++ b/app/code/Magento/Quote/Model/Quote/Item.php @@ -198,6 +198,7 @@ class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem implements \Mage * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * + * @param \Magento\Framework\Serialize\SerializerInterface $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -214,13 +215,16 @@ public function __construct( \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->_errorInfos = $statusListFactory->create(); $this->_localeFormat = $localeFormat; $this->_itemOptionFactory = $itemOptionFactory; $this->quoteItemCompare = $quoteItemCompare; $this->stockRegistry = $stockRegistry; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); parent::__construct( $context, $registry, @@ -815,7 +819,7 @@ public function __clone() public function getBuyRequest() { $option = $this->getOptionByCode('info_buyRequest'); - $data = $option ? $this->getSerializer()->unserialize($option->getValue()) : []; + $data = $option ? $this->serializer->unserialize($option->getValue()) : []; $buyRequest = new \Magento\Framework\DataObject($data); // Overwrite standard buy request qty, because item qty could have changed since adding to quote @@ -824,22 +828,6 @@ public function getBuyRequest() return $buyRequest; } - /** - * Get Serializer interface. - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - - return $this->serializer; - } - /** * Sets flag, whether this quote item has some error associated with it. * diff --git a/app/code/Magento/Quote/Model/Quote/Item/Updater.php b/app/code/Magento/Quote/Model/Quote/Item/Updater.php index 556ec5035e3ac..4dc17705568bd 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Updater.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Updater.php @@ -54,7 +54,8 @@ public function __construct( $this->productFactory = $productFactory; $this->localeFormat = $localeFormat; $this->objectFactory = $objectFactory; - $this->serializer = $serializer; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); } /** diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php index 1d817ccfbe818..5d95daf1673f5 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php @@ -38,6 +38,11 @@ class UpdaterTest extends \PHPUnit_Framework_TestCase */ protected $productMock; + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + protected function setUp() { $this->productMock = $this->getMock( @@ -94,12 +99,16 @@ protected function setUp() '', false ); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['serialize']) + ->getMockForAbstractClass(); $this->object = (new ObjectManager($this)) ->getObject( \Magento\Quote\Model\Quote\Item\Updater::class, [ - 'localeFormat' => $this->localeFormat + 'localeFormat' => $this->localeFormat, + 'serializer' => $this->serializer ] ); } @@ -252,16 +261,9 @@ public function testUpdateCustomPrice() $buyRequestMock->expects($this->any()) ->method('getData') ->will($this->returnValue(['custom_price' => $customPrice])); - - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) - ->setMethods(['serialize']) - ->getMockForAbstractClass(); - $serializer->expects($this->any()) + $this->serializer->expects($this->any()) ->method('serialize') ->willReturn(json_encode($buyRequestMock->getData())); - $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $objectManagerHelper->setBackwardCompatibleProperty($this->object, 'serializer', $serializer); - $buyRequestMock->expects($this->any()) ->method('setValue') ->with($this->equalTo('{"custom_price":' . $customPrice . '}')); diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php index ec5ff92982fd2..f14ffb10b4a00 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php @@ -61,6 +61,11 @@ class ItemTest extends \PHPUnit_Framework_TestCase */ protected $stockRegistry; + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + const PRODUCT_ID = 1; const PRODUCT_TYPE = 'simple'; const PRODUCT_SKU = '12345'; @@ -134,6 +139,10 @@ protected function setUp() ->method('getStockItem') ->will($this->returnValue($this->stockItemMock)); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->setMethods(['unserialize']) + ->getMockForAbstractClass(); + $this->model = $this->objectManagerHelper->getObject( \Magento\Quote\Model\Quote\Item::class, [ @@ -142,7 +151,8 @@ protected function setUp() 'statusListFactory' => $statusListFactory, 'itemOptionFactory' => $this->itemOptionFactory, 'quoteItemCompare' => $this->compareHelper, - 'stockRegistry' => $this->stockRegistry + 'stockRegistry' => $this->stockRegistry, + 'serializer' => $this->serializer ] ); } @@ -1071,13 +1081,9 @@ public function testGetBuyRequestOptionByCode() ->will($this->returnValue($quantity)); $this->model->setQty($quantity); $this->assertEquals($quantity, $this->model->getQty()); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) - ->setMethods(['unserialize']) - ->getMockForAbstractClass(); - $serializer->expects($this->any()) + $this->serializer->expects($this->any()) ->method('unserialize') ->willReturn(json_decode($optionMock->getValue(), true)); - $this->objectManagerHelper->setBackwardCompatibleProperty($this->model, 'serializer', $serializer); $buyRequest = $this->model->getBuyRequest(); $this->assertEquals($buyRequestQuantity, $buyRequest->getOriginalQty()); $this->assertEquals($quantity, $buyRequest->getQty()); diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 767c35f3a07eb..c6545b36faecf 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -260,6 +260,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ * @param \Magento\Sales\Api\OrderManagementInterface $orderManagement * @param \Magento\Quote\Model\QuoteFactory $quoteFactory * @param array $data + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -290,7 +291,8 @@ public function __construct( \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Sales\Api\OrderManagementInterface $orderManagement, \Magento\Quote\Model\QuoteFactory $quoteFactory, - array $data = [] + array $data = [], + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->_objectManager = $objectManager; $this->_eventManager = $eventManager; @@ -319,6 +321,8 @@ public function __construct( $this->dataObjectHelper = $dataObjectHelper; $this->orderManagement = $orderManagement; $this->quoteFactory = $quoteFactory; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); parent::__construct($data); } @@ -802,7 +806,7 @@ public function moveQuoteItem($item, $moveTo, $qty) $info = $item->getOptionByCode('info_buyRequest'); if ($info) { $info = new \Magento\Framework\DataObject( - $this->getSerializer()->unserialize($info->getValue()) + $this->serializer->unserialize($info->getValue()) ); $info->setQty($qty); $info->setOptions($this->_prepareOptionsForRequest($item)); @@ -881,22 +885,6 @@ public function moveQuoteItem($item, $moveTo, $qty) return $this; } - /** - * Get Serializer interface. - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - - return $this->serializer; - } - /** * Handle data sent from sidebar * diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index 2492ce1980ac2..100b8b69a44e9 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -115,6 +115,7 @@ class Item extends AbstractModel implements OrderItemInterface * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -127,7 +128,8 @@ public function __construct( \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { parent::__construct( $context, @@ -138,6 +140,8 @@ public function __construct( $resourceCollection, $data ); + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); $this->_orderFactory = $orderFactory; $this->_storeManager = $storeManager; $this->productRepository = $productRepository; @@ -473,23 +477,7 @@ public function setProductOptions(array $options = null) public function getProductOptions() { $data = $this->_getData('product_options'); - return is_string($data) ? $this->getSerializer()->unserialize($data) : $data; - } - - /** - * Get Serializer interface. - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - - return $this->serializer; + return is_string($data) ? $this->serializer->unserialize($data) : $data; } /** diff --git a/app/code/Magento/Wishlist/Model/Item.php b/app/code/Magento/Wishlist/Model/Item.php index f9cba6712ebd7..2d6bd18fcc0ba 100644 --- a/app/code/Magento/Wishlist/Model/Item.php +++ b/app/code/Magento/Wishlist/Model/Item.php @@ -140,6 +140,7 @@ class Item extends AbstractModel implements ItemInterface * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -154,7 +155,8 @@ public function __construct( ProductRepositoryInterface $productRepository, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->productTypeConfig = $productTypeConfig; $this->_storeManager = $storeManager; @@ -162,6 +164,8 @@ public function __construct( $this->_catalogUrl = $catalogUrl; $this->_wishlistOptFactory = $wishlistOptFactory; $this->_wishlOptionCollectionFactory = $wishlOptionCollectionFactory; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); parent::__construct($context, $registry, $resource, $resourceCollection, $data); $this->productRepository = $productRepository; } @@ -479,7 +483,7 @@ public function getProductUrl() public function getBuyRequest() { $option = $this->getOptionByCode('info_buyRequest'); - $initialData = $option ? $this->getSerializer()->unserialize($option->getValue()) : null; + $initialData = $option ? $this->serializer->unserialize($option->getValue()) : null; if ($initialData instanceof \Magento\Framework\DataObject) { $initialData = $initialData->getData(); @@ -507,7 +511,7 @@ public function mergeBuyRequest($buyRequest) } $oldBuyRequest = $this->getBuyRequest()->getData(); - $sBuyRequest = $this->getSerializer()->serialize($buyRequest + $oldBuyRequest); + $sBuyRequest = $this->serializer->serialize($buyRequest + $oldBuyRequest); $option = $this->getOptionByCode('info_buyRequest'); if ($option) { @@ -530,27 +534,11 @@ public function setBuyRequest($buyRequest) { $buyRequest->setId($this->getId()); - $_buyRequest = $this->getSerializer()->serialize($buyRequest->getData()); + $_buyRequest = $this->serializer->serialize($buyRequest->getData()); $this->setData('buy_request', $_buyRequest); return $this; } - /** - * Get Serializer interface. - * - * @return \Magento\Framework\Serialize\SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (!$this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); - } - - return $this->serializer; - } - /** * Check product representation in item * diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php index 20d40abd61821..8f88186753030 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php @@ -35,6 +35,9 @@ protected function setUp() $filesystem = $this->getMock(\Magento\Framework\Filesystem::class, [], [], '', false); $registry = $this->getMock(\Magento\Framework\Registry::class, [], [], '', false); $logger = $this->getMock(\Psr\Log\LoggerInterface::class, [], [], '', false); + $serializer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + \Magento\Framework\Serialize\SerializerInterface::class + ); $this->_model = $this->getMockForAbstractClass( \Magento\Catalog\Model\Product\Type\AbstractType::class, [ @@ -46,7 +49,8 @@ protected function setUp() $filesystem, $registry, $logger, - $productRepository + $productRepository, + $serializer ] ); } diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php b/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php index 411ac4421f888..e46b8524b7b5e 100644 --- a/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php +++ b/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php @@ -45,9 +45,9 @@ public function testBuyRequest() /** @var \Magento\Wishlist\Model\Item\Option $option */ $option = $this->objectManager->create( - \Magento\Wishlist\Model\Item\Option::class, - ['data' => ['code' => 'info_buyRequest', 'value' => '{"qty":23}']] - ); + \Magento\Wishlist\Model\Item\Option::class, + ['data' => ['code' => 'info_buyRequest', 'value' => '{"qty":23}']] + ); $option->setProduct($product); $this->model->addOption($option); From b3104e4882c91d8f27addc416d11e4446408ea0c Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Fri, 9 Dec 2016 16:19:38 +0200 Subject: [PATCH 064/132] MAGETWO-61672: Module Catalog and unit tests - Refactored - Added unit test --- .../Model/Product/Option/Type/File.php | 32 +++-- .../Model/Product/Option/Type/FileTest.php | 128 +++++++++++++++++- .../Adminhtml/Order/Create/Items/Grid.php | 2 + .../Magento/Sales/Model/AdminOrder/Create.php | 2 + 4 files changed, 151 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index 70c20a4e31490..6cac282f295b1 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -9,6 +9,8 @@ use Magento\Framework\Filesystem; use Magento\Framework\Exception\LocalizedException; use Magento\Catalog\Model\Product\Exception as ProductException; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; /** * Catalog product option file type @@ -70,6 +72,11 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType */ protected $validatorFile; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @var Filesystem */ @@ -87,6 +94,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param array $data * @param Filesystem $filesystem * @SuppressWarnings(PHPMD.ExcessiveParameterList) + * @param SerializerInterface|null $serializer */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, @@ -98,7 +106,8 @@ public function __construct( \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder, \Magento\Framework\Escaper $escaper, array $data = [], - Filesystem $filesystem = null + Filesystem $filesystem = null, + SerializerInterface $serializer = null ) { $this->_itemOptionFactory = $itemOptionFactory; $this->_urlBuilder = $urlBuilder; @@ -108,6 +117,7 @@ public function __construct( $this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); $this->validatorInfo = $validatorInfo; $this->validatorFile = $validatorFile; + $this->serializer = $serializer ? $serializer : ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct($checkoutSession, $scopeConfig, $data); } @@ -275,7 +285,7 @@ public function prepareForCart() // Save option in request, because we have no $_FILES['options'] $requestOptions[$this->getOption()->getId()] = $value; - $result = serialize($value); + $result = $this->serializer->serialize($value); } else { /* * Clear option info from request, so it won't be stored in our db upon @@ -306,7 +316,7 @@ public function getFormattedOptionValue($optionValue) { if ($this->_formattedOptionValue === null) { try { - $value = unserialize($optionValue); + $value = $this->serializer->unserialize($optionValue); $customOptionUrlParams = $this->getCustomOptionUrlParams() ? $this->getCustomOptionUrlParams() : [ 'id' => $this->getConfigurationItemOption()->getId(), @@ -316,7 +326,7 @@ public function getFormattedOptionValue($optionValue) $value['url'] = ['route' => $this->_customOptionDownloadUrl, 'params' => $customOptionUrlParams]; $this->_formattedOptionValue = $this->_getOptionHtml($value); - $this->getConfigurationItemOption()->setValue(serialize($value)); + $this->getConfigurationItemOption()->setValue($this->serializer->serialize($value)); return $this->_formattedOptionValue; } catch (\Exception $e) { return $optionValue; @@ -364,7 +374,7 @@ protected function _unserializeValue($value) if (is_array($value)) { return $value; } elseif (is_string($value) && !empty($value)) { - return unserialize($value); + return $this->serializer->unserialize($value); } else { return []; } @@ -386,11 +396,13 @@ public function getPrintableOptionValue($optionValue) * * @param string $optionValue Prepared for cart option value * @return string + * + * @deprecated */ public function getEditableOptionValue($optionValue) { try { - $value = unserialize($optionValue); + $value = $this->serializer->unserialize($optionValue); return sprintf( '%s [%d]', $this->_escaper->escapeHtml($value['title']), @@ -409,6 +421,8 @@ public function getEditableOptionValue($optionValue) * @return string|null * * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @deprecated */ public function parseOptionValue($optionValue, $productOptionValues) { @@ -417,7 +431,7 @@ public function parseOptionValue($optionValue, $productOptionValues) $confItemOptionId = $matches[1]; $option = $this->_itemOptionFactory->create()->load($confItemOptionId); try { - unserialize($option->getValue()); + $this->serializer->unserialize($option->getValue()); return $option->getValue(); } catch (\Exception $e) { return null; @@ -436,7 +450,7 @@ public function parseOptionValue($optionValue, $productOptionValues) public function prepareOptionValueForRequest($optionValue) { try { - $result = unserialize($optionValue); + $result = $this->serializer->unserialize($optionValue); return $result; } catch (\Exception $e) { return null; @@ -452,7 +466,7 @@ public function copyQuoteToOrder() { $quoteOption = $this->getConfigurationItemOption(); try { - $value = unserialize($quoteOption->getValue()); + $value = $this->serializer->unserialize($quoteOption->getValue()); if (!isset($value['quote_path'])) { throw new \Exception(); } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php index 6682b29547632..48e8f79bd0d72 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php @@ -33,6 +33,21 @@ class FileTest extends \PHPUnit_Framework_TestCase */ private $filesystemMock; + /** + * @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializer; + + /** + * @var \Magento\Catalog\Model\Product\Option\UrlBuilder|\PHPUnit_Framework_MockObject_MockObject + */ + private $urlBuilder; + + /** + * @var \Magento\Framework\Escaper|\PHPUnit_Framework_MockObject_MockObject + */ + private $escaper; + protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -44,11 +59,23 @@ protected function setUp() $this->rootDirectory = $this->getMockBuilder(ReadInterface::class) ->getMock(); - $this->filesystemMock->expects($this->once()) + $this->filesystemMock->expects($this->any()) ->method('getDirectoryRead') ->with(DirectoryList::MEDIA, DriverPool::FILE) ->willReturn($this->rootDirectory); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->urlBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\UrlBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->escaper = $this->getMockBuilder(\Magento\Framework\Escaper::class) + ->disableOriginalConstructor() + ->getMock(); + $this->coreFileStorageDatabase = $this->getMock( \Magento\MediaStorage\Helper\File\Storage\Database::class, ['copyFile'], @@ -67,11 +94,41 @@ protected function getFileObject() \Magento\Catalog\Model\Product\Option\Type\File::class, [ 'filesystem' => $this->filesystemMock, - 'coreFileStorageDatabase' => $this->coreFileStorageDatabase + 'coreFileStorageDatabase' => $this->coreFileStorageDatabase, + 'serializer' => $this->serializer, + 'urlBuilder' => $this->urlBuilder, + 'escaper' => $this->escaper ] ); } + + public function testGetCustomizedView() + { + $fileObject = $this->getFileObject(); + $optionInfo = ['option_value' => 'some serialized data']; + + $dataAfterSerialize = ['some' => 'array']; + + $this->serializer->expects($this->once()) + ->method('unserialize') + ->with('some serialized data') + ->willReturn($dataAfterSerialize); + + $this->urlBuilder->expects($this->once()) + ->method('getUrl') + ->willReturn('someUrl'); + + $this->escaper->expects($this->once()) + ->method('escapeHtml') + ->willReturn('string'); + + $this->assertEquals( + 'string ', + $fileObject->getCustomizedView($optionInfo) + ); + } + public function testCopyQuoteToOrder() { $optionMock = $this->getMockBuilder(OptionInterface::class) @@ -82,11 +139,22 @@ public function testCopyQuoteToOrder() $quotePath = '/quote/path/path/uploaded.file'; $orderPath = '/order/path/path/uploaded.file'; + $quoteValue = "{\"quote_path\":\"$quotePath\",\"order_path\":\"$orderPath\"}"; + + $this->serializer->expects($this->once()) + ->method('unserialize') + ->with($quoteValue) + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + $optionMock->expects($this->any()) ->method('getValue') - ->will($this->returnValue(serialize(['quote_path' => $quotePath, 'order_path' => $orderPath]))); + ->will($this->returnValue($quoteValue)); - $this->rootDirectory->expects($this->once()) + $this->rootDirectory->expects($this->any()) ->method('isFile') ->with($this->equalTo($quotePath)) ->will($this->returnValue(true)); @@ -112,4 +180,56 @@ public function testCopyQuoteToOrder() $fileObject->copyQuoteToOrder() ); } + + public function testGetFormattedOptionValue() + { + $resultValue = ['result']; + $optionValue = json_encode($resultValue); + $urlParameter = 'parameter'; + + $fileObject = $this->getFileObject(); + $fileObject->setCustomOptionUrlParams($urlParameter); + $this->serializer->expects($this->once()) + ->method('unserialize') + ->with($optionValue) + ->willReturn($resultValue); + + $resultValue['url'] = [ + 'route' => 'sales/download/downloadCustomOption', + 'params' => $fileObject->getCustomOptionUrlParams() + ]; + + $this->serializer->expects($this->once()) + ->method('serialize') + ->with($resultValue) + ->willReturn(json_encode($resultValue)); + + $option = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Option::class) + ->setMethods(['setValue']) + ->disableOriginalConstructor() + ->getMock(); + + $option->expects($this->once()) + ->method('setValue') + ->with(json_encode($resultValue)); + + $fileObject->setConfigurationItemOption($option); + + $fileObject->getFormattedOptionValue($optionValue); + } + + public function testPrepareOptionValueForRequest() + { + $optionValue = 'string'; + $resultValue = ['result']; + $fileObject = $this->getFileObject(); + + $this->serializer->expects($this->once()) + ->method('unserialize') + ->with($optionValue) + ->willReturn($resultValue); + + $this->assertEquals($resultValue, $fileObject->prepareOptionValueForRequest($optionValue)); + } } + diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php index 3af13c7b1ead2..d5d0da9c4676c 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php @@ -425,6 +425,8 @@ protected function _getTierPriceInfo($prices) * * @param Item $item * @return string + * + * @deprecated */ public function getCustomOptions(Item $item) { diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 3715c02357a96..da9d6bdb0940d 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -1102,6 +1102,8 @@ public function updateQuoteItems($items) * @param string $additionalOptions * @return array * @throws \Magento\Framework\Exception\LocalizedException + * + * @deprecated */ protected function _parseOptions(\Magento\Quote\Model\Quote\Item $item, $additionalOptions) { From e32a6f0291794b6a170b1434202026778efc7370 Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Fri, 9 Dec 2016 16:33:54 +0200 Subject: [PATCH 065/132] MAGETWO-61647: Detailed investigation for info_buyrequest field and extension points for its modifications - stabilization bamboo builds - changes after CR --- .../Helper/Catalog/Product/Configuration.php | 15 ++++++++++-- .../Magento/Bundle/Model/Product/Price.php | 17 ++++++++++--- .../Magento/Bundle/Model/Product/Type.php | 10 ++++---- .../Bundle/Pricing/Price/ConfiguredPrice.php | 15 ++++++++++-- .../Catalog/Product/ConfigurationTest.php | 2 +- .../Test/Unit/Model/Product/PriceTest.php | 24 ++++++++++++++++--- .../Test/Unit/Model/Product/TypeTest.php | 8 +++---- .../Model/Product/Type/ConfigurableTest.php | 16 +++++++++++++ .../Test/Unit/Model/Product/TypeTest.php | 3 +-- 9 files changed, 88 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php b/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php index 8305bb0137ed2..f9e08bba754d6 100644 --- a/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php +++ b/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php @@ -35,21 +35,32 @@ class Configuration extends AbstractHelper implements ConfigurationInterface */ protected $escaper; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper * @param \Magento\Framework\Escaper $escaper + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Helper\Product\Configuration $productConfiguration, \Magento\Framework\Pricing\Helper\Data $pricingHelper, - \Magento\Framework\Escaper $escaper + \Magento\Framework\Escaper $escaper, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->productConfiguration = $productConfiguration; $this->pricingHelper = $pricingHelper; $this->escaper = $escaper; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); parent::__construct($context); } @@ -121,7 +132,7 @@ public function getBundleOptions(ItemInterface $item) // get and add bundle selections collection $selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids'); - $bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue()); + $bundleSelectionIds = $this->serializer->unserialize($selectionsQuoteItemOption->getValue()); if (!empty($bundleSelectionIds)) { $selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $product); diff --git a/app/code/Magento/Bundle/Model/Product/Price.php b/app/code/Magento/Bundle/Model/Product/Price.php index 83bfcbbabc253..a1e845f68f795 100644 --- a/app/code/Magento/Bundle/Model/Product/Price.php +++ b/app/code/Magento/Bundle/Model/Product/Price.php @@ -39,6 +39,13 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price */ protected $_catalogData = null; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * Price constructor. * @@ -52,7 +59,7 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price * @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Catalog\Helper\Data $catalogData - * + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -65,9 +72,12 @@ public function __construct( GroupManagementInterface $groupManagement, \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory, \Magento\Framework\App\Config\ScopeConfigInterface $config, - \Magento\Catalog\Helper\Data $catalogData + \Magento\Catalog\Helper\Data $catalogData, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->_catalogData = $catalogData; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); parent::__construct( $ruleFactory, $storeManager, @@ -154,7 +164,8 @@ protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product { $customOption = $product->getCustomOption('bundle_selection_ids'); if ($customOption) { - $selectionIds = unserialize($customOption->getValue()); + $r = json_decode('{"0":1}', true); + $selectionIds = $this->serializer->unserialize($customOption->getValue()); if (!empty($selectionIds) && is_array($selectionIds)) { return $selectionIds; } diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index 418d7081ffe69..2e8e602a6d37a 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -279,7 +279,7 @@ public function getSku($product) if ($product->hasCustomOptions()) { $customOption = $product->getCustomOption('bundle_selection_ids'); - $selectionIds = unserialize($customOption->getValue()); + $selectionIds = $this->serializer->unserialize($customOption->getValue()); if (!empty($selectionIds)) { $selections = $this->getSelectionsByIds($selectionIds, $product); foreach ($selections->getItems() as $selection) { @@ -307,7 +307,7 @@ public function getWeight($product) if ($product->hasCustomOptions()) { $customOption = $product->getCustomOption('bundle_selection_ids'); - $selectionIds = unserialize($customOption->getValue()); + $selectionIds = $this->serializer->unserialize($customOption->getValue()); $selections = $this->getSelectionsByIds($selectionIds, $product); foreach ($selections->getItems() as $selection) { $qtyOption = $product->getCustomOption('selection_qty_' . $selection->getSelectionId()); @@ -333,7 +333,7 @@ public function isVirtual($product) { if ($product->hasCustomOptions()) { $customOption = $product->getCustomOption('bundle_selection_ids'); - $selectionIds = unserialize($customOption->getValue()); + $selectionIds = $this->serializer->unserialize($customOption->getValue()); $selections = $this->getSelectionsByIds($selectionIds, $product); $virtualCount = 0; foreach ($selections->getItems() as $selection) { @@ -717,7 +717,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p $item->addCustomOption('bundle_identity', $uniqueKey); } $product->addCustomOption('bundle_option_ids', serialize(array_map('intval', $optionIds))); - $product->addCustomOption('bundle_selection_ids', serialize($selectionIds)); + $product->addCustomOption('bundle_selection_ids', $this->serializer->serialize($selectionIds)); return $result; } @@ -862,7 +862,7 @@ public function getOrderOptions($product) $optionIds = unserialize($customOption->getValue()); $options = $this->getOptionsByIds($optionIds, $product); $customOption = $product->getCustomOption('bundle_selection_ids'); - $selectionIds = unserialize($customOption->getValue()); + $selectionIds = $this->serializer->unserialize($customOption->getValue()); $selections = $this->getSelectionsByIds($selectionIds, $product); foreach ($selections->getItems() as $selection) { if ($selection->isSalable()) { diff --git a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php index e6c0f90e24a5c..52ec835795aa2 100644 --- a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php @@ -32,21 +32,32 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice */ protected $item; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param Product $saleableItem * @param float $quantity * @param BundleCalculatorInterface $calculator * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param ItemInterface $item + * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] */ public function __construct( Product $saleableItem, $quantity, BundleCalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, - ItemInterface $item = null + ItemInterface $item = null, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->item = $item; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); } @@ -80,7 +91,7 @@ public function getOptions() $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $bundleProduct); // get and add bundle selections collection $selectionsQuoteItemOption = $this->item->getOptionByCode('bundle_selection_ids'); - $bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue()); + $bundleSelectionIds = $this->serializer->unserialize($selectionsQuoteItemOption->getValue()); if ($bundleSelectionIds) { $selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $bundleProduct); $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true); diff --git a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php index 0919e95a9a09d..aaffa90fa0d2f 100644 --- a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php @@ -170,7 +170,7 @@ public function testGetBundleOptionsEmptyBundleSelectionIds() public function testGetOptions() { $optionIds = 'a:1:{i:0;i:1;}'; - $selectionIds = 'a:1:{i:0;s:1:"2";}'; + $selectionIds = '{"0":"2"}'; $selectionId = '2'; $product = $this->getMock( \Magento\Catalog\Model\Product::class, diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php index e97f0bbc1558d..aa388747698d2 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php @@ -62,6 +62,13 @@ class PriceTest extends \PHPUnit_Framework_TestCase */ protected $groupManagement; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + protected function setUp() { $this->ruleFactoryMock = $this->getMock( @@ -90,6 +97,16 @@ protected function setUp() false ); $scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); $objectManagerHelper = new ObjectManagerHelper($this); $this->model = $objectManagerHelper->getObject( @@ -104,7 +121,8 @@ protected function setUp() 'groupManagement' => $this->groupManagement, 'tierPriceFactory' => $tpFactory, 'config' => $scopeConfig, - 'catalogData' => $this->catalogHelperMock + 'catalogData' => $this->catalogHelperMock, + 'serializer' => $this->serializer ] ); } @@ -201,7 +219,7 @@ public function testGetTotalBundleItemsPriceWithEmptyOptions($value) public function dataProviderWithEmptyOptions() { return [ - ['a:0:{}'], + ['{}'], [''], [null], ]; @@ -244,7 +262,7 @@ public function testGetTotalBundleItemsPriceWithNoItems() $dataObjectMock->expects($this->once()) ->method('getValue') - ->willReturn('a:1:{i:0;s:1:"1";}'); + ->willReturn('{"0":1}'); $productTypeMock->expects($this->once()) ->method('getSelectionsByIds') diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php index da340dbbfadcf..62036a3372444 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php @@ -1562,7 +1562,7 @@ public function testGetSkuWithoutType() $sku = 'sku'; $itemSku = 'item'; $selectionIds = [1, 2, 3]; - $serializeIds = serialize($selectionIds); + $serializeIds = json_encode($selectionIds); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) ->disableOriginalConstructor() @@ -1639,7 +1639,7 @@ public function testGetWeightWithCustomOption() { $weight = 5; $selectionIds = [1, 2, 3]; - $serializeIds = serialize($selectionIds); + $serializeIds = json_encode($selectionIds); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) ->disableOriginalConstructor() @@ -1693,7 +1693,7 @@ public function testGetWeightWithSeveralCustomOption() $weight = 5; $qtyOption = 5; $selectionIds = [1, 2, 3]; - $serializeIds = serialize($selectionIds); + $serializeIds = json_encode($selectionIds); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->setMethods(['__wakeup', 'getData', 'hasCustomOptions', 'getCustomOption']) ->disableOriginalConstructor() @@ -1768,7 +1768,7 @@ public function testIsVirtualWithoutCustomOption() public function testIsVirtual() { $selectionIds = [1, 2, 3]; - $serializeIds = serialize($selectionIds); + $serializeIds = json_encode($selectionIds); $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) ->disableOriginalConstructor() diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php index f9570a91eb170..e1c40ec3fbc0c 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php @@ -625,6 +625,7 @@ function ($value) { public function testCheckProductBuyState() { $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['getSkipCheckRequiredOption', 'getCustomOption']) ->disableOriginalConstructor() ->getMock(); $optionMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Option::class) @@ -639,6 +640,13 @@ public function testCheckProductBuyState() $optionMock->expects($this->once()) ->method('getValue') ->willReturn(json_encode(['super_attribute' => ['test_key' => 'test_value', 'empty_key' => '']])); + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); $this->assertEquals($this->_model, $this->_model->checkProductBuyState($productMock)); } @@ -651,6 +659,7 @@ public function testCheckProductBuyState() public function testCheckProductBuyStateException() { $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->setMethods(['getSkipCheckRequiredOption', 'getCustomOption']) ->disableOriginalConstructor() ->getMock(); $optionMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Option::class) @@ -663,6 +672,13 @@ public function testCheckProductBuyStateException() ->with('info_buyRequest') ->willReturn($optionMock); $optionMock->expects($this->once())->method('getValue')->willReturn(json_encode([])); + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); $this->_model->checkProductBuyState($productMock); } diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php index d3a9b8914777d..ae8a5625024fc 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php @@ -153,7 +153,6 @@ function ($value) { $this->product->expects($this->any())->method('setLinksExist')->with($this->equalTo(false)); $this->product->expects($this->any())->method('canAffectOptions')->with($this->equalTo(true)); - $eavConfigMock = $this->getMock(\Magento\Eav\Model\Config::class, ['getEntityAttributeCodes'], [], '', false); $eavConfigMock->expects($this->any()) ->method('getEntityAttributeCodes') @@ -182,7 +181,7 @@ function ($value) { 'linkFactory' => $linkFactory, 'eavConfig' => $eavConfigMock, 'typeHandler' => $this->typeHandler, - + 'serializer' => $this->serializerMock ] ); } From 707f676995d73a96d41a237d486cc0f2a28b6355 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Fri, 9 Dec 2016 17:12:44 +0200 Subject: [PATCH 066/132] MAGETWO-61674: Fix seralization in Module Downloadable - codestyle fixes --- .../Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php index 6c8d817a9004a..ae8a5625024fc 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php @@ -153,7 +153,6 @@ function ($value) { $this->product->expects($this->any())->method('setLinksExist')->with($this->equalTo(false)); $this->product->expects($this->any())->method('canAffectOptions')->with($this->equalTo(true)); - $eavConfigMock = $this->getMock(\Magento\Eav\Model\Config::class, ['getEntityAttributeCodes'], [], '', false); $eavConfigMock->expects($this->any()) ->method('getEntityAttributeCodes') From 0ba7890efaccfa8cd7d4ee07dfecd1083effa69f Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Fri, 9 Dec 2016 17:15:33 +0200 Subject: [PATCH 067/132] MAGETWO-61672: Module Catalog and unit tests - Fixed acc Code-style --- app/code/Magento/Catalog/Model/Product/Option/Type/File.php | 2 +- .../Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index 6cac282f295b1..9dddbdf2e9988 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -93,8 +93,8 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param \Magento\Framework\Escaper $escaper * @param array $data * @param Filesystem $filesystem - * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @param SerializerInterface|null $serializer + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php index 48e8f79bd0d72..0f35e113c5414 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php @@ -102,7 +102,6 @@ protected function getFileObject() ); } - public function testGetCustomizedView() { $fileObject = $this->getFileObject(); From 3f3ae655ce4a6258af5ba554ec3a93aea8fcd7f3 Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Fri, 9 Dec 2016 17:46:23 +0200 Subject: [PATCH 068/132] MAGETWO-61672: Module Catalog and unit tests - Remove list line - Add phpDoc for class with Suppress --- .../Test/Unit/Model/Product/Option/Type/FileTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php index 0f35e113c5414..6ebbc2059dbac 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php @@ -11,6 +11,11 @@ use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\Filesystem\DriverPool; +/** + * Class FileTest. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class FileTest extends \PHPUnit_Framework_TestCase { /** @@ -231,4 +236,3 @@ public function testPrepareOptionValueForRequest() $this->assertEquals($resultValue, $fileObject->prepareOptionValueForRequest($optionValue)); } } - From 4b11f703e2a60d8b0514f77a53e528358eea4cd4 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Fri, 9 Dec 2016 10:21:22 -0600 Subject: [PATCH 069/132] MAGETWO-61872: Create FieldDataConverter Adding ability to modify query --- .../Framework/DB/FieldDataConverter.php | 14 ++++++-- .../QueryModifierInterface.php | 22 ++++++++++++ .../DB/Test/Unit/FieldDataConverterTest.php | 36 +++++++++++++++++-- 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 lib/internal/Magento/Framework/DB/FieldDataConverter/QueryModifierInterface.php diff --git a/lib/internal/Magento/Framework/DB/FieldDataConverter.php b/lib/internal/Magento/Framework/DB/FieldDataConverter.php index 55bd6ae0d1805..1cdbc180b476a 100644 --- a/lib/internal/Magento/Framework/DB/FieldDataConverter.php +++ b/lib/internal/Magento/Framework/DB/FieldDataConverter.php @@ -8,6 +8,7 @@ use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Query\Generator; use Magento\Framework\DB\DataConverter\DataConverterInterface; +use Magento\Framework\DB\FieldDataConverter\QueryModifierInterface; /** * Convert field data from one representation to another @@ -45,13 +46,22 @@ public function __construct( * @param string $table * @param string $identifier * @param string $field + * @param QueryModifierInterface|null $queryModifier * @return void */ - public function convert(AdapterInterface $connection, $table, $identifier, $field) - { + public function convert( + AdapterInterface $connection, + $table, + $identifier, + $field, + QueryModifierInterface $queryModifier = null + ) { $select = $connection->select() ->from($table, [$identifier, $field]) ->where($field . ' IS NOT NULL'); + if ($queryModifier) { + $queryModifier->modify($select); + } $iterator = $this->queryGenerator->generate($identifier, $select); foreach ($iterator as $selectByRange) { $rows = $connection->fetchAll($selectByRange); diff --git a/lib/internal/Magento/Framework/DB/FieldDataConverter/QueryModifierInterface.php b/lib/internal/Magento/Framework/DB/FieldDataConverter/QueryModifierInterface.php new file mode 100644 index 0000000000000..80b9326f89f4b --- /dev/null +++ b/lib/internal/Magento/Framework/DB/FieldDataConverter/QueryModifierInterface.php @@ -0,0 +1,22 @@ +queryGeneratorMock = $this->getMock(Generator::class, [], [], '', false); $this->dataConverterMock = $this->getMock(DataConverterInterface::class); $this->selectMock = $this->getMock(Select::class, [], [], '', false); + $this->queryModifierMock = $this->getMock(QueryModifierInterface::class); $this->fieldDataConverter = $objectManager->getObject( FieldDataConverter::class, [ @@ -55,7 +62,12 @@ protected function setUp() ); } - public function testConvert() + /** + * @param boolean $useQueryModifier + * @param int $numQueryModifierCalls + * @dataProvider convertDataProvider + */ + public function testConvert($useQueryModifier, $numQueryModifierCalls) { $table = 'table'; $identifier = 'id'; @@ -83,6 +95,9 @@ public function testConvert() ->method('where') ->with($where) ->willReturnSelf(); + $this->queryModifierMock->expects($this->exactly($numQueryModifierCalls)) + ->method('modify') + ->with($this->selectMock); $this->queryGeneratorMock->expects($this->once()) ->method('generate') ->with($identifier, $this->selectMock) @@ -102,6 +117,23 @@ public function testConvert() [$field => $convertedValue], [$identifier . ' = ?' => $rows[0][$identifier]] ); - $this->fieldDataConverter->convert($this->connectionMock, $table, $identifier, $field); + $this->fieldDataConverter->convert( + $this->connectionMock, + $table, + $identifier, + $field, + $useQueryModifier ? $this->queryModifierMock : null + ); + } + + /** + * @return array + */ + public function convertDataProvider() + { + return [ + [false, 0], + [true, 1] + ]; } } From fe9cb5c19f2145d9ad385469d41b7cce1f188c4b Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Fri, 9 Dec 2016 18:22:58 +0200 Subject: [PATCH 070/132] MAGETWO-61647: Detailed investigation for info_buyrequest field and extension points for its modifications - stabilization bamboo builds --- .../Magento/Bundle/Model/Product/Price.php | 1 - .../Catalog/Product/ConfigurationTest.php | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Product/Price.php b/app/code/Magento/Bundle/Model/Product/Price.php index a1e845f68f795..08fe2e2d1cadf 100644 --- a/app/code/Magento/Bundle/Model/Product/Price.php +++ b/app/code/Magento/Bundle/Model/Product/Price.php @@ -164,7 +164,6 @@ protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product { $customOption = $product->getCustomOption('bundle_selection_ids'); if ($customOption) { - $r = json_decode('{"0":1}', true); $selectionIds = $this->serializer->unserialize($customOption->getValue()); if (!empty($selectionIds) && is_array($selectionIds)) { return $selectionIds; diff --git a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php index aaffa90fa0d2f..17f0dbbf9559f 100644 --- a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php @@ -27,6 +27,11 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $item; + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + protected function setUp() { $this->pricingHelper = $this->getMock( @@ -48,6 +53,15 @@ protected function setUp() \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface::class, ['getQty', 'getProduct', 'getOptionByCode', 'getFileDownloadParams'] ); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->getMockForAbstractClass(); + + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + }); $this->helper = (new ObjectManager($this))->getObject( \Magento\Bundle\Helper\Catalog\Product\Configuration::class, @@ -55,6 +69,7 @@ protected function setUp() 'pricingHelper' => $this->pricingHelper, 'productConfiguration' => $this->productConfiguration, 'escaper' => $this->escaper, + 'serializer' => $this->serializer ] ); } @@ -239,7 +254,9 @@ public function testGetOptions() $itemOption->expects($this->once())->method('getValue')->will($this->returnValue($optionIds)); $typeInstance->expects($this->once())->method('getOptionsByIds')->with(unserialize($optionIds), $product) ->will($this->returnValue($collection)); - $typeInstance->expects($this->once())->method('getSelectionsByIds')->with(unserialize($selectionIds), $product) + $typeInstance->expects($this->once()) + ->method('getSelectionsByIds') + ->with(json_decode($selectionIds, true), $product) ->will($this->returnValue($collection2)); $product->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstance)); $product->expects($this->any())->method('getCustomOption')->with('selection_qty_' . $selectionId) From 654791d389bbfc1b29b48d45245a456f3892723a Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Fri, 9 Dec 2016 19:15:30 +0200 Subject: [PATCH 071/132] MAGETWO-61647: Detailed investigation for info_buyrequest field and extension points for its modifications - fixed code style --- .../Test/Unit/Helper/Catalog/Product/ConfigurationTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php index 17f0dbbf9559f..15b4e9449160a 100644 --- a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php @@ -61,7 +61,8 @@ protected function setUp() ->willReturnCallback( function ($value) { return json_decode($value, true); - }); + } + ); $this->helper = (new ObjectManager($this))->getObject( \Magento\Bundle\Helper\Catalog\Product\Configuration::class, From cf992d22afd8dbd62687d6f9bacbb5ccd9087de7 Mon Sep 17 00:00:00 2001 From: Andrey Konosov Date: Fri, 9 Dec 2016 19:37:05 +0200 Subject: [PATCH 072/132] MAGETWO-61655: Magento/Sales/Model/Order/ShipmentFactory.php and unit tests - Fixed static tests --- .../Adminhtml/Sales/Order/View/Items/Renderer.php | 10 +++++++++- .../Model/Sales/Order/Pdf/Items/AbstractItems.php | 4 +++- .../Adminhtml/Sales/Order/View/Items/RendererTest.php | 1 - .../Model/Sales/Order/Pdf/Items/AbstractItemsTest.php | 1 - 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php index ffd850556a99e..5e22c4be6a139 100644 --- a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php @@ -43,7 +43,15 @@ public function __construct( $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(SerializerInterface::class); - parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $messageHelper, $checkoutHelper, $data); + parent::__construct( + $context, + $stockRegistry, + $stockConfiguration, + $registry, + $messageHelper, + $checkoutHelper, + $data + ); } /** diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index 4ae62543e212f..0f5b583052952 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -10,6 +10,7 @@ /** * Sales Order Pdf Items renderer + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ abstract class AbstractItems extends \Magento\Sales\Model\Order\Pdf\Items\AbstractItems { @@ -44,7 +45,8 @@ public function __construct( ) { $this->serializer = $serializer; - parent::__construct($context, + parent::__construct( + $context, $registry, $taxData, $filesystem, diff --git a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php index 1c0c7df002ece..8d3ff4bd1ba9e 100644 --- a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php @@ -145,7 +145,6 @@ public function isChildCalculatedWithItemDataProvider() ]; } - public function testGetSelectionAttributes() { $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue([])); diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php index 5ee7479e78491..3d39e29143489 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php @@ -244,7 +244,6 @@ public function getBundleOptionsDataProvider() ]; } - public function testGetSelectionAttributes() { $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue([])); From fcf3e48bc4edd67c8c23a0505ce36176df2e6cb5 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Mon, 12 Dec 2016 11:42:50 +0200 Subject: [PATCH 073/132] MAGETWO-61670: Fix serialization in module Sales (other) and unit tests - codestyle and code mess fixes --- .../Download/DownloadCustomOption.php | 30 ++++++++++--------- .../Download/DownloadCustomOptionTest.php | 1 + 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php index 1e034228fec1d..a73c46a494584 100644 --- a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php +++ b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php @@ -1,19 +1,19 @@ resultForwardFactory = $resultForwardFactory; $this->download = $download; $this->unserialize = $unserialize; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get( + \Magento\Framework\Serialize\SerializerInterface::class + ); } /** diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php index cbb4adce24a02..192cefec7d13e 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Sales\Test\Unit\Controller\Download; + use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\Unserialize\Unserialize; From 0072bcbafe59262dbb8ad74ec799b3908d0d2257 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Mon, 12 Dec 2016 13:20:53 +0200 Subject: [PATCH 074/132] MAGETWO-61670: Fix serialization in module Sales (other) and unit tests --- .../Sales/Controller/Download/DownloadCustomOption.php | 1 + .../static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php index a73c46a494584..edee3051f55f0 100644 --- a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php +++ b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php @@ -3,6 +3,7 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Sales\Controller\Download; use Magento\Framework\App\ObjectManager; diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php index ec670e2f2ea24..6de630bd0a6d7 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php @@ -196,10 +196,10 @@ function ($file) { */ protected function _testObsoleteClasses($content) { + /* avoid collision between obsolete class name and valid namespace */ + $content = preg_replace('/namespace[^;]+;/', '', $content); foreach (self::$_classes as $row) { list($class, , $replacement) = $row; - /* avoid collision between obsolete class name and valid namespace */ - $content = preg_replace('/namespace[^;]+;/', '', $content); $this->_assertNotRegExp( '/[^a-z\d_]' . preg_quote($class, '/') . '[^a-z\d_\\\\]/iS', $content, From 4ef3e21703a4708f22d35983b426304603df34fc Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Mon, 12 Dec 2016 13:43:11 +0200 Subject: [PATCH 075/132] MAGETWO-61670: Fix serialization in module Sales (other) and unit tests --- .../static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php index 6de630bd0a6d7..2c3ee9649dc3a 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php @@ -196,8 +196,9 @@ function ($file) { */ protected function _testObsoleteClasses($content) { - /* avoid collision between obsolete class name and valid namespace */ + /* avoid collision between obsolete class name and valid namespace and package tag */ $content = preg_replace('/namespace[^;]+;/', '', $content); + $content = preg_replace('/\@package\s[a-zA-Z0-9\\\_]+/', '', $content); foreach (self::$_classes as $row) { list($class, , $replacement) = $row; $this->_assertNotRegExp( From b2984b358988b81df198c9a6990a5ad3697a5b77 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Mon, 12 Dec 2016 15:18:06 +0200 Subject: [PATCH 076/132] MAGETWO-61683: Remove uses of serialize and unserialize in Module Tax --- .../Magento/Quote/Model/Quote/Address.php | 17 ++++-- .../Test/Unit/Model/Quote/AddressTest.php | 31 +++++++++- app/code/Magento/Tax/Helper/Data.php | 15 ++++- .../Model/Quote/GrandTotalDetailsPlugin.php | 15 ++++- .../Tax/Model/Sales/Total/Quote/Tax.php | 14 ++++- .../Magento/Tax/Test/Unit/Helper/DataTest.php | 29 +++++++-- .../Quote/GrandTotalDetailsPluginTest.php | 25 +++++++- .../Unit/Model/Sales/Total/Quote/TaxTest.php | 60 +++++++++++++++---- 8 files changed, 178 insertions(+), 28 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Address.php b/app/code/Magento/Quote/Model/Quote/Address.php index f1764da5e555b..f4a350d39ebcd 100644 --- a/app/code/Magento/Quote/Model/Quote/Address.php +++ b/app/code/Magento/Quote/Model/Quote/Address.php @@ -8,7 +8,8 @@ use Magento\Customer\Api\AddressMetadataInterface; use Magento\Customer\Api\Data\AddressInterfaceFactory; use Magento\Customer\Api\Data\RegionInterfaceFactory; -use Magento\Quote\Api\Data\AddressInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; /** * Sales Quote address model @@ -233,6 +234,11 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements */ protected $totalsReader; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -266,6 +272,7 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data + * @param SerializerInterface $serializer * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -301,7 +308,8 @@ public function __construct( \Magento\Quote\Model\Quote\TotalsReader $totalsReader, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + SerializerInterface $serializer = null ) { $this->_scopeConfig = $scopeConfig; $this->_addressItemFactory = $addressItemFactory; @@ -320,6 +328,7 @@ public function __construct( $this->attributeList = $attributeList; $this->totalsCollector = $totalsCollector; $this->totalsReader = $totalsReader; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct( $context, $registry, @@ -1143,7 +1152,7 @@ public function validateMinimumAmount() */ public function getAppliedTaxes() { - return unserialize($this->getData('applied_taxes')); + return $this->serializer->unserialize($this->getData('applied_taxes')); } /** @@ -1154,7 +1163,7 @@ public function getAppliedTaxes() */ public function setAppliedTaxes($data) { - return $this->setData('applied_taxes', serialize($data)); + return $this->setData('applied_taxes', $this->serializer->serialize($data)); } /******************************* Start Total Collector Interface *******************************************/ diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php index 7a8ccb232ba06..4d6644ac33b4f 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php @@ -32,16 +32,23 @@ class AddressTest extends \PHPUnit_Framework_TestCase */ private $scopeConfig; + /** + * @var \Magento\Framework\Serialize\SerializerInterface | \PHPUnit_Framework_MockObject_MockObject + */ + protected $serializer; + protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->scopeConfig = $this->getMock(\Magento\Framework\App\Config::class, [], [], '', false); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class, [], [], '', false); $this->address = $objectManager->getObject( \Magento\Quote\Model\Quote\Address::class, [ - 'scopeConfig' => $this->scopeConfig + 'scopeConfig' => $this->scopeConfig, + 'serializer' => $this->serializer ] ); $this->quote = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); @@ -134,4 +141,26 @@ public function testValidateMiniumumAmountNegative() $this->assertTrue($this->address->validateMinimumAmount()); } + + public function testGetAppliedTaxes() + { + $result = ['result']; + $this->serializer->expects($this->once()) + ->method('unserialize') + ->willReturn($result); + + $this->assertEquals($result, $this->address->getAppliedTaxes()); + } + + public function testSetAppliedTaxes() + { + $data = ['data']; + + $this->serializer->expects($this->once()) + ->method('serialize') + ->with($data) + ->willReturn('result'); + + $this->assertInstanceOf(\Magento\Quote\Model\Quote\Address::class, $this->address->setAppliedTaxes($data)); + } } diff --git a/app/code/Magento/Tax/Helper/Data.php b/app/code/Magento/Tax/Helper/Data.php index 3f9d9648b4bb4..67ef0e9b71db1 100644 --- a/app/code/Magento/Tax/Helper/Data.php +++ b/app/code/Magento/Tax/Helper/Data.php @@ -12,13 +12,14 @@ use Magento\Store\Model\Store; use Magento\Customer\Model\Address; use Magento\Tax\Model\Config; -use Magento\Tax\Api\TaxCalculationInterface; use Magento\Customer\Model\Session as CustomerSession; use Magento\Tax\Api\OrderTaxManagementInterface; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Creditmemo; use Magento\Tax\Api\Data\OrderTaxDetailsItemInterface; use Magento\Sales\Model\EntityInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; /** * Catalog data helper @@ -95,6 +96,11 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper */ protected $priceCurrency; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\Json\Helper\Data $jsonHelper @@ -106,6 +112,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper * @param \Magento\Catalog\Helper\Data $catalogHelper * @param OrderTaxManagementInterface $orderTaxManagement * @param PriceCurrencyInterface $priceCurrency + * @param SerializerInterface $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -118,7 +125,8 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Catalog\Helper\Data $catalogHelper, OrderTaxManagementInterface $orderTaxManagement, - PriceCurrencyInterface $priceCurrency + PriceCurrencyInterface $priceCurrency, + SerializerInterface $serializer = null ) { parent::__construct($context); $this->priceCurrency = $priceCurrency; @@ -130,6 +138,7 @@ public function __construct( $this->_localeResolver = $localeResolver; $this->catalogHelper = $catalogHelper; $this->orderTaxManagement = $orderTaxManagement; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** @@ -738,7 +747,7 @@ protected function calculateTaxForItems(EntityInterface $order, EntityInterface $taxableItemType = $itemTaxDetail->getType(); $ratio = $itemRatio; if ($item->getTaxRatio()) { - $taxRatio = unserialize($item->getTaxRatio()); + $taxRatio = $fullInfo = $this->serializer->unserialize($item->getTaxRatio()); if (isset($taxRatio[$taxableItemType])) { $ratio = $taxRatio[$taxableItemType]; } diff --git a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php index a727beef10b06..b24204cad4efc 100644 --- a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php +++ b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php @@ -6,6 +6,8 @@ namespace Magento\Tax\Model\Quote; use Magento\Quote\Api\Data\TotalSegmentExtensionFactory; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; class GrandTotalDetailsPlugin { @@ -34,23 +36,32 @@ class GrandTotalDetailsPlugin */ protected $code; + /** + * @var SerializerInterface + */ + private $serializer; + /** * @param \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory * @param \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory * @param TotalSegmentExtensionFactory $totalSegmentExtensionFactory * @param \Magento\Tax\Model\Config $taxConfig + * @param SerializerInterface $serializer */ public function __construct( \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory, \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory, TotalSegmentExtensionFactory $totalSegmentExtensionFactory, - \Magento\Tax\Model\Config $taxConfig + \Magento\Tax\Model\Config $taxConfig, + SerializerInterface $serializer = null + ) { $this->detailsFactory = $detailsFactory; $this->ratesFactory = $ratesFactory; $this->totalSegmentExtensionFactory = $totalSegmentExtensionFactory; $this->taxConfig = $taxConfig; $this->code = 'tax'; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** @@ -97,7 +108,7 @@ public function afterProcess( $finalData = []; $fullInfo = $taxes['full_info']; if (is_string($fullInfo)) { - $fullInfo = unserialize($fullInfo); + $fullInfo = $this->serializer->unserialize($fullInfo); } foreach ($fullInfo as $info) { if ((array_key_exists('hidden', $info) && $info['hidden']) diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php index da3b86958eb4b..f8999419dccec 100755 --- a/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php +++ b/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php @@ -11,6 +11,8 @@ use Magento\Tax\Api\Data\TaxClassKeyInterface; use Magento\Tax\Model\Calculation; use Magento\Quote\Api\Data\ShippingAssignmentInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; /** * Tax totals calculation model @@ -46,6 +48,11 @@ class Tax extends CommonTaxCollector */ protected $_discountTaxCompensationes = []; + /** + * @var SerializerInterface + */ + private $serializer; + /** * Class constructor * @@ -57,6 +64,7 @@ class Tax extends CommonTaxCollector * @param CustomerAddressFactory $customerAddressFactory * @param CustomerAddressRegionFactory $customerAddressRegionFactory * @param \Magento\Tax\Helper\Data $taxData + * @param SerializerInterface $serializer */ public function __construct( \Magento\Tax\Model\Config $taxConfig, @@ -66,10 +74,12 @@ public function __construct( \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory, CustomerAddressFactory $customerAddressFactory, CustomerAddressRegionFactory $customerAddressRegionFactory, - \Magento\Tax\Helper\Data $taxData + \Magento\Tax\Helper\Data $taxData, + SerializerInterface $serializer = null ) { $this->setCode('tax'); $this->_taxData = $taxData; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct( $taxConfig, $taxCalculationService, @@ -300,7 +310,7 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu $store = $quote->getStore(); $applied = $total->getAppliedTaxes(); if (is_string($applied)) { - $applied = unserialize($applied); + $applied = $this->serializer->unserialize($applied); } $amount = $total->getTaxAmount(); if ($amount === null) { diff --git a/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php b/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php index ea716a0c474b0..90da21367f8ad 100644 --- a/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php +++ b/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php @@ -29,6 +29,9 @@ class DataTest extends \PHPUnit_Framework_TestCase /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $taxConfigMock; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $serializer; + protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -42,13 +45,31 @@ protected function setUp() $this->taxConfigMock = $this->getMockBuilder(\Magento\Tax\Model\Config::class) ->disableOriginalConstructor() ->getMock(); + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->serializer->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); - $this->helper = $objectManager->getObject( + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + $this->helper = $objectManager->getObject( \Magento\Tax\Helper\Data::class, [ 'orderTaxManagement' => $this->orderTaxManagementMock, 'priceCurrency' => $this->priceCurrencyMock, - 'taxConfig' => $this->taxConfigMock + 'taxConfig' => $this->taxConfigMock, + 'serializer' => $this->serializer ] ); } @@ -147,7 +168,7 @@ protected function mapOrderTaxItemDetail($inputArray) $appliedTaxesData = $orderTaxDetailsItemData['applied_taxes']; $appliedTaxesMocks = []; foreach ($appliedTaxesData as $appliedTaxData) { - $appliedTaxesMock = $this->getMockBuilder( + $appliedTaxesMock = $this->getMockBuilder( \Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxInterface::class) ->getMock(); $appliedTaxesMock->expects($this->any()) @@ -363,7 +384,7 @@ public function getCalculatedTaxesForOrderItemsDataProvider() ), 'tax_amount' => 5.0, //half of weee tax is invoiced - 'tax_ratio' => serialize(['weee' => 0.5]), + 'tax_ratio' => json_encode(['weee' => 0.5]), ] ), ], diff --git a/app/code/Magento/Tax/Test/Unit/Model/Quote/GrandTotalDetailsPluginTest.php b/app/code/Magento/Tax/Test/Unit/Model/Quote/GrandTotalDetailsPluginTest.php index 693b0d437afc4..21a2209390d85 100644 --- a/app/code/Magento/Tax/Test/Unit/Model/Quote/GrandTotalDetailsPluginTest.php +++ b/app/code/Magento/Tax/Test/Unit/Model/Quote/GrandTotalDetailsPluginTest.php @@ -75,6 +75,26 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $serializer->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); + + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + $this->objectManagerHelper = new ObjectManager($this); $this->model = $this->objectManagerHelper->getObject( \Magento\Tax\Model\Quote\GrandTotalDetailsPlugin::class, @@ -83,6 +103,7 @@ protected function setUp() 'ratesFactory' => $this->ratesFactoryMock, 'detailsFactory' => $this->detailsFactoryMock, 'taxConfig' => $this->taxConfigMock, + 'serializer' => $serializer ] ); } @@ -166,12 +187,12 @@ public function testAfterProcess() ); $taxTotalData = [ - 'full_info' => [ + 'full_info' => json_encode([ [ 'amount' => $taxAmount, 'rates' => [$taxRate], ], - ], + ]), ]; $taxTotalMock = $this->setupTaxTotal($taxTotalData); $addressTotals = [ diff --git a/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php b/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php index a74b5fe13ec78..2f5850f336124 100644 --- a/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php +++ b/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php @@ -38,7 +38,7 @@ class TaxTest extends \PHPUnit_Framework_TestCase * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function testCollect($itemData, $appliedRatesData, $taxDetailsData, $quoteDetailsData, - $addressData, $verifyData + $addressData, $verifyData ) { $this->markTestIncomplete('Source code is not testable. Need to be refactored before unit testing'); $shippingAssignmentMock = $this->getMock(\Magento\Quote\Api\Data\ShippingAssignmentInterface::class); @@ -247,8 +247,8 @@ public function testCollect($itemData, $appliedRatesData, $taxDetailsData, $quot $address = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address::class) ->disableOriginalConstructor() ->setMethods(['getAssociatedTaxables', - 'getQuote', 'getBillingAddress', 'getRegionId', - '__wakeup', 'getCustomAttributesCodes']) + 'getQuote', 'getBillingAddress', 'getRegionId', + '__wakeup', 'getCustomAttributesCodes']) ->getMock(); $item ->expects($this->any()) @@ -613,13 +613,36 @@ public function testFetch($appliedTaxesData, $addressData) ->will($this->returnValue(true)); $objectManager = new ObjectManager($this); + + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $serializer->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); + + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); + /** @var \Magento\Tax\Model\Sales\Total\Quote\Tax $taxTotalsCalcModel */ $taxTotalsCalcModel = $objectManager->getObject( \Magento\Tax\Model\Sales\Total\Quote\Tax::class, - ['taxConfig' => $taxConfig] + [ + 'taxConfig' => $taxConfig, + 'serializer' => $serializer + ] ); - $appliedTaxes = unserialize($appliedTaxesData); $store = $this->getMockBuilder(\Magento\Store\Model\Store::class) ->disableOriginalConstructor() ->setMethods(['convertPrice', '__wakeup']) @@ -641,7 +664,7 @@ public function testFetch($appliedTaxesData, $addressData) $totalsMock ->expects($this->once()) ->method('getAppliedTaxes') - ->will($this->returnValue($appliedTaxes)); + ->will($this->returnValue($appliedTaxesData)); $totalsMock ->expects($this->any()) ->method('getGrandTotal') @@ -675,6 +698,7 @@ public function testFetch($appliedTaxesData, $addressData) $totalsArray = $taxTotalsCalcModel->fetch($quote, $totalsMock); $this->assertArrayHasKey('value', $totalsArray[0]); $this->assertEquals($taxAmount, $totalsArray[0]['value']); + $this->assertEquals(json_decode($appliedTaxesData, true), $totalsArray[0]['full_info']); } /** @@ -685,10 +709,26 @@ public function testFetch($appliedTaxesData, $addressData) */ public function dataProviderFetchArray() { - $appliedDataString = 'a:1:{s:7:"TX Rate";a:9:{s:6:"amount";d:80;s:11:"base_amount";d:80;s:7:"percent";'; - $appliedDataString .= 'd:10;s:2:"id";s:7:"TX Rate";s:5:"rates";a:1:{i:0;a:3:{s:7:"percent";d:10;s:4:"code";'; - $appliedDataString .= 's:7:"TX Rate";s:5:"title";s:7:"TX Rate";}}s:7:"item_id";s:1:"1";s:9:"item_type";'; - $appliedDataString .= 's:7:"product";s:18:"associated_item_id";N;s:7:"process";i:0;}}'; + $appliedDataString = [ + 'amount' => 80.0, + 'base_amount' => 80.0, + 'percent' => 10.0, + 'id' => 'TX Rate', + 'rates' => [ + 0 => [ + 'percent' => 10.0, + 'code' => 'TX Rate', + 'title' => 'TX Rate', + ], + ], + 'item_id' => '1', + 'item_type' => 'product', + 'associated_item_id' => NULL, + 'process' => 0, + ]; + + $appliedDataString = json_encode($appliedDataString); + $data = [ 'default' => [ 'appliedTaxesData' => $appliedDataString, From 65d0c88e457c31b929824a2dca071b6dcca3ba37 Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Mon, 12 Dec 2016 15:29:34 +0200 Subject: [PATCH 077/132] MAGETWO-61682: Module Quote and unit tests --- .../Quote/Model/Quote/Address/Total.php | 22 ++++++- .../Quote/Model/Quote/Item/Compare.php | 20 ++++++- .../Magento/Quote/Model/Quote/Payment.php | 15 ++++- .../Unit/Model/Quote/Address/TotalTest.php | 19 +++++- .../Unit/Model/Quote/Item/CompareTest.php | 35 +++++++---- .../Test/Unit/Model/Quote/PaymentTest.php | 60 ++++++++++++++++++- 6 files changed, 152 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Address/Total.php b/app/code/Magento/Quote/Model/Quote/Address/Total.php index aeaa71fb8daad..f764c9df6a3cb 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/Total.php +++ b/app/code/Magento/Quote/Model/Quote/Address/Total.php @@ -17,6 +17,26 @@ class Total extends \Magento\Framework\DataObject */ protected $baseTotalAmounts; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + + /** + * @param array $data [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer [optional] + */ + public function __construct( + array $data = [], + \Magento\Framework\Serialize\SerializerInterface $serializer = null + ) { + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + parent::__construct($data); + } + /** * Set total amount value * @@ -159,7 +179,7 @@ public function getFullInfo() { $fullInfo = $this->getData('full_info'); if (is_string($fullInfo)) { - $fullInfo = unserialize($fullInfo); + $fullInfo = $this->serializer->unserialize($fullInfo); } return $fullInfo; } diff --git a/app/code/Magento/Quote/Model/Quote/Item/Compare.php b/app/code/Magento/Quote/Model/Quote/Item/Compare.php index 10bb712025462..ab4303b7e9771 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Compare.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Compare.php @@ -12,6 +12,22 @@ */ class Compare { + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + + /** + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer [optional] + */ + public function __construct(\Magento\Framework\Serialize\SerializerInterface $serializer = null) + { + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); + } + /** * Returns option values adopted to compare * @@ -20,8 +36,8 @@ class Compare */ protected function getOptionValues($value) { - if (is_string($value) && is_array(@unserialize($value))) { - $value = @unserialize($value); + if (is_string($value) && is_array($this->serializer->unserialize($value))) { + $value = $this->serializer->unserialize($value); unset($value['qty'], $value['uenc']); $value = array_filter($value, function ($optionValue) { return !empty($optionValue); diff --git a/app/code/Magento/Quote/Model/Quote/Payment.php b/app/code/Magento/Quote/Model/Quote/Payment.php index 612802ccd279d..7c8080b180996 100644 --- a/app/code/Magento/Quote/Model/Quote/Payment.php +++ b/app/code/Magento/Quote/Model/Quote/Payment.php @@ -65,6 +65,13 @@ class Payment extends \Magento\Payment\Model\Info implements PaymentInterface */ private $additionalChecks; + /** + * Serializer interface instance. + * + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -77,6 +84,7 @@ class Payment extends \Magento\Payment\Model\Info implements PaymentInterface * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * @param array $additionalChecks + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer [optional] * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -90,10 +98,13 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - array $additionalChecks = [] + array $additionalChecks = [], + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->methodSpecificationFactory = $methodSpecificationFactory; $this->additionalChecks = $additionalChecks; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\SerializerInterface::class); parent::__construct( $context, $registry, @@ -326,7 +337,7 @@ public function getAdditionalData() { $additionalDataValue = $this->getData(self::KEY_ADDITIONAL_DATA); if (is_string($additionalDataValue)) { - $additionalData = @unserialize($additionalDataValue); + $additionalData = $this->serializer->unserialize($additionalDataValue); if (is_array($additionalData)) { return $additionalData; } diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php index efe6a81ce9242..3e79ffb5dfa81 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php @@ -15,7 +15,21 @@ class TotalTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->model = new \Magento\Quote\Model\Quote\Address\Total(); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback(function ($value) { + return json_decode($value, true); + }); + + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->model = $objectManagerHelper->getObject( + \Magento\Quote\Model\Quote\Address\Total::class, + [ + 'serializer' => $serializer + ]); } /** @@ -171,6 +185,7 @@ public function testGetBaseTotalAmountAbsent() /** * Verify handling of serialized, non-serialized input into and out of getFullInfo() * + * @covers \Magento\Quote\Model\Quote\Address\Total::getFullInfo() * @param $input * @param $expected * @dataProvider getFullInfoDataProvider @@ -187,7 +202,7 @@ public function testGetFullInfo($input, $expected) public function getFullInfoDataProvider() { $myArray = ['team' => 'kiwis']; - $serializedInput = serialize($myArray); + $serializedInput = json_encode($myArray); return [ 'simple array' => [ diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php index f8b72e4df6b7c..b362aae263800 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php @@ -38,29 +38,42 @@ class CompareTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->itemMock = $this->getMock( + $this->itemMock = $this->getMock( \Magento\Quote\Model\Quote\Item::class, ['__wakeup', 'getProductId', 'getOptions'], [], '', false ); - $this->comparedMock = $this->getMock( + $this->comparedMock = $this->getMock( \Magento\Quote\Model\Quote\Item::class, ['__wakeup', 'getProductId', 'getOptions'], [], '', false ); - $this->optionMock = $this->getMock( + $this->optionMock = $this->getMock( \Magento\Quote\Model\Quote\Item\Option::class, ['__wakeup', 'getCode', 'getValue'], [], '', false ); - - $this->helper = new \Magento\Quote\Model\Quote\Item\Compare(); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback(function ($value) { + return json_decode($value, true); + }); + + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->helper = $objectManagerHelper->getObject( + \Magento\Quote\Model\Quote\Item\Compare::class, + [ + 'serializer' => $serializer + ]); } /** @@ -112,7 +125,7 @@ public function testCompareProductWithDifferentOptions() ->will($this->returnValue([ $this->getOptionMock('option-1', 1), $this->getOptionMock('option-2', 'option-value'), - $this->getOptionMock('option-3', serialize([ + $this->getOptionMock('option-3', json_encode([ 'value' => 'value-1', 'qty' => 2, ]) @@ -123,7 +136,7 @@ public function testCompareProductWithDifferentOptions() ->will($this->returnValue([ $this->getOptionMock('option-4', 1), $this->getOptionMock('option-2', 'option-value'), - $this->getOptionMock('option-3', serialize([ + $this->getOptionMock('option-3', json_encode([ 'value' => 'value-1', 'qty' => 2, ])), @@ -148,7 +161,7 @@ public function testCompareItemWithComparedWithoutOption() ->will($this->returnValue([ $this->getOptionMock('option-1', 1), $this->getOptionMock('option-2', 'option-value'), - $this->getOptionMock('option-3', serialize([ + $this->getOptionMock('option-3', json_encode([ 'value' => 'value-1', 'qty' => 2, ]) @@ -176,7 +189,7 @@ public function testCompareItemWithoutOptionWithCompared() ->will($this->returnValue([ $this->getOptionMock('option-1', 1), $this->getOptionMock('option-2', 'option-value'), - $this->getOptionMock('option-3', serialize([ + $this->getOptionMock('option-3', json_encode([ 'value' => 'value-1', 'qty' => 2, ]) @@ -201,13 +214,13 @@ public function testCompareWithEmptyValues() ->will($this->returnValue(1)); $this->itemMock->expects($this->once())->method('getOptions')->willReturn([ - $this->getOptionMock('option-1', serialize([ + $this->getOptionMock('option-1', json_encode([ 'non-empty-option' => 'test', 'empty_option' => '' ])) ]); $this->comparedMock->expects($this->once())->method('getOptions')->willReturn([ - $this->getOptionMock('option-1', serialize([ + $this->getOptionMock('option-1', json_encode([ 'non-empty-option' => 'test' ])) ]); diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/PaymentTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/PaymentTest.php index cc23683cb481b..8473f62f88366 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/PaymentTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/PaymentTest.php @@ -41,12 +41,21 @@ protected function setUp() )->disableOriginalConstructor() ->getMock(); $this->eventManager = $this->getMock(ManagerInterface::class); + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback(function ($value) { + return json_decode($value, true); + }); $this->model = $objectManager->getObject( Payment::class, [ 'methodSpecificationFactory' => $this->specificationFactory, - 'eventDispatcher' => $this->eventManager + 'eventDispatcher' => $this->eventManager, + 'serializer' => $serializer ] ); } @@ -144,6 +153,55 @@ public function testImportDataPositiveCheck( $this->model->importData($data); } + /** + * @covers \Magento\Quote\Model\Quote\Payment::getAdditionalData() + * @dataProvider getAdditionalDataDataProvider + * @param mixed $expected + * @param mixed $additionalData + */ + public function testGetAdditionalData($expected, $additionalData) + { + $this->model->setData(Payment::KEY_ADDITIONAL_DATA, $additionalData); + $this->assertSame($expected, $this->model->getAdditionalData()); + } + + /** + * @return array + */ + public function getAdditionalDataDataProvider() + { + return [ + // Variation #1 + [ + //$expected + ['field1' => 'value1', 'field2' => 'value2'], + //$additionalData + ['field1' => 'value1', 'field2' => 'value2'], + ], + // Variation #2 + [ + //$expected + ['field1' => 'value1', 'field2' => 'value2'], + //$additionalData + '{"field1":"value1","field2":"value2"}', + ], + // Variation #3 + [ + //$expected + null, + //$additionalData + '{"field1":field2":"value2"}', + ], + // Variation #4 + [ + //$expected + null, + //$additionalData + 123, + ], + ]; + } + /** * @return array */ From a1849ef1f81c1cfa0aa1c672ee2c2134f5d83877 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Mon, 12 Dec 2016 15:45:46 +0200 Subject: [PATCH 078/132] MAGETWO-61683: Remove uses of serialize and unserialize in Module Tax --- app/code/Magento/Tax/Helper/Data.php | 2 +- app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php | 1 - app/code/Magento/Tax/Test/Unit/Helper/DataTest.php | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Tax/Helper/Data.php b/app/code/Magento/Tax/Helper/Data.php index 67ef0e9b71db1..5659275fc2896 100644 --- a/app/code/Magento/Tax/Helper/Data.php +++ b/app/code/Magento/Tax/Helper/Data.php @@ -747,7 +747,7 @@ protected function calculateTaxForItems(EntityInterface $order, EntityInterface $taxableItemType = $itemTaxDetail->getType(); $ratio = $itemRatio; if ($item->getTaxRatio()) { - $taxRatio = $fullInfo = $this->serializer->unserialize($item->getTaxRatio()); + $taxRatio = $this->serializer->unserialize($item->getTaxRatio()); if (isset($taxRatio[$taxableItemType])) { $ratio = $taxRatio[$taxableItemType]; } diff --git a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php index b24204cad4efc..96c3b3ec00d09 100644 --- a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php +++ b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php @@ -54,7 +54,6 @@ public function __construct( TotalSegmentExtensionFactory $totalSegmentExtensionFactory, \Magento\Tax\Model\Config $taxConfig, SerializerInterface $serializer = null - ) { $this->detailsFactory = $detailsFactory; $this->ratesFactory = $ratesFactory; diff --git a/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php b/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php index 90da21367f8ad..a5536960f5d19 100644 --- a/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php +++ b/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php @@ -12,6 +12,8 @@ /** * Class DataTest + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class DataTest extends \PHPUnit_Framework_TestCase { From 95d691c1f7ec0febee53c080d8038b2c4e28c14a Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Mon, 12 Dec 2016 19:25:36 +0200 Subject: [PATCH 079/132] MAGETWO-61682: Module Quote and unit tests - Refactored serializer - Added Integration test --- .../Magento/Quote/Model/Quote/Address.php | 15 +++++++++--- .../Magento/Quote/Model/Quote/AddressTest.php | 24 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Address.php b/app/code/Magento/Quote/Model/Quote/Address.php index f1764da5e555b..4137cffa5e890 100644 --- a/app/code/Magento/Quote/Model/Quote/Address.php +++ b/app/code/Magento/Quote/Model/Quote/Address.php @@ -9,7 +9,8 @@ use Magento\Customer\Api\Data\AddressInterfaceFactory; use Magento\Customer\Api\Data\RegionInterfaceFactory; use Magento\Quote\Api\Data\AddressInterface; - +use \Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; /** * Sales Quote address model * @@ -233,6 +234,11 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements */ protected $totalsReader; + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ + protected $serializer; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -265,6 +271,7 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements * @param \Magento\Quote\Model\Quote\TotalsReader $totalsReader * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer [optional] * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -301,6 +308,7 @@ public function __construct( \Magento\Quote\Model\Quote\TotalsReader $totalsReader, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + SerializerInterface $serializer = null, array $data = [] ) { $this->_scopeConfig = $scopeConfig; @@ -320,6 +328,7 @@ public function __construct( $this->attributeList = $attributeList; $this->totalsCollector = $totalsCollector; $this->totalsReader = $totalsReader; + $this->serializer = $serializer ? $serializer : ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct( $context, $registry, @@ -1143,7 +1152,7 @@ public function validateMinimumAmount() */ public function getAppliedTaxes() { - return unserialize($this->getData('applied_taxes')); + return $this->serializer->unserialize($this->getData('applied_taxes')); } /** @@ -1154,7 +1163,7 @@ public function getAppliedTaxes() */ public function setAppliedTaxes($data) { - return $this->setData('applied_taxes', serialize($data)); + return $this->setData('applied_taxes', $this->serializer->serialize($data)); } /******************************* Start Total Collector Interface *******************************************/ diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/AddressTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/AddressTest.php index d71f5c2df7e10..ad7b87407608c 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/AddressTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/Quote/AddressTest.php @@ -285,4 +285,28 @@ public function testPopulateBeforeSaveData() $this->assertEquals($this->_quote->getId(), $this->_address->getQuoteId()); $this->assertEquals($customerAddressId, $this->_address->getCustomerAddressId()); } + + /** + * Tests + * + * @covers \Magento\Quote\Model\Quote\Address::setAppliedTaxes() + * @covers \Magento\Quote\Model\Quote\Address::getAppliedTaxes() + * @dataProvider dataProvider + * @param $taxes + * @param $expected + */ + public function testAppliedTaxes($taxes, $expected) + { + $this->_address->setAppliedTaxes($taxes); + + $this->assertSame($expected, $this->_address->getAppliedTaxes()); + } + + public function dataProvider() + { + return [ + ['test', 'test'], + [[123, true], [123, true]] + ]; + } } From 04ea09b20709094de0acf833009f35f6de7a4841 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Mon, 12 Dec 2016 19:42:44 +0200 Subject: [PATCH 080/132] MAGETWO-61683: Remove uses of serialize and unserialize in Module Tax --- .../Test/Unit/Model/Quote/AddressTest.php | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php index 4d6644ac33b4f..817be7eb9c090 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php @@ -142,25 +142,22 @@ public function testValidateMiniumumAmountNegative() $this->assertTrue($this->address->validateMinimumAmount()); } - public function testGetAppliedTaxes() - { - $result = ['result']; - $this->serializer->expects($this->once()) - ->method('unserialize') - ->willReturn($result); - - $this->assertEquals($result, $this->address->getAppliedTaxes()); - } - - public function testSetAppliedTaxes() + public function testSetAndGetAppliedTaxes() { $data = ['data']; + $result = json_encode($data); $this->serializer->expects($this->once()) ->method('serialize') ->with($data) - ->willReturn('result'); + ->willReturn($result); + + $this->serializer->expects($this->once()) + ->method('unserialize') + ->with($result) + ->willReturn($data); $this->assertInstanceOf(\Magento\Quote\Model\Quote\Address::class, $this->address->setAppliedTaxes($data)); + $this->assertEquals($data, $this->address->getAppliedTaxes()); } } From 67c05709f4b5e4e2589f261b15b8e2874bd16208 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 12 Dec 2016 13:52:51 -0600 Subject: [PATCH 081/132] MAGETWO-61872: Create FieldDataConverter Moving QueryModifierInterface under Magento\Framework\DB\Select namespace --- lib/internal/Magento/Framework/DB/FieldDataConverter.php | 2 +- .../{FieldDataConverter => Select}/QueryModifierInterface.php | 2 +- .../Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename lib/internal/Magento/Framework/DB/{FieldDataConverter => Select}/QueryModifierInterface.php (87%) diff --git a/lib/internal/Magento/Framework/DB/FieldDataConverter.php b/lib/internal/Magento/Framework/DB/FieldDataConverter.php index 1cdbc180b476a..39dcd3238c9b8 100644 --- a/lib/internal/Magento/Framework/DB/FieldDataConverter.php +++ b/lib/internal/Magento/Framework/DB/FieldDataConverter.php @@ -8,7 +8,7 @@ use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Query\Generator; use Magento\Framework\DB\DataConverter\DataConverterInterface; -use Magento\Framework\DB\FieldDataConverter\QueryModifierInterface; +use Magento\Framework\DB\Select\QueryModifierInterface; /** * Convert field data from one representation to another diff --git a/lib/internal/Magento/Framework/DB/FieldDataConverter/QueryModifierInterface.php b/lib/internal/Magento/Framework/DB/Select/QueryModifierInterface.php similarity index 87% rename from lib/internal/Magento/Framework/DB/FieldDataConverter/QueryModifierInterface.php rename to lib/internal/Magento/Framework/DB/Select/QueryModifierInterface.php index 80b9326f89f4b..5cf676e088c44 100644 --- a/lib/internal/Magento/Framework/DB/FieldDataConverter/QueryModifierInterface.php +++ b/lib/internal/Magento/Framework/DB/Select/QueryModifierInterface.php @@ -3,7 +3,7 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\DB\FieldDataConverter; +namespace Magento\Framework\DB\Select; use Magento\Framework\DB\Select; diff --git a/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php index 62aa83ca41c5d..f0005de98dcda 100644 --- a/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php +++ b/lib/internal/Magento/Framework/DB/Test/Unit/FieldDataConverterTest.php @@ -11,7 +11,7 @@ use Magento\Framework\DB\FieldDataConverter; use Magento\Framework\DB\DataConverter\DataConverterInterface; use Magento\Framework\DB\Select; -use Magento\Framework\DB\FieldDataConverter\QueryModifierInterface; +use Magento\Framework\DB\Select\QueryModifierInterface; class FieldDataConverterTest extends \PHPUnit_Framework_TestCase { From 67a31e752bfa938342bce60f3c07033818912471 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 12 Dec 2016 19:34:04 -0600 Subject: [PATCH 082/132] MAGETWO-62133: Create QueryModifier to select only options of type file and info_buyRequest Creating QueryModifier --- app/code/Magento/Quote/Setup/UpgradeData.php | 59 ++++++++++++++++++- .../Framework/DB/Select/InQueryModifier.php | 34 +++++++++++ .../DB/Select/QueryModifierFactory.php | 42 +++++++++++++ 3 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 lib/internal/Magento/Framework/DB/Select/InQueryModifier.php create mode 100644 lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 19873352c33be..6e34728803667 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -8,9 +8,11 @@ use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Eav\Model\Config; use Magento\Framework\DB\FieldDataConverterFactory; use Magento\Framework\DB\DataConverter\SerializedToJson; +use Magento\Framework\DB\Select\QueryModifierFactory; +use Magento\Framework\DB\Select\InQueryModifier; +use Magento\Framework\DB\Query\Generator; class UpgradeData implements UpgradeDataInterface { @@ -19,15 +21,31 @@ class UpgradeData implements UpgradeDataInterface */ private $fieldDataConverterFactory; + /** + * @var QueryModifierFactory + */ + private $queryModifierFactory; + + /** + * @var Generator + */ + private $queryGenerator; + /** * Constructor * * @param FieldDataConverterFactory $fieldDataConverterFactory + * @param QueryModifierFactory $queryModifierFactory + * @param Generator $generator */ public function __construct( - FieldDataConverterFactory $fieldDataConverterFactory + FieldDataConverterFactory $fieldDataConverterFactory, + QueryModifierFactory $queryModifierFactory, + Generator $queryGenerator ) { $this->fieldDataConverterFactory = $fieldDataConverterFactory; + $this->queryModifierFactory = $queryModifierFactory; + $this->queryGenerator = $queryGenerator; } /** @@ -56,5 +74,42 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) 'payment_id', 'additional_information' ); + $queryModifier = $this->queryModifierFactory->create( + InQueryModifier::class, + [ + 'code' => [ + 'parameters', + 'info_buyRequest', + 'bundle_option_ids', + 'bundle_selection_attributes', + ] + ] + ); + $fieldDataConverter->convert( + $setup->getConnection(), + $setup->getTable('quote_item_option'), + 'option_id', + 'value', + $queryModifier + ); + $select = $setup->getConnection() + ->select() + ->from( + $setup->getTable('catalog_product_option'), + ['CONCAT("option_", option_id)'] + ) + ->where('type = ?', 'file'); + $iterator = $this->queryGenerator->generate('option_id', $select); + foreach ($iterator as $selectByRange) { + $codes = $setup->getConnection()->fetchCol($selectByRange); + $queryModifier = $this->queryModifierFactory->create(InQueryModifier::class, ['code' => $codes]); + $fieldDataConverter->convert( + $setup->getConnection(), + $setup->getTable('quote_item_option'), + 'option_id', + 'value', + $queryModifier + ); + } } } diff --git a/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php b/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php new file mode 100644 index 0000000000000..bb1b3d35346c6 --- /dev/null +++ b/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php @@ -0,0 +1,34 @@ +values = $values; + } + + /** + * {@inheritdoc} + */ + public function modify(Select $select) + { + foreach ($this->values as $field => $values) { + $select->where($field . ' IN (?)', $values); + } + } +} diff --git a/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php b/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php new file mode 100644 index 0000000000000..fe2933627d51f --- /dev/null +++ b/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php @@ -0,0 +1,42 @@ +objectManager = $objectManager; + } + + /** + * Create instance of QueryModifierInterface + * + * @param string $queryModifierClassName + * @param array $data + * @return QueryModifierInterface + */ + public function create($queryModifierClassName, $data) + { + return $this->objectManager->create($queryModifierClassName, $data); + } +} From 8358e49e4e612600b1611d216ffcaf3feb778340 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 12 Dec 2016 21:58:47 -0600 Subject: [PATCH 083/132] MAGETWO-62133: Create QueryModifier to select only options of type file and info_buyRequest Creating QueryModifier --- app/code/Magento/Quote/Setup/UpgradeData.php | 29 ++++++++++++++----- .../Framework/DB/Select/InQueryModifier.php | 10 +++++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 6e34728803667..96b05d2e2447d 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -77,11 +77,13 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) $queryModifier = $this->queryModifierFactory->create( InQueryModifier::class, [ - 'code' => [ - 'parameters', - 'info_buyRequest', - 'bundle_option_ids', - 'bundle_selection_attributes', + 'values' => [ + 'code' => [ + 'parameters', + 'info_buyRequest', + 'bundle_option_ids', + 'bundle_selection_attributes', + ] ] ] ); @@ -96,13 +98,26 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) ->select() ->from( $setup->getTable('catalog_product_option'), - ['CONCAT("option_", option_id)'] + ['option_id'] ) ->where('type = ?', 'file'); $iterator = $this->queryGenerator->generate('option_id', $select); foreach ($iterator as $selectByRange) { $codes = $setup->getConnection()->fetchCol($selectByRange); - $queryModifier = $this->queryModifierFactory->create(InQueryModifier::class, ['code' => $codes]); + $codes = array_map( + function ($id) { + return 'option_' . $id; + }, + $codes + ); + $queryModifier = $this->queryModifierFactory->create( + InQueryModifier::class, + [ + 'values' => [ + 'code' => $codes + ] + ] + ); $fieldDataConverter->convert( $setup->getConnection(), $setup->getTable('quote_item_option'), diff --git a/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php b/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php index bb1b3d35346c6..cf20152d8043e 100644 --- a/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php +++ b/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php @@ -17,8 +17,14 @@ class InQueryModifier implements QueryModifierInterface */ private $values; - public function __constructor($values) - { + /** + * Constructor + * + * @param array $values + */ + public function __construct( + $values = [] + ) { $this->values = $values; } From 1891b7927e17cfe3ae397878d87b793ed9b6b90b Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Tue, 13 Dec 2016 08:35:30 +0200 Subject: [PATCH 084/132] MAGETWO-61682: Module Quote and unit tests --- .../Quote/Test/Unit/Model/Quote/Address/TotalTest.php | 3 ++- .../Magento/Checkout/_files/quote_with_payment_saved.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php index 3e79ffb5dfa81..9bade22caf894 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php @@ -29,7 +29,8 @@ protected function setUp() \Magento\Quote\Model\Quote\Address\Total::class, [ 'serializer' => $serializer - ]); + ] + ); } /** diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php index c3dbc4baaf3f7..e480f982bd6b1 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php @@ -6,6 +6,9 @@ require 'quote_with_address.php'; +/** @var \Magento\Framework\Serialize\SerializerInterface $serializer */ +$serializer = $objectManager->create(\Magento\Framework\Serialize\SerializerInterface::class); + $quote->setReservedOrderId( 'test_order_1_with_payment' ); @@ -22,7 +25,7 @@ ->setCcType('visa') ->setCcExpYear(2014) ->setCcExpMonth(1) - ->setAdditionalData(serialize($paymentDetails)); + ->setAdditionalData($serializer->serialize($paymentDetails)); $quote->collectTotals()->save(); From 8966e104987ffccb818db8204fd5df53ef9ed1c6 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Tue, 13 Dec 2016 15:08:00 +0200 Subject: [PATCH 085/132] MAGETWO-61658: Create upgrade scripts for sales-related data - Wishlist module upgrade --- .../Magento/Wishlist/Setup/UpgradeData.php | 124 ++++++++++++++++++ app/code/Magento/Wishlist/etc/module.xml | 2 +- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Wishlist/Setup/UpgradeData.php diff --git a/app/code/Magento/Wishlist/Setup/UpgradeData.php b/app/code/Magento/Wishlist/Setup/UpgradeData.php new file mode 100644 index 0000000000000..1f45b801b245a --- /dev/null +++ b/app/code/Magento/Wishlist/Setup/UpgradeData.php @@ -0,0 +1,124 @@ +fieldDataConverterFactory = $fieldDataConverterFactory; + $this->queryModifierFactory = $queryModifierFactory; + $this->queryGenerator = $queryGenerator; + } + + /** + * {@inheritdoc} + */ + public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + { + if (version_compare($context->getVersion(), '2.0.1', '<')) { + $this->upgradeToVersionTwoZeroOne($setup); + } + } + + /** + * Upgrade to version 2.0.1, convert data for `value` field in `wishlist_item_option table` + * from php-serialized to JSON format + * + * @param ModuleDataSetupInterface $setup + * @return void + */ + private function upgradeToVersionTwoZeroOne(ModuleDataSetupInterface $setup) + { + $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class); + $queryModifier = $this->queryModifierFactory->create( + InQueryModifier::class, + [ + 'values' => [ + 'code' => [ + 'parameters', + 'info_buyRequest', + 'bundle_option_ids', + 'bundle_selection_attributes', + ] + ] + ] + ); + $fieldDataConverter->convert( + $setup->getConnection(), + $setup->getTable('wishlist_item_option'), + 'option_id', + 'value', + $queryModifier + ); + $select = $setup->getConnection() + ->select() + ->from( + $setup->getTable('catalog_product_option'), + ['option_id'] + ) + ->where('type = ?', 'file'); + $iterator = $this->queryGenerator->generate('option_id', $select); + foreach ($iterator as $selectByRange) { + $codes = $setup->getConnection()->fetchCol($selectByRange); + $codes = array_map( + function ($id) { + return 'option_' . $id; + }, + $codes + ); + $queryModifier = $this->queryModifierFactory->create( + InQueryModifier::class, + [ + 'values' => [ + 'code' => $codes + ] + ] + ); + $fieldDataConverter->convert( + $setup->getConnection(), + $setup->getTable('wishlist_item_option'), + 'option_id', + 'value', + $queryModifier + ); + } + } +} diff --git a/app/code/Magento/Wishlist/etc/module.xml b/app/code/Magento/Wishlist/etc/module.xml index a8b0fa21edee3..5643b2dc285a9 100644 --- a/app/code/Magento/Wishlist/etc/module.xml +++ b/app/code/Magento/Wishlist/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + From cf67b73d46df933ede6ff7d28ef63204a59b7d8c Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 14 Dec 2016 12:13:50 +0200 Subject: [PATCH 086/132] MAGETWO-62134: Create data converter that can process nested serialized data --- .../ProductOptions/SerializedToJson.php | 39 +++++++++++++ app/code/Magento/Sales/Setup/UpgradeData.php | 11 +++- .../ProductOptions/SerializedToJsonTest.php | 58 +++++++++++++++++++ .../DB/DataConverter/SerializedToJson.php | 4 +- 4 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php create mode 100644 app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php diff --git a/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php b/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php new file mode 100644 index 0000000000000..b4ceccad248f8 --- /dev/null +++ b/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php @@ -0,0 +1,39 @@ +serialize->unserialize($value); + if (isset($valueUnserialized['options'])) { + foreach ($valueUnserialized['options'] as $key => $option) { + if ($option['option_type'] === 'file') { + $valueUnserialized['options'][$key]['option_value'] = $this->json->serialize( + $this->serialize->unserialize( + $option['option_value'] + ) + ); + } + } + } + return $this->json->serialize($valueUnserialized); + } +} diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index a4a38f5cdcbab..5f97f74f4a967 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -5,6 +5,8 @@ */ namespace Magento\Sales\Setup; +use Magento\Sales\Model\Order\Item\Converter\ProductOptions\SerializedToJson; + class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface { /** @@ -120,15 +122,18 @@ private function upgradeToTwoZeroOne(\Magento\Sales\Setup\SalesSetup $setup) */ private function upgradeToVersionTwoZeroFive(\Magento\Framework\Setup\ModuleDataSetupInterface $setup) { - $fieldDataConverter = $this->fieldDataConverterFactory->create( - \Magento\Framework\DB\DataConverter\SerializedToJson::class + $productOptionsDataConverter = $this->fieldDataConverterFactory->create( + SerializedToJson::class ); - $fieldDataConverter->convert( + $productOptionsDataConverter->convert( $setup->getConnection(), $setup->getTable('sales_order_item'), 'item_id', 'product_options' ); + $fieldDataConverter = $this->fieldDataConverterFactory->create( + \Magento\Framework\DB\DataConverter\SerializedToJson::class + ); $fieldDataConverter->convert( $setup->getConnection(), $setup->getTable('sales_shipment'), diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php new file mode 100644 index 0000000000000..c7a04748580dd --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php @@ -0,0 +1,58 @@ +model = new SerializedToJson(new Serialize(), new Json()); + } + + /** + * @param string $serialized + * @param string $expectedJson + * + * @dataProvider convertDataProvider + */ + public function testConvert($serialized, $expectedJson) + { + $this->assertEquals($expectedJson, $this->model->convert($serialized)); + } + + /** + * Data provider for convert method test + * + * Slashes in PHP string are implicitly escaped so they MUST be escaped manually to correspond real expected data + * + * @return array + */ + public function convertDataProvider() + { + // @codingStandardsIgnoreStart + return [ + 'dataset_1' => [ + 'serialized' => 'a:6:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:52:"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,";s:7:"product";s:1:"1";s:28:"selected_configurable_option";s:0:"";s:15:"related_product";s:0:"";s:7:"options";a:3:{i:1;s:4:"test";i:3;s:1:"2";i:2;a:9:{s:4:"type";s:10:"image/jpeg";s:5:"title";s:7:"476.jpg";s:10:"quote_path";s:61:"custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:10:"order_path";s:61:"custom_options/order/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:8:"fullpath";s:89:"C:/www/magento/ce/pub/media/custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:4:"size";s:6:"122340";s:5:"width";i:666;s:6:"height";i:940;s:10:"secret_key";s:20:"bc61f16f0cc3a8c5abd7";}}s:3:"qty";s:1:"1";}s:7:"options";a:3:{i:0;a:7:{s:5:"label";s:11:"testoption1";s:5:"value";s:4:"test";s:11:"print_value";s:4:"test";s:9:"option_id";s:1:"1";s:11:"option_type";s:5:"field";s:12:"option_value";s:4:"test";s:11:"custom_view";b:0;}i:1;a:7:{s:5:"label";s:11:"testoption2";s:5:"value";s:132:"476.jpg 666 x 940 px.";s:11:"print_value";s:21:"476.jpg 666 x 940 px.";s:9:"option_id";s:1:"2";s:11:"option_type";s:4:"file";s:12:"option_value";s:600:"a:10:{s:4:"type";s:10:"image/jpeg";s:5:"title";s:7:"476.jpg";s:10:"quote_path";s:61:"custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:10:"order_path";s:61:"custom_options/order/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:8:"fullpath";s:89:"C:/www/magento/ce/pub/media/custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:4:"size";s:6:"122340";s:5:"width";i:666;s:6:"height";i:940;s:10:"secret_key";s:20:"bc61f16f0cc3a8c5abd7";s:3:"url";a:2:{s:5:"route";s:35:"sales/download/downloadCustomOption";s:6:"params";a:2:{s:2:"id";s:1:"9";s:3:"key";s:20:"bc61f16f0cc3a8c5abd7";}}}";s:11:"custom_view";b:1;}i:2;a:7:{s:5:"label";s:8:"testopt3";s:5:"value";s:3:"222";s:11:"print_value";s:3:"222";s:9:"option_id";s:1:"3";s:11:"option_type";s:9:"drop_down";s:12:"option_value";s:1:"2";s:11:"custom_view";b:0;}}s:17:"giftcard_lifetime";N;s:22:"giftcard_is_redeemable";i:0;s:23:"giftcard_email_template";N;s:13:"giftcard_type";N;}', + 'expectedJson' => '{"info_buyRequest":{"uenc":"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,","product":"1","selected_configurable_option":"","related_product":"","options":{"1":"test","3":"2","2":{"type":"image\/jpeg","title":"476.jpg","quote_path":"custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","order_path":"custom_options\/order\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","fullpath":"C:\/www\/magento\/ce\/pub\/media\/custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","size":"122340","width":666,"height":940,"secret_key":"bc61f16f0cc3a8c5abd7"}},"qty":"1"},"options":[{"label":"testoption1","value":"test","print_value":"test","option_id":"1","option_type":"field","option_value":"test","custom_view":false},{"label":"testoption2","value":"476.jpg<\/a> 666 x 940 px.","print_value":"476.jpg 666 x 940 px.","option_id":"2","option_type":"file","option_value":"{\"type\":\"image\\\\\/jpeg\",\"title\":\"476.jpg\",\"quote_path\":\"custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"order_path\":\"custom_options\\\\\/order\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"fullpath\":\"C:\\\\\/www\\\\\/magento\\\\\/ce\\\\\/pub\\\\\/media\\\\\/custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"size\":\"122340\",\"width\":666,\"height\":940,\"secret_key\":\"bc61f16f0cc3a8c5abd7\",\"url\":{\"route\":\"sales\\\\\/download\\\\\/downloadCustomOption\",\"params\":{\"id\":\"9\",\"key\":\"bc61f16f0cc3a8c5abd7\"}}}","custom_view":true},{"label":"testopt3","value":"222","print_value":"222","option_id":"3","option_type":"drop_down","option_value":"2","custom_view":false}],"giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":null}', + ], + ]; + // @codingStandardsIgnoreEnd + } +} diff --git a/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php b/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php index ae675784021d4..361701d961e10 100644 --- a/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php +++ b/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php @@ -16,12 +16,12 @@ class SerializedToJson implements DataConverterInterface /** * @var Serialize */ - private $serialize; + protected $serialize; /** * @var Json */ - private $json; + protected $json; /** * Constructor From 88e2404b691aded5aed06184204d172773e7d4af Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 14 Dec 2016 12:18:50 +0200 Subject: [PATCH 087/132] MAGETWO-61655: Magento/Sales/Model/Order/ShipmentFactory.php and unit tests - fixed bundle type --- app/code/Magento/Bundle/Model/Product/Type.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index 5e9a452c85060..c1e8295e0a870 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -146,13 +146,6 @@ class Type extends \Magento\Catalog\Model\Product\Type\AbstractType */ protected $_stockState; - /** - * Serializer - * - * @var SerializerInterface - */ - private $serializer; - /** * @param \Magento\Catalog\Model\Product\Option $catalogProductOption * @param \Magento\Eav\Model\Config $eavConfig @@ -215,7 +208,6 @@ public function __construct( $this->priceCurrency = $priceCurrency; $this->_stockRegistry = $stockRegistry; $this->_stockState = $stockState; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); parent::__construct( $catalogProductOption, From 6ee34caaebb95a82753a2e6fe8a11154ed5de8e7 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 14 Dec 2016 12:42:56 +0200 Subject: [PATCH 088/132] MAGETWO-62134: Create data converter that can process nested serialized data --- .../Item/Converter/ProductOptions/SerializedToJson.php | 7 +++++++ .../Item/Converter/ProductOptions/SerializedToJsonTest.php | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php b/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php index b4ceccad248f8..d92d7e15fac8f 100644 --- a/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php +++ b/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php @@ -34,6 +34,13 @@ public function convert($value) } } } + if (isset($valueUnserialized['bundle_selection_attributes'])) { + $valueUnserialized['bundle_selection_attributes'] = $this->json->serialize( + $this->serialize->unserialize( + $valueUnserialized['bundle_selection_attributes'] + ) + ); + } return $this->json->serialize($valueUnserialized); } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php index c7a04748580dd..04e1f0c6064d2 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php @@ -52,6 +52,10 @@ public function convertDataProvider() 'serialized' => 'a:6:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:52:"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,";s:7:"product";s:1:"1";s:28:"selected_configurable_option";s:0:"";s:15:"related_product";s:0:"";s:7:"options";a:3:{i:1;s:4:"test";i:3;s:1:"2";i:2;a:9:{s:4:"type";s:10:"image/jpeg";s:5:"title";s:7:"476.jpg";s:10:"quote_path";s:61:"custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:10:"order_path";s:61:"custom_options/order/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:8:"fullpath";s:89:"C:/www/magento/ce/pub/media/custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:4:"size";s:6:"122340";s:5:"width";i:666;s:6:"height";i:940;s:10:"secret_key";s:20:"bc61f16f0cc3a8c5abd7";}}s:3:"qty";s:1:"1";}s:7:"options";a:3:{i:0;a:7:{s:5:"label";s:11:"testoption1";s:5:"value";s:4:"test";s:11:"print_value";s:4:"test";s:9:"option_id";s:1:"1";s:11:"option_type";s:5:"field";s:12:"option_value";s:4:"test";s:11:"custom_view";b:0;}i:1;a:7:{s:5:"label";s:11:"testoption2";s:5:"value";s:132:"476.jpg 666 x 940 px.";s:11:"print_value";s:21:"476.jpg 666 x 940 px.";s:9:"option_id";s:1:"2";s:11:"option_type";s:4:"file";s:12:"option_value";s:600:"a:10:{s:4:"type";s:10:"image/jpeg";s:5:"title";s:7:"476.jpg";s:10:"quote_path";s:61:"custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:10:"order_path";s:61:"custom_options/order/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:8:"fullpath";s:89:"C:/www/magento/ce/pub/media/custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:4:"size";s:6:"122340";s:5:"width";i:666;s:6:"height";i:940;s:10:"secret_key";s:20:"bc61f16f0cc3a8c5abd7";s:3:"url";a:2:{s:5:"route";s:35:"sales/download/downloadCustomOption";s:6:"params";a:2:{s:2:"id";s:1:"9";s:3:"key";s:20:"bc61f16f0cc3a8c5abd7";}}}";s:11:"custom_view";b:1;}i:2;a:7:{s:5:"label";s:8:"testopt3";s:5:"value";s:3:"222";s:11:"print_value";s:3:"222";s:9:"option_id";s:1:"3";s:11:"option_type";s:9:"drop_down";s:12:"option_value";s:1:"2";s:11:"custom_view";b:0;}}s:17:"giftcard_lifetime";N;s:22:"giftcard_is_redeemable";i:0;s:23:"giftcard_email_template";N;s:13:"giftcard_type";N;}', 'expectedJson' => '{"info_buyRequest":{"uenc":"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,","product":"1","selected_configurable_option":"","related_product":"","options":{"1":"test","3":"2","2":{"type":"image\/jpeg","title":"476.jpg","quote_path":"custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","order_path":"custom_options\/order\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","fullpath":"C:\/www\/magento\/ce\/pub\/media\/custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","size":"122340","width":666,"height":940,"secret_key":"bc61f16f0cc3a8c5abd7"}},"qty":"1"},"options":[{"label":"testoption1","value":"test","print_value":"test","option_id":"1","option_type":"field","option_value":"test","custom_view":false},{"label":"testoption2","value":"476.jpg<\/a> 666 x 940 px.","print_value":"476.jpg 666 x 940 px.","option_id":"2","option_type":"file","option_value":"{\"type\":\"image\\\\\/jpeg\",\"title\":\"476.jpg\",\"quote_path\":\"custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"order_path\":\"custom_options\\\\\/order\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"fullpath\":\"C:\\\\\/www\\\\\/magento\\\\\/ce\\\\\/pub\\\\\/media\\\\\/custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"size\":\"122340\",\"width\":666,\"height\":940,\"secret_key\":\"bc61f16f0cc3a8c5abd7\",\"url\":{\"route\":\"sales\\\\\/download\\\\\/downloadCustomOption\",\"params\":{\"id\":\"9\",\"key\":\"bc61f16f0cc3a8c5abd7\"}}}","custom_view":true},{"label":"testopt3","value":"222","print_value":"222","option_id":"3","option_type":"drop_down","option_value":"2","custom_view":false}],"giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":null}', ], + 'dataset_2' => [ + 'serialized' => 'a:6:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:36:"aHR0cDovL20yLmxvYy9idW5kbGUuaHRtbA,,";s:7:"product";s:1:"4";s:28:"selected_configurable_option";s:0:"";s:15:"related_product";s:0:"";s:13:"bundle_option";a:2:{i:1;s:1:"1";i:2;s:1:"2";}s:3:"qty";s:1:"3";}s:27:"bundle_selection_attributes";s:97:"a:4:{s:5:"price";d:100;s:3:"qty";d:1;s:12:"option_label";s:8:"option 1";s:9:"option_id";s:1:"1";}";s:17:"giftcard_lifetime";N;s:22:"giftcard_is_redeemable";i:0;s:23:"giftcard_email_template";N;s:13:"giftcard_type";N;}', + 'expectedJson' => '{"info_buyRequest":{"uenc":"aHR0cDovL20yLmxvYy9idW5kbGUuaHRtbA,,","product":"4","selected_configurable_option":"","related_product":"","bundle_option":{"1":"1","2":"2"},"qty":"3"},"bundle_selection_attributes":"{\"price\":100,\"qty\":1,\"option_label\":\"option 1\",\"option_id\":\"1\"}","giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":null}', + ], ]; // @codingStandardsIgnoreEnd } From 3649bd5b2c6f70f9207ffcd1ce9d8e372c25c943 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 14 Dec 2016 16:55:37 +0200 Subject: [PATCH 089/132] MAGETWO-61684: Create data upgrade for quote-related database fields --- app/code/Magento/Quote/Setup/UpgradeData.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 96b05d2e2447d..f0a79ba22b67e 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -74,6 +74,18 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) 'payment_id', 'additional_information' ); + $fieldDataConverter->convert( + $setup->getConnection(), + $setup->getTable('quote_address'), + 'address_id', + 'applied_taxes' + ); + $fieldDataConverter->convert( + $setup->getConnection(), + $setup->getTable('quote_payment'), + 'payment_id', + 'additional_data' + ); $queryModifier = $this->queryModifierFactory->create( InQueryModifier::class, [ From cbd01d1aff9f867c32251c322e6bd0b5383e15e1 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 14 Dec 2016 17:54:48 +0200 Subject: [PATCH 090/132] MAGETWO-62134: Create data converter that can process nested serialized data - Codestyle fix - coupling issue with use statement --- app/code/Magento/Sales/Setup/UpgradeData.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 5f97f74f4a967..56d6463b1d6fb 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -5,8 +5,6 @@ */ namespace Magento\Sales\Setup; -use Magento\Sales\Model\Order\Item\Converter\ProductOptions\SerializedToJson; - class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface { /** @@ -123,7 +121,7 @@ private function upgradeToTwoZeroOne(\Magento\Sales\Setup\SalesSetup $setup) private function upgradeToVersionTwoZeroFive(\Magento\Framework\Setup\ModuleDataSetupInterface $setup) { $productOptionsDataConverter = $this->fieldDataConverterFactory->create( - SerializedToJson::class + \Magento\Sales\Model\Order\Item\Converter\ProductOptions\SerializedToJson::class ); $productOptionsDataConverter->convert( $setup->getConnection(), From dbb7c3a0c6c3b8f38e61516a234ae25ec1f69b74 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 14 Dec 2016 18:09:53 +0200 Subject: [PATCH 091/132] MAGETWO-62134: Create data converter that can process nested serialized data --- app/code/Magento/Sales/Setup/UpgradeData.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 56d6463b1d6fb..7501811573fcb 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -5,6 +5,11 @@ */ namespace Magento\Sales\Setup; +/** + * Class UpgradeData + * @package Magento\Sales\Setup + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface { /** From de31dea556b9f89ea6ad1175f08d0170d6d16e31 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 14 Dec 2016 18:16:49 +0200 Subject: [PATCH 092/132] MAGETWO-62134: Create data converter that can process nested serialized data --- .../Item/Converter/ProductOptions/SerializedToJsonTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php index 04e1f0c6064d2..9c091f1f3b81c 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php @@ -53,8 +53,8 @@ public function convertDataProvider() 'expectedJson' => '{"info_buyRequest":{"uenc":"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,","product":"1","selected_configurable_option":"","related_product":"","options":{"1":"test","3":"2","2":{"type":"image\/jpeg","title":"476.jpg","quote_path":"custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","order_path":"custom_options\/order\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","fullpath":"C:\/www\/magento\/ce\/pub\/media\/custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","size":"122340","width":666,"height":940,"secret_key":"bc61f16f0cc3a8c5abd7"}},"qty":"1"},"options":[{"label":"testoption1","value":"test","print_value":"test","option_id":"1","option_type":"field","option_value":"test","custom_view":false},{"label":"testoption2","value":"476.jpg<\/a> 666 x 940 px.","print_value":"476.jpg 666 x 940 px.","option_id":"2","option_type":"file","option_value":"{\"type\":\"image\\\\\/jpeg\",\"title\":\"476.jpg\",\"quote_path\":\"custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"order_path\":\"custom_options\\\\\/order\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"fullpath\":\"C:\\\\\/www\\\\\/magento\\\\\/ce\\\\\/pub\\\\\/media\\\\\/custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"size\":\"122340\",\"width\":666,\"height\":940,\"secret_key\":\"bc61f16f0cc3a8c5abd7\",\"url\":{\"route\":\"sales\\\\\/download\\\\\/downloadCustomOption\",\"params\":{\"id\":\"9\",\"key\":\"bc61f16f0cc3a8c5abd7\"}}}","custom_view":true},{"label":"testopt3","value":"222","print_value":"222","option_id":"3","option_type":"drop_down","option_value":"2","custom_view":false}],"giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":null}', ], 'dataset_2' => [ - 'serialized' => 'a:6:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:36:"aHR0cDovL20yLmxvYy9idW5kbGUuaHRtbA,,";s:7:"product";s:1:"4";s:28:"selected_configurable_option";s:0:"";s:15:"related_product";s:0:"";s:13:"bundle_option";a:2:{i:1;s:1:"1";i:2;s:1:"2";}s:3:"qty";s:1:"3";}s:27:"bundle_selection_attributes";s:97:"a:4:{s:5:"price";d:100;s:3:"qty";d:1;s:12:"option_label";s:8:"option 1";s:9:"option_id";s:1:"1";}";s:17:"giftcard_lifetime";N;s:22:"giftcard_is_redeemable";i:0;s:23:"giftcard_email_template";N;s:13:"giftcard_type";N;}', - 'expectedJson' => '{"info_buyRequest":{"uenc":"aHR0cDovL20yLmxvYy9idW5kbGUuaHRtbA,,","product":"4","selected_configurable_option":"","related_product":"","bundle_option":{"1":"1","2":"2"},"qty":"3"},"bundle_selection_attributes":"{\"price\":100,\"qty\":1,\"option_label\":\"option 1\",\"option_id\":\"1\"}","giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":null}', + 'serialized' => 'a:2:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:36:"aHR0cDovL20yLmxvYy9idW5kbGUuaHRtbA,,";s:7:"product";s:1:"4";s:28:"selected_configurable_option";s:0:"";s:15:"related_product";s:0:"";s:13:"bundle_option";a:2:{i:1;s:1:"1";i:2;s:1:"2";}s:3:"qty";s:1:"3";}s:27:"bundle_selection_attributes";s:97:"a:4:{s:5:"price";d:100;s:3:"qty";d:1;s:12:"option_label";s:8:"option 1";s:9:"option_id";s:1:"1";}";}', + 'expectedJson' => '{"info_buyRequest":{"uenc":"aHR0cDovL20yLmxvYy9idW5kbGUuaHRtbA,,","product":"4","selected_configurable_option":"","related_product":"","bundle_option":{"1":"1","2":"2"},"qty":"3"},"bundle_selection_attributes":"{\"price\":100,\"qty\":1,\"option_label\":\"option 1\",\"option_id\":\"1\"}"}', ], ]; // @codingStandardsIgnoreEnd From ee2e1e00117cb87686bea5f7e719fcd2a8e90221 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Wed, 14 Dec 2016 18:18:53 +0200 Subject: [PATCH 093/132] MAGETWO-62134: Create data converter that can process nested serialized data --- .../Item/Converter/ProductOptions/SerializedToJsonTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php index 9c091f1f3b81c..3b6f7436c58f9 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php @@ -49,8 +49,8 @@ public function convertDataProvider() // @codingStandardsIgnoreStart return [ 'dataset_1' => [ - 'serialized' => 'a:6:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:52:"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,";s:7:"product";s:1:"1";s:28:"selected_configurable_option";s:0:"";s:15:"related_product";s:0:"";s:7:"options";a:3:{i:1;s:4:"test";i:3;s:1:"2";i:2;a:9:{s:4:"type";s:10:"image/jpeg";s:5:"title";s:7:"476.jpg";s:10:"quote_path";s:61:"custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:10:"order_path";s:61:"custom_options/order/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:8:"fullpath";s:89:"C:/www/magento/ce/pub/media/custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:4:"size";s:6:"122340";s:5:"width";i:666;s:6:"height";i:940;s:10:"secret_key";s:20:"bc61f16f0cc3a8c5abd7";}}s:3:"qty";s:1:"1";}s:7:"options";a:3:{i:0;a:7:{s:5:"label";s:11:"testoption1";s:5:"value";s:4:"test";s:11:"print_value";s:4:"test";s:9:"option_id";s:1:"1";s:11:"option_type";s:5:"field";s:12:"option_value";s:4:"test";s:11:"custom_view";b:0;}i:1;a:7:{s:5:"label";s:11:"testoption2";s:5:"value";s:132:"476.jpg 666 x 940 px.";s:11:"print_value";s:21:"476.jpg 666 x 940 px.";s:9:"option_id";s:1:"2";s:11:"option_type";s:4:"file";s:12:"option_value";s:600:"a:10:{s:4:"type";s:10:"image/jpeg";s:5:"title";s:7:"476.jpg";s:10:"quote_path";s:61:"custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:10:"order_path";s:61:"custom_options/order/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:8:"fullpath";s:89:"C:/www/magento/ce/pub/media/custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:4:"size";s:6:"122340";s:5:"width";i:666;s:6:"height";i:940;s:10:"secret_key";s:20:"bc61f16f0cc3a8c5abd7";s:3:"url";a:2:{s:5:"route";s:35:"sales/download/downloadCustomOption";s:6:"params";a:2:{s:2:"id";s:1:"9";s:3:"key";s:20:"bc61f16f0cc3a8c5abd7";}}}";s:11:"custom_view";b:1;}i:2;a:7:{s:5:"label";s:8:"testopt3";s:5:"value";s:3:"222";s:11:"print_value";s:3:"222";s:9:"option_id";s:1:"3";s:11:"option_type";s:9:"drop_down";s:12:"option_value";s:1:"2";s:11:"custom_view";b:0;}}s:17:"giftcard_lifetime";N;s:22:"giftcard_is_redeemable";i:0;s:23:"giftcard_email_template";N;s:13:"giftcard_type";N;}', - 'expectedJson' => '{"info_buyRequest":{"uenc":"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,","product":"1","selected_configurable_option":"","related_product":"","options":{"1":"test","3":"2","2":{"type":"image\/jpeg","title":"476.jpg","quote_path":"custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","order_path":"custom_options\/order\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","fullpath":"C:\/www\/magento\/ce\/pub\/media\/custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","size":"122340","width":666,"height":940,"secret_key":"bc61f16f0cc3a8c5abd7"}},"qty":"1"},"options":[{"label":"testoption1","value":"test","print_value":"test","option_id":"1","option_type":"field","option_value":"test","custom_view":false},{"label":"testoption2","value":"476.jpg<\/a> 666 x 940 px.","print_value":"476.jpg 666 x 940 px.","option_id":"2","option_type":"file","option_value":"{\"type\":\"image\\\\\/jpeg\",\"title\":\"476.jpg\",\"quote_path\":\"custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"order_path\":\"custom_options\\\\\/order\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"fullpath\":\"C:\\\\\/www\\\\\/magento\\\\\/ce\\\\\/pub\\\\\/media\\\\\/custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"size\":\"122340\",\"width\":666,\"height\":940,\"secret_key\":\"bc61f16f0cc3a8c5abd7\",\"url\":{\"route\":\"sales\\\\\/download\\\\\/downloadCustomOption\",\"params\":{\"id\":\"9\",\"key\":\"bc61f16f0cc3a8c5abd7\"}}}","custom_view":true},{"label":"testopt3","value":"222","print_value":"222","option_id":"3","option_type":"drop_down","option_value":"2","custom_view":false}],"giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":null}', + 'serialized' => 'a:2:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:52:"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,";s:7:"product";s:1:"1";s:28:"selected_configurable_option";s:0:"";s:15:"related_product";s:0:"";s:7:"options";a:3:{i:1;s:4:"test";i:3;s:1:"2";i:2;a:9:{s:4:"type";s:10:"image/jpeg";s:5:"title";s:7:"476.jpg";s:10:"quote_path";s:61:"custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:10:"order_path";s:61:"custom_options/order/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:8:"fullpath";s:89:"C:/www/magento/ce/pub/media/custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:4:"size";s:6:"122340";s:5:"width";i:666;s:6:"height";i:940;s:10:"secret_key";s:20:"bc61f16f0cc3a8c5abd7";}}s:3:"qty";s:1:"1";}s:7:"options";a:3:{i:0;a:7:{s:5:"label";s:11:"testoption1";s:5:"value";s:4:"test";s:11:"print_value";s:4:"test";s:9:"option_id";s:1:"1";s:11:"option_type";s:5:"field";s:12:"option_value";s:4:"test";s:11:"custom_view";b:0;}i:1;a:7:{s:5:"label";s:11:"testoption2";s:5:"value";s:132:"476.jpg 666 x 940 px.";s:11:"print_value";s:21:"476.jpg 666 x 940 px.";s:9:"option_id";s:1:"2";s:11:"option_type";s:4:"file";s:12:"option_value";s:600:"a:10:{s:4:"type";s:10:"image/jpeg";s:5:"title";s:7:"476.jpg";s:10:"quote_path";s:61:"custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:10:"order_path";s:61:"custom_options/order/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:8:"fullpath";s:89:"C:/www/magento/ce/pub/media/custom_options/quote/4/7/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg";s:4:"size";s:6:"122340";s:5:"width";i:666;s:6:"height";i:940;s:10:"secret_key";s:20:"bc61f16f0cc3a8c5abd7";s:3:"url";a:2:{s:5:"route";s:35:"sales/download/downloadCustomOption";s:6:"params";a:2:{s:2:"id";s:1:"9";s:3:"key";s:20:"bc61f16f0cc3a8c5abd7";}}}";s:11:"custom_view";b:1;}i:2;a:7:{s:5:"label";s:8:"testopt3";s:5:"value";s:3:"222";s:11:"print_value";s:3:"222";s:9:"option_id";s:1:"3";s:11:"option_type";s:9:"drop_down";s:12:"option_value";s:1:"2";s:11:"custom_view";b:0;}}}', + 'expectedJson' => '{"info_buyRequest":{"uenc":"aHR0cDovL20yLmxvYy9zaW1wbGUuaHRtbD9vcHRpb25zPWNhcnQ,","product":"1","selected_configurable_option":"","related_product":"","options":{"1":"test","3":"2","2":{"type":"image\/jpeg","title":"476.jpg","quote_path":"custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","order_path":"custom_options\/order\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","fullpath":"C:\/www\/magento\/ce\/pub\/media\/custom_options\/quote\/4\/7\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg","size":"122340","width":666,"height":940,"secret_key":"bc61f16f0cc3a8c5abd7"}},"qty":"1"},"options":[{"label":"testoption1","value":"test","print_value":"test","option_id":"1","option_type":"field","option_value":"test","custom_view":false},{"label":"testoption2","value":"476.jpg<\/a> 666 x 940 px.","print_value":"476.jpg 666 x 940 px.","option_id":"2","option_type":"file","option_value":"{\"type\":\"image\\\\\/jpeg\",\"title\":\"476.jpg\",\"quote_path\":\"custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"order_path\":\"custom_options\\\\\/order\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"fullpath\":\"C:\\\\\/www\\\\\/magento\\\\\/ce\\\\\/pub\\\\\/media\\\\\/custom_options\\\\\/quote\\\\\/4\\\\\/7\\\\\/bc61f16f0cc3a8c5abd7ebbaad4cc139.jpg\",\"size\":\"122340\",\"width\":666,\"height\":940,\"secret_key\":\"bc61f16f0cc3a8c5abd7\",\"url\":{\"route\":\"sales\\\\\/download\\\\\/downloadCustomOption\",\"params\":{\"id\":\"9\",\"key\":\"bc61f16f0cc3a8c5abd7\"}}}","custom_view":true},{"label":"testopt3","value":"222","print_value":"222","option_id":"3","option_type":"drop_down","option_value":"2","custom_view":false}]}', ], 'dataset_2' => [ 'serialized' => 'a:2:{s:15:"info_buyRequest";a:6:{s:4:"uenc";s:36:"aHR0cDovL20yLmxvYy9idW5kbGUuaHRtbA,,";s:7:"product";s:1:"4";s:28:"selected_configurable_option";s:0:"";s:15:"related_product";s:0:"";s:13:"bundle_option";a:2:{i:1;s:1:"1";i:2;s:1:"2";}s:3:"qty";s:1:"3";}s:27:"bundle_selection_attributes";s:97:"a:4:{s:5:"price";d:100;s:3:"qty";d:1;s:12:"option_label";s:8:"option 1";s:9:"option_id";s:1:"1";}";}', From 12bbd96d62d1831f936e041f362a4d9fb8e44bf4 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 11:36:09 +0200 Subject: [PATCH 094/132] MAGETWO-62269: Fix general architecture review notices --- .../Sales/Model/Order/CreditmemoFactory.php | 23 +++++++---- .../SerializedDataConverter.php} | 39 ++++++++++++++++--- app/code/Magento/Sales/Setup/UpgradeData.php | 2 +- .../SerializedDataConverter.php} | 9 ++--- .../DB/DataConverter/SerializedToJson.php | 4 +- 5 files changed, 57 insertions(+), 20 deletions(-) rename app/code/Magento/Sales/{Model/Order/Item/Converter/ProductOptions/SerializedToJson.php => Setup/SerializedDataConverter.php} (63%) rename app/code/Magento/Sales/Test/Unit/{Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php => Setup/SerializedDataConverter.php} (94%) diff --git a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php index e222d3de5bd94..6431190326c3b 100644 --- a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php +++ b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php @@ -23,10 +23,15 @@ class CreditmemoFactory protected $taxConfig; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Unserialize\Unserialize */ protected $unserialize; + /** + * @var \Magento\Framework\Serialize\SerializerInterface + */ + private $serializer; + /** * Factory constructor * @@ -35,10 +40,14 @@ class CreditmemoFactory */ public function __construct( \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory, - \Magento\Tax\Model\Config $taxConfig + \Magento\Tax\Model\Config $taxConfig, + \Magento\Framework\Serialize\SerializerInterface $serializer = null ) { $this->convertor = $convertOrderFactory->create(); $this->taxConfig = $taxConfig; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManage::getInstance()->get( + \Magento\Framework\Serialize\SerializerInterface::class + ); } /** @@ -270,7 +279,7 @@ private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterf $qty = $parentQty; $productOptions = $orderItem->getProductOptions(); if (isset($productOptions['bundle_selection_attributes'])) { - $bundleSelectionAttributes = $this->getSerializer() + $bundleSelectionAttributes = $this->serializer ->unserialize($productOptions['bundle_selection_attributes']); if ($bundleSelectionAttributes) { $qty = $bundleSelectionAttributes['qty'] * $parentQty; @@ -280,16 +289,16 @@ private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterf } /** - * Get instance of Serializer. + * Get Unserialize * - * @return \Magento\Framework\Serialize\SerializerInterface + * @return \Magento\Framework\Unserialize\Unserialize * @deprecated */ - private function getSerializer() + private function getUnserialize() { if (!$this->unserialize) { $this->unserialize = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Unserialize\Unserialize::class); } return $this->unserialize; } diff --git a/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php b/app/code/Magento/Sales/Setup/SerializedDataConverter.php similarity index 63% rename from app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php rename to app/code/Magento/Sales/Setup/SerializedDataConverter.php index d92d7e15fac8f..0b5e9bde5e702 100644 --- a/app/code/Magento/Sales/Model/Order/Item/Converter/ProductOptions/SerializedToJson.php +++ b/app/code/Magento/Sales/Setup/SerializedDataConverter.php @@ -4,18 +4,47 @@ * See COPYING.txt for license details. */ -namespace Magento\Sales\Model\Order\Item\Converter\ProductOptions; +namespace Magento\Sales\Setup; + +use Magento\Framework\Serialize\Serializer\Serialize; +use Magento\Framework\Serialize\Serializer\Json; /** - * Class SerializedToJson + * Class SerializedToJson. + * * @package Magento\Sales\Model\Order\Item\Converter\ProductOptions * - * Serializer used to update nested serialized data in product_options field + * Serializer used to update nested serialized data in product_options field. */ -class SerializedToJson extends \Magento\Framework\DB\DataConverter\SerializedToJson +class SerializedDataConverter implements \Magento\Framework\DB\DataConverter\DataConverterInterface { /** - * Convert from serialized to JSON format + * @var Serialize + */ + private $serialize; + + /** + * @var Json + */ + private $json; + + /** + * SerializedDataConverter constructor. + * + * @param Serialize $serialize + * @param Json $json + */ + public function __construct( + Serialize $serialize, + Json $json + ) + { + $this->serialize = $serialize; + $this->json = $json; + } + + /** + * Convert from serialized to JSON format. * * @param string $value * @return string diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 7501811573fcb..9db92988c6cdf 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -126,7 +126,7 @@ private function upgradeToTwoZeroOne(\Magento\Sales\Setup\SalesSetup $setup) private function upgradeToVersionTwoZeroFive(\Magento\Framework\Setup\ModuleDataSetupInterface $setup) { $productOptionsDataConverter = $this->fieldDataConverterFactory->create( - \Magento\Sales\Model\Order\Item\Converter\ProductOptions\SerializedToJson::class + \Magento\Sales\Setup\SerializedDataConverter::class ); $productOptionsDataConverter->convert( $setup->getConnection(), diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php b/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php similarity index 94% rename from app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php rename to app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php index 3b6f7436c58f9..903d2462ae21d 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Item/Converter/ProductOptions/SerializedToJsonTest.php +++ b/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php @@ -3,27 +3,26 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sales\Test\Unit\Model\Order\Item\Converter\ProductOptions; +namespace Magento\Sales\Test\Unit\Setup; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\Serialize\Serializer\Serialize; -use Magento\Sales\Model\Order\Item\Converter\ProductOptions\SerializedToJson; /** * Unit test for order address repository class. * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class SerializedToJsonTest extends \PHPUnit_Framework_TestCase +class SerializedDataConverterTest extends \PHPUnit_Framework_TestCase { /** - * @var SerializedToJson + * @var \Magento\Sales\Setup\SerializedDataConverter */ protected $model; public function setUp() { - $this->model = new SerializedToJson(new Serialize(), new Json()); + $this->model = new \Magento\Sales\Setup\SerializedDataConverter(new Serialize(), new Json()); } /** diff --git a/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php b/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php index 361701d961e10..ae675784021d4 100644 --- a/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php +++ b/lib/internal/Magento/Framework/DB/DataConverter/SerializedToJson.php @@ -16,12 +16,12 @@ class SerializedToJson implements DataConverterInterface /** * @var Serialize */ - protected $serialize; + private $serialize; /** * @var Json */ - protected $json; + private $json; /** * Constructor From aabfc5c3352ee5f2597487beef148dcbec755041 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 13:12:59 +0200 Subject: [PATCH 095/132] MAGETWO-62269: Fix general architecture review notices --- .../Unit/Setup/SerializedDataConverter.php | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php b/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php index 903d2462ae21d..137a8b5b19baf 100644 --- a/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php +++ b/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php @@ -20,9 +20,41 @@ class SerializedDataConverterTest extends \PHPUnit_Framework_TestCase */ protected $model; + /** + * @var Serialize|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializeMock; + + /** + * @var Json|\PHPUnit_Framework_MockObject_MockObject + */ + private $jsonMock; + public function setUp() { - $this->model = new \Magento\Sales\Setup\SerializedDataConverter(new Serialize(), new Json()); + $this->serializeMock = $this->getMock(Serialize::class, ['unserialize'], [], '', false); + $this->serializeMock->expects($this->any()) + ->method('unserialize') + ->will( + $this->returnCallback( + function ($value) { + return unserialize($value); + } + ) + ); + $this->jsonMock = $this->getMock(Json::class, ['serialize'], [], '', false); + $this->jsonMock->expects($this->any()) + ->method('serialize') + ->will( + $this->returnCallback( + function ($value) { + return json_encode($value); + } + ) + ); + + $this->model = new \Magento\Sales\Setup\SerializedDataConverter($this->serializeMock, $this->jsonMock); + } /** From 08163ab06b4a9df0145a8c3452b3513ce6090ea9 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 14:06:19 +0200 Subject: [PATCH 096/132] MAGETWO-62269: Fix general architecture review notices --- app/code/Magento/Sales/Model/Order/CreditmemoFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php index 6431190326c3b..f3f4055c1cc8d 100644 --- a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php +++ b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php @@ -45,7 +45,7 @@ public function __construct( ) { $this->convertor = $convertOrderFactory->create(); $this->taxConfig = $taxConfig; - $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManage::getInstance()->get( + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get( \Magento\Framework\Serialize\SerializerInterface::class ); } From e08b25f678f8cbf689198e43a8e7e5a63cce6b16 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 14:26:36 +0200 Subject: [PATCH 097/132] MAGETWO-62280: Fix complex product types serialization in order flow --- .../Helper/Catalog/Product/Configuration.php | 5 +++- .../Magento/Bundle/Model/Product/Type.php | 24 +++++++++++++++---- .../Bundle/Pricing/Price/ConfiguredPrice.php | 5 +++- .../Catalog/Product/ConfigurationTest.php | 9 ++++--- app/code/Magento/Quote/Setup/UpgradeData.php | 1 + .../Magento/Wishlist/Setup/UpgradeData.php | 1 + 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php b/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php index f9e08bba754d6..2de5db073ecc5 100644 --- a/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php +++ b/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php @@ -124,7 +124,10 @@ public function getBundleOptions(ItemInterface $item) // get bundle options $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids'); - $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : []; + $bundleOptionsIds = $optionsQuoteItemOption + ? $this->serializer->unserialize($optionsQuoteItemOption->getValue()) + : []; + if ($bundleOptionsIds) { /** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */ $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product); diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index c1e8295e0a870..779e1446bc619 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -700,8 +700,14 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p $this->checkIsResult($_result); $result[] = $_result[0]->setParentProductId($product->getId()) - ->addCustomOption('bundle_option_ids', serialize(array_map('intval', $optionIds))) - ->addCustomOption('bundle_selection_attributes', $this->serializer->serialize($attributes)); + ->addCustomOption( + 'bundle_option_ids', + $this->serializer->serialize(array_map('intval', $optionIds)) + ) + ->addCustomOption( + 'bundle_selection_attributes', + $this->serializer->serialize($attributes) + ); if ($isStrictProcessMode) { $_result[0]->setCartQty($qty); @@ -718,7 +724,12 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p foreach ($result as $item) { $item->addCustomOption('bundle_identity', $uniqueKey); } - $product->addCustomOption('bundle_option_ids', serialize(array_map('intval', $optionIds))); + $product->addCustomOption( + 'bundle_option_ids', + $this->serializer->serialize( + array_map('intval', $optionIds) + ) + ); $product->addCustomOption('bundle_selection_ids', $this->serializer->serialize($selectionIds)); return $result; @@ -829,7 +840,10 @@ public function getOptionsByIds($optionIds, $product) $usedOptions = $product->getData($this->_keyUsedOptions); $usedOptionsIds = $product->getData($this->_keyUsedOptionsIds); - if (!$usedOptions || serialize($usedOptionsIds) != serialize($optionIds)) { + if ( + !$usedOptions + || $this->serializer->serialize($usedOptionsIds) != $this->serializer->serialize($optionIds) + ) { $usedOptions = $this->_bundleOption ->create() ->getResourceCollection() @@ -861,7 +875,7 @@ public function getOrderOptions($product) if ($product->hasCustomOptions()) { $customOption = $product->getCustomOption('bundle_option_ids'); - $optionIds = unserialize($customOption->getValue()); + $optionIds = $this->serializer->unserialize($customOption->getValue()); $options = $this->getOptionsByIds($optionIds, $product); $customOption = $product->getCustomOption('bundle_selection_ids'); $selectionIds = $this->serializer->unserialize($customOption->getValue()); diff --git a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php index 52ec835795aa2..454faead3aa0c 100644 --- a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php @@ -85,7 +85,10 @@ public function getOptions() // get bundle options $optionsQuoteItemOption = $this->item->getOptionByCode('bundle_option_ids'); - $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : []; + $bundleOptionsIds = $optionsQuoteItemOption + ? $this->serializer->unserialize($optionsQuoteItemOption->getValue()) + : []; + if ($bundleOptionsIds) { /** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */ $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $bundleProduct); diff --git a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php index 15b4e9449160a..e46a0213b6147 100644 --- a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php @@ -143,8 +143,7 @@ public function testGetBundleOptionsEmptyBundleOptionsIds() public function testGetBundleOptionsEmptyBundleSelectionIds() { - $optionIds = 'a:1:{i:0;i:1;}'; - + $optionIds = '{"0":"1"}'; $collection = $this->getMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class, [], [], '', false); $product = $this->getMock( \Magento\Catalog\Model\Product::class, @@ -168,7 +167,7 @@ public function testGetBundleOptionsEmptyBundleSelectionIds() $selectionOption->expects($this->once())->method('getValue')->will($this->returnValue('')); $itemOption->expects($this->once())->method('getValue')->will($this->returnValue($optionIds)); - $typeInstance->expects($this->once())->method('getOptionsByIds')->with(unserialize($optionIds), $product) + $typeInstance->expects($this->once())->method('getOptionsByIds')->with(json_decode($optionIds, true), $product) ->will($this->returnValue($collection)); $product->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstance)); $this->item->expects($this->once())->method('getProduct')->will($this->returnValue($product)); @@ -185,7 +184,7 @@ public function testGetBundleOptionsEmptyBundleSelectionIds() */ public function testGetOptions() { - $optionIds = 'a:1:{i:0;i:1;}'; + $optionIds = '{"0":"1"}'; $selectionIds = '{"0":"2"}'; $selectionId = '2'; $product = $this->getMock( @@ -253,7 +252,7 @@ public function testGetOptions() $collection->expects($this->once())->method('appendSelections')->with($collection2, true) ->will($this->returnValue([$bundleOption])); $itemOption->expects($this->once())->method('getValue')->will($this->returnValue($optionIds)); - $typeInstance->expects($this->once())->method('getOptionsByIds')->with(unserialize($optionIds), $product) + $typeInstance->expects($this->once())->method('getOptionsByIds')->with(json_decode($optionIds, true), $product) ->will($this->returnValue($collection)); $typeInstance->expects($this->once()) ->method('getSelectionsByIds') diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index f0a79ba22b67e..48e2d7bb9c61d 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -94,6 +94,7 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) 'parameters', 'info_buyRequest', 'bundle_option_ids', + 'attributes', 'bundle_selection_attributes', ] ] diff --git a/app/code/Magento/Wishlist/Setup/UpgradeData.php b/app/code/Magento/Wishlist/Setup/UpgradeData.php index 1f45b801b245a..66aef201c9e70 100644 --- a/app/code/Magento/Wishlist/Setup/UpgradeData.php +++ b/app/code/Magento/Wishlist/Setup/UpgradeData.php @@ -76,6 +76,7 @@ private function upgradeToVersionTwoZeroOne(ModuleDataSetupInterface $setup) 'parameters', 'info_buyRequest', 'bundle_option_ids', + 'attributes', 'bundle_selection_attributes', ] ] From 83f8095c6175a6de4e726b92797a57f65b11ae8c Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 15:41:35 +0200 Subject: [PATCH 098/132] MAGETWO-62269: Fix general architecture review notices --- ...erializedDataConverter.php => SerializedDataConverterTest.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/code/Magento/Sales/Test/Unit/Setup/{SerializedDataConverter.php => SerializedDataConverterTest.php} (100%) diff --git a/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php b/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverterTest.php similarity index 100% rename from app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverter.php rename to app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverterTest.php From 3281969e92b2ffa0aafe89917bd37630653de4b2 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 15:44:27 +0200 Subject: [PATCH 099/132] MAGETWO-62269: Fix general architecture review notices - CR fix --- app/code/Magento/Sales/Model/Order/CreditmemoFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php index f3f4055c1cc8d..68808f56edd02 100644 --- a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php +++ b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php @@ -37,6 +37,7 @@ class CreditmemoFactory * * @param \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory * @param \Magento\Tax\Model\Config $taxConfig + * @param \Magento\Framework\Serialize\SerializerInterface $serializer */ public function __construct( \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory, From 7bb825e75dddb4c6f420fe32ea6e058e24e37c35 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 15:54:34 +0200 Subject: [PATCH 100/132] MAGETWO-62269: Fix general architecture review notices --- app/code/Magento/Sales/Setup/SerializedDataConverter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Setup/SerializedDataConverter.php b/app/code/Magento/Sales/Setup/SerializedDataConverter.php index 0b5e9bde5e702..e12007e844562 100644 --- a/app/code/Magento/Sales/Setup/SerializedDataConverter.php +++ b/app/code/Magento/Sales/Setup/SerializedDataConverter.php @@ -37,8 +37,7 @@ class SerializedDataConverter implements \Magento\Framework\DB\DataConverter\Dat public function __construct( Serialize $serialize, Json $json - ) - { + ) { $this->serialize = $serialize; $this->json = $json; } From df337b5b92a8d0df286b193d982975c91978e299 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 16:01:59 +0200 Subject: [PATCH 101/132] MAGETWO-62280: Fix complex product types serialization in order flow --- app/code/Magento/Quote/Setup/UpgradeData.php | 1 + app/code/Magento/Wishlist/Setup/UpgradeData.php | 1 + 2 files changed, 2 insertions(+) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 48e2d7bb9c61d..f6119d1c93fdc 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -94,6 +94,7 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) 'parameters', 'info_buyRequest', 'bundle_option_ids', + 'bundle_selection_ids', 'attributes', 'bundle_selection_attributes', ] diff --git a/app/code/Magento/Wishlist/Setup/UpgradeData.php b/app/code/Magento/Wishlist/Setup/UpgradeData.php index 66aef201c9e70..496db7f2caba5 100644 --- a/app/code/Magento/Wishlist/Setup/UpgradeData.php +++ b/app/code/Magento/Wishlist/Setup/UpgradeData.php @@ -76,6 +76,7 @@ private function upgradeToVersionTwoZeroOne(ModuleDataSetupInterface $setup) 'parameters', 'info_buyRequest', 'bundle_option_ids', + 'bundle_selection_ids', 'attributes', 'bundle_selection_attributes', ] From d7061c3dd0f7f5b8f5250aa5334b9ab8c593ead0 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 16:09:29 +0200 Subject: [PATCH 102/132] MAGETWO-62280: Fix complex product types serialization in order flow --- app/code/Magento/Quote/Setup/UpgradeData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index f6119d1c93fdc..25e784be91ca3 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -36,7 +36,7 @@ class UpgradeData implements UpgradeDataInterface * * @param FieldDataConverterFactory $fieldDataConverterFactory * @param QueryModifierFactory $queryModifierFactory - * @param Generator $generator + * @param Generator $queryGenerator */ public function __construct( FieldDataConverterFactory $fieldDataConverterFactory, From 636ea5c6a8cc63e11efc9ebf1aa9f5bbe83f6924 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 15 Dec 2016 16:18:09 +0200 Subject: [PATCH 103/132] MAGETWO-62269: Fix general architecture review notices --- .../Sales/Model/Order/CreditmemoFactory.php | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php index 68808f56edd02..37f71d2d9fa2c 100644 --- a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php +++ b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php @@ -24,6 +24,7 @@ class CreditmemoFactory /** * @var \Magento\Framework\Unserialize\Unserialize + * @deprecated */ protected $unserialize; @@ -288,19 +289,4 @@ private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterf } return $qty; } - - /** - * Get Unserialize - * - * @return \Magento\Framework\Unserialize\Unserialize - * @deprecated - */ - private function getUnserialize() - { - if (!$this->unserialize) { - $this->unserialize = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Unserialize\Unserialize::class); - } - return $this->unserialize; - } } From a7761084f0c0e8c22e2883f6ccb27e12b5bfb27c Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 19 Dec 2016 10:08:04 -0600 Subject: [PATCH 104/132] MAGETWO-62133: Create QueryModifier to select only options of type file and info_buyRequest Refactoring --- .../Magento/Framework/DB/Select/InQueryModifier.php | 2 +- .../Framework/DB/Select/QueryModifierFactory.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php b/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php index cf20152d8043e..e8a03f709568a 100644 --- a/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php +++ b/lib/internal/Magento/Framework/DB/Select/InQueryModifier.php @@ -8,7 +8,7 @@ use Magento\Framework\DB\Select; /** - * Add in condition to select + * Add IN condition to select */ class InQueryModifier implements QueryModifierInterface { diff --git a/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php b/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php index fe2933627d51f..8c7e0fed8f916 100644 --- a/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php +++ b/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php @@ -34,9 +34,16 @@ public function __construct( * @param string $queryModifierClassName * @param array $data * @return QueryModifierInterface + * @throws \InvalidArgumentException */ - public function create($queryModifierClassName, $data) + public function create($queryModifierClassName, array $data = []) { - return $this->objectManager->create($queryModifierClassName, $data); + $queryModifier = $this->objectManager->create($queryModifierClassName, $data); + if (!($queryModifier instanceof QueryModifierInterface)) { + throw new \InvalidArgumentException( + $queryModifierClassName . ' must implement ' . QueryModifierInterface::class + ); + } + return $queryModifier; } } From 3d63fb970d3ffb126ea0f7e1101f7bdf575527e4 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 19 Dec 2016 14:33:03 -0600 Subject: [PATCH 105/132] MAGETWO-62133: Create QueryModifier to select only options of type file and info_buyRequest Refactoring --- app/code/Magento/Quote/Setup/UpgradeData.php | 5 +++-- app/etc/di.xml | 7 +++++++ .../DB/Select/QueryModifierFactory.php | 21 ++++++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 96b05d2e2447d..42c47404f7e26 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -64,6 +64,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface * * @param ModuleDataSetupInterface $setup * @return void + * @throws \InvalidArgumentException */ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) { @@ -75,7 +76,7 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) 'additional_information' ); $queryModifier = $this->queryModifierFactory->create( - InQueryModifier::class, + 'in', [ 'values' => [ 'code' => [ @@ -111,7 +112,7 @@ function ($id) { $codes ); $queryModifier = $this->queryModifierFactory->create( - InQueryModifier::class, + 'in', [ 'values' => [ 'code' => $codes diff --git a/app/etc/di.xml b/app/etc/di.xml index e9767eccb2811..f922c9c15e7a9 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1214,4 +1214,11 @@ + + + + Magento\Framework\DB\Select\InQueryModifier + + + diff --git a/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php b/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php index 8c7e0fed8f916..21eb484b43268 100644 --- a/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php +++ b/lib/internal/Magento/Framework/DB/Select/QueryModifierFactory.php @@ -17,31 +17,42 @@ class QueryModifierFactory */ private $objectManager; + /** + * @var array + */ + private $queryModifiers; + /** * Constructor * * @param ObjectManagerInterface $objectManager + * @param array $queryModifiers */ public function __construct( - ObjectManagerInterface $objectManager + ObjectManagerInterface $objectManager, + array $queryModifiers = [] ) { $this->objectManager = $objectManager; + $this->queryModifiers = $queryModifiers; } /** * Create instance of QueryModifierInterface * - * @param string $queryModifierClassName + * @param string $type * @param array $data * @return QueryModifierInterface * @throws \InvalidArgumentException */ - public function create($queryModifierClassName, array $data = []) + public function create($type, array $data = []) { - $queryModifier = $this->objectManager->create($queryModifierClassName, $data); + if (!isset($this->queryModifiers[$type])) { + throw new \InvalidArgumentException('Unknown query modifier type ' . $type); + } + $queryModifier = $this->objectManager->create($this->queryModifiers[$type], $data); if (!($queryModifier instanceof QueryModifierInterface)) { throw new \InvalidArgumentException( - $queryModifierClassName . ' must implement ' . QueryModifierInterface::class + $this->queryModifiers[$type] . ' must implement ' . QueryModifierInterface::class ); } return $queryModifier; From 621230f6ba88954d07c8b3c49d9bf7b91e192b41 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 19 Dec 2016 14:35:46 -0600 Subject: [PATCH 106/132] MAGETWO-62133: Create QueryModifier to select only options of type file and info_buyRequest Refactoring --- app/code/Magento/Quote/Setup/UpgradeData.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 42c47404f7e26..44f2ad661d74c 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -11,7 +11,6 @@ use Magento\Framework\DB\FieldDataConverterFactory; use Magento\Framework\DB\DataConverter\SerializedToJson; use Magento\Framework\DB\Select\QueryModifierFactory; -use Magento\Framework\DB\Select\InQueryModifier; use Magento\Framework\DB\Query\Generator; class UpgradeData implements UpgradeDataInterface From fae04fe274e963669d6fc3f78e0b6cd601b0734b Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Mon, 19 Dec 2016 15:20:49 -0600 Subject: [PATCH 107/132] MAGETWO-62133: Create QueryModifier to select only options of type file and info_buyRequest Refactoring --- .../Unit/Select/QueryModifierFactoryTest.php | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 lib/internal/Magento/Framework/DB/Test/Unit/Select/QueryModifierFactoryTest.php diff --git a/lib/internal/Magento/Framework/DB/Test/Unit/Select/QueryModifierFactoryTest.php b/lib/internal/Magento/Framework/DB/Test/Unit/Select/QueryModifierFactoryTest.php new file mode 100644 index 0000000000000..b083b730bbdba --- /dev/null +++ b/lib/internal/Magento/Framework/DB/Test/Unit/Select/QueryModifierFactoryTest.php @@ -0,0 +1,106 @@ +objectManager = new ObjectManager($this); + $this->objectManagerMock = $this->getMock(ObjectManagerInterface::class); + $this->inQueryModifierMock = $this->getMock(InQueryModifier::class, [], [], '', false); + } + + public function testCreate() + { + $params = ['foo' => 'bar']; + $this->queryModifierFactory = $this->objectManager->getObject( + QueryModifierFactory::class, + [ + 'objectManager' => $this->objectManagerMock, + 'queryModifiers' => [ + 'in' => InQueryModifier::class + ] + ] + ); + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with( + InQueryModifier::class, + $params + ) + ->willReturn($this->inQueryModifierMock); + $this->queryModifierFactory->create('in', $params); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testCreateUnknownQueryModifierType() + { + $params = ['foo' => 'bar']; + $this->queryModifierFactory = $this->objectManager->getObject( + QueryModifierFactory::class, + [ + 'objectManager' => $this->objectManagerMock, + 'queryModifiers' => [] + ] + ); + $this->objectManagerMock->expects($this->never()) + ->method('create'); + $this->queryModifierFactory->create('in', $params); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testCreateDoesNotImplementInterface() + { + $params = ['foo' => 'bar']; + $this->queryModifierFactory = $this->objectManager->getObject( + QueryModifierFactory::class, + [ + 'objectManager' => $this->objectManagerMock, + 'queryModifiers' => [ + 'in' => \stdClass::class + ] + ] + ); + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with( + \stdClass::class, + $params + ) + ->willReturn(new \stdClass()); + $this->queryModifierFactory->create('in', $params); + } +} From 33ecec9d6b68980512684732510db06a2bd5eaba Mon Sep 17 00:00:00 2001 From: Vitaliy Goncharenko Date: Thu, 22 Dec 2016 08:33:41 +0200 Subject: [PATCH 108/132] MAGETWO-62573: Update of use SerializerInterface --- .../Helper/Catalog/Product/Configuration.php | 2 +- .../Magento/Bundle/Model/Product/Price.php | 2 +- .../Magento/Bundle/Model/Product/Type.php | 21 ++++++++++++++++--- .../Bundle/Pricing/Price/ConfiguredPrice.php | 2 +- .../CustomOptions/CustomOptionProcessor.php | 2 +- .../Model/Product/Option/Type/Date.php | 2 +- .../Model/Product/Type/AbstractType.php | 2 +- .../Downloadable/Model/Product/Type.php | 2 +- .../Model/Product/Type/Grouped.php | 2 +- .../Quote/Model/Quote/Address/Total.php | 2 +- .../Quote/Model/Quote/Item/Compare.php | 2 +- .../Quote/Model/Quote/Item/Updater.php | 2 +- .../Magento/Quote/Model/Quote/Payment.php | 2 +- .../Magento/Sales/Model/AdminOrder/Create.php | 2 +- app/code/Magento/Sales/Model/Order/Item.php | 2 +- .../Sales/Setup/SerializedDataConverter.php | 4 ---- .../Setup/SerializedDataConverterTest.php | 4 +--- app/code/Magento/Wishlist/Model/Item.php | 2 +- 18 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php b/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php index 2de5db073ecc5..13e7a8a4f72a1 100644 --- a/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php +++ b/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php @@ -47,7 +47,7 @@ class Configuration extends AbstractHelper implements ConfigurationInterface * @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper * @param \Magento\Framework\Escaper $escaper - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer */ public function __construct( \Magento\Framework\App\Helper\Context $context, diff --git a/app/code/Magento/Bundle/Model/Product/Price.php b/app/code/Magento/Bundle/Model/Product/Price.php index d78810264d2bb..30001fcc4297e 100644 --- a/app/code/Magento/Bundle/Model/Product/Price.php +++ b/app/code/Magento/Bundle/Model/Product/Price.php @@ -59,7 +59,7 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price * @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Catalog\Helper\Data $catalogData - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index 779e1446bc619..20527f580c0c0 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -1028,9 +1028,7 @@ public function checkProductBuyState($product) $productSelections = $this->getSelectionsCollection($productOptionIds, $product); $selectionIds = $product->getCustomOption('bundle_selection_ids'); $selectionIds = $this->serializer->unserialize($selectionIds->getValue()); - $buyRequest = $product->getCustomOption('info_buyRequest'); - $buyRequest = new \Magento\Framework\DataObject($this->serializer->unserialize($buyRequest->getValue())); - $bundleOption = $buyRequest->getBundleOption(); + $bundleOption = $this->getBundleOption($product); if (empty($bundleOption)) { throw new \Magento\Framework\Exception\LocalizedException($this->getSpecifyOptionMessage()); @@ -1059,6 +1057,23 @@ public function checkProductBuyState($product) return $this; } + /** + * Get Bundle option as array from 'info_buyRequest' data. + * + * @param \Magento\Catalog\Model\Product $product + * @return array + */ + private function getBundleOption(\Magento\Catalog\Model\Product $product) + { + $buyRequest = $product->getCustomOption('info_buyRequest'); + $data = $this->serializer->unserialize($buyRequest->getValue()); + $data = is_array($data) ? $data : []; + $buyRequest = \Magento\Framework\App\ObjectManager::getInstance() + ->create(\Magento\Framework\DataObject::class, ['data' => $data]); + + return $buyRequest->getBundleOption(); + } + /** * Retrieve products divided into groups required to purchase * At least one product in each group has to be purchased diff --git a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php index 454faead3aa0c..cd5754e1ce1bb 100644 --- a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php @@ -45,7 +45,7 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice * @param BundleCalculatorInterface $calculator * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param ItemInterface $item - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer */ public function __construct( Product $saleableItem, diff --git a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php index 252c0bcb796b5..212da848d7d20 100644 --- a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php +++ b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php @@ -40,7 +40,7 @@ class CustomOptionProcessor implements CartItemProcessorInterface * @param ProductOptionFactory $productOptionFactory * @param ProductOptionExtensionFactory $extensionFactory * @param CustomOptionFactory $customOptionFactory - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer */ public function __construct( \Magento\Framework\DataObject\Factory $objectFactory, diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php index 205cf420f5c9f..b11440daf9e09 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php @@ -34,7 +34,7 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, diff --git a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php index f0e8d37921ca0..07a200f81355d 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php +++ b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php @@ -180,7 +180,7 @@ abstract public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $ * @param \Magento\Framework\Registry $coreRegistry * @param \Psr\Log\LoggerInterface $logger * @param ProductRepositoryInterface $productRepository - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/Downloadable/Model/Product/Type.php b/app/code/Magento/Downloadable/Model/Product/Type.php index 5c5807f66b205..2b15a5b7d7d91 100644 --- a/app/code/Magento/Downloadable/Model/Product/Type.php +++ b/app/code/Magento/Downloadable/Model/Product/Type.php @@ -85,7 +85,7 @@ class Type extends \Magento\Catalog\Model\Product\Type\Virtual * @param \Magento\Downloadable\Model\LinkFactory $linkFactory * @param TypeHandler\TypeHandlerInterface $typeHandler * @param JoinProcessorInterface $extensionAttributesJoinProcessor - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php b/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php index 8796976fa8210..af277548a7212 100644 --- a/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php @@ -95,7 +95,7 @@ class Grouped extends \Magento\Catalog\Model\Product\Type\AbstractType * @param \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus * @param \Magento\Framework\App\State $appState * @param \Magento\Msrp\Helper\Data $msrpData - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/Quote/Model/Quote/Address/Total.php b/app/code/Magento/Quote/Model/Quote/Address/Total.php index f764c9df6a3cb..be319ef205d14 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/Total.php +++ b/app/code/Magento/Quote/Model/Quote/Address/Total.php @@ -26,7 +26,7 @@ class Total extends \Magento\Framework\DataObject /** * @param array $data [optional] - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer */ public function __construct( array $data = [], diff --git a/app/code/Magento/Quote/Model/Quote/Item/Compare.php b/app/code/Magento/Quote/Model/Quote/Item/Compare.php index ab4303b7e9771..0de26b8a6f43f 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Compare.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Compare.php @@ -20,7 +20,7 @@ class Compare private $serializer; /** - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer */ public function __construct(\Magento\Framework\Serialize\SerializerInterface $serializer = null) { diff --git a/app/code/Magento/Quote/Model/Quote/Item/Updater.php b/app/code/Magento/Quote/Model/Quote/Item/Updater.php index 4dc17705568bd..a159f0857252b 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Updater.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Updater.php @@ -43,7 +43,7 @@ class Updater * @param ProductFactory $productFactory * @param FormatInterface $localeFormat * @param ObjectFactory $objectFactory - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer */ public function __construct( ProductFactory $productFactory, diff --git a/app/code/Magento/Quote/Model/Quote/Payment.php b/app/code/Magento/Quote/Model/Quote/Payment.php index 7c8080b180996..b71b87464d380 100644 --- a/app/code/Magento/Quote/Model/Quote/Payment.php +++ b/app/code/Magento/Quote/Model/Quote/Payment.php @@ -84,7 +84,7 @@ class Payment extends \Magento\Payment\Model\Info implements PaymentInterface * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * @param array $additionalChecks - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 700f196e9c2f7..027be39e7c65f 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -260,7 +260,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ * @param \Magento\Sales\Api\OrderManagementInterface $orderManagement * @param \Magento\Quote\Model\QuoteFactory $quoteFactory * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index 100b8b69a44e9..4d2412b97cf9e 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -115,7 +115,7 @@ class Item extends AbstractModel implements OrderItemInterface * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/Sales/Setup/SerializedDataConverter.php b/app/code/Magento/Sales/Setup/SerializedDataConverter.php index e12007e844562..507713b910f59 100644 --- a/app/code/Magento/Sales/Setup/SerializedDataConverter.php +++ b/app/code/Magento/Sales/Setup/SerializedDataConverter.php @@ -10,10 +10,6 @@ use Magento\Framework\Serialize\Serializer\Json; /** - * Class SerializedToJson. - * - * @package Magento\Sales\Model\Order\Item\Converter\ProductOptions - * * Serializer used to update nested serialized data in product_options field. */ class SerializedDataConverter implements \Magento\Framework\DB\DataConverter\DataConverterInterface diff --git a/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverterTest.php b/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverterTest.php index 137a8b5b19baf..e5f7e162a77c7 100644 --- a/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverterTest.php +++ b/app/code/Magento/Sales/Test/Unit/Setup/SerializedDataConverterTest.php @@ -9,9 +9,7 @@ use Magento\Framework\Serialize\Serializer\Serialize; /** - * Unit test for order address repository class. - * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * Unit test for serialized data converter test. */ class SerializedDataConverterTest extends \PHPUnit_Framework_TestCase { diff --git a/app/code/Magento/Wishlist/Model/Item.php b/app/code/Magento/Wishlist/Model/Item.php index 2d6bd18fcc0ba..954ce98b4abbc 100644 --- a/app/code/Magento/Wishlist/Model/Item.php +++ b/app/code/Magento/Wishlist/Model/Item.php @@ -140,7 +140,7 @@ class Item extends AbstractModel implements ItemInterface * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface $serializer [optional] + * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( From a6aaab7538da1837fa609436e823813b72d1e051 Mon Sep 17 00:00:00 2001 From: Roman Ganin Date: Thu, 22 Dec 2016 18:44:41 +0200 Subject: [PATCH 109/132] MAGETWO-62573: Update of use SerializerInterface --- .../Magento/Bundle/Model/Product/Type.php | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index 20527f580c0c0..0ac7c50290049 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -1028,7 +1028,9 @@ public function checkProductBuyState($product) $productSelections = $this->getSelectionsCollection($productOptionIds, $product); $selectionIds = $product->getCustomOption('bundle_selection_ids'); $selectionIds = $this->serializer->unserialize($selectionIds->getValue()); - $bundleOption = $this->getBundleOption($product); + $buyRequest = $product->getCustomOption('info_buyRequest'); + $buyRequest = new \Magento\Framework\DataObject($this->serializer->unserialize($buyRequest->getValue())); + $bundleOption = $buyRequest->getBundleOption(); if (empty($bundleOption)) { throw new \Magento\Framework\Exception\LocalizedException($this->getSpecifyOptionMessage()); @@ -1057,23 +1059,6 @@ public function checkProductBuyState($product) return $this; } - /** - * Get Bundle option as array from 'info_buyRequest' data. - * - * @param \Magento\Catalog\Model\Product $product - * @return array - */ - private function getBundleOption(\Magento\Catalog\Model\Product $product) - { - $buyRequest = $product->getCustomOption('info_buyRequest'); - $data = $this->serializer->unserialize($buyRequest->getValue()); - $data = is_array($data) ? $data : []; - $buyRequest = \Magento\Framework\App\ObjectManager::getInstance() - ->create(\Magento\Framework\DataObject::class, ['data' => $data]); - - return $buyRequest->getBundleOption(); - } - /** * Retrieve products divided into groups required to purchase * At least one product in each group has to be purchased From 5137f97b12614a8ed082b0636e7f3bd1a5260ec2 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Thu, 22 Dec 2016 11:25:48 -0600 Subject: [PATCH 110/132] MAGETWO-62610: Data upgrade fails on multi-database setup Refactoring Quote and Sales modules to use specific connection --- app/code/Magento/Quote/Setup/UpgradeData.php | 11 ++++++++--- app/code/Magento/Sales/Setup/UpgradeData.php | 13 +++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 44f2ad661d74c..3126f5816effc 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -15,6 +15,11 @@ class UpgradeData implements UpgradeDataInterface { + /** + * Name of the database connection + */ + const CONNECTION_NAME = 'checkout'; + /** * @var FieldDataConverterFactory */ @@ -69,7 +74,7 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) { $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class); $fieldDataConverter->convert( - $setup->getConnection(), + $setup->getConnection(self::CONNECTION_NAME), $setup->getTable('quote_payment'), 'payment_id', 'additional_information' @@ -88,7 +93,7 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) ] ); $fieldDataConverter->convert( - $setup->getConnection(), + $setup->getConnection(self::CONNECTION_NAME), $setup->getTable('quote_item_option'), 'option_id', 'value', @@ -119,7 +124,7 @@ function ($id) { ] ); $fieldDataConverter->convert( - $setup->getConnection(), + $setup->getConnection(self::CONNECTION_NAME), $setup->getTable('quote_item_option'), 'option_id', 'value', diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index a4a38f5cdcbab..8738c37164b41 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -7,6 +7,11 @@ class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface { + /** + * Name of the database connection + */ + const CONNECTION_NAME = 'sales'; + /** * Sales setup factory * @@ -124,25 +129,25 @@ private function upgradeToVersionTwoZeroFive(\Magento\Framework\Setup\ModuleData \Magento\Framework\DB\DataConverter\SerializedToJson::class ); $fieldDataConverter->convert( - $setup->getConnection(), + $setup->getConnection(self::CONNECTION_NAME), $setup->getTable('sales_order_item'), 'item_id', 'product_options' ); $fieldDataConverter->convert( - $setup->getConnection(), + $setup->getConnection(self::CONNECTION_NAME), $setup->getTable('sales_shipment'), 'entity_id', 'packages' ); $fieldDataConverter->convert( - $setup->getConnection(), + $setup->getConnection(self::CONNECTION_NAME), $setup->getTable('sales_order_payment'), 'entity_id', 'additional_information' ); $fieldDataConverter->convert( - $setup->getConnection(), + $setup->getConnection(self::CONNECTION_NAME), $setup->getTable('sales_payment_transaction'), 'transaction_id', 'additional_information' From 77a19559b56e174193c11600dd6c69b9f268fd38 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Thu, 22 Dec 2016 12:25:06 -0600 Subject: [PATCH 111/132] MAGETWO-62610: Data upgrade fails on multi-database setup Refactoring Quote and Sales modules to use specific connection --- app/code/Magento/Quote/Setup/UpgradeData.php | 6 +++--- app/code/Magento/Sales/Setup/UpgradeData.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 3126f5816effc..9ec643e100e84 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -75,7 +75,7 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class); $fieldDataConverter->convert( $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('quote_payment'), + $setup->getTable('quote_payment', self::CONNECTION_NAME), 'payment_id', 'additional_information' ); @@ -94,7 +94,7 @@ private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) ); $fieldDataConverter->convert( $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('quote_item_option'), + $setup->getTable('quote_item_option', self::CONNECTION_NAME), 'option_id', 'value', $queryModifier @@ -125,7 +125,7 @@ function ($id) { ); $fieldDataConverter->convert( $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('quote_item_option'), + $setup->getTable('quote_item_option', self::CONNECTION_NAME), 'option_id', 'value', $queryModifier diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 8738c37164b41..375c823697356 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -130,25 +130,25 @@ private function upgradeToVersionTwoZeroFive(\Magento\Framework\Setup\ModuleData ); $fieldDataConverter->convert( $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('sales_order_item'), + $setup->getTable('sales_order_item', self::CONNECTION_NAME), 'item_id', 'product_options' ); $fieldDataConverter->convert( $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('sales_shipment'), + $setup->getTable('sales_shipment', self::CONNECTION_NAME), 'entity_id', 'packages' ); $fieldDataConverter->convert( $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('sales_order_payment'), + $setup->getTable('sales_order_payment', self::CONNECTION_NAME), 'entity_id', 'additional_information' ); $fieldDataConverter->convert( $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('sales_payment_transaction'), + $setup->getTable('sales_payment_transaction', self::CONNECTION_NAME), 'transaction_id', 'additional_information' ); From 1721504253effe12ddc6e187719a291d5b66d3fd Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 23 Dec 2016 19:35:20 +0200 Subject: [PATCH 112/132] MAGETWO-62650: Replace SerializerIntreface with Json implementation --- .../Block/Adminhtml/Sales/Order/Items/Renderer.php | 8 ++++---- .../Adminhtml/Sales/Order/View/Items/Renderer.php | 8 ++++---- .../Bundle/Block/Sales/Order/Items/Renderer.php | 8 ++++---- .../Bundle/Helper/Catalog/Product/Configuration.php | 8 ++++---- app/code/Magento/Bundle/Model/Product/Price.php | 8 ++++---- app/code/Magento/Bundle/Model/Product/Type.php | 6 +++--- .../Model/Sales/Order/Pdf/Items/AbstractItems.php | 10 +++++----- .../Magento/Bundle/Pricing/Price/ConfiguredPrice.php | 8 ++++---- .../Block/Adminhtml/Sales/Order/Items/RendererTest.php | 4 ++-- .../Adminhtml/Sales/Order/View/Items/RendererTest.php | 4 ++-- .../Test/Unit/Block/Sales/Order/Items/RendererTest.php | 4 ++-- .../Unit/Helper/Catalog/Product/ConfigurationTest.php | 4 ++-- .../Bundle/Test/Unit/Model/Product/PriceTest.php | 4 ++-- .../Model/Sales/Order/Pdf/Items/AbstractItemsTest.php | 4 ++-- .../Magento/Catalog/Helper/Product/Configuration.php | 8 ++++---- .../Model/CustomOptions/CustomOptionProcessor.php | 8 ++++---- .../Magento/Catalog/Model/Product/Option/Type/Date.php | 8 ++++---- .../Magento/Catalog/Model/Product/Option/Type/File.php | 8 ++++---- .../Catalog/Model/Product/Type/AbstractType.php | 8 ++++---- .../Test/Unit/Helper/Product/ConfigurationTest.php | 4 ++-- .../Model/CustomOptions/CustomOptionProcessorTest.php | 4 ++-- .../Test/Unit/Model/Product/Option/Type/FileTest.php | 4 ++-- .../Model/Product/Type/Configurable.php | 4 ++-- .../Model/Quote/Item/CartItemProcessor.php | 8 ++++---- .../Test/Unit/Model/Product/Type/ConfigurableTest.php | 2 +- .../Unit/Model/Quote/Item/CartItemProcessorTest.php | 2 +- app/code/Magento/Downloadable/Model/Product/Type.php | 4 ++-- .../Downloadable/Test/Unit/Model/Product/TypeTest.php | 6 +++--- .../GroupedProduct/Model/Product/Type/Grouped.php | 4 ++-- .../Test/Unit/Model/Product/Type/GroupedTest.php | 4 ++-- app/code/Magento/Quote/Model/Quote/Address.php | 8 ++++---- app/code/Magento/Quote/Model/Quote/Address/Total.php | 8 ++++---- app/code/Magento/Quote/Model/Quote/Item.php | 8 ++++---- app/code/Magento/Quote/Model/Quote/Item/Compare.php | 8 ++++---- app/code/Magento/Quote/Model/Quote/Item/Updater.php | 8 ++++---- app/code/Magento/Quote/Model/Quote/Payment.php | 8 ++++---- .../Quote/Test/Unit/Model/Quote/Address/TotalTest.php | 2 +- .../Quote/Test/Unit/Model/Quote/AddressTest.php | 4 ++-- .../Quote/Test/Unit/Model/Quote/Item/CompareTest.php | 2 +- .../Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php | 6 +++--- .../Magento/Quote/Test/Unit/Model/Quote/ItemTest.php | 4 ++-- .../Quote/Test/Unit/Model/Quote/PaymentTest.php | 2 +- .../Sales/Controller/Download/DownloadCustomOption.php | 8 ++++---- app/code/Magento/Sales/Model/AdminOrder/Create.php | 8 ++++---- .../Magento/Sales/Model/Order/CreditmemoFactory.php | 8 ++++---- app/code/Magento/Sales/Model/Order/Item.php | 8 ++++---- app/code/Magento/Sales/Model/Order/ShipmentFactory.php | 8 ++++---- .../Controller/Download/DownloadCustomOptionTest.php | 2 +- .../Magento/Sales/Test/Unit/Model/Order/ItemTest.php | 4 ++-- app/code/Magento/Tax/Helper/Data.php | 8 ++++---- .../Tax/Model/Quote/GrandTotalDetailsPlugin.php | 8 ++++---- app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php | 8 ++++---- app/code/Magento/Tax/Test/Unit/Helper/DataTest.php | 2 +- .../Unit/Model/Quote/GrandTotalDetailsPluginTest.php | 2 +- .../Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php | 2 +- app/code/Magento/Wishlist/Model/Item.php | 8 ++++---- .../Catalog/Model/Product/Type/AbstractTypeTest.php | 2 +- .../Checkout/_files/quote_with_payment_saved.php | 4 ++-- .../Model/Product/Type/ConfigurableTest.php | 8 ++++---- .../Magento/Sales/Model/AdminOrder/CreateTest.php | 4 ++-- 60 files changed, 172 insertions(+), 172 deletions(-) diff --git a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php index 9b095867d31ad..06fb993cc5fc2 100644 --- a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php @@ -6,7 +6,7 @@ namespace Magento\Bundle\Block\Adminhtml\Sales\Order\Items; use Magento\Catalog\Model\Product\Type\AbstractType; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; /** * Adminhtml sales order item renderer @@ -16,7 +16,7 @@ class Renderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRend /** * Serializer * - * @var SerializerInterface + * @var Json */ private $serializer; @@ -26,7 +26,7 @@ class Renderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRend * @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration * @param \Magento\Framework\Registry $registry * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Backend\Block\Template\Context $context, @@ -34,7 +34,7 @@ public function __construct( \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration, \Magento\Framework\Registry $registry, array $data = [], - SerializerInterface $serializer = null + Json $serializer = null ) { $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(SerializerInterface::class); diff --git a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php index 5e22c4be6a139..078b3ecfb4476 100644 --- a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php @@ -6,7 +6,7 @@ namespace Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items; use Magento\Catalog\Model\Product\Type\AbstractType; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; /** * Adminhtml sales order item renderer @@ -16,7 +16,7 @@ class Renderer extends \Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\ /** * Serializer * - * @var SerializerInterface + * @var Json */ private $serializer; @@ -28,7 +28,7 @@ class Renderer extends \Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\ * @param \Magento\GiftMessage\Helper\Message $messageHelper * @param \Magento\Checkout\Helper\Data $checkoutHelper * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Backend\Block\Template\Context $context, @@ -38,7 +38,7 @@ public function __construct( \Magento\GiftMessage\Helper\Message $messageHelper, \Magento\Checkout\Helper\Data $checkoutHelper, array $data = [], - SerializerInterface $serializer = null + Json $serializer = null ) { $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(SerializerInterface::class); diff --git a/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php b/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php index 46dc764291a4b..fbf04ecdb93db 100644 --- a/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php @@ -6,7 +6,7 @@ namespace Magento\Bundle\Block\Sales\Order\Items; use Magento\Catalog\Model\Product\Type\AbstractType; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; /** * Order item render block @@ -18,7 +18,7 @@ class Renderer extends \Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer /** * Serializer * - * @var SerializerInterface + * @var Json */ private $serializer; @@ -27,14 +27,14 @@ class Renderer extends \Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer * @param \Magento\Framework\Stdlib\StringUtils $string * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Stdlib\StringUtils $string, \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, array $data = [], - SerializerInterface $serializer = null + Json $serializer = null ) { $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(SerializerInterface::class); diff --git a/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php b/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php index 13e7a8a4f72a1..3ad004fabead1 100644 --- a/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php +++ b/app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php @@ -38,7 +38,7 @@ class Configuration extends AbstractHelper implements ConfigurationInterface /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -47,20 +47,20 @@ class Configuration extends AbstractHelper implements ConfigurationInterface * @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper * @param \Magento\Framework\Escaper $escaper - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Helper\Product\Configuration $productConfiguration, \Magento\Framework\Pricing\Helper\Data $pricingHelper, \Magento\Framework\Escaper $escaper, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->productConfiguration = $productConfiguration; $this->pricingHelper = $pricingHelper; $this->escaper = $escaper; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct($context); } diff --git a/app/code/Magento/Bundle/Model/Product/Price.php b/app/code/Magento/Bundle/Model/Product/Price.php index 30001fcc4297e..f5043f1f7edc6 100644 --- a/app/code/Magento/Bundle/Model/Product/Price.php +++ b/app/code/Magento/Bundle/Model/Product/Price.php @@ -42,7 +42,7 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -59,7 +59,7 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price * @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Catalog\Helper\Data $catalogData - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -73,11 +73,11 @@ public function __construct( \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Catalog\Helper\Data $catalogData, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->_catalogData = $catalogData; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct( $ruleFactory, $storeManager, diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index 0ac7c50290049..10cb3b8a846a2 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -10,7 +10,7 @@ use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; /** * Bundle Type Model @@ -168,7 +168,7 @@ class Type extends \Magento\Catalog\Model\Product\Type\AbstractType * @param PriceCurrencyInterface $priceCurrency * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry * @param \Magento\CatalogInventory\Api\StockStateInterface $stockState - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -194,7 +194,7 @@ public function __construct( PriceCurrencyInterface $priceCurrency, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\CatalogInventory\Api\StockStateInterface $stockState, - SerializerInterface $serializer = null + Json $serializer = null ) { $this->_catalogProduct = $catalogProduct; $this->_catalogData = $catalogData; diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index 0f5b583052952..ad6d342b6e596 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -6,7 +6,7 @@ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; use Magento\Catalog\Model\Product\Type\AbstractType; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; /** * Sales Order Pdf Items renderer @@ -17,7 +17,7 @@ abstract class AbstractItems extends \Magento\Sales\Model\Order\Pdf\Items\Abstra /** * Serializer * - * @var SerializerInterface + * @var Json */ private $serializer; @@ -30,7 +30,7 @@ abstract class AbstractItems extends \Magento\Sales\Model\Order\Pdf\Items\Abstra * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -41,7 +41,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - SerializerInterface $serializer = null + Json $serializer = null ) { $this->serializer = $serializer; @@ -291,7 +291,7 @@ public function canShowPriceInfo($item) /** * The getter function to get serializer * - * @return SerializerInterface + * @return Json * * @deprecated */ diff --git a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php index cd5754e1ce1bb..2069b91426fad 100644 --- a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php @@ -35,7 +35,7 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -45,7 +45,7 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice * @param BundleCalculatorInterface $calculator * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param ItemInterface $item - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( Product $saleableItem, @@ -53,11 +53,11 @@ public function __construct( BundleCalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, ItemInterface $item = null, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->item = $item; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); } diff --git a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php index 816dcba4c0c07..af02f9d6129c4 100644 --- a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php @@ -13,7 +13,7 @@ class RendererTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer $model */ protected $model; - /** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject $serializer */ + /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject $serializer */ protected $serializer; protected function setUp() @@ -25,7 +25,7 @@ protected function setUp() '', false ); - $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject( \Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer::class, diff --git a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php index 8d3ff4bd1ba9e..a2802f5c39ac6 100644 --- a/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php @@ -13,7 +13,7 @@ class RendererTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items\Renderer $model */ protected $model; - /** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject $serializer */ + /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject $serializer */ protected $serializer; protected function setUp() @@ -25,7 +25,7 @@ protected function setUp() '', false ); - $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject( \Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items\Renderer::class, diff --git a/app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php b/app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php index fc37687625b83..1e2c0ed3b5df8 100644 --- a/app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php @@ -13,7 +13,7 @@ class RendererTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Block\Sales\Order\Items\Renderer $model */ protected $model; - /** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject $serializer */ + /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject $serializer */ protected $serializer; protected function setUp() @@ -26,7 +26,7 @@ protected function setUp() false ); - $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject( \Magento\Bundle\Block\Sales\Order\Items\Renderer::class, diff --git a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php index e46a0213b6147..656d37c710ddd 100644 --- a/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Helper/Catalog/Product/ConfigurationTest.php @@ -28,7 +28,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase protected $item; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -53,7 +53,7 @@ protected function setUp() \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface::class, ['getQty', 'getProduct', 'getOptionByCode', 'getFileDownloadParams'] ); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->getMockForAbstractClass(); $this->serializer->expects($this->any()) diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php index 5f0b6ba5cdb06..70289f437402e 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php @@ -65,7 +65,7 @@ class PriceTest extends \PHPUnit_Framework_TestCase /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -97,7 +97,7 @@ protected function setUp() false ); $scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMock(); $this->serializer->expects($this->any()) diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php index 3d39e29143489..9038b070f588d 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php @@ -13,7 +13,7 @@ class AbstractItemsTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment $model */ protected $model; - /** @var \Magento\Framework\Serialize\SerializerInterface $serializer */ + /** @var \Magento\Framework\Serialize\Serializer\Json $serializer */ protected $serializer; protected function setUp() @@ -29,7 +29,7 @@ protected function setUp() $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->model = $objectManager->getObject(\Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class); - $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class); $reflection = new \ReflectionClass(\Magento\Bundle\Model\Sales\Order\Pdf\Items\AbstractItems::class); $reflectionProperty = $reflection->getProperty('serializer'); $reflectionProperty->setAccessible(true); diff --git a/app/code/Magento/Catalog/Helper/Product/Configuration.php b/app/code/Magento/Catalog/Helper/Product/Configuration.php index c8b720d0f5ced..c95c25229e3ec 100644 --- a/app/code/Magento/Catalog/Helper/Product/Configuration.php +++ b/app/code/Magento/Catalog/Helper/Product/Configuration.php @@ -6,7 +6,7 @@ namespace Magento\Catalog\Helper\Product; use Magento\Framework\App\ObjectManager; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Catalog\Helper\Product\Configuration\ConfigurationInterface; use Magento\Framework\App\Helper\AbstractHelper; @@ -39,7 +39,7 @@ class Configuration extends AbstractHelper implements ConfigurationInterface protected $string; /** - * @var SerializerInterface + * @var Json */ private $serializer; @@ -48,14 +48,14 @@ class Configuration extends AbstractHelper implements ConfigurationInterface * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory * @param \Magento\Framework\Filter\FilterManager $filter * @param \Magento\Framework\Stdlib\StringUtils $string - * @param SerializerInterface $serializer + * @param Json $serializer */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, \Magento\Framework\Filter\FilterManager $filter, \Magento\Framework\Stdlib\StringUtils $string, - SerializerInterface $serializer = null + Json $serializer = null ) { $this->_productOptionFactory = $productOptionFactory; $this->filter = $filter; diff --git a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php index 212da848d7d20..7fe7147d1d272 100644 --- a/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php +++ b/app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php @@ -31,7 +31,7 @@ class CustomOptionProcessor implements CartItemProcessorInterface /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -40,21 +40,21 @@ class CustomOptionProcessor implements CartItemProcessorInterface * @param ProductOptionFactory $productOptionFactory * @param ProductOptionExtensionFactory $extensionFactory * @param CustomOptionFactory $customOptionFactory - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( \Magento\Framework\DataObject\Factory $objectFactory, \Magento\Quote\Model\Quote\ProductOptionFactory $productOptionFactory, \Magento\Quote\Api\Data\ProductOptionExtensionFactory $extensionFactory, \Magento\Catalog\Model\CustomOptions\CustomOptionFactory $customOptionFactory, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->objectFactory = $objectFactory; $this->productOptionFactory = $productOptionFactory; $this->extensionFactory = $extensionFactory; $this->customOptionFactory = $customOptionFactory; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php index b11440daf9e09..3d121cbc741c3 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php @@ -25,7 +25,7 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -34,18 +34,18 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, array $data = [], - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->_localeDate = $localeDate; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct($checkoutSession, $scopeConfig, $data); } diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index 9dddbdf2e9988..4ec15a0c145aa 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -9,7 +9,7 @@ use Magento\Framework\Filesystem; use Magento\Framework\Exception\LocalizedException; use Magento\Catalog\Model\Product\Exception as ProductException; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\App\ObjectManager; /** @@ -73,7 +73,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType protected $validatorFile; /** - * @var SerializerInterface + * @var Json */ private $serializer; @@ -93,7 +93,7 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param \Magento\Framework\Escaper $escaper * @param array $data * @param Filesystem $filesystem - * @param SerializerInterface|null $serializer + * @param Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -107,7 +107,7 @@ public function __construct( \Magento\Framework\Escaper $escaper, array $data = [], Filesystem $filesystem = null, - SerializerInterface $serializer = null + Json $serializer = null ) { $this->_itemOptionFactory = $itemOptionFactory; $this->_urlBuilder = $urlBuilder; diff --git a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php index 07a200f81355d..8745903acc4a8 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php +++ b/app/code/Magento/Catalog/Model/Product/Type/AbstractType.php @@ -164,7 +164,7 @@ abstract public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $ /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ protected $serializer; @@ -180,7 +180,7 @@ abstract public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $ * @param \Magento\Framework\Registry $coreRegistry * @param \Psr\Log\LoggerInterface $logger * @param ProductRepositoryInterface $productRepository - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -193,7 +193,7 @@ public function __construct( \Magento\Framework\Registry $coreRegistry, \Psr\Log\LoggerInterface $logger, ProductRepositoryInterface $productRepository, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->_catalogProductOption = $catalogProductOption; $this->_eavConfig = $eavConfig; @@ -205,7 +205,7 @@ public function __construct( $this->_logger = $logger; $this->productRepository = $productRepository; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** diff --git a/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php b/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php index 9a2e46776c6f5..66a2b34686896 100644 --- a/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php @@ -8,7 +8,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\Serialize\SerializerInterface | \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Serialize\Serializer\Json | \PHPUnit_Framework_MockObject_MockObject */ protected $serializer; @@ -23,7 +23,7 @@ protected function setUp() $optionFactoryMock = $this->getMock(\Magento\Catalog\Model\Product\OptionFactory::class, [], [], '', false); $filterManagerMock = $this->getMock(\Magento\Framework\Filter\FilterManager::class, [], [], '', false); $stringUtilsMock = $this->getMock(\Magento\Framework\Stdlib\StringUtils::class, [], [], '', false); - $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class, [], [], '', false); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, [], [], '', false); $this->helper = new \Magento\Catalog\Helper\Product\Configuration( $contextMock, diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php index 7e41275c5908e..5e8e8bde253ae 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionProcessorTest.php @@ -51,7 +51,7 @@ class CustomOptionProcessorTest extends \PHPUnit_Framework_TestCase /** @var CustomOptionProcessor */ protected $processor; - /** @var \Magento\Framework\Serialize\SerializerInterface */ + /** @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; protected function setUp() @@ -93,7 +93,7 @@ protected function setUp() $this->buyRequest = $this->getMockBuilder(\Magento\Framework\DataObject::class) ->disableOriginalConstructor() ->getMock(); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->setMethods(['unserialize']) ->getMockForAbstractClass(); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php index 6ebbc2059dbac..5584f63a2ddf8 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php @@ -39,7 +39,7 @@ class FileTest extends \PHPUnit_Framework_TestCase private $filesystemMock; /** - * @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */ private $serializer; @@ -69,7 +69,7 @@ protected function setUp() ->with(DirectoryList::MEDIA, DriverPool::FILE) ->willReturn($this->rootDirectory); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php index ded185fb85c7d..d9ff7a92f08c6 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php @@ -183,7 +183,7 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType * @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $catalogProductTypeConfigurable * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -206,7 +206,7 @@ public function __construct( \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor, \Magento\Framework\Cache\FrontendInterface $cache = null, \Magento\Customer\Model\Session $customerSession = null, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->typeConfigurableFactory = $typeConfigurableFactory; $this->_eavAttributeFactory = $eavAttributeFactory; diff --git a/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php b/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php index 6e9d439ade646..2011a95bd77f8 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php +++ b/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php @@ -7,7 +7,7 @@ use Magento\Quote\Model\Quote\Item\CartItemProcessorInterface; use Magento\Quote\Api\Data\CartItemInterface; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\App\ObjectManager; class CartItemProcessor implements CartItemProcessorInterface @@ -33,7 +33,7 @@ class CartItemProcessor implements CartItemProcessorInterface protected $itemOptionValueFactory; /** - * @var SerializerInterface + * @var Json */ private $serializer; @@ -42,14 +42,14 @@ class CartItemProcessor implements CartItemProcessorInterface * @param \Magento\Quote\Model\Quote\ProductOptionFactory $productOptionFactory * @param \Magento\Quote\Api\Data\ProductOptionExtensionFactory $extensionFactory * @param \Magento\ConfigurableProduct\Model\Quote\Item\ConfigurableItemOptionValueFactory $itemOptionValueFactory - * @param SerializerInterface $serializer + * @param Json $serializer */ public function __construct( \Magento\Framework\DataObject\Factory $objectFactory, \Magento\Quote\Model\Quote\ProductOptionFactory $productOptionFactory, \Magento\Quote\Api\Data\ProductOptionExtensionFactory $extensionFactory, \Magento\ConfigurableProduct\Model\Quote\Item\ConfigurableItemOptionValueFactory $itemOptionValueFactory, - SerializerInterface $serializer = null + Json $serializer = null ) { $this->objectFactory = $objectFactory; $this->productOptionFactory = $productOptionFactory; diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php index e1c40ec3fbc0c..a1a153731d073 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php @@ -169,7 +169,7 @@ protected function setUp() $this->eavConfig = $this->getMockBuilder(\Magento\Eav\Model\Config::class) ->disableOriginalConstructor() ->getMock(); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php index 271787eead256..227c9cc36b308 100644 --- a/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php +++ b/app/code/Magento/ConfigurableProduct/Test/Unit/Model/Quote/Item/CartItemProcessorTest.php @@ -88,7 +88,7 @@ protected function setUp() ); $this->serializer = $this->getMock( - \Magento\Framework\Serialize\SerializerInterface::class, + \Magento\Framework\Serialize\Serializer\Json::class, [], [], '', diff --git a/app/code/Magento/Downloadable/Model/Product/Type.php b/app/code/Magento/Downloadable/Model/Product/Type.php index 2b15a5b7d7d91..1ab363d5b2b58 100644 --- a/app/code/Magento/Downloadable/Model/Product/Type.php +++ b/app/code/Magento/Downloadable/Model/Product/Type.php @@ -85,7 +85,7 @@ class Type extends \Magento\Catalog\Model\Product\Type\Virtual * @param \Magento\Downloadable\Model\LinkFactory $linkFactory * @param TypeHandler\TypeHandlerInterface $typeHandler * @param JoinProcessorInterface $extensionAttributesJoinProcessor - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -106,7 +106,7 @@ public function __construct( \Magento\Downloadable\Model\LinkFactory $linkFactory, \Magento\Downloadable\Model\Product\TypeHandler\TypeHandlerInterface $typeHandler, JoinProcessorInterface $extensionAttributesJoinProcessor, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->_sampleResFactory = $sampleResFactory; $this->_linkResource = $linkResource; diff --git a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php index ae8a5625024fc..b93a6a8386116 100644 --- a/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Downloadable/Test/Unit/Model/Product/TypeTest.php @@ -6,7 +6,7 @@ namespace Magento\Downloadable\Test\Unit\Model\Product; use Magento\Downloadable\Model\Product\TypeHandler\TypeHandlerInterface; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; /** * Class TypeTest @@ -32,7 +32,7 @@ class TypeTest extends \PHPUnit_Framework_TestCase private $product; /** - * @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */ private $serializerMock; @@ -98,7 +98,7 @@ protected function setUp() $resourceProductMock->expects($this->any())->method('getEntityType')->will($this->returnValue($entityTypeMock)); $this->serializerMock = $this->getMock( - SerializerInterface::class, + Json::class, [], ['serialize', 'unserialize'], '', diff --git a/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php b/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php index af277548a7212..08dd1553d99b1 100644 --- a/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php @@ -95,7 +95,7 @@ class Grouped extends \Magento\Catalog\Model\Product\Type\AbstractType * @param \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus * @param \Magento\Framework\App\State $appState * @param \Magento\Msrp\Helper\Data $msrpData - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -113,7 +113,7 @@ public function __construct( \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus, \Magento\Framework\App\State $appState, \Magento\Msrp\Helper\Data $msrpData, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->productLinks = $catalogProductLink; $this->_storeManager = $storeManager; diff --git a/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php b/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php index b02cd7d2e385f..42afe71e16c30 100644 --- a/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php +++ b/app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php @@ -38,7 +38,7 @@ class GroupedTest extends \PHPUnit_Framework_TestCase protected $objectHelper; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -72,7 +72,7 @@ protected function setUp() '', false ); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->setMethods(['serialize']) ->getMockForAbstractClass(); diff --git a/app/code/Magento/Quote/Model/Quote/Address.php b/app/code/Magento/Quote/Model/Quote/Address.php index f4a350d39ebcd..0420ead089529 100644 --- a/app/code/Magento/Quote/Model/Quote/Address.php +++ b/app/code/Magento/Quote/Model/Quote/Address.php @@ -8,7 +8,7 @@ use Magento\Customer\Api\AddressMetadataInterface; use Magento\Customer\Api\Data\AddressInterfaceFactory; use Magento\Customer\Api\Data\RegionInterfaceFactory; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\App\ObjectManager; /** @@ -235,7 +235,7 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements protected $totalsReader; /** - * @var SerializerInterface + * @var Json */ private $serializer; @@ -272,7 +272,7 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data - * @param SerializerInterface $serializer + * @param Json $serializer * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -309,7 +309,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - SerializerInterface $serializer = null + Json $serializer = null ) { $this->_scopeConfig = $scopeConfig; $this->_addressItemFactory = $addressItemFactory; diff --git a/app/code/Magento/Quote/Model/Quote/Address/Total.php b/app/code/Magento/Quote/Model/Quote/Address/Total.php index be319ef205d14..499147b9bf747 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/Total.php +++ b/app/code/Magento/Quote/Model/Quote/Address/Total.php @@ -20,20 +20,20 @@ class Total extends \Magento\Framework\DataObject /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; /** * @param array $data [optional] - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( array $data = [], - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct($data); } diff --git a/app/code/Magento/Quote/Model/Quote/Item.php b/app/code/Magento/Quote/Model/Quote/Item.php index 1e6a6e1e5ace8..a8aa2b2dc273b 100644 --- a/app/code/Magento/Quote/Model/Quote/Item.php +++ b/app/code/Magento/Quote/Model/Quote/Item.php @@ -178,7 +178,7 @@ class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem implements \Mage /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -198,7 +198,7 @@ class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem implements \Mage * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -216,7 +216,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->_errorInfos = $statusListFactory->create(); $this->_localeFormat = $localeFormat; @@ -224,7 +224,7 @@ public function __construct( $this->quoteItemCompare = $quoteItemCompare; $this->stockRegistry = $stockRegistry; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct( $context, $registry, diff --git a/app/code/Magento/Quote/Model/Quote/Item/Compare.php b/app/code/Magento/Quote/Model/Quote/Item/Compare.php index 0de26b8a6f43f..ca788f0985ca2 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Compare.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Compare.php @@ -15,17 +15,17 @@ class Compare /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; /** - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ - public function __construct(\Magento\Framework\Serialize\SerializerInterface $serializer = null) + public function __construct(\Magento\Framework\Serialize\Serializer\Json $serializer = null) { $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** diff --git a/app/code/Magento/Quote/Model/Quote/Item/Updater.php b/app/code/Magento/Quote/Model/Quote/Item/Updater.php index a159f0857252b..1ea7676cca405 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Updater.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Updater.php @@ -35,7 +35,7 @@ class Updater /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -43,19 +43,19 @@ class Updater * @param ProductFactory $productFactory * @param FormatInterface $localeFormat * @param ObjectFactory $objectFactory - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( ProductFactory $productFactory, FormatInterface $localeFormat, ObjectFactory $objectFactory, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->productFactory = $productFactory; $this->localeFormat = $localeFormat; $this->objectFactory = $objectFactory; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** diff --git a/app/code/Magento/Quote/Model/Quote/Payment.php b/app/code/Magento/Quote/Model/Quote/Payment.php index b71b87464d380..03acf1d6500e1 100644 --- a/app/code/Magento/Quote/Model/Quote/Payment.php +++ b/app/code/Magento/Quote/Model/Quote/Payment.php @@ -68,7 +68,7 @@ class Payment extends \Magento\Payment\Model\Info implements PaymentInterface /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -84,7 +84,7 @@ class Payment extends \Magento\Payment\Model\Info implements PaymentInterface * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * @param array $additionalChecks - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -99,12 +99,12 @@ public function __construct( \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], array $additionalChecks = [], - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->methodSpecificationFactory = $methodSpecificationFactory; $this->additionalChecks = $additionalChecks; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct( $context, $registry, diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php index 9bade22caf894..b29fbe698811c 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Address/TotalTest.php @@ -15,7 +15,7 @@ class TotalTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); $serializer->expects($this->any()) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php index 817be7eb9c090..507b2b00203d0 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php @@ -33,7 +33,7 @@ class AddressTest extends \PHPUnit_Framework_TestCase private $scopeConfig; /** - * @var \Magento\Framework\Serialize\SerializerInterface | \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Serialize\Serializer\Json | \PHPUnit_Framework_MockObject_MockObject */ protected $serializer; @@ -42,7 +42,7 @@ protected function setUp() $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->scopeConfig = $this->getMock(\Magento\Framework\App\Config::class, [], [], '', false); - $this->serializer = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class, [], [], '', false); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, [], [], '', false); $this->address = $objectManager->getObject( \Magento\Quote\Model\Quote\Address::class, diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php index b362aae263800..1811a2e4ce6a8 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php @@ -59,7 +59,7 @@ protected function setUp() '', false ); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); $serializer->expects($this->any()) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php index 5d95daf1673f5..ebf857fd0f1fa 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/UpdaterTest.php @@ -39,7 +39,7 @@ class UpdaterTest extends \PHPUnit_Framework_TestCase protected $productMock; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -99,7 +99,7 @@ protected function setUp() '', false ); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->setMethods(['serialize']) ->getMockForAbstractClass(); @@ -330,7 +330,7 @@ public function testUpdateUnsetCustomPrice() ); $buyRequestMock->expects($this->never())->method('setCustomPrice'); $buyRequestMock->expects($this->once())->method('getData')->will($this->returnValue([])); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->setMethods(['serialize']) ->getMockForAbstractClass(); $serializer->expects($this->any()) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php index f14ffb10b4a00..b012d7db61f00 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php @@ -62,7 +62,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase protected $stockRegistry; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -139,7 +139,7 @@ protected function setUp() ->method('getStockItem') ->will($this->returnValue($this->stockItemMock)); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->setMethods(['unserialize']) ->getMockForAbstractClass(); diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/PaymentTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/PaymentTest.php index 8473f62f88366..b710dba828a4c 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/PaymentTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/PaymentTest.php @@ -41,7 +41,7 @@ protected function setUp() )->disableOriginalConstructor() ->getMock(); $this->eventManager = $this->getMock(ManagerInterface::class); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); $serializer->expects($this->any()) diff --git a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php index edee3051f55f0..951fef40b8e35 100644 --- a/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php +++ b/app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php @@ -34,7 +34,7 @@ class DownloadCustomOption extends \Magento\Framework\App\Action\Action protected $unserialize; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -43,21 +43,21 @@ class DownloadCustomOption extends \Magento\Framework\App\Action\Action * @param ForwardFactory $resultForwardFactory * @param \Magento\Sales\Model\Download $download * @param \Magento\Framework\Unserialize\Unserialize $unserialize - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( Context $context, ForwardFactory $resultForwardFactory, \Magento\Sales\Model\Download $download, \Magento\Framework\Unserialize\Unserialize $unserialize, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { parent::__construct($context); $this->resultForwardFactory = $resultForwardFactory; $this->download = $download; $this->unserialize = $unserialize; $this->serializer = $serializer ?: ObjectManager::getInstance()->get( - \Magento\Framework\Serialize\SerializerInterface::class + \Magento\Framework\Serialize\Serializer\Json::class ); } diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index 027be39e7c65f..a64d081ffd160 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -227,7 +227,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -260,7 +260,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\ * @param \Magento\Sales\Api\OrderManagementInterface $orderManagement * @param \Magento\Quote\Model\QuoteFactory $quoteFactory * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -292,7 +292,7 @@ public function __construct( \Magento\Sales\Api\OrderManagementInterface $orderManagement, \Magento\Quote\Model\QuoteFactory $quoteFactory, array $data = [], - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->_objectManager = $objectManager; $this->_eventManager = $eventManager; @@ -322,7 +322,7 @@ public function __construct( $this->orderManagement = $orderManagement; $this->quoteFactory = $quoteFactory; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct($data); } diff --git a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php index 37f71d2d9fa2c..75f100a93e4a3 100644 --- a/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php +++ b/app/code/Magento/Sales/Model/Order/CreditmemoFactory.php @@ -29,7 +29,7 @@ class CreditmemoFactory protected $unserialize; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -38,17 +38,17 @@ class CreditmemoFactory * * @param \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory * @param \Magento\Tax\Model\Config $taxConfig - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory, \Magento\Tax\Model\Config $taxConfig, - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->convertor = $convertOrderFactory->create(); $this->taxConfig = $taxConfig; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get( - \Magento\Framework\Serialize\SerializerInterface::class + \Magento\Framework\Serialize\Serializer\Json::class ); } diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index 4d2412b97cf9e..caf3352de0ee0 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -98,7 +98,7 @@ class Item extends AbstractModel implements OrderItemInterface /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -115,7 +115,7 @@ class Item extends AbstractModel implements OrderItemInterface * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -129,7 +129,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { parent::__construct( $context, @@ -141,7 +141,7 @@ public function __construct( $data ); $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); $this->_orderFactory = $orderFactory; $this->_storeManager = $storeManager; $this->productRepository = $productRepository; diff --git a/app/code/Magento/Sales/Model/Order/ShipmentFactory.php b/app/code/Magento/Sales/Model/Order/ShipmentFactory.php index 73331b203d996..c08ca3503f509 100644 --- a/app/code/Magento/Sales/Model/Order/ShipmentFactory.php +++ b/app/code/Magento/Sales/Model/Order/ShipmentFactory.php @@ -8,7 +8,7 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\Sales\Model\Order\Shipment\ShipmentValidatorInterface; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; /** * Factory class for @see \Magento\Sales\Api\Data\ShipmentInterface @@ -39,7 +39,7 @@ class ShipmentFactory /** * Serializer * - * @var SerializerInterface + * @var Json */ private $serializer; @@ -48,12 +48,12 @@ class ShipmentFactory * * @param \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory * @param \Magento\Sales\Model\Order\Shipment\TrackFactory $trackFactory - * @param \Magento\Framework\Serialize\SerializerInterface $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Sales\Model\Convert\OrderFactory $convertOrderFactory, \Magento\Sales\Model\Order\Shipment\TrackFactory $trackFactory, - SerializerInterface $serializer = null + Json $serializer = null ) { $this->converter = $convertOrderFactory->create(); $this->trackFactory = $trackFactory; diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php index 192cefec7d13e..fd6b82e332023 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php @@ -6,7 +6,7 @@ namespace Magento\Sales\Test\Unit\Controller\Download; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\Unserialize\Unserialize; /** diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php index 78e0127b9a4f0..15791fb32ffb9 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php @@ -6,7 +6,7 @@ namespace Magento\Sales\Test\Unit\Model\Order; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Sales\Model\ResourceModel\OrderFactory; use \Magento\Sales\Model\Order; @@ -33,7 +33,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase protected $orderFactory; /** - * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var Json|\PHPUnit_Framework_MockObject_MockObject */ private $serializerMock; diff --git a/app/code/Magento/Tax/Helper/Data.php b/app/code/Magento/Tax/Helper/Data.php index 5659275fc2896..25773fbdc8870 100644 --- a/app/code/Magento/Tax/Helper/Data.php +++ b/app/code/Magento/Tax/Helper/Data.php @@ -18,7 +18,7 @@ use Magento\Sales\Model\Order\Creditmemo; use Magento\Tax\Api\Data\OrderTaxDetailsItemInterface; use Magento\Sales\Model\EntityInterface; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\App\ObjectManager; /** @@ -97,7 +97,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper protected $priceCurrency; /** - * @var SerializerInterface + * @var Json */ private $serializer; @@ -112,7 +112,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper * @param \Magento\Catalog\Helper\Data $catalogHelper * @param OrderTaxManagementInterface $orderTaxManagement * @param PriceCurrencyInterface $priceCurrency - * @param SerializerInterface $serializer + * @param Json $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -126,7 +126,7 @@ public function __construct( \Magento\Catalog\Helper\Data $catalogHelper, OrderTaxManagementInterface $orderTaxManagement, PriceCurrencyInterface $priceCurrency, - SerializerInterface $serializer = null + Json $serializer = null ) { parent::__construct($context); $this->priceCurrency = $priceCurrency; diff --git a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php index 96c3b3ec00d09..0e94b9ebb71e1 100644 --- a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php +++ b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php @@ -6,7 +6,7 @@ namespace Magento\Tax\Model\Quote; use Magento\Quote\Api\Data\TotalSegmentExtensionFactory; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\App\ObjectManager; class GrandTotalDetailsPlugin @@ -37,7 +37,7 @@ class GrandTotalDetailsPlugin protected $code; /** - * @var SerializerInterface + * @var Json */ private $serializer; @@ -46,14 +46,14 @@ class GrandTotalDetailsPlugin * @param \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory * @param TotalSegmentExtensionFactory $totalSegmentExtensionFactory * @param \Magento\Tax\Model\Config $taxConfig - * @param SerializerInterface $serializer + * @param Json $serializer */ public function __construct( \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory, \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory, TotalSegmentExtensionFactory $totalSegmentExtensionFactory, \Magento\Tax\Model\Config $taxConfig, - SerializerInterface $serializer = null + Json $serializer = null ) { $this->detailsFactory = $detailsFactory; $this->ratesFactory = $ratesFactory; diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php index f8999419dccec..cccc058a65d36 100755 --- a/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php +++ b/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php @@ -11,7 +11,7 @@ use Magento\Tax\Api\Data\TaxClassKeyInterface; use Magento\Tax\Model\Calculation; use Magento\Quote\Api\Data\ShippingAssignmentInterface; -use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\App\ObjectManager; /** @@ -49,7 +49,7 @@ class Tax extends CommonTaxCollector protected $_discountTaxCompensationes = []; /** - * @var SerializerInterface + * @var Json */ private $serializer; @@ -64,7 +64,7 @@ class Tax extends CommonTaxCollector * @param CustomerAddressFactory $customerAddressFactory * @param CustomerAddressRegionFactory $customerAddressRegionFactory * @param \Magento\Tax\Helper\Data $taxData - * @param SerializerInterface $serializer + * @param Json $serializer */ public function __construct( \Magento\Tax\Model\Config $taxConfig, @@ -75,7 +75,7 @@ public function __construct( CustomerAddressFactory $customerAddressFactory, CustomerAddressRegionFactory $customerAddressRegionFactory, \Magento\Tax\Helper\Data $taxData, - SerializerInterface $serializer = null + Json $serializer = null ) { $this->setCode('tax'); $this->_taxData = $taxData; diff --git a/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php b/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php index a5536960f5d19..7a292fdaedb54 100644 --- a/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php +++ b/app/code/Magento/Tax/Test/Unit/Helper/DataTest.php @@ -47,7 +47,7 @@ protected function setUp() $this->taxConfigMock = $this->getMockBuilder(\Magento\Tax\Model\Config::class) ->disableOriginalConstructor() ->getMock(); - $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMock(); $this->serializer->expects($this->any()) diff --git a/app/code/Magento/Tax/Test/Unit/Model/Quote/GrandTotalDetailsPluginTest.php b/app/code/Magento/Tax/Test/Unit/Model/Quote/GrandTotalDetailsPluginTest.php index 21a2209390d85..1b2e269e7add4 100644 --- a/app/code/Magento/Tax/Test/Unit/Model/Quote/GrandTotalDetailsPluginTest.php +++ b/app/code/Magento/Tax/Test/Unit/Model/Quote/GrandTotalDetailsPluginTest.php @@ -75,7 +75,7 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php b/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php index 2f5850f336124..749ee1424d503 100644 --- a/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php +++ b/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php @@ -614,7 +614,7 @@ public function testFetch($appliedTaxesData, $addressData) $objectManager = new ObjectManager($this); - $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\SerializerInterface::class) + $serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/Wishlist/Model/Item.php b/app/code/Magento/Wishlist/Model/Item.php index 954ce98b4abbc..2db7ff7ac2032 100644 --- a/app/code/Magento/Wishlist/Model/Item.php +++ b/app/code/Magento/Wishlist/Model/Item.php @@ -123,7 +123,7 @@ class Item extends AbstractModel implements ItemInterface /** * Serializer interface instance. * - * @var \Magento\Framework\Serialize\SerializerInterface + * @var \Magento\Framework\Serialize\Serializer\Json */ private $serializer; @@ -140,7 +140,7 @@ class Item extends AbstractModel implements ItemInterface * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\SerializerInterface|null $serializer + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -156,7 +156,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - \Magento\Framework\Serialize\SerializerInterface $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->productTypeConfig = $productTypeConfig; $this->_storeManager = $storeManager; @@ -165,7 +165,7 @@ public function __construct( $this->_wishlistOptFactory = $wishlistOptFactory; $this->_wishlOptionCollectionFactory = $wishlOptionCollectionFactory; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\Serialize\SerializerInterface::class); + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct($context, $registry, $resource, $resourceCollection, $data); $this->productRepository = $productRepository; } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php index 8f88186753030..17c29a4e82ad3 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Type/AbstractTypeTest.php @@ -36,7 +36,7 @@ protected function setUp() $registry = $this->getMock(\Magento\Framework\Registry::class, [], [], '', false); $logger = $this->getMock(\Psr\Log\LoggerInterface::class, [], [], '', false); $serializer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - \Magento\Framework\Serialize\SerializerInterface::class + \Magento\Framework\Serialize\Serializer\Json::class ); $this->_model = $this->getMockForAbstractClass( \Magento\Catalog\Model\Product\Type\AbstractType::class, diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php index e480f982bd6b1..f1759a9eb0c4b 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_payment_saved.php @@ -6,8 +6,8 @@ require 'quote_with_address.php'; -/** @var \Magento\Framework\Serialize\SerializerInterface $serializer */ -$serializer = $objectManager->create(\Magento\Framework\Serialize\SerializerInterface::class); +/** @var \Magento\Framework\Serialize\Serializer\Json $serializer */ +$serializer = $objectManager->create(\Magento\Framework\Serialize\Serializer\Json::class); $quote->setReservedOrderId( 'test_order_1_with_payment' diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php index 7058188a3efbd..69179686d3ee4 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php @@ -293,8 +293,8 @@ public function testGetProductByAttributes() */ public function testGetSelectedAttributesInfo() { - /** @var $serializer \Magento\Framework\Serialize\SerializerInterface */ - $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\SerializerInterface::class); + /** @var $serializer \Magento\Framework\Serialize\Serializer\Json */ + $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\Serializer\Json::class); $product = $this->productRepository->getById(1, true); $attributes = $this->model->getConfigurableAttributesAsArray($product); @@ -317,8 +317,8 @@ public function testGetSelectedAttributesInfo() */ public function testGetSelectedAttributesInfoForStore() { - /** @var $serializer \Magento\Framework\Serialize\SerializerInterface */ - $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\SerializerInterface::class); + /** @var $serializer \Magento\Framework\Serialize\Serializer\Json */ + $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\Serializer\Json::class); $attributes = $this->model->getConfigurableAttributesAsArray($this->product); diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index 3e801ef5e0570..ea76d4eebe156 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -61,8 +61,8 @@ public function testInitFromOrderShippingAddressSameAsBillingWhenEmpty() */ public function testInitFromOrderAndCreateOrderFromQuoteWithAdditionalOptions() { - /** @var $serializer \Magento\Framework\Serialize\SerializerInterface */ - $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\SerializerInterface::class); + /** @var $serializer \Magento\Framework\Serialize\Serializer\Json */ + $serializer = Bootstrap::getObjectManager()->create(\Magento\Framework\Serialize\Serializer\Json::class); /** @var $order \Magento\Sales\Model\Order */ $order = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class); From cf9812580dcb5deed3114599b55e2fb82b0d71d3 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 23 Dec 2016 20:05:25 +0200 Subject: [PATCH 113/132] MAGETWO-62650: Replace SerializerIntreface with Json implementation --- .../Test/Unit/Controller/Download/DownloadCustomOptionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php index fd6b82e332023..b7ceaf727edb0 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Download/DownloadCustomOptionTest.php @@ -92,7 +92,7 @@ protected function setUp() ->setMethods(['downloadFile']) ->getMock(); - $this->serializerMock = $this->getMockBuilder(SerializerInterface::class) + $this->serializerMock = $this->getMockBuilder(Json::class) ->disableOriginalConstructor() ->setMethods(['serialize', 'unserialize']) ->getMock(); From 760ceeb7042db53236898c7b03648427bb7cf5ee Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 23 Dec 2016 20:21:57 +0200 Subject: [PATCH 114/132] MAGETWO-62650: Replace SerializerIntreface with Json implementation --- .../Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php | 2 +- .../Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php | 2 +- app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php | 2 +- .../Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php | 2 +- app/code/Magento/Catalog/Helper/Product/Configuration.php | 2 +- app/code/Magento/Catalog/Model/Product/Option/Type/File.php | 2 +- .../ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php | 2 +- app/code/Magento/Quote/Model/Quote/Address.php | 2 +- app/code/Magento/Sales/Model/Order/ShipmentFactory.php | 2 +- app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php | 2 +- app/code/Magento/Tax/Helper/Data.php | 2 +- app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php | 2 +- app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php index 06fb993cc5fc2..914da1144bc0b 100644 --- a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php @@ -37,7 +37,7 @@ public function __construct( Json $serializer = null ) { $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(SerializerInterface::class); + ->get(Json::class); parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data); } diff --git a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php index 078b3ecfb4476..0cb7cc0b45ad5 100644 --- a/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php @@ -41,7 +41,7 @@ public function __construct( Json $serializer = null ) { $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(SerializerInterface::class); + ->get(Json::class); parent::__construct( $context, diff --git a/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php b/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php index fbf04ecdb93db..a8e85e6c5fa66 100644 --- a/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php +++ b/app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php @@ -37,7 +37,7 @@ public function __construct( Json $serializer = null ) { $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(SerializerInterface::class); + ->get(Json::class); parent::__construct($context, $string, $productOptionFactory, $data); } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index ad6d342b6e596..d1d5e44f077b8 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -298,7 +298,7 @@ public function canShowPriceInfo($item) private function getSerializer() { if ($this->serializer === null) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); } return $this->serializer; } diff --git a/app/code/Magento/Catalog/Helper/Product/Configuration.php b/app/code/Magento/Catalog/Helper/Product/Configuration.php index c95c25229e3ec..2e8290a1ed2ad 100644 --- a/app/code/Magento/Catalog/Helper/Product/Configuration.php +++ b/app/code/Magento/Catalog/Helper/Product/Configuration.php @@ -60,7 +60,7 @@ public function __construct( $this->_productOptionFactory = $productOptionFactory; $this->filter = $filter; $this->string = $string; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct($context); } diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php index 4ec15a0c145aa..865e57f9b71f0 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/File.php @@ -117,7 +117,7 @@ public function __construct( $this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); $this->validatorInfo = $validatorInfo; $this->validatorFile = $validatorFile; - $this->serializer = $serializer ? $serializer : ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = $serializer ? $serializer : ObjectManager::getInstance()->get(Json::class); parent::__construct($checkoutSession, $scopeConfig, $data); } diff --git a/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php b/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php index 2011a95bd77f8..a4ff02482b019 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php +++ b/app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php @@ -55,7 +55,7 @@ public function __construct( $this->productOptionFactory = $productOptionFactory; $this->extensionFactory = $extensionFactory; $this->itemOptionValueFactory = $itemOptionValueFactory; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** diff --git a/app/code/Magento/Quote/Model/Quote/Address.php b/app/code/Magento/Quote/Model/Quote/Address.php index 0420ead089529..b1126549e3bcf 100644 --- a/app/code/Magento/Quote/Model/Quote/Address.php +++ b/app/code/Magento/Quote/Model/Quote/Address.php @@ -328,7 +328,7 @@ public function __construct( $this->attributeList = $attributeList; $this->totalsCollector = $totalsCollector; $this->totalsReader = $totalsReader; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct( $context, $registry, diff --git a/app/code/Magento/Sales/Model/Order/ShipmentFactory.php b/app/code/Magento/Sales/Model/Order/ShipmentFactory.php index c08ca3503f509..cde0efcb8e0fe 100644 --- a/app/code/Magento/Sales/Model/Order/ShipmentFactory.php +++ b/app/code/Magento/Sales/Model/Order/ShipmentFactory.php @@ -59,7 +59,7 @@ public function __construct( $this->trackFactory = $trackFactory; $this->instanceName = \Magento\Sales\Api\Data\ShipmentInterface::class; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(SerializerInterface::class); + ->get(Json::class); } /** diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php index 15791fb32ffb9..b40fc6c7f5916 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php @@ -43,7 +43,7 @@ protected function setUp() $this->orderFactory = $this->getMock(\Magento\Sales\Model\OrderFactory::class, ['create'], [], '', false); - $this->serializerMock = $this->getMock(SerializerInterface::class, [], ['unserialize'], '', false); + $this->serializerMock = $this->getMock(Json::class, [], ['unserialize'], '', false); $arguments = [ 'orderFactory' => $this->orderFactory, diff --git a/app/code/Magento/Tax/Helper/Data.php b/app/code/Magento/Tax/Helper/Data.php index 25773fbdc8870..3d5179b8f617a 100644 --- a/app/code/Magento/Tax/Helper/Data.php +++ b/app/code/Magento/Tax/Helper/Data.php @@ -138,7 +138,7 @@ public function __construct( $this->_localeResolver = $localeResolver; $this->catalogHelper = $catalogHelper; $this->orderTaxManagement = $orderTaxManagement; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** diff --git a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php index 0e94b9ebb71e1..5df42af4493de 100644 --- a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php +++ b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php @@ -60,7 +60,7 @@ public function __construct( $this->totalSegmentExtensionFactory = $totalSegmentExtensionFactory; $this->taxConfig = $taxConfig; $this->code = 'tax'; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php index cccc058a65d36..819f5a06349ea 100755 --- a/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php +++ b/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php @@ -79,7 +79,7 @@ public function __construct( ) { $this->setCode('tax'); $this->_taxData = $taxData; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct( $taxConfig, $taxCalculationService, From 0df87fc6e448ab903c1458d046f788de0bc8b51c Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Fri, 23 Dec 2016 14:30:40 -0600 Subject: [PATCH 115/132] MAGETWO-62610: Data upgrade fails on multi-database setup Refactoring --- .../Setup/ConvertSerializedDataToJson.php | 128 ++++++++++++++++++ app/code/Magento/Quote/Setup/QuoteSetup.php | 37 +++-- app/code/Magento/Quote/Setup/UpgradeData.php | 112 ++------------- .../Setup/ConvertSerializedDataToJson.php | 87 ++++++++++++ app/code/Magento/Sales/Setup/SalesSetup.php | 49 +++++-- app/code/Magento/Sales/Setup/UpgradeData.php | 61 ++------- 6 files changed, 302 insertions(+), 172 deletions(-) create mode 100644 app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php create mode 100644 app/code/Magento/Sales/Setup/ConvertSerializedDataToJson.php diff --git a/app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php b/app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php new file mode 100644 index 0000000000000..b95632ab197ce --- /dev/null +++ b/app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php @@ -0,0 +1,128 @@ +quoteSetup = $quoteSetup; + $this->fieldDataConverterFactory = $fieldDataConverterFactory; + $this->queryModifierFactory = $queryModifierFactory; + $this->queryGenerator = $queryGenerator; + } + + /** + * Convert data for additional_information field in quote_payment table from serialized + * to JSON format + * + * @return void + * @throws \InvalidArgumentException + */ + public function convert() + { + $fieldDataConverter = $this->fieldDataConverterFactory->create( + \Magento\Framework\DB\DataConverter\SerializedToJson::class + ); + $fieldDataConverter->convert( + $this->quoteSetup->getConnection(), + $this->quoteSetup->getTable('quote_payment'), + 'payment_id', + 'additional_information' + ); + $queryModifier = $this->queryModifierFactory->create( + 'in', + [ + 'values' => [ + 'code' => [ + 'parameters', + 'info_buyRequest', + 'bundle_option_ids', + 'bundle_selection_attributes', + ] + ] + ] + ); + $fieldDataConverter->convert( + $this->quoteSetup->getConnection(), + $this->quoteSetup->getTable('quote_item_option'), + 'option_id', + 'value', + $queryModifier + ); + $select = $this->quoteSetup->getSetup() + ->getConnection() + ->select() + ->from( + $this->quoteSetup->getSetup() + ->getTable('catalog_product_option'), + ['option_id'] + ) + ->where('type = ?', 'file'); + $iterator = $this->queryGenerator->generate('option_id', $select); + foreach ($iterator as $selectByRange) { + $codes = $this->quoteSetup->getSetup() + ->getConnection() + ->fetchCol($selectByRange); + $codes = array_map( + function ($id) { + return 'option_' . $id; + }, + $codes + ); + $queryModifier = $this->queryModifierFactory->create( + 'in', + [ + 'values' => [ + 'code' => $codes + ] + ] + ); + $fieldDataConverter->convert( + $this->quoteSetup->getConnection(), + $this->quoteSetup->getTable('quote_item_option'), + 'option_id', + 'value', + $queryModifier + ); + } + } +} diff --git a/app/code/Magento/Quote/Setup/QuoteSetup.php b/app/code/Magento/Quote/Setup/QuoteSetup.php index 1ef5f4b0dae2e..9b9aaa78b1e10 100644 --- a/app/code/Magento/Quote/Setup/QuoteSetup.php +++ b/app/code/Magento/Quote/Setup/QuoteSetup.php @@ -13,7 +13,8 @@ use Magento\Framework\Setup\ModuleDataSetupInterface; /** - * Setup Model of Quote Module + * Quote module setup class + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @codeCoverageIgnore */ @@ -75,9 +76,9 @@ public function __construct( */ protected function _flatTableExist($table) { - $tablesList = $this->getSetup()->getConnection(self::$connectionName)->listTables(); + $tablesList = $this->getConnection()->listTables(); return in_array( - strtoupper($this->getSetup()->getTable($table, self::$connectionName)), + strtoupper($this->getTable($table)), array_map('strtoupper', $tablesList) ); } @@ -115,15 +116,14 @@ public function addAttribute($entityTypeId, $code, array $attr) */ protected function _addFlatAttribute($table, $attribute, $attr) { - $tableInfo = $this->getSetup() - ->getConnection(self::$connectionName) - ->describeTable($this->getSetup()->getTable($table, self::$connectionName)); + $tableInfo = $this->getConnection() + ->describeTable($this->getTable($table)); if (isset($tableInfo[$attribute])) { return $this; } $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr); - $this->getSetup()->getConnection(self::$connectionName)->addColumn( - $this->getSetup()->getTable($table, self::$connectionName), + $this->getConnection()->addColumn( + $this->getTable($table), $attribute, $columnDefinition ); @@ -195,4 +195,25 @@ public function getEncryptor() { return $this->_encryptor; } + + /** + * Get quote connection + * + * @return \Magento\Framework\DB\Adapter\AdapterInterface + */ + public function getConnection() + { + return $this->getSetup()->getConnection(self::$connectionName); + } + + /** + * Get table name for + * + * @param string $table + * @return string + */ + public function getTable($table) + { + return $this->getSetup()->getTable($table, self::$connectionName); + } } diff --git a/app/code/Magento/Quote/Setup/UpgradeData.php b/app/code/Magento/Quote/Setup/UpgradeData.php index 9ec643e100e84..5b9e3482081cd 100644 --- a/app/code/Magento/Quote/Setup/UpgradeData.php +++ b/app/code/Magento/Quote/Setup/UpgradeData.php @@ -8,48 +8,31 @@ use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Framework\DB\FieldDataConverterFactory; -use Magento\Framework\DB\DataConverter\SerializedToJson; -use Magento\Framework\DB\Select\QueryModifierFactory; -use Magento\Framework\DB\Query\Generator; class UpgradeData implements UpgradeDataInterface { /** - * Name of the database connection + * @var QuoteSetupFactory */ - const CONNECTION_NAME = 'checkout'; + private $quoteSetupFactory; /** - * @var FieldDataConverterFactory + * @var ConvertSerializedDataToJsonFactory */ - private $fieldDataConverterFactory; - - /** - * @var QueryModifierFactory - */ - private $queryModifierFactory; - - /** - * @var Generator - */ - private $queryGenerator; + private $convertSerializedDataToJsonFactory; /** * Constructor * - * @param FieldDataConverterFactory $fieldDataConverterFactory - * @param QueryModifierFactory $queryModifierFactory - * @param Generator $generator + * @param QuoteSetupFactory $quoteSetupFactory + * @param ConvertSerializedDataToJsonFactory $convertSerializedDataToJsonFactory */ public function __construct( - FieldDataConverterFactory $fieldDataConverterFactory, - QueryModifierFactory $queryModifierFactory, - Generator $queryGenerator + QuoteSetupFactory $quoteSetupFactory, + ConvertSerializedDataToJsonFactory $convertSerializedDataToJsonFactory ) { - $this->fieldDataConverterFactory = $fieldDataConverterFactory; - $this->queryModifierFactory = $queryModifierFactory; - $this->queryGenerator = $queryGenerator; + $this->quoteSetupFactory = $quoteSetupFactory; + $this->convertSerializedDataToJsonFactory = $convertSerializedDataToJsonFactory; } /** @@ -58,78 +41,9 @@ public function __construct( public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { if (version_compare($context->getVersion(), '2.0.4', '<')) { - $this->upgradeToVersionTwoZeroFour($setup); - } - } - - /** - * Upgrade to version 2.0.4, convert data for additional_information field in quote_payment table from serialized - * to JSON format - * - * @param ModuleDataSetupInterface $setup - * @return void - * @throws \InvalidArgumentException - */ - private function upgradeToVersionTwoZeroFour(ModuleDataSetupInterface $setup) - { - $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class); - $fieldDataConverter->convert( - $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('quote_payment', self::CONNECTION_NAME), - 'payment_id', - 'additional_information' - ); - $queryModifier = $this->queryModifierFactory->create( - 'in', - [ - 'values' => [ - 'code' => [ - 'parameters', - 'info_buyRequest', - 'bundle_option_ids', - 'bundle_selection_attributes', - ] - ] - ] - ); - $fieldDataConverter->convert( - $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('quote_item_option', self::CONNECTION_NAME), - 'option_id', - 'value', - $queryModifier - ); - $select = $setup->getConnection() - ->select() - ->from( - $setup->getTable('catalog_product_option'), - ['option_id'] - ) - ->where('type = ?', 'file'); - $iterator = $this->queryGenerator->generate('option_id', $select); - foreach ($iterator as $selectByRange) { - $codes = $setup->getConnection()->fetchCol($selectByRange); - $codes = array_map( - function ($id) { - return 'option_' . $id; - }, - $codes - ); - $queryModifier = $this->queryModifierFactory->create( - 'in', - [ - 'values' => [ - 'code' => $codes - ] - ] - ); - $fieldDataConverter->convert( - $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('quote_item_option', self::CONNECTION_NAME), - 'option_id', - 'value', - $queryModifier - ); + $quoteSetup = $this->quoteSetupFactory->create(['setup' => $setup]); + $this->convertSerializedDataToJsonFactory->create(['quoteSetup' => $quoteSetup]) + ->convert(); } } } diff --git a/app/code/Magento/Sales/Setup/ConvertSerializedDataToJson.php b/app/code/Magento/Sales/Setup/ConvertSerializedDataToJson.php new file mode 100644 index 0000000000000..52047d0e59dc6 --- /dev/null +++ b/app/code/Magento/Sales/Setup/ConvertSerializedDataToJson.php @@ -0,0 +1,87 @@ + 'sales_order_item', + 'identifier' => 'item_id', + 'title' => 'product_options' + ], + [ + 'table' => 'sales_shipment', + 'identifier' => 'entity_id', + 'title' => 'packages' + ], + [ + 'table' => 'sales_order_payment', + 'identifier' => 'entity_id', + 'title' => 'additional_information' + ], + [ + 'table' => 'sales_payment_transaction', + 'identifier' => 'transaction_id', + 'title' => 'additional_information' + ] + ]; + + /** + * Constructor + * + * @param SalesSetup $salesSetup + * @param FieldDataConverterFactory $fieldDataConverterFactory + */ + public function __construct( + SalesSetup $salesSetup, + FieldDataConverterFactory $fieldDataConverterFactory + ) { + $this->salesSetup = $salesSetup; + $this->fieldDataConverterFactory = $fieldDataConverterFactory; + } + + /** + * Convert data for the following fields from serialized to JSON format: + * sales_order_item.product_options + * sales_shipment.packages + * sales_order_payment.additional_information + * sales_payment_transaction.additional_information + * + * @return void + */ + public function convert() + { + $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class); + foreach ($this->fieldsToUpdate as $field) { + $fieldDataConverter->convert( + $this->salesSetup->getConnection(), + $this->salesSetup->getTable($field['table']), + $field['identifier'], + $field['title'] + ); + } + } +} diff --git a/app/code/Magento/Sales/Setup/SalesSetup.php b/app/code/Magento/Sales/Setup/SalesSetup.php index 3a2c999678a03..b8e73f32cf880 100644 --- a/app/code/Magento/Sales/Setup/SalesSetup.php +++ b/app/code/Magento/Sales/Setup/SalesSetup.php @@ -11,13 +11,15 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Encryption\EncryptorInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; +use Magento\Eav\Setup\EavSetup; /** - * Setup Model of Sales Module - * @codeCoverageIgnore + * Sales module setup class + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @codeCoverageIgnore */ -class SalesSetup extends \Magento\Eav\Setup\EavSetup +class SalesSetup extends EavSetup { /** * This should be set explicitly @@ -55,6 +57,8 @@ class SalesSetup extends \Magento\Eav\Setup\EavSetup private static $connectionName = 'sales'; /** + * Constructor + * * @param ModuleDataSetupInterface $setup * @param Context $context * @param CacheInterface $cache @@ -111,9 +115,10 @@ public function __construct( */ protected function _flatTableExist($table) { - $tablesList = $this->getSetup()->getConnection(self::$connectionName)->listTables(); + $tablesList = $this->getConnection() + ->listTables(); return in_array( - strtoupper($this->getSetup()->getTable($table, self::$connectionName)), + strtoupper($this->getTable($table)), array_map('strtoupper', $tablesList) ); } @@ -152,15 +157,14 @@ public function addAttribute($entityTypeId, $code, array $attr) */ protected function _addFlatAttribute($table, $attribute, $attr) { - $tableInfo = $this->getSetup() - ->getConnection(self::$connectionName) - ->describeTable($this->getSetup()->getTable($table, self::$connectionName)); + $tableInfo = $this->getConnection() + ->describeTable($this->getTable($table)); if (isset($tableInfo[$attribute])) { return $this; } $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr); - $this->getSetup()->getConnection(self::$connectionName)->addColumn( - $this->getSetup()->getTable($table, self::$connectionName), + $this->getConnection()->addColumn( + $this->getTable($table), $attribute, $columnDefinition ); @@ -180,8 +184,8 @@ protected function _addGridAttribute($table, $attribute, $attr, $entityTypeId) { if (in_array($entityTypeId, $this->_flatEntitiesGrid) && !empty($attr['grid'])) { $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr); - $this->getSetup()->getConnection(self::$connectionName)->addColumn( - $this->getSetup()->getTable($table . '_grid', self::$connectionName), + $this->getConnection()->addColumn( + $this->getTable($table . '_grid'), $attribute, $columnDefinition ); @@ -297,4 +301,25 @@ public function getEncryptor() { return $this->encryptor; } + + /** + * Get quote connection + * + * @return \Magento\Framework\DB\Adapter\AdapterInterface + */ + public function getConnection() + { + return $this->getSetup()->getConnection(self::$connectionName); + } + + /** + * Get table name + * + * @param string $table + * @return string + */ + public function getTable($table) + { + return $this->getSetup()->getTable($table, self::$connectionName); + } } diff --git a/app/code/Magento/Sales/Setup/UpgradeData.php b/app/code/Magento/Sales/Setup/UpgradeData.php index 375c823697356..634f330a8834e 100644 --- a/app/code/Magento/Sales/Setup/UpgradeData.php +++ b/app/code/Magento/Sales/Setup/UpgradeData.php @@ -7,11 +7,6 @@ class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface { - /** - * Name of the database connection - */ - const CONNECTION_NAME = 'sales'; - /** * Sales setup factory * @@ -25,25 +20,25 @@ class UpgradeData implements \Magento\Framework\Setup\UpgradeDataInterface private $eavConfig; /** - * @var \Magento\Framework\DB\FieldDataConverterFactory + * @var \Magento\Sales\Setup\ConvertSerializedDataToJsonFactory */ - private $fieldDataConverterFactory; + private $convertSerializedDataToJsonFactory; /** * Constructor * * @param \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory + * @param \Magento\Sales\Setup\ConvertSerializedDataToJsonFactory $convertSerializedDataToJsonFactory * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory */ public function __construct( \Magento\Sales\Setup\SalesSetupFactory $salesSetupFactory, - \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory + \Magento\Sales\Setup\ConvertSerializedDataToJsonFactory $convertSerializedDataToJsonFactory, + \Magento\Eav\Model\Config $eavConfig ) { $this->salesSetupFactory = $salesSetupFactory; + $this->convertSerializedDataToJsonFactory = $convertSerializedDataToJsonFactory; $this->eavConfig = $eavConfig; - $this->fieldDataConverterFactory = $fieldDataConverterFactory; } /** @@ -58,7 +53,8 @@ public function upgrade( $this->upgradeToTwoZeroOne($salesSetup); } if (version_compare($context->getVersion(), '2.0.5', '<')) { - $this->upgradeToVersionTwoZeroFive($setup); + $this->convertSerializedDataToJsonFactory->create(['salesSetup' => $salesSetup]) + ->convert(); } $this->eavConfig->clear(); } @@ -112,45 +108,4 @@ private function upgradeToTwoZeroOne(\Magento\Sales\Setup\SalesSetup $setup) \Magento\Eav\Model\Entity\Increment\NumericValue::class ); } - - /** - * Upgrade to version 2.0.5, convert data for the following fields from serialized to JSON format: - * sales_order_item.product_options - * sales_shipment.packages - * sales_order_payment.additional_information - * sales_payment_transaction.additional_information - * - * @param \Magento\Framework\Setup\ModuleDataSetupInterface $setup - * @return void - */ - private function upgradeToVersionTwoZeroFive(\Magento\Framework\Setup\ModuleDataSetupInterface $setup) - { - $fieldDataConverter = $this->fieldDataConverterFactory->create( - \Magento\Framework\DB\DataConverter\SerializedToJson::class - ); - $fieldDataConverter->convert( - $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('sales_order_item', self::CONNECTION_NAME), - 'item_id', - 'product_options' - ); - $fieldDataConverter->convert( - $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('sales_shipment', self::CONNECTION_NAME), - 'entity_id', - 'packages' - ); - $fieldDataConverter->convert( - $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('sales_order_payment', self::CONNECTION_NAME), - 'entity_id', - 'additional_information' - ); - $fieldDataConverter->convert( - $setup->getConnection(self::CONNECTION_NAME), - $setup->getTable('sales_payment_transaction', self::CONNECTION_NAME), - 'transaction_id', - 'additional_information' - ); - } } From b2800d5adef2016729325801a459373f327973b3 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Fri, 23 Dec 2016 14:41:20 -0600 Subject: [PATCH 116/132] MAGETWO-62610: Data upgrade fails on multi-database setup Refactoring --- .../Setup/ConvertSerializedDataToJson.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php b/app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php index b95632ab197ce..6e8183b5769ca 100644 --- a/app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php +++ b/app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php @@ -5,44 +5,48 @@ */ namespace Magento\Quote\Setup; +use Magento\Framework\DB\FieldDataConverterFactory; +use Magento\Framework\DB\Select\QueryModifierFactory; +use Magento\Framework\DB\Query\Generator; + /** * Convert serialized data in quote tables to JSON */ class ConvertSerializedDataToJson { /** - * @var \Magento\Quote\Setup\QuoteSetup + * @var QuoteSetup */ private $quoteSetup; /** - * @var \Magento\Framework\DB\FieldDataConverterFactory + * @var FieldDataConverterFactory */ private $fieldDataConverterFactory; /** - * @var \Magento\Framework\DB\Select\QueryModifierFactory + * @var QueryModifierFactory */ private $queryModifierFactory; /** - * @var \Magento\Framework\DB\Query\Generator + * @var Generator */ private $queryGenerator; /** * Constructor * - * @param \Magento\Quote\Setup\QuoteSetup $quoteSetup - * @param \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory - * @param \Magento\Framework\DB\Select\QueryModifierFactory $queryModifierFactory - * @param \Magento\Framework\DB\Query\Generator $queryGenerator + * @param QuoteSetup $quoteSetup + * @param FieldDataConverterFactory $fieldDataConverterFactory + * @param QueryModifierFactory $queryModifierFactory + * @param Generator $queryGenerator */ public function __construct( - \Magento\Quote\Setup\QuoteSetup $quoteSetup, - \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory, - \Magento\Framework\DB\Select\QueryModifierFactory $queryModifierFactory, - \Magento\Framework\DB\Query\Generator $queryGenerator + QuoteSetup $quoteSetup, + FieldDataConverterFactory $fieldDataConverterFactory, + QueryModifierFactory $queryModifierFactory, + Generator $queryGenerator ) { $this->quoteSetup = $quoteSetup; $this->fieldDataConverterFactory = $fieldDataConverterFactory; From 30294fdc9205b441795eabe9c800fd9a5cb40289 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Mon, 26 Dec 2016 11:44:31 +0200 Subject: [PATCH 117/132] MAGETWO-62650: Replace SerializerIntreface with Json implementation --- .../Sales/Order/Pdf/Items/AbstractItems.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index d1d5e44f077b8..a8442144e3f62 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -43,7 +43,7 @@ public function __construct( array $data = [], Json $serializer = null ) { - $this->serializer = $serializer; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); parent::__construct( $context, @@ -202,7 +202,7 @@ public function getSelectionAttributes($item) $options = $item->getOrderItem()->getProductOptions(); } if (isset($options['bundle_selection_attributes'])) { - return $this->getSerializer()->unserialize($options['bundle_selection_attributes']); + return $this->serializer->unserialize($options['bundle_selection_attributes']); } return null; } @@ -287,19 +287,4 @@ public function canShowPriceInfo($item) } return false; } - - /** - * The getter function to get serializer - * - * @return Json - * - * @deprecated - */ - private function getSerializer() - { - if ($this->serializer === null) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); - } - return $this->serializer; - } } From 1708ef23d86f3849a441644857f113bf0f4cf978 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Mon, 26 Dec 2016 12:34:24 +0200 Subject: [PATCH 118/132] MAGETWO-62650: Replace SerializerIntreface with Json implementation --- .../Model/Sales/Order/Pdf/Items/Creditmemo.php | 9 +++++++-- .../Bundle/Model/Sales/Order/Pdf/Items/Invoice.php | 9 +++++++-- .../Bundle/Model/Sales/Order/Pdf/Items/Shipment.php | 9 +++++++-- .../Sales/Order/Pdf/Items/AbstractItemsTest.php | 13 ++++++------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index 2ac6e484bb5b5..fce6fbf035d9d 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -5,6 +5,8 @@ */ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; +use Magento\Framework\Serialize\Serializer\Json; + /** * Sales Order Creditmemo Pdf default items renderer */ @@ -27,6 +29,7 @@ class Creditmemo extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -37,7 +40,8 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + Json $serializer = null ) { $this->string = $string; parent::__construct( @@ -48,7 +52,8 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data + $data, + $serializer ); } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index 9b5d0b4a9c018..6c16bebe5ca70 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -8,6 +8,8 @@ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; +use Magento\Framework\Serialize\Serializer\Json; + /** * Sales Order Invoice Pdf default items renderer */ @@ -28,6 +30,7 @@ class Invoice extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -38,7 +41,8 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $coreString, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + Json $serializer = null ) { $this->string = $coreString; parent::__construct( @@ -49,7 +53,8 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data + $data, + $serializer ); } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index fec75878c3053..14772ab822290 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -5,6 +5,8 @@ */ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; +use Magento\Framework\Serialize\Serializer\Json; + /** * Sales Order Shipment Pdf items renderer */ @@ -25,6 +27,7 @@ class Shipment extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -35,7 +38,8 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + Json $serializer = null ) { $this->string = $string; parent::__construct( @@ -46,7 +50,8 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data + $data, + $serializer ); } diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php index 9038b070f588d..9a332b3aa2030 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php @@ -27,14 +27,13 @@ protected function setUp() ); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->model = $objectManager->getObject(\Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class); - $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class); - $reflection = new \ReflectionClass(\Magento\Bundle\Model\Sales\Order\Pdf\Items\AbstractItems::class); - $reflectionProperty = $reflection->getProperty('serializer'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($this->model, $this->serializer); - + $this->model = $objectManager->getObject( + \Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class, + [ + 'serializer' => $this->serializer, + ] + ); } /** From cbc0107ce4e6407dee2770117aa479a884adcadb Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Mon, 26 Dec 2016 13:46:57 +0200 Subject: [PATCH 119/132] MAGETWO-62650: Replace SerializerIntreface with Json implementation --- .../Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php | 6 ++---- .../Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php | 6 ++---- .../Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index fce6fbf035d9d..ead00ae0f0bc7 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -5,8 +5,6 @@ */ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; -use Magento\Framework\Serialize\Serializer\Json; - /** * Sales Order Creditmemo Pdf default items renderer */ @@ -29,7 +27,7 @@ class Creditmemo extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param Json $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -41,7 +39,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - Json $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->string = $string; parent::__construct( diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index 6c16bebe5ca70..eb43f30315e49 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -8,8 +8,6 @@ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; -use Magento\Framework\Serialize\Serializer\Json; - /** * Sales Order Invoice Pdf default items renderer */ @@ -30,7 +28,7 @@ class Invoice extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param Json $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -42,7 +40,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - Json $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->string = $coreString; parent::__construct( diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index 14772ab822290..1e2f2c6168d0a 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -5,8 +5,6 @@ */ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; -use Magento\Framework\Serialize\Serializer\Json; - /** * Sales Order Shipment Pdf items renderer */ @@ -27,7 +25,7 @@ class Shipment extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param Json $serializer + * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -39,7 +37,7 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], - Json $serializer = null + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->string = $string; parent::__construct( From 384d4472511834ce9b8a513ef69b61c118fcbcff Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Mon, 26 Dec 2016 14:34:04 +0200 Subject: [PATCH 120/132] MAGETWO-62650: Replace SerializerIntreface with Json implementation --- .../Sales/Order/Pdf/Items/AbstractItems.php | 19 +++++++++++++++++-- .../Sales/Order/Pdf/Items/Creditmemo.php | 7 ++----- .../Model/Sales/Order/Pdf/Items/Invoice.php | 7 ++----- .../Model/Sales/Order/Pdf/Items/Shipment.php | 7 ++----- .../Order/Pdf/Items/AbstractItemsTest.php | 13 +++++++------ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index a8442144e3f62..d1d5e44f077b8 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -43,7 +43,7 @@ public function __construct( array $data = [], Json $serializer = null ) { - $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); + $this->serializer = $serializer; parent::__construct( $context, @@ -202,7 +202,7 @@ public function getSelectionAttributes($item) $options = $item->getOrderItem()->getProductOptions(); } if (isset($options['bundle_selection_attributes'])) { - return $this->serializer->unserialize($options['bundle_selection_attributes']); + return $this->getSerializer()->unserialize($options['bundle_selection_attributes']); } return null; } @@ -287,4 +287,19 @@ public function canShowPriceInfo($item) } return false; } + + /** + * The getter function to get serializer + * + * @return Json + * + * @deprecated + */ + private function getSerializer() + { + if ($this->serializer === null) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); + } + return $this->serializer; + } } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index ead00ae0f0bc7..2ac6e484bb5b5 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -27,7 +27,6 @@ class Creditmemo extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -38,8 +37,7 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [], - \Magento\Framework\Serialize\Serializer\Json $serializer = null + array $data = [] ) { $this->string = $string; parent::__construct( @@ -50,8 +48,7 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data, - $serializer + $data ); } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index eb43f30315e49..9b5d0b4a9c018 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -28,7 +28,6 @@ class Invoice extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -39,8 +38,7 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $coreString, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [], - \Magento\Framework\Serialize\Serializer\Json $serializer = null + array $data = [] ) { $this->string = $coreString; parent::__construct( @@ -51,8 +49,7 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data, - $serializer + $data ); } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index 1e2f2c6168d0a..fec75878c3053 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -25,7 +25,6 @@ class Shipment extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -36,8 +35,7 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [], - \Magento\Framework\Serialize\Serializer\Json $serializer = null + array $data = [] ) { $this->string = $string; parent::__construct( @@ -48,8 +46,7 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data, - $serializer + $data ); } diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php index 9a332b3aa2030..9038b070f588d 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php @@ -27,13 +27,14 @@ protected function setUp() ); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->model = $objectManager->getObject(\Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class); + $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class); - $this->model = $objectManager->getObject( - \Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class, - [ - 'serializer' => $this->serializer, - ] - ); + $reflection = new \ReflectionClass(\Magento\Bundle\Model\Sales\Order\Pdf\Items\AbstractItems::class); + $reflectionProperty = $reflection->getProperty('serializer'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->model, $this->serializer); + } /** From d0c8a41f8fd5914618659a5d87a0a7be44a5c2ae Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 27 Dec 2016 13:31:32 -0600 Subject: [PATCH 121/132] MAGETWO-62610: Data upgrade fails on multi-database setup Changing method description --- app/code/Magento/Quote/Setup/QuoteSetup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Setup/QuoteSetup.php b/app/code/Magento/Quote/Setup/QuoteSetup.php index 9b9aaa78b1e10..cbd357d537fb1 100644 --- a/app/code/Magento/Quote/Setup/QuoteSetup.php +++ b/app/code/Magento/Quote/Setup/QuoteSetup.php @@ -207,7 +207,7 @@ public function getConnection() } /** - * Get table name for + * Get table name * * @param string $table * @return string From 0f32a098a93e0c6d7b1231a8c98d8080c1af88bb Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 27 Dec 2016 13:33:11 -0600 Subject: [PATCH 122/132] MAGETWO-62610: Data upgrade fails on multi-database setup Changing method description --- app/code/Magento/Sales/Setup/SalesSetup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Setup/SalesSetup.php b/app/code/Magento/Sales/Setup/SalesSetup.php index b8e73f32cf880..80b1ec4e8dc5f 100644 --- a/app/code/Magento/Sales/Setup/SalesSetup.php +++ b/app/code/Magento/Sales/Setup/SalesSetup.php @@ -303,7 +303,7 @@ public function getEncryptor() } /** - * Get quote connection + * Get sales connection * * @return \Magento\Framework\DB\Adapter\AdapterInterface */ From 9ee114f4f2ba9877e3e578abcd6e103663e5454b Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 27 Dec 2016 16:34:04 -0600 Subject: [PATCH 123/132] MAGETWO-62133: Create QueryModifier to select only options of type file and info_buyRequest Updating upgrade script --- app/code/Magento/Wishlist/Setup/UpgradeData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Wishlist/Setup/UpgradeData.php b/app/code/Magento/Wishlist/Setup/UpgradeData.php index 496db7f2caba5..440ac0d63d818 100644 --- a/app/code/Magento/Wishlist/Setup/UpgradeData.php +++ b/app/code/Magento/Wishlist/Setup/UpgradeData.php @@ -69,7 +69,7 @@ private function upgradeToVersionTwoZeroOne(ModuleDataSetupInterface $setup) { $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class); $queryModifier = $this->queryModifierFactory->create( - InQueryModifier::class, + 'in', [ 'values' => [ 'code' => [ From 4adcde5dfd9b2686e33583990a78a1a502f87b97 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 27 Dec 2016 16:37:03 -0600 Subject: [PATCH 124/132] MAGETWO-62133: Create QueryModifier to select only options of type file and info_buyRequest Updating upgrade script --- app/code/Magento/Wishlist/Setup/UpgradeData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Wishlist/Setup/UpgradeData.php b/app/code/Magento/Wishlist/Setup/UpgradeData.php index 440ac0d63d818..f18ca29acf333 100644 --- a/app/code/Magento/Wishlist/Setup/UpgradeData.php +++ b/app/code/Magento/Wishlist/Setup/UpgradeData.php @@ -107,7 +107,7 @@ function ($id) { $codes ); $queryModifier = $this->queryModifierFactory->create( - InQueryModifier::class, + 'in', [ 'values' => [ 'code' => $codes From e6225cca2d13c1b077776448687376bcf353de49 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 28 Dec 2016 10:51:32 -0600 Subject: [PATCH 125/132] MAGETWO-62134: Create data converter that can process nested serialized data Whitelisting usage of Magento\Framework\Serialize\Serializer\Serialize --- .../Magento/Test/Legacy/_files/restricted_classes.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php index 196112e437989..9c99bf96cf225 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php @@ -108,6 +108,11 @@ 'type' => 'setup', 'path' => 'src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php' ], + [ + 'type' => 'module', + 'name' => 'magento/sales', + 'path' => 'app/code/Magento/Sales/Setup/SerializedDataConverter.php' + ], ] ] ]; From b1bc6a397b8ebafa8b06f6edf96ec53bd05020b6 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 28 Dec 2016 11:49:22 -0600 Subject: [PATCH 126/132] MAGETWO-62134: Create data converter that can process nested serialized data Resolving code review feedback --- .../Sales/Order/Pdf/Items/AbstractItems.php | 27 ++++----------- .../Unit/Helper/Product/ConfigurationTest.php | 2 +- .../Quote/Model/Quote/Address/Total.php | 4 ++- app/code/Magento/Tax/Helper/Data.php | 33 +++++++++---------- 4 files changed, 27 insertions(+), 39 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index d1d5e44f077b8..ccba97b753b32 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -9,7 +9,8 @@ use Magento\Framework\Serialize\Serializer\Json; /** - * Sales Order Pdf Items renderer + * Order pdf items renderer + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ abstract class AbstractItems extends \Magento\Sales\Model\Order\Pdf\Items\AbstractItems @@ -22,10 +23,12 @@ abstract class AbstractItems extends \Magento\Sales\Model\Order\Pdf\Items\Abstra private $serializer; /** + * Constructor + * * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Tax\Helper\Data $taxData - * @param \Magento\Framework\Filesystem $filesystem , + * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\Filter\FilterManager $filterManager * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection @@ -43,8 +46,7 @@ public function __construct( array $data = [], Json $serializer = null ) { - $this->serializer = $serializer; - + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); parent::__construct( $context, $registry, @@ -202,7 +204,7 @@ public function getSelectionAttributes($item) $options = $item->getOrderItem()->getProductOptions(); } if (isset($options['bundle_selection_attributes'])) { - return $this->getSerializer()->unserialize($options['bundle_selection_attributes']); + return $this->serializer->unserialize($options['bundle_selection_attributes']); } return null; } @@ -287,19 +289,4 @@ public function canShowPriceInfo($item) } return false; } - - /** - * The getter function to get serializer - * - * @return Json - * - * @deprecated - */ - private function getSerializer() - { - if ($this->serializer === null) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); - } - return $this->serializer; - } } diff --git a/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php b/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php index 66a2b34686896..902f63c578ab6 100644 --- a/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php @@ -8,7 +8,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\Serialize\Serializer\Json | \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */ protected $serializer; diff --git a/app/code/Magento/Quote/Model/Quote/Address/Total.php b/app/code/Magento/Quote/Model/Quote/Address/Total.php index 499147b9bf747..cd7aa54e1497b 100644 --- a/app/code/Magento/Quote/Model/Quote/Address/Total.php +++ b/app/code/Magento/Quote/Model/Quote/Address/Total.php @@ -25,7 +25,9 @@ class Total extends \Magento\Framework\DataObject private $serializer; /** - * @param array $data [optional] + * Constructor + * + * @param array $data * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( diff --git a/app/code/Magento/Tax/Helper/Data.php b/app/code/Magento/Tax/Helper/Data.php index 3d5179b8f617a..0626b336b3321 100644 --- a/app/code/Magento/Tax/Helper/Data.php +++ b/app/code/Magento/Tax/Helper/Data.php @@ -3,9 +3,6 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ - -// @codingStandardsIgnoreFile - namespace Magento\Tax\Helper; use Magento\Framework\Pricing\PriceCurrencyInterface; @@ -22,9 +19,11 @@ use Magento\Framework\App\ObjectManager; /** - * Catalog data helper + * Tax helper + * * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @codingStandardsIgnoreFile */ class Data extends \Magento\Framework\App\Helper\AbstractHelper { @@ -80,9 +79,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper protected $_localeResolver; /** - * \Magento\Catalog\Helper\Data - * - * @var CatalogHelper + * @var \Magento\Catalog\Helper\Data */ protected $catalogHelper; @@ -102,17 +99,19 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper private $serializer; /** - * @param \Magento\Framework\App\Helper\Context $context - * @param \Magento\Framework\Json\Helper\Data $jsonHelper - * @param Config $taxConfig - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\Locale\FormatInterface $localeFormat + * Constructor + * + * @param \Magento\Framework\App\Helper\Context $context + * @param \Magento\Framework\Json\Helper\Data $jsonHelper + * @param Config $taxConfig + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\Locale\FormatInterface $localeFormat * @param \Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory $orderTaxCollectionFactory - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Catalog\Helper\Data $catalogHelper - * @param OrderTaxManagementInterface $orderTaxManagement - * @param PriceCurrencyInterface $priceCurrency - * @param Json $serializer + * @param \Magento\Framework\Locale\ResolverInterface $localeResolver + * @param \Magento\Catalog\Helper\Data $catalogHelper + * @param OrderTaxManagementInterface $orderTaxManagement + * @param PriceCurrencyInterface $priceCurrency + * @param Json $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( From abd634bb2dd1fb5cf807c37882f053610e4eb1be Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 28 Dec 2016 13:28:17 -0600 Subject: [PATCH 127/132] MAGETWO-62134: Create data converter that can process nested serialized data Resolving code review feedback --- .../Sales/Order/Pdf/Items/Creditmemo.php | 15 +++++++++++--- .../Model/Sales/Order/Pdf/Items/Invoice.php | 20 +++++++++++++------ .../Model/Sales/Order/Pdf/Items/Shipment.php | 15 +++++++++++--- .../Order/Pdf/Items/AbstractItemsTest.php | 13 ++++++------ 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index 2ac6e484bb5b5..c6f643b5afb8b 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -5,8 +5,11 @@ */ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Json; + /** - * Sales Order Creditmemo Pdf default items renderer + * Order creditmemo pdf default items renderer */ class Creditmemo extends AbstractItems { @@ -18,6 +21,8 @@ class Creditmemo extends AbstractItems protected $string; /** + * Constructor + * * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Tax\Helper\Data $taxData @@ -27,6 +32,7 @@ class Creditmemo extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -37,9 +43,11 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + Json $serializer = null ) { $this->string = $string; + $serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct( $context, $registry, @@ -48,7 +56,8 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data + $data, + $serializer ); } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index 9b5d0b4a9c018..89c84c623aad5 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -3,13 +3,15 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ - -// @codingStandardsIgnoreFile - namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Json; + /** - * Sales Order Invoice Pdf default items renderer + * Order invoice pdf default items renderer + * + * @codingStandardsIgnoreFile */ class Invoice extends AbstractItems { @@ -19,6 +21,8 @@ class Invoice extends AbstractItems protected $string; /** + * Constructor + * * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Tax\Helper\Data $taxData @@ -28,6 +32,7 @@ class Invoice extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -38,8 +43,10 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $coreString, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + Json $serializer = null ) { + $serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); $this->string = $coreString; parent::__construct( $context, @@ -49,7 +56,8 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data + $data, + $serializer ); } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index fec75878c3053..17aaadaf7f9f5 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -5,8 +5,11 @@ */ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Json; + /** - * Sales Order Shipment Pdf items renderer + * Order shipment pdf items renderer */ class Shipment extends AbstractItems { @@ -16,6 +19,8 @@ class Shipment extends AbstractItems protected $string; /** + * Constructor + * * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Tax\Helper\Data $taxData @@ -25,6 +30,7 @@ class Shipment extends AbstractItems * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer */ public function __construct( \Magento\Framework\Model\Context $context, @@ -35,9 +41,11 @@ public function __construct( \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + array $data = [], + Json $serializer = null ) { $this->string = $string; + $serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct( $context, $registry, @@ -46,7 +54,8 @@ public function __construct( $filterManager, $resource, $resourceCollection, - $data + $data, + $serializer ); } diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php index 9038b070f588d..b74deab061f24 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php @@ -27,14 +27,13 @@ protected function setUp() ); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->model = $objectManager->getObject(\Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class); - $this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class); - $reflection = new \ReflectionClass(\Magento\Bundle\Model\Sales\Order\Pdf\Items\AbstractItems::class); - $reflectionProperty = $reflection->getProperty('serializer'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($this->model, $this->serializer); - + $this->model = $objectManager->getObject( + \Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class, + [ + 'serializer' => $this->serializer + ] + ); } /** From 9a66bf9d9b82abb28e27b80d87fcbd707b393252 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 28 Dec 2016 13:36:45 -0600 Subject: [PATCH 128/132] MAGETWO-62134: Create data converter that can process nested serialized data Resolving code review feedback --- .../Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index ccba97b753b32..d96294eacc0b7 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -6,6 +6,7 @@ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; use Magento\Catalog\Model\Product\Type\AbstractType; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Serialize\Serializer\Json; /** @@ -46,7 +47,7 @@ public function __construct( array $data = [], Json $serializer = null ) { - $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct( $context, $registry, From 078ad97ab7d11d22f56b4181337f6ef0e1e7c36d Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 28 Dec 2016 13:52:35 -0600 Subject: [PATCH 129/132] MAGETWO-62134: Create data converter that can process nested serialized data Resolving code review feedback --- .../Tax/Model/Quote/GrandTotalDetailsPlugin.php | 17 +++++++++-------- .../Model/Product/Type/GroupedTest.php | 3 +-- .../Sales/Model/AdminOrder/CreateTest.php | 5 ++--- .../Magento/Sales/Model/Order/ItemTest.php | 3 +-- .../Magento/Wishlist/Model/ItemTest.php | 7 +------ 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php index 5df42af4493de..6340c697d1009 100644 --- a/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php +++ b/app/code/Magento/Tax/Model/Quote/GrandTotalDetailsPlugin.php @@ -14,27 +14,27 @@ class GrandTotalDetailsPlugin /** * @var \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory */ - protected $detailsFactory; + private $detailsFactory; /** * @var \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory */ - protected $ratesFactory; + private $ratesFactory; /** * @var TotalSegmentExtensionFactory */ - protected $totalSegmentExtensionFactory; + private $totalSegmentExtensionFactory; /** * @var \Magento\Tax\Model\Config */ - protected $taxConfig; + private $taxConfig; /** * @var string */ - protected $code; + private $code; /** * @var Json @@ -42,6 +42,8 @@ class GrandTotalDetailsPlugin private $serializer; /** + * Constructor + * * @param \Magento\Tax\Api\Data\GrandTotalDetailsInterfaceFactory $detailsFactory * @param \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory * @param TotalSegmentExtensionFactory $totalSegmentExtensionFactory @@ -53,14 +55,14 @@ public function __construct( \Magento\Tax\Api\Data\GrandTotalRatesInterfaceFactory $ratesFactory, TotalSegmentExtensionFactory $totalSegmentExtensionFactory, \Magento\Tax\Model\Config $taxConfig, - Json $serializer = null + Json $serializer ) { $this->detailsFactory = $detailsFactory; $this->ratesFactory = $ratesFactory; $this->totalSegmentExtensionFactory = $totalSegmentExtensionFactory; $this->taxConfig = $taxConfig; + $this->serializer = $serializer; $this->code = 'tax'; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** @@ -83,7 +85,6 @@ protected function getRatesData($rates) * @param \Magento\Quote\Model\Cart\TotalsConverter $subject * @param \Magento\Quote\Api\Data\TotalSegmentInterface[] $totalSegments * @param \Magento\Quote\Model\Quote\Address\Total[] $addressTotals - * * @return \Magento\Quote\Api\Data\TotalSegmentInterface[] * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @SuppressWarnings(PHPMD.CyclomaticComplexity) diff --git a/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php b/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php index 87e015a0a5215..97762b6c39c3c 100644 --- a/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php +++ b/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/Product/Type/GroupedTest.php @@ -82,10 +82,9 @@ private function assertProductInfo($product) } /** + * @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php * @magentoAppIsolation enabled * @magentoDbIsolation disabled - * @covers \Magento\GroupedProduct\Model\Product\Type\Grouped::_prepareProduct() - * @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php */ public function testPrepareProduct() { diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index ea76d4eebe156..acbbbef1b1ed6 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -508,9 +508,9 @@ public function testCreateOrderExistingCustomer() } /** - * @magentoAppIsolation enabled * @magentoDataFixture Magento/Sales/_files/quote.php * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoAppIsolation enabled */ public function testGetCustomerCartExistingCart() { @@ -535,10 +535,9 @@ public function testGetCustomerCartExistingCart() } /** - * @covers \Magento\Sales\Model\AdminOrder\Create::moveQuoteItem() - * @magentoAppIsolation enabled * @magentoDataFixture Magento/Sales/_files/quote.php * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoAppIsolation enabled */ public function testMoveQuoteItemToCart() { diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php index c05d0747973d8..2b0ec3bc7cac9 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Order/ItemTest.php @@ -12,10 +12,9 @@ class ItemTest extends \PHPUnit_Framework_TestCase { /** - * @covers \Magento\Sales\Model\Order\Item::getProductOptions - * @dataProvider getProductOptionsDataProvider * @param string $options * @param array $expectedData + * @dataProvider getProductOptionsDataProvider */ public function testGetProductOptions($options, $expectedData) { diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php b/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php index e46b8524b7b5e..004b605a7f1d7 100644 --- a/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php +++ b/dev/tests/integration/testsuite/Magento/Wishlist/Model/ItemTest.php @@ -31,11 +31,9 @@ public function setUp() } /** + * @magentoDataFixture Magento/Catalog/_files/product_simple.php * @magentoAppIsolation enabled * @magentoDbIsolation enabled - * @magentoDataFixture Magento/Catalog/_files/product_simple.php - * @covers \Magento\Wishlist\Model\Item::getBuyRequest() - * @covers \Magento\Wishlist\Model\Item::mergeBuyRequest() */ public function testBuyRequest() { @@ -64,9 +62,6 @@ public function testBuyRequest() ); } - /** - * @covers \Magento\Wishlist\Model\Item::setBuyRequest() - */ public function testSetBuyRequest() { $buyRequest = $this->objectManager->create( From 0068a8b7d16f65dd7eff88b5975acc2b4dfc91e4 Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 28 Dec 2016 14:15:48 -0600 Subject: [PATCH 130/132] MAGETWO-62134: Create data converter that can process nested serialized data Resolving code review feedback --- .../Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php | 2 +- app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php | 2 +- .../Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index c6f643b5afb8b..b9efefa03ebe1 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -33,6 +33,7 @@ class Creditmemo extends AbstractItems * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Framework\Model\Context $context, @@ -47,7 +48,6 @@ public function __construct( Json $serializer = null ) { $this->string = $string; - $serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct( $context, $registry, diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index 89c84c623aad5..e164ffa394a96 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -33,6 +33,7 @@ class Invoice extends AbstractItems * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Framework\Model\Context $context, @@ -46,7 +47,6 @@ public function __construct( array $data = [], Json $serializer = null ) { - $serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); $this->string = $coreString; parent::__construct( $context, diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index 17aaadaf7f9f5..0df79bd57b1b4 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -31,6 +31,7 @@ class Shipment extends AbstractItems * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Framework\Model\Context $context, @@ -45,7 +46,6 @@ public function __construct( Json $serializer = null ) { $this->string = $string; - $serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); parent::__construct( $context, $registry, From b723cb12d624e7d1d0e92bc112ee58ba71b2097c Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Wed, 28 Dec 2016 15:06:47 -0600 Subject: [PATCH 131/132] MAGETWO-62134: Create data converter that can process nested serialized data - Correctly whitelisting classes that use Magento\Framework\Serialize\Serializer\Serialize --- .../Magento/Test/Legacy/_files/restricted_classes.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php index 9c99bf96cf225..1c593657742f9 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/restricted_classes.php @@ -110,8 +110,13 @@ ], [ 'type' => 'module', - 'name' => 'magento/sales', - 'path' => 'app/code/Magento/Sales/Setup/SerializedDataConverter.php' + 'name' => 'Magento_Sales', + 'path' => 'Setup/SerializedDataConverter.php' + ], + [ + 'type' => 'module', + 'name' => 'Magento_Sales', + 'path' => 'Test/Unit/Setup/SerializedDataConverterTest.php' ], ] ] From 22df83cd5e6b2bab973a0ee2ac13a1a80c08cded Mon Sep 17 00:00:00 2001 From: Igor Melnikov Date: Tue, 3 Jan 2017 15:59:00 -0600 Subject: [PATCH 132/132] MAGETWO-62902: Bundle and custom options of type file not converted - Use \Magento\Sales\Setup\SerializedDataConverter for sales_order_item.product_options --- .../Setup/ConvertSerializedDataToJson.php | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Sales/Setup/ConvertSerializedDataToJson.php b/app/code/Magento/Sales/Setup/ConvertSerializedDataToJson.php index 52047d0e59dc6..7fe2e2743e132 100644 --- a/app/code/Magento/Sales/Setup/ConvertSerializedDataToJson.php +++ b/app/code/Magento/Sales/Setup/ConvertSerializedDataToJson.php @@ -7,6 +7,7 @@ use Magento\Framework\DB\FieldDataConverterFactory; use Magento\Framework\DB\DataConverter\SerializedToJson; +use Magento\Framework\DB\FieldDataConverter; /** * Convert serialized data in sales tables to JSON @@ -23,6 +24,11 @@ class ConvertSerializedDataToJson */ private $fieldDataConverterFactory; + /** + * @var array + */ + private $fieldDataConverters = []; + /** * @var array */ @@ -30,22 +36,26 @@ class ConvertSerializedDataToJson [ 'table' => 'sales_order_item', 'identifier' => 'item_id', - 'title' => 'product_options' + 'title' => 'product_options', + 'data_converter' => SerializedDataConverter::class ], [ 'table' => 'sales_shipment', 'identifier' => 'entity_id', - 'title' => 'packages' + 'title' => 'packages', + 'data_converter' => SerializedToJson::class ], [ 'table' => 'sales_order_payment', 'identifier' => 'entity_id', - 'title' => 'additional_information' + 'title' => 'additional_information', + 'data_converter' => SerializedToJson::class ], [ 'table' => 'sales_payment_transaction', 'identifier' => 'transaction_id', - 'title' => 'additional_information' + 'title' => 'additional_information', + 'data_converter' => SerializedToJson::class ] ]; @@ -74,8 +84,8 @@ public function __construct( */ public function convert() { - $fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class); foreach ($this->fieldsToUpdate as $field) { + $fieldDataConverter = $this->getFieldDataConverter($field['data_converter']); $fieldDataConverter->convert( $this->salesSetup->getConnection(), $this->salesSetup->getTable($field['table']), @@ -84,4 +94,20 @@ public function convert() ); } } + + /** + * Get field data converter + * + * @param string $dataConverterClassName + * @return FieldDataConverter + */ + private function getFieldDataConverter($dataConverterClassName) + { + if (!isset($this->fieldDataConverters[$dataConverterClassName])) { + $this->fieldDataConverters[$dataConverterClassName] = $this->fieldDataConverterFactory->create( + $dataConverterClassName + ); + } + return $this->fieldDataConverters[$dataConverterClassName]; + } }