From 4af1597e55be62c5a692af92c4c471ce145410fc Mon Sep 17 00:00:00 2001 From: Rafael Kassner Date: Wed, 24 Aug 2016 15:49:52 +0200 Subject: [PATCH 01/25] Admin product edit block getHeader is not used Just removing this method since it's not used, so people don't get mislead into creating a plugin for that and wondering why it does not work. `\Magento\Theme\Block\Html\Title::getPageTitle()` returns the title instead. --- .../Catalog/Block/Adminhtml/Product/Edit.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php index a253b2c7c7a09..ab2f0ffbbb1ec 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php @@ -248,19 +248,6 @@ public function getDuplicateUrl() return $this->getUrl('catalog/*/duplicate', ['_current' => true]); } - /** - * @return string - */ - public function getHeader() - { - if ($this->getProduct()->getId()) { - $header = $this->escapeHtml($this->getProduct()->getName()); - } else { - $header = __('New Product'); - } - return $header; - } - /** * @return string */ From aec7a82f6ba939ceba2d155c92c945e598c20c02 Mon Sep 17 00:00:00 2001 From: Will-I4M Date: Mon, 17 Oct 2016 08:42:40 +0200 Subject: [PATCH 02/25] In case something wrong with underlying products call to a member function getAmount() on boolean in vendor/magento/module-bundle/Pricing/Adjustment/Calculator.php on line 315 Fix this issue --- app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php b/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php index ae605a842d06f..2f093d10188f6 100644 --- a/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php +++ b/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php @@ -312,9 +312,11 @@ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, foreach ($selectionPriceList as $selectionPrice) { ++$i; - $amountList[$i]['amount'] = $selectionPrice->getAmount(); - // always honor the quantity given - $amountList[$i]['quantity'] = $selectionPrice->getQuantity(); + if ($selectionPrice) { + $amountList[$i]['amount'] = $selectionPrice->getAmount(); + // always honor the quantity given + $amountList[$i]['quantity'] = $selectionPrice->getQuantity(); + } } /** @var Store $store */ From 57384ab453e63c0ddf6c7ef3f9f762e2cb23ba41 Mon Sep 17 00:00:00 2001 From: torreytsui Date: Mon, 20 Feb 2017 22:02:49 +0000 Subject: [PATCH 03/25] Generalise address perference unsetting --- .../Model/Paypal/Helper/QuoteUpdater.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php b/app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php index ad6a97e573de2..778e55f0a0a4e 100644 --- a/app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php +++ b/app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php @@ -130,11 +130,6 @@ private function updateShippingAddress(Quote $quote, array $details) $shippingAddress->setCollectShippingRates(true); $this->updateAddressData($shippingAddress, $details['shippingAddress']); - - // PayPal's address supposes not saving against customer account - $shippingAddress->setSaveInAddressBook(false); - $shippingAddress->setSameAsBilling(false); - $shippingAddress->unsCustomerAddressId(); } /** @@ -157,11 +152,6 @@ private function updateBillingAddress(Quote $quote, array $details) $billingAddress->setFirstname($details['firstName']); $billingAddress->setLastname($details['lastName']); $billingAddress->setEmail($details['email']); - - // PayPal's address supposes not saving against customer account - $billingAddress->setSaveInAddressBook(false); - $billingAddress->setSameAsBilling(false); - $billingAddress->unsCustomerAddressId(); } /** @@ -182,5 +172,10 @@ private function updateAddressData(Address $address, array $addressData) $address->setRegionCode($addressData['region']); $address->setCountryId($addressData['countryCodeAlpha2']); $address->setPostcode($addressData['postalCode']); + + // PayPal's address supposes not saving against customer account + $address->setSaveInAddressBook(false); + $address->setSameAsBilling(false); + $address->unsCustomerAddressId(); } } From 60a2a218b4ad24d66187b0c477de8889dc0ceffa Mon Sep 17 00:00:00 2001 From: torreytsui Date: Mon, 20 Feb 2017 22:04:52 +0000 Subject: [PATCH 04/25] Avoid using unsCustomerAddressId; use setCustomerAddressId(null) instead --- app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php b/app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php index 778e55f0a0a4e..cfe99192d90e5 100644 --- a/app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php +++ b/app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php @@ -176,6 +176,6 @@ private function updateAddressData(Address $address, array $addressData) // PayPal's address supposes not saving against customer account $address->setSaveInAddressBook(false); $address->setSameAsBilling(false); - $address->unsCustomerAddressId(); + $address->setCustomerAddressId(null); } } From d185b017e7064b7546818606fb465fde2c503a54 Mon Sep 17 00:00:00 2001 From: Volodymyr Sevostianov Date: Thu, 9 Mar 2017 11:39:38 +0200 Subject: [PATCH 05/25] MAGETWO-59343: Automate new update wishlist flow --- ...ductsToCartFromCustomerWishlistOnFrontendTest.php | 12 ++++++++---- ...ductsToCartFromCustomerWishlistOnFrontendTest.xml | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php index caaf179cec4ac..982bf0f1b3637 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php @@ -37,9 +37,10 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli * @param Customer $customer * @param string $products * @param int $qty + * @param bool $toUpdate * @return array */ - public function test(Customer $customer, $products, $qty) + public function test(Customer $customer, $products, $qty, $toUpdate = true) { // Preconditions $customer->persist(); @@ -48,7 +49,7 @@ public function test(Customer $customer, $products, $qty) $this->addToWishlist($products); // Steps - $this->addToCart($products, $qty); + $this->addToCart($products, $qty, $toUpdate); // Prepare data for asserts $cart = $this->createCart($products); @@ -61,9 +62,10 @@ public function test(Customer $customer, $products, $qty) * * @param array $products * @param int $qty + * @param bool $toUpdate * @return void */ - protected function addToCart(array $products, $qty) + protected function addToCart(array $products, $qty, $toUpdate) { $productBlock = $this->wishlistIndex->getWishlistBlock()->getProductItemsBlock(); foreach ($products as $product) { @@ -71,7 +73,9 @@ protected function addToCart(array $products, $qty) $this->cmsIndex->getCmsPageBlock()->waitPageInit(); if ($qty != '-') { $productBlock->getItemProduct($product)->fillProduct(['qty' => $qty]); - $this->wishlistIndex->getWishlistBlock()->clickUpdateWishlist(); + if ($toUpdate) { + $this->wishlistIndex->getWishlistBlock()->clickUpdateWishlist(); + } } $productBlock->getItemProduct($product)->clickAddToCart(); $this->cmsIndex->getCmsPageBlock()->waitPageInit(); diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml index 1f1e02115cc37..f0d754f09b604 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml @@ -11,6 +11,7 @@ stable:no catalogProductSimple::product_100_dollar 2 + false From f4fc43e784264129cc015734157905e8d4d24222 Mon Sep 17 00:00:00 2001 From: Volodymyr Sevostianov Date: Thu, 9 Mar 2017 15:24:03 +0200 Subject: [PATCH 06/25] MAGETWO-65696: Automate VAT ID domestic group validation test --- .../Magento/Customer/Test/Repository/Address.xml | 15 +++++++++++++++ .../Magento/Customer/Test/Repository/Customer.xml | 14 ++++++++++++++ .../Customer/Test/TestCase/ApplyVatIdTest.xml | 10 ++++++++++ 3 files changed, 39 insertions(+) diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Address.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Address.xml index 37325842aeeea..b5384d04beb15 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Address.xml +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Address.xml @@ -251,6 +251,21 @@ 333-33-333-33 + + Jan + Jansen + JaneDoe_%isolation%@example.com + Magento %isolation% + Berlin + Augsburger Strabe 41 + 10789 + Germany + Berlin + 333-33-333-33 + Yes + Yes + + Jan Jansen diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Customer.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Customer.xml index 6d3e1976d0b72..bfaa2a7df7dc8 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Customer.xml +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Repository/Customer.xml @@ -228,6 +228,20 @@ + + John + Doe%isolation% + John.Doe%isolation%@example.com + 123123^q + 123123^q + + DE_address_default + + + default + + + John Doe%isolation% diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/ApplyVatIdTest.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/ApplyVatIdTest.xml index 0ec2503362a57..a1b93aa8f7ee7 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/ApplyVatIdTest.xml +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/ApplyVatIdTest.xml @@ -27,5 +27,15 @@ + + enable_VAT_on_frontend + store_information_DE_with_VAT, enable_VAT_on_frontend + customer_DE_default_billing_address + 111607872 + valid_domestic_group + test_type:3rd_party_test + + + From 8c7960c8490d46494eec658c2c2aa54f1a889de0 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Thu, 9 Mar 2017 20:15:06 +0200 Subject: [PATCH 07/25] MAGETWO-58651: Refactor saveFormHandler() method --- .../adminhtml/web/js/variations/variations.js | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js b/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js index c8301fcc79a45..cf72276fbb679 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js @@ -383,12 +383,7 @@ define([ * Chose action for the form save button */ saveFormHandler: function () { - this.source.data['configurable-matrix-serialized'] = - JSON.stringify(this.source.data['configurable-matrix']); - delete this.source.data['configurable-matrix']; - this.source.data['associated_product_ids_serialized'] = - JSON.stringify(this.source.data['associated_product_ids']); - delete this.source.data['associated_product_ids']; + this.serializeData(); if (this.checkForNewAttributes()) { this.formSaveParams = arguments; @@ -398,6 +393,31 @@ define([ } }, + /** + * Serialize data for specific form fields + * + * Get data from outdated fields, serialize it and produce new form fields. + * + * Outdated fields: + * - configurable-matrix; + * - associated_product_ids. + * + * New fields: + * - configurable-matrix-serialized; + * - associated_product_ids_serialized. + */ + serializeData: function () { + this.source.data['configurable-matrix-serialized'] = + JSON.stringify(this.source.data['configurable-matrix']); + + delete this.source.data['configurable-matrix']; + + this.source.data['associated_product_ids_serialized'] = + JSON.stringify(this.source.data['associated_product_ids']); + + delete this.source.data['associated_product_ids']; + }, + /** * Check for newly added attributes * @returns {Boolean} From 9f1c19db41287f1b9d80c0d0466764a021444a50 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Thu, 9 Mar 2017 20:15:32 +0200 Subject: [PATCH 08/25] MAGETWO-58651: Remove unused method unserializeProductData() --- .../Controller/Adminhtml/Product/Save.php | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php index 53bef748d68e1..4ece5cd47f9d9 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php @@ -97,7 +97,6 @@ public function execute() $productTypeId = $this->getRequest()->getParam('type'); if ($data) { try { - $this->unserializeProductData($data); $product = $this->initializationHelper->initialize( $this->productBuilder->build($this->getRequest()) ); @@ -181,30 +180,6 @@ public function execute() return $resultRedirect; } - /** - * Unserialize product data for configurable products - * - * @param array $postData - * @return void - */ - private function unserializeProductData($postData) - { - if (isset($postData["configurable-matrix-serialized"])) { - $configurableMatrixSerialized = $postData["configurable-matrix-serialized"]; - if ($configurableMatrixSerialized != null && !empty($configurableMatrixSerialized)) { - $postData["configurable-matrix"] = json_decode($configurableMatrixSerialized, true); - unset($postData["configurable-matrix-serialized"]); - } - } - if (isset($postData["associated_product_ids_serialized"])) { - $associatedProductIdsSerialized = $postData["associated_product_ids_serialized"]; - if ($associatedProductIdsSerialized != null && !empty($associatedProductIdsSerialized)) { - $postData["associated_product_ids"] = json_decode($associatedProductIdsSerialized, true); - unset($postData["associated_product_ids_serialized"]); - } - } - } - /** * Notify customer when image was not deleted in specific case. * TODO: temporary workaround must be eliminated in MAGETWO-45306 From 54b05b1aa5c73fc8ca01bdc2704d6b60d2c1da2e Mon Sep 17 00:00:00 2001 From: Sviatoslav Mankivskyi Date: Fri, 17 Mar 2017 13:59:18 +0200 Subject: [PATCH 09/25] MAGETWO-61425: Fix timeline status detection --- app/code/Magento/Ui/view/base/web/js/timeline/timeline.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/timeline/timeline.js b/app/code/Magento/Ui/view/base/web/js/timeline/timeline.js index 571b03317ac09..e86064a8606f8 100644 --- a/app/code/Magento/Ui/view/base/web/js/timeline/timeline.js +++ b/app/code/Magento/Ui/view/base/web/js/timeline/timeline.js @@ -104,7 +104,7 @@ define([ * @returns {Boolean} */ isActive: function (record) { - return record.status === 1; + return Number(record.status) === 1; }, /** @@ -115,7 +115,7 @@ define([ * @returns {Boolean} */ isUpcoming: function (record) { - return record.status === 2; + return Number(record.status) === 2; }, /** From 25c50ec24a41024e1fd7ebd0ebaf4d060b81518e Mon Sep 17 00:00:00 2001 From: Sviatoslav Mankivskyi Date: Mon, 20 Mar 2017 17:58:47 +0200 Subject: [PATCH 10/25] MAGETWO-61425: Fix timeline status detection --- .../Ui/base/js/timeline/timeline.test.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/timeline/timeline.test.js diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/timeline/timeline.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/timeline/timeline.test.js new file mode 100644 index 0000000000000..ee6ad67abff22 --- /dev/null +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/timeline/timeline.test.js @@ -0,0 +1,46 @@ +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'Magento_Ui/js/timeline/timeline' +], function (Timeline) { + 'use strict'; + + describe('Magento_Ui/js/timeline/timeline', function () { + var timeline; + + beforeEach(function () { + timeline = new Timeline({}); + }); + + describe('isActive method', function () { + it('record status is 1', function () { + expect(timeline.isActive({status: 1})).toBe(true); + }); + + it('record status is "1"', function () { + expect(timeline.isActive({status: '1'})).toBe(true); + }); + + it('record status is 2', function () { + expect(timeline.isActive({status: 2})).toBe(false); + }); + }); + + describe('isUpcoming method', function () { + it('record status is 2', function () { + expect(timeline.isUpcoming({status: 2})).toBe(true); + }); + + it('record status is "2"', function () { + expect(timeline.isUpcoming({status: '2'})).toBe(true); + }); + + it('record status is 1', function () { + expect(timeline.isUpcoming({status: 1})).toBe(false); + }); + }); + }); +}); From 306af3e1cedfe2b0b767a1df79c853a4245483de Mon Sep 17 00:00:00 2001 From: Sviatoslav Mankivskyi Date: Thu, 23 Mar 2017 18:01:29 +0200 Subject: [PATCH 11/25] MAGETWO-61425: Fix timeline status detection --- .../Ui/base/js/timeline/timeline.test.js | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/timeline/timeline.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/timeline/timeline.test.js index ee6ad67abff22..204e79c8451cd 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/timeline/timeline.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/timeline/timeline.test.js @@ -17,29 +17,41 @@ define([ describe('isActive method', function () { it('record status is 1', function () { - expect(timeline.isActive({status: 1})).toBe(true); + expect(timeline.isActive({ + status: 1 + })).toBe(true); }); it('record status is "1"', function () { - expect(timeline.isActive({status: '1'})).toBe(true); + expect(timeline.isActive({ + status: '1' + })).toBe(true); }); it('record status is 2', function () { - expect(timeline.isActive({status: 2})).toBe(false); + expect(timeline.isActive({ + status: 2 + })).toBe(false); }); }); describe('isUpcoming method', function () { it('record status is 2', function () { - expect(timeline.isUpcoming({status: 2})).toBe(true); + expect(timeline.isUpcoming({ + status: 2 + })).toBe(true); }); it('record status is "2"', function () { - expect(timeline.isUpcoming({status: '2'})).toBe(true); + expect(timeline.isUpcoming({ + status: '2' + })).toBe(true); }); it('record status is 1', function () { - expect(timeline.isUpcoming({status: 1})).toBe(false); + expect(timeline.isUpcoming({ + status: 1 + })).toBe(false); }); }); }); From 239efc3e5552cc135c73aba9ed904aa4fee8e4d4 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 24 Mar 2017 12:33:57 +0200 Subject: [PATCH 12/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- .../ObjectManager/ConfigLoader/Compiled.php | 5 +-- .../ObjectManager/Config/Compiled.php | 4 +-- .../Console/Command/DiCompileCommand.php | 3 -- .../src/Magento/Setup/Model/AdminAccount.php | 16 ++++++++-- .../Config/Chain/ArgumentsSerialization.php | 27 +++++++++++++++- .../Di/Compiler/Config/Writer/Filesystem.php | 6 ++-- .../Chain/ArgumentsSerializationTest.php | 32 ++++++++++++++++--- 7 files changed, 75 insertions(+), 18 deletions(-) diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index 328c9b0da7bce..4cbf46f68ba87 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -33,7 +33,8 @@ public function load($area) if (isset($this->configCache[$area])) { return $this->configCache[$area]; } - $this->configCache[$area] = $this->getSerializer()->unserialize(\file_get_contents(self::getFilePath($area))); + $diConfiguration = include_once(self::getFilePath($area)); + $this->configCache[$area] = $diConfiguration; return $this->configCache[$area]; } @@ -46,7 +47,7 @@ public function load($area) public static function getFilePath($area) { $diPath = DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_METADATA][DirectoryList::PATH]; - return BP . '/' . $diPath . '/' . $area . '.ser'; + return BP . '/' . $diPath . '/' . $area . '.php'; } /** diff --git a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php index b21894b78144f..907c27ef18c20 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php @@ -83,9 +83,7 @@ public function setCache(ConfigCacheInterface $cache) public function getArguments($type) { if (array_key_exists($type, $this->arguments)) { - if (is_string($this->arguments[$type])) { - $this->arguments[$type] = $this->getSerializer()->unserialize($this->arguments[$type]); - } elseif ($this->arguments[$type] === null) { + if ($this->arguments[$type] === null) { $this->arguments[$type] = []; } return $this->arguments[$type]; diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php index bc443379a6bd4..6dfb0d3e73f7c 100644 --- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php @@ -284,9 +284,6 @@ private function configureObjectManager(OutputInterface $output) 'InterceptionPreferencesResolving' => ['instance' => \Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class], - 'ArgumentsSerialization' => - ['instance' => - \Magento\Setup\Module\Di\Compiler\Config\Chain\ArgumentsSerialization::class], ] ] ], \Magento\Setup\Module\Di\Code\Generator\PluginList::class => [ diff --git a/setup/src/Magento/Setup/Model/AdminAccount.php b/setup/src/Magento/Setup/Model/AdminAccount.php index 6acb57dcf6cbb..580c5f70ad0d4 100644 --- a/setup/src/Magento/Setup/Model/AdminAccount.php +++ b/setup/src/Magento/Setup/Model/AdminAccount.php @@ -11,6 +11,8 @@ use Magento\Authorization\Model\UserContextInterface; use Magento\Framework\Encryption\EncryptorInterface; use Magento\Setup\Module\Setup; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\App\ObjectManager; class AdminAccount { @@ -43,21 +45,31 @@ class AdminAccount */ private $encryptor; + /** + * Used for serialize/unserialize data. + * + * @var Json + */ + private $serializer; + /** * Default Constructor * * @param Setup $setup * @param EncryptorInterface $encryptor * @param array $data + * @param Json|null $serializer */ public function __construct( Setup $setup, EncryptorInterface $encryptor, - array $data + array $data, + Json $serializer = null ) { $this->setup = $setup; $this->encryptor = $encryptor; $this->data = $data; + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** @@ -119,7 +131,7 @@ private function saveAdminUser() // User does not exist, create it $adminData['username'] = $this->data[self::KEY_USER]; $adminData['email'] = $this->data[self::KEY_EMAIL]; - $adminData['extra'] = serialize(null); + $adminData['extra'] = $this->serializer->serialize(null); $this->setup->getConnection()->insert( $this->setup->getTable('admin_user'), $adminData diff --git a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/ArgumentsSerialization.php b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/ArgumentsSerialization.php index 8129f3e958de4..d97e81b2c1e2f 100644 --- a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/ArgumentsSerialization.php +++ b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/ArgumentsSerialization.php @@ -7,9 +7,34 @@ namespace Magento\Setup\Module\Di\Compiler\Config\Chain; use Magento\Setup\Module\Di\Compiler\Config\ModificationInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\App\ObjectManager; +/** + * Used for argument's array serialization and store to the DI configuration. + * + * @deprecated We don't need anymore serialize arguments, this class will be removed in the next + * backward incompatible release. + */ class ArgumentsSerialization implements ModificationInterface { + /** + * Used for serialize/unserialize data. + * + * @var Json + */ + private $serializer; + + /** + * Constructor. + * + * @param SerializerInterface|null $serializer + */ + public function __construct(SerializerInterface $serializer = null) + { + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); + } + /** * Modifies input config * @@ -24,7 +49,7 @@ public function modify(array $config) foreach ($config['arguments'] as $key => $value) { if ($value !== null) { - $config['arguments'][$key] = serialize($value); + $config['arguments'][$key] = $this->serializer->serialize($value); } } diff --git a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php index e8d1de55427f3..6d8d9331bcf24 100644 --- a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php +++ b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php @@ -44,10 +44,10 @@ public function __construct(DirectoryList $directoryList) public function write($key, array $config) { $this->initialize(); - + $configuration = sprintf('directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $key . '.ser', - $this->getSerializer()->serialize($config) + $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) . '/' . $key . '.php', + $configuration ); } diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/Compiler/Config/Chain/ArgumentsSerializationTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/Compiler/Config/Chain/ArgumentsSerializationTest.php index d9b407efe3462..70f0fa69fbde9 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/Di/Compiler/Config/Chain/ArgumentsSerializationTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/Compiler/Config/Chain/ArgumentsSerializationTest.php @@ -6,16 +6,40 @@ namespace Magento\Setup\Test\Unit\Module\Di\Compiler\Config\Chain; -use \Magento\Setup\Module\Di\Compiler\Config\Chain\ArgumentsSerialization; +use Magento\Setup\Module\Di\Compiler\Config\Chain\ArgumentsSerialization; +use Magento\Framework\Serialize\SerializerInterface; +/** + * Unit test for the ArgumentsSerialization class. + * + * @deprecated We don't need anymore serialize arguments, this class will be removed in the next + * backward incompatible release. + */ class ArgumentsSerializationTest extends \PHPUnit_Framework_TestCase { + /** + * @var SerializerInterface|PHPUnit_Framework_MockObject_MockObject + */ + private $serializer; + + /** + * Set up mocks. + */ + protected function setUp() + { + $this->serializer = $this->getMockBuilder(SerializerInterface::class) + ->getMock(); + $this->serializer->expects($this->any())->method('serialize')->willReturnCallback(function ($param) { + return json_encode($param); + }); + } + public function testModifyArgumentsDoNotExist() { $inputConfig = [ 'data' => [] ]; - $modifier = new ArgumentsSerialization(); + $modifier = new ArgumentsSerialization($this->serializer); $this->assertSame($inputConfig, $modifier->modify($inputConfig)); } @@ -30,12 +54,12 @@ public function testModifyArguments() $expected = [ 'arguments' => [ - 'argument1' => serialize([]), + 'argument1' => json_encode([]), 'argument2' => null, ] ]; - $modifier = new ArgumentsSerialization(); + $modifier = new ArgumentsSerialization($this->serializer); $this->assertEquals($expected, $modifier->modify($inputConfig)); } } From 3311cf4d829a11fdcce66203b7994b1172c853a2 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 24 Mar 2017 14:16:06 +0200 Subject: [PATCH 13/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- .../Setup/Model/AdminAccountFactory.php | 4 +++- .../Test/Unit/Model/AdminAccountTest.php | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Model/AdminAccountFactory.php b/setup/src/Magento/Setup/Model/AdminAccountFactory.php index f165c60bf68f7..b7eac370c520f 100644 --- a/setup/src/Magento/Setup/Model/AdminAccountFactory.php +++ b/setup/src/Magento/Setup/Model/AdminAccountFactory.php @@ -8,6 +8,7 @@ use Magento\Setup\Module\Setup; use Zend\ServiceManager\ServiceLocatorInterface; +use Magento\Framework\Serialize\Serializer\Json; class AdminAccountFactory { @@ -34,7 +35,8 @@ public function create(Setup $setup, $data) return new AdminAccount( $setup, $this->serviceLocator->get(\Magento\Framework\Encryption\Encryptor::class), - $data + $data, + new Json() ); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php b/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php index 466d92ba25cd1..c08482fcc254c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php @@ -7,6 +7,7 @@ namespace Magento\Setup\Test\Unit\Model; use \Magento\Setup\Model\AdminAccount; +use Magento\Framework\Serialize\Serializer\Json; class AdminAccountTest extends \PHPUnit_Framework_TestCase { @@ -30,6 +31,11 @@ class AdminAccountTest extends \PHPUnit_Framework_TestCase */ private $adminAccount; + /** + * @var Json|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializer; + public function setUp() { $this->setUpMock = $this->getMock(\Magento\Setup\Module\Setup::class, [], [], '', false); @@ -53,6 +59,12 @@ function ($table) { $this->encryptor = $this->getMockBuilder(\Magento\Framework\Encryption\EncryptorInterface::class) ->getMockForAbstractClass(); + $this->serializer = $this->getMockBuilder(Json::class) + ->getMock(); + $this->serializer->expects($this->any())->method('serialize')->willReturnCallback(function ($param) { + return json_encode($param); + }); + $data = [ AdminAccount::KEY_FIRST_NAME => 'John', AdminAccount::KEY_LAST_NAME => 'Doe', @@ -61,7 +73,12 @@ function ($table) { AdminAccount::KEY_USER => 'admin', ]; - $this->adminAccount = new AdminAccount($this->setUpMock, $this->encryptor, $data); + $this->adminAccount = new AdminAccount( + $this->setUpMock, + $this->encryptor, + $data, + $this->serializer + ); } public function testSaveUserExistsAdminRoleExists() From ef57302ca97784e5271b47d006775ece3854e5c1 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 24 Mar 2017 15:18:45 +0200 Subject: [PATCH 14/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- .../ObjectManager/Config/Compiled.php | 16 --- .../Test/Unit/Config/CompiledTest.php | 106 +++++++++--------- 2 files changed, 55 insertions(+), 67 deletions(-) diff --git a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php index 907c27ef18c20..34e8f03553d36 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php @@ -7,7 +7,6 @@ use Magento\Framework\ObjectManager\ConfigInterface; use Magento\Framework\Serialize\SerializerInterface; -use Magento\Framework\Serialize\Serializer\Serialize; use Magento\Framework\ObjectManager\ConfigCacheInterface; use Magento\Framework\ObjectManager\RelationsInterface; @@ -171,19 +170,4 @@ public function getPreferences() { return $this->preferences; } - - /** - * Get serializer - * - * @return SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (null === $this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(Serialize::class); - } - return $this->serializer; - } } diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Config/CompiledTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Config/CompiledTest.php index 4897e95ad2d07..bdb0ee79fd578 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Config/CompiledTest.php +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Config/CompiledTest.php @@ -7,7 +7,6 @@ use Magento\Framework\ObjectManager\Config\Compiled; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManager; -use Magento\Framework\Serialize\SerializerInterface; class CompiledTest extends \PHPUnit_Framework_TestCase { @@ -16,11 +15,6 @@ class CompiledTest extends \PHPUnit_Framework_TestCase */ private $objectManager; - /** - * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $serializerMock; - /** * @var \Magento\Framework\ObjectManager\Config\Compiled */ @@ -29,15 +23,14 @@ class CompiledTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->objectManager = new ObjectManager($this); - $this->serializerMock = $this->getMock(SerializerInterface::class); $initialData = [ 'arguments' => [ 'type1' => 'initial serialized configuration for type1', 'class_with_no_arguments_serialized' => null, - 'class_with_arguments_serialized' => 'serialized arguments', - 'class_with_arguments_unserialized' => ['unserialized', 'arguments'], - 'class_with_no_arguments_unserialized' => [], + 'class_with_arguments_string' => 'string arguments', + 'class_with_arguments_array' => ['unserialized', 'arguments'], + 'class_with_no_arguments_empty_array' => [], ], 'instanceTypes' => [ 'instanceType1' => 'instanceTypeValue1', @@ -53,59 +46,79 @@ protected function setUp() Compiled::class, [ 'data' => $initialData, - 'serializer' => $this->serializerMock ] ); } - public function testExtend() + /** + * Test is it possible extend/overwrite arguments for the DI. + * + */ + public function testExtendArguments() { - $configuration = [ 'arguments' => [ - 'type1' => 'serialized configuration for type1', - 'type2' => 'serialized configuration for type2' + 'type1' => 'configuration for type1', + 'type2' => [ + 'argument2_1' => 'newArgumentValue2_1', + ] ], 'instanceTypes' => [ 'instanceType2' => 'newInstanceTypeValue2', - 'instanceType3' => 'newInstanceTypeValue3' + 'instanceType3' => 'newInstanceTypeValue3', ], 'preferences' => [ - 'preference1' => 'newPreferenceValue1' - ] + 'preference1' => 'newPreferenceValue1', + ], ]; $expectedArguments = [ - 'type1' => [ - 'argument1_1' => 'newArgumentValue1_1' - ], + 'type1' => 'configuration for type1', 'type2' => [ - 'argument2_1' => 'newArgumentValue2_1' + 'argument2_1' => 'newArgumentValue2_1', ] ]; - $expectedVirtualTypes = [ + + $this->compiled->extend($configuration); + foreach ($expectedArguments as $type => $arguments) { + $this->assertEquals($arguments, $this->compiled->getArguments($type)); + } + } + + /** + * Test getting virtual types from the DI. + */ + public function testVirtualTypes() + { + $configuration = [ + 'instanceTypes' => [ + 'instanceType2' => 'newInstanceTypeValue2', + 'instanceType3' => 'newInstanceTypeValue3' + ], + ]; + $expectedTypes = [ 'instanceType1' => 'instanceTypeValue1', 'instanceType2' => 'newInstanceTypeValue2', 'instanceType3' => 'newInstanceTypeValue3' ]; + $this->compiled->extend($configuration); + $this->assertEquals($expectedTypes, $this->compiled->getVirtualTypes()); + } + + /** + * Test getting preferences from the DI. + */ + public function testPreferences() + { + $configuration = [ + 'preferences' => [ + 'preference1' => 'newPreferenceValue1' + ] + ]; $expectedPreferences = [ 'preference1' => 'newPreferenceValue1', 'preference2' => 'preferenceValue2' ]; - - $this->serializerMock->expects($this->at(0)) - ->method('unserialize') - ->with($configuration['arguments']['type1']) - ->willReturn($expectedArguments['type1']); - $this->serializerMock->expects($this->at(1)) - ->method('unserialize') - ->with($configuration['arguments']['type2']) - ->willReturn($expectedArguments['type2']); - $this->compiled->extend($configuration); - foreach ($expectedArguments as $type => $arguments) { - $this->assertEquals($arguments, $this->compiled->getArguments($type)); - } - $this->assertEquals($expectedVirtualTypes, $this->compiled->getVirtualTypes()); $this->assertEquals($expectedPreferences, $this->compiled->getPreferences()); } @@ -114,15 +127,10 @@ public function testExtend() */ public function testGetArgumentsSerialized() { - $unserializedArguments = ['unserialized', 'arguments']; - - // method called twice but after one unserialization, unserialized version should be stored - $this->serializerMock->expects($this->once())->method('unserialize') - ->with('serialized arguments') - ->willReturn($unserializedArguments); + $unserializedArguments = 'string arguments'; - $this->assertSame($unserializedArguments, $this->compiled->getArguments('class_with_arguments_serialized')); - $this->assertSame($unserializedArguments, $this->compiled->getArguments('class_with_arguments_serialized')); + $this->assertSame($unserializedArguments, $this->compiled->getArguments('class_with_arguments_string')); + $this->assertSame($unserializedArguments, $this->compiled->getArguments('class_with_arguments_string')); } /** @@ -130,7 +138,6 @@ public function testGetArgumentsSerialized() */ public function testGetArgumentsSerializedEmpty() { - $this->serializerMock->expects($this->never())->method('unserialize'); $this->assertSame([], $this->compiled->getArguments('class_with_no_arguments_serialized')); } @@ -140,8 +147,7 @@ public function testGetArgumentsSerializedEmpty() public function testGetArgumentsUnserialized() { $unserializedArguments = ['unserialized', 'arguments']; - $this->serializerMock->expects($this->never())->method('unserialize'); - $this->assertSame($unserializedArguments, $this->compiled->getArguments('class_with_arguments_unserialized')); + $this->assertSame($unserializedArguments, $this->compiled->getArguments('class_with_arguments_array')); } /** @@ -149,8 +155,7 @@ public function testGetArgumentsUnserialized() */ public function testGetArgumentsUnserializedEmpty() { - $this->serializerMock->expects($this->never())->method('unserialize'); - $this->assertSame([], $this->compiled->getArguments('class_with_no_arguments_unserialized')); + $this->assertSame([], $this->compiled->getArguments('class_with_no_arguments_empty_array')); } /** @@ -158,7 +163,6 @@ public function testGetArgumentsUnserializedEmpty() */ public function testGetArgumentsNotDefined() { - $this->serializerMock->expects($this->never())->method('unserialize'); $this->assertSame(null, $this->compiled->getArguments('class_not_stored_in_config')); } } From c9611f339f4f57501768a99e287afdff09657c51 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 24 Mar 2017 15:36:38 +0200 Subject: [PATCH 15/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- .../App/ObjectManager/ConfigLoader/Compiled.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index 4cbf46f68ba87..9ab5002a134f2 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -49,18 +49,4 @@ public static function getFilePath($area) $diPath = DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_METADATA][DirectoryList::PATH]; return BP . '/' . $diPath . '/' . $area . '.php'; } - - /** - * Get serializer - * - * @return SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (null === $this->serializer) { - $this->serializer = new Serialize(); - } - return $this->serializer; - } } From 3670318cbcd75aef73a091af226f203c377f9f76 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 24 Mar 2017 15:52:52 +0200 Subject: [PATCH 16/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- .../ObjectManager/ConfigLoader/Compiled.php | 5 ----- .../ObjectManager/Config/Compiled.php | 6 ----- .../Di/Compiler/Config/Writer/Filesystem.php | 22 ------------------- 3 files changed, 33 deletions(-) diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index 9ab5002a134f2..c7e9158cf658f 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -20,11 +20,6 @@ class Compiled implements ConfigLoaderInterface */ private $configCache = []; - /** - * @var SerializerInterface - */ - private $serializer; - /** * {inheritdoc} */ diff --git a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php index 34e8f03553d36..dd16821b4c1e0 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php @@ -6,7 +6,6 @@ namespace Magento\Framework\ObjectManager\Config; use Magento\Framework\ObjectManager\ConfigInterface; -use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\ObjectManager\ConfigCacheInterface; use Magento\Framework\ObjectManager\RelationsInterface; @@ -30,11 +29,6 @@ class Compiled implements ConfigInterface */ private $preferences; - /** - * @var SerializerInterface - */ - private $serializer; - /** * Constructor * diff --git a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php index 6d8d9331bcf24..90db6761c5e53 100644 --- a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php +++ b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php @@ -9,8 +9,6 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Setup\Module\Di\Compiler\Config\WriterInterface; -use Magento\Framework\Serialize\SerializerInterface; -use Magento\Framework\Serialize\Serializer\Serialize; class Filesystem implements WriterInterface { @@ -19,11 +17,6 @@ class Filesystem implements WriterInterface */ private $directoryList; - /** - * @var SerializerInterface - */ - private $serializer; - /** * Constructor * @@ -62,19 +55,4 @@ private function initialize() mkdir($this->directoryList->getPath(DirectoryList::GENERATED_METADATA)); } } - - /** - * Get serializer - * - * @return SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if (null === $this->serializer) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(Serialize::class); - } - return $this->serializer; - } } From ab69c0ad7bcd7a13b8a280d67b05f8bf8fdc8237 Mon Sep 17 00:00:00 2001 From: Mykola Palamar Date: Fri, 24 Mar 2017 17:26:10 +0200 Subject: [PATCH 17/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- .../Magento/Framework/ObjectManager/Config/Compiled.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php index dd16821b4c1e0..d5f5e20688dfe 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php @@ -36,9 +36,9 @@ class Compiled implements ConfigInterface */ public function __construct($data) { - $this->arguments = $data['arguments']; - $this->virtualTypes = $data['instanceTypes']; - $this->preferences = $data['preferences']; + $this->arguments = $data['arguments'] ?: []; + $this->virtualTypes = $data['instanceTypes'] ?: []; + $this->preferences = $data['preferences'] ?: []; } /** From 309253ca633eb0e918329094ea85cc2761dc68ec Mon Sep 17 00:00:00 2001 From: Rafael Kassner Date: Sun, 26 Mar 2017 21:40:13 +0200 Subject: [PATCH 18/25] Update Edit.php --- .../Catalog/Block/Adminhtml/Product/Edit.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php index ab2f0ffbbb1ec..25591ef17fb72 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php @@ -247,6 +247,20 @@ public function getDuplicateUrl() { return $this->getUrl('catalog/*/duplicate', ['_current' => true]); } + + /** + * @deprecated + * @return string + */ + public function getHeader() + { + if ($this->getProduct()->getId()) { + $header = $this->escapeHtml($this->getProduct()->getName()); + } else { + $header = __('New Product'); + } + return $header; + } /** * @return string From 6a291094869be65af752c77450a9b80c6336949b Mon Sep 17 00:00:00 2001 From: Rafael Kassner Date: Sun, 26 Mar 2017 21:40:46 +0200 Subject: [PATCH 19/25] Update Edit.php --- app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php index 25591ef17fb72..c06ca17255361 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php @@ -247,7 +247,7 @@ public function getDuplicateUrl() { return $this->getUrl('catalog/*/duplicate', ['_current' => true]); } - + /** * @deprecated * @return string From 8c4b1595fe514e2b50c9d6a3f2e4661f674c7884 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Tue, 28 Mar 2017 15:38:09 +0300 Subject: [PATCH 20/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- .../Framework/App/ObjectManager/ConfigLoader/Compiled.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index c7e9158cf658f..fcba254076611 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -28,7 +28,7 @@ public function load($area) if (isset($this->configCache[$area])) { return $this->configCache[$area]; } - $diConfiguration = include_once(self::getFilePath($area)); + $diConfiguration = include(self::getFilePath($area)); $this->configCache[$area] = $diConfiguration; return $this->configCache[$area]; } From 300320853fb88cdf6a7d9f8ab8904394f1d5814e Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Tue, 28 Mar 2017 16:23:44 +0300 Subject: [PATCH 21/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- setup/src/Magento/Setup/Model/AdminAccount.php | 15 +-------------- .../Magento/Setup/Model/AdminAccountFactory.php | 3 +-- .../Config/Chain/ArgumentsSerialization.php | 5 +++-- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/setup/src/Magento/Setup/Model/AdminAccount.php b/setup/src/Magento/Setup/Model/AdminAccount.php index 580c5f70ad0d4..bc759725e88a6 100644 --- a/setup/src/Magento/Setup/Model/AdminAccount.php +++ b/setup/src/Magento/Setup/Model/AdminAccount.php @@ -11,8 +11,6 @@ use Magento\Authorization\Model\UserContextInterface; use Magento\Framework\Encryption\EncryptorInterface; use Magento\Setup\Module\Setup; -use Magento\Framework\Serialize\Serializer\Json; -use Magento\Framework\App\ObjectManager; class AdminAccount { @@ -45,31 +43,21 @@ class AdminAccount */ private $encryptor; - /** - * Used for serialize/unserialize data. - * - * @var Json - */ - private $serializer; - /** * Default Constructor * * @param Setup $setup * @param EncryptorInterface $encryptor * @param array $data - * @param Json|null $serializer */ public function __construct( Setup $setup, EncryptorInterface $encryptor, - array $data, - Json $serializer = null + array $data ) { $this->setup = $setup; $this->encryptor = $encryptor; $this->data = $data; - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); } /** @@ -131,7 +119,6 @@ private function saveAdminUser() // User does not exist, create it $adminData['username'] = $this->data[self::KEY_USER]; $adminData['email'] = $this->data[self::KEY_EMAIL]; - $adminData['extra'] = $this->serializer->serialize(null); $this->setup->getConnection()->insert( $this->setup->getTable('admin_user'), $adminData diff --git a/setup/src/Magento/Setup/Model/AdminAccountFactory.php b/setup/src/Magento/Setup/Model/AdminAccountFactory.php index b7eac370c520f..e4b28ba25be60 100644 --- a/setup/src/Magento/Setup/Model/AdminAccountFactory.php +++ b/setup/src/Magento/Setup/Model/AdminAccountFactory.php @@ -35,8 +35,7 @@ public function create(Setup $setup, $data) return new AdminAccount( $setup, $this->serviceLocator->get(\Magento\Framework\Encryption\Encryptor::class), - $data, - new Json() + $data ); } } diff --git a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/ArgumentsSerialization.php b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/ArgumentsSerialization.php index d97e81b2c1e2f..310f75b6d01d0 100644 --- a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/ArgumentsSerialization.php +++ b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/ArgumentsSerialization.php @@ -9,12 +9,13 @@ use Magento\Setup\Module\Di\Compiler\Config\ModificationInterface; use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Serialize\Serializer\Json; /** * Used for argument's array serialization and store to the DI configuration. * - * @deprecated We don't need anymore serialize arguments, this class will be removed in the next - * backward incompatible release. + * @deprecated Di arguments are now stored in raw php format and could be cached by OPcache, + * this class will be removed in the next backward incompatible release. */ class ArgumentsSerialization implements ModificationInterface { From c9ae9357aaf82bb162b302c4ec2fb4f0067e0a64 Mon Sep 17 00:00:00 2001 From: Sergii Kovalenko Date: Tue, 28 Mar 2017 17:01:40 +0300 Subject: [PATCH 22/25] MAGETWO-60756: "Uses per Coupon" limit does not work for auto generated coupons --fix coupling --- .../Adminhtml/Promo/Quote/Generate.php | 48 +++-- .../SalesRule/Model/CouponGenerator.php | 90 +++++++++ .../Model/Service/CouponManagementService.php | 2 - .../Adminhtml/Promo/Quote/GenerateTest.php | 174 ++++++++++++++++++ 4 files changed, 299 insertions(+), 15 deletions(-) create mode 100644 app/code/Magento/SalesRule/Model/CouponGenerator.php create mode 100644 app/code/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/GenerateTest.php diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php index e22fa448f4d1a..2c8db58a8ee41 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php @@ -6,8 +6,36 @@ */ namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote; +use Magento\Framework\App\ObjectManager; +use Magento\SalesRule\Model\CouponGenerator; + class Generate extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote { + /** + * @var CouponGenerator + */ + private $couponGenerator; + + /** + * Generate constructor. + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter + * @param CouponGenerator|null $couponGenerator + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Registry $coreRegistry, + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, + \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter, + CouponGenerator $couponGenerator = null + ) { + parent::__construct($context, $coreRegistry, $fileFactory, $dateFilter); + $this->couponGenerator = $couponGenerator ?: + $this->_objectManager->get(CouponGenerator::class); + } + /** * Generate Coupons action * @@ -22,7 +50,6 @@ public function execute() $result = []; $this->_initRule(); - /** @var $rule \Magento\SalesRule\Model\Rule */ $rule = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE); if (!$rule->getId()) { @@ -35,18 +62,13 @@ public function execute() $data = $inputFilter->getUnescaped(); } - /** @var $generator \Magento\SalesRule\Model\Coupon\Massgenerator */ - $generator = $this->_objectManager->get(\Magento\SalesRule\Model\Coupon\Massgenerator::class); - if (!$generator->validateData($data)) { - $result['error'] = __('Invalid data provided'); - } else { - $generator->setData($data); - $generator->generatePool(); - $generated = $generator->getGeneratedCount(); - $this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated)); - $this->_view->getLayout()->initMessages(); - $result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml(); - } + $couponCodes = $this->couponGenerator->generateCodes($data); + $generated = count($couponCodes); + $this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated)); + $this->_view->getLayout()->initMessages(); + $result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml(); + } catch (\Magento\Framework\Exception\InputException $inputException) { + $result['error'] = __('Invalid data provided'); } catch (\Magento\Framework\Exception\LocalizedException $e) { $result['error'] = $e->getMessage(); } catch (\Exception $e) { diff --git a/app/code/Magento/SalesRule/Model/CouponGenerator.php b/app/code/Magento/SalesRule/Model/CouponGenerator.php new file mode 100644 index 0000000000000..5bfe0f52042c2 --- /dev/null +++ b/app/code/Magento/SalesRule/Model/CouponGenerator.php @@ -0,0 +1,90 @@ + 'qty' + ]; + + /** + * @var Service\CouponManagementService + */ + private $couponManagementService; + + /** + * @var \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory + */ + private $generationSpecFactory; + + /** + * All objects should be injected through constructor, because we need to have working service already + * after it initializing + * + * @param Service\CouponManagementService $couponManagementService + * @param \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory $generationSpecFactory + */ + public function __construct( + \Magento\SalesRule\Model\Service\CouponManagementService $couponManagementService, + \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory $generationSpecFactory + ) { + $this->couponManagementService = $couponManagementService; + $this->generationSpecFactory = $generationSpecFactory; + } + + /** + * Generate a pool of generated coupon codes + * + * This method is used as proxy, due to high coupling in constructor + * @see \Magento\SalesRule\Controller\Adminhtml\Promo\Quote\Generate + * In order to generate valid coupon codes, we need to initialize DTO object and run service. + * @see \Magento\SalesRule\Api\Data\CouponGenerationSpecInterface -> DTO object + * + * @param array $parameters + * @return string[] + */ + public function generateCodes(array $parameters) + { + $couponSpecData = $this->convertCouponSpecData($parameters); + $couponSpec = $this->generationSpecFactory->create(['data' => $couponSpecData]); + return $this->couponManagementService->generate($couponSpec); + } + + /** + * We should map old values to new one + * We need to do this, as new service with another key names was added + * + * @param array $data + * @return array + */ + private function convertCouponSpecData(array $data) + { + foreach ($this->keyMap as $mapKey => $mapValue) { + $data[$mapKey] = isset($data[$mapValue]) ? $data[$mapValue] : null; + } + + return $data; + } +} diff --git a/app/code/Magento/SalesRule/Model/Service/CouponManagementService.php b/app/code/Magento/SalesRule/Model/Service/CouponManagementService.php index 153b26fbad496..a69e17478dea4 100644 --- a/app/code/Magento/SalesRule/Model/Service/CouponManagementService.php +++ b/app/code/Magento/SalesRule/Model/Service/CouponManagementService.php @@ -5,8 +5,6 @@ */ namespace Magento\SalesRule\Model\Service; -use Magento\SalesRule\Model\Coupon; - /** * Coupon management service class * diff --git a/app/code/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/GenerateTest.php b/app/code/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/GenerateTest.php new file mode 100644 index 0000000000000..fcd2d16e59c05 --- /dev/null +++ b/app/code/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/GenerateTest.php @@ -0,0 +1,174 @@ +contextMock = $this->getMockBuilder(\Magento\Backend\App\Action\Context::class) + ->disableOriginalConstructor() + ->getMock(); + $this->requestMock = $this + ->getMockBuilder(\Magento\Framework\App\Request\Http::class) + ->disableOriginalConstructor() + ->getMock(); + $this->responseMock = $this + ->getMockBuilder(\Magento\Framework\App\Response\Http::class) + ->disableOriginalConstructor() + ->getMock(); + $this->messageManager = $this->getMock(\Magento\Framework\Message\ManagerInterface::class); + $this->objectManagerMock = $this->getMockBuilder(ObjectManager::class) + ->disableOriginalConstructor() + ->getMock(); + $this->view = $this->getMock(\Magento\Framework\App\ViewInterface::class); + $this->contextMock->expects($this->once()) + ->method('getView') + ->willReturn($this->view); + $this->contextMock->expects($this->once()) + ->method('getMessageManager') + ->willReturn($this->messageManager); + $this->contextMock->expects($this->once()) + ->method('getRequest') + ->willReturn($this->requestMock); + $this->contextMock->expects($this->once()) + ->method('getObjectManager') + ->willReturn($this->objectManagerMock); + $this->contextMock->expects($this->once()) + ->method('getResponse') + ->willReturn($this->responseMock); + $this->registryMock = $this->getMockBuilder(\Magento\Framework\Registry::class) + ->disableOriginalConstructor() + ->getMock(); + $this->fileFactoryMock = $this->getMockBuilder(\Magento\Framework\App\Response\Http\FileFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->dateMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\Filter\Date::class) + ->disableOriginalConstructor() + ->getMock(); + $this->couponGenerator = $this->getMockBuilder(CouponGenerator::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->model = $this->objectManagerHelper->getObject( + \Magento\SalesRule\Controller\Adminhtml\Promo\Quote\Generate::class, + [ + 'context' => $this->contextMock, + 'coreRegistry' => $this->registryMock, + 'fileFactory' => $this->fileFactoryMock, + 'dateFilter' => $this->dateMock, + 'couponGenerator' => $this->couponGenerator + ] + ); + } + + public function testExecute() + { + $helperData = $this->getMockBuilder(\Magento\Framework\Json\Helper\Data::class) + ->disableOriginalConstructor() + ->getMock(); + $this->objectManagerMock->expects($this->any()) + ->method('get') + ->with(\Magento\Framework\Json\Helper\Data::class) + ->willReturn($helperData); + $requestData = [ + 'qty' => 2, + 'length' => 10, + 'rule_id' => 1 + ]; + $this->requestMock->expects($this->once()) + ->method('isAjax') + ->willReturn(true); + $ruleMock = $this->getMockBuilder(\Magento\SalesRule\Model\Rule::class) + ->disableOriginalConstructor() + ->getMock(); + $this->registryMock->expects($this->once()) + ->method('registry') + ->willReturn($ruleMock); + $ruleMock->expects($this->once()) + ->method('getId') + ->willReturn(1); + $this->requestMock->expects($this->once()) + ->method('getParams') + ->willReturn($requestData); + $this->couponGenerator->expects($this->once()) + ->method('generateCodes') + ->with($requestData) + ->willReturn(['some_data', 'some_data_2']); + $this->messageManager->expects($this->once()) + ->method('addSuccess'); + $this->responseMock->expects($this->once()) + ->method('representJson') + ->with(); + $helperData->expects($this->once()) + ->method('jsonEncode') + ->with([ + 'messages' => __('%1 coupon(s) have been generated.', 2) + ]); + $layout = $this->getMockBuilder(\Magento\Framework\View\Layout::class) + ->disableOriginalConstructor() + ->getMock(); + $this->view->expects($this->any()) + ->method('getLayout') + ->willReturn($layout); + $messageBlock = $this->getMockBuilder(\Magento\Framework\View\Element\Messages::class) + ->disableOriginalConstructor() + ->getMock(); + $layout->expects($this->once()) + ->method('initMessages'); + $layout->expects($this->once()) + ->method('getMessagesBlock') + ->willReturn($messageBlock); + $messageBlock->expects($this->once()) + ->method('getGroupedHtml') + ->willReturn(__('%1 coupon(s) have been generated.', 2)); + $this->model->execute(); + } +} From c81519ad3d92ec7c8785460f3b84194d9a869fe3 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Wed, 29 Mar 2017 12:25:08 +0300 Subject: [PATCH 23/25] MAGETWO-66100: Remove usages of unserialize in module Magento/Setup --- .../Setup/Test/Unit/Model/AdminAccountTest.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php b/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php index c08482fcc254c..ed8600420a2f0 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php @@ -7,7 +7,6 @@ namespace Magento\Setup\Test\Unit\Model; use \Magento\Setup\Model\AdminAccount; -use Magento\Framework\Serialize\Serializer\Json; class AdminAccountTest extends \PHPUnit_Framework_TestCase { @@ -31,11 +30,6 @@ class AdminAccountTest extends \PHPUnit_Framework_TestCase */ private $adminAccount; - /** - * @var Json|\PHPUnit_Framework_MockObject_MockObject - */ - private $serializer; - public function setUp() { $this->setUpMock = $this->getMock(\Magento\Setup\Module\Setup::class, [], [], '', false); @@ -59,12 +53,6 @@ function ($table) { $this->encryptor = $this->getMockBuilder(\Magento\Framework\Encryption\EncryptorInterface::class) ->getMockForAbstractClass(); - $this->serializer = $this->getMockBuilder(Json::class) - ->getMock(); - $this->serializer->expects($this->any())->method('serialize')->willReturnCallback(function ($param) { - return json_encode($param); - }); - $data = [ AdminAccount::KEY_FIRST_NAME => 'John', AdminAccount::KEY_LAST_NAME => 'Doe', @@ -76,8 +64,7 @@ function ($table) { $this->adminAccount = new AdminAccount( $this->setUpMock, $this->encryptor, - $data, - $this->serializer + $data ); } From bfbf6047f33eaeef74dd538b45ebe0f8705880af Mon Sep 17 00:00:00 2001 From: wb Date: Wed, 29 Mar 2017 22:30:55 +0200 Subject: [PATCH 24/25] remove duplicate method call (#9017) --- app/code/Magento/Catalog/Model/ResourceModel/Category.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category.php b/app/code/Magento/Catalog/Model/ResourceModel/Category.php index 86e10f6485eef..d8bf411eefbb3 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category.php @@ -768,7 +768,6 @@ public function getChildren($category, $recursive = true) $backendTable = $this->getTable([$this->getEntityTablePrefix(), 'int']); $connection = $this->getConnection(); $checkSql = $connection->getCheckSql('c.value_id > 0', 'c.value', 'd.value'); - $linkField = $this->getLinkField(); $bind = [ 'attribute_id' => $attributeId, 'store_id' => $category->getStoreId(), From 9e308efc188a69a4418a723ab26854d4ddd5b1fa Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 30 Mar 2017 15:14:56 -0500 Subject: [PATCH 25/25] MAGETWO-66959: Fix failing static test --- app/code/Magento/Catalog/Model/ResourceModel/Category.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category.php b/app/code/Magento/Catalog/Model/ResourceModel/Category.php index d8bf411eefbb3..05e0cd677db7b 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category.php @@ -584,8 +584,10 @@ public function getIsActiveAttributeId() */ public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue) { + // @codingStandardsIgnoreStart $serializeData = $this->serializer->serialize($entityIdsFilter); $entityIdsFilterHash = md5($serializeData); + // @codingStandardsIgnoreEnd if (!isset($this->entitiesWhereAttributesIs[$entityIdsFilterHash][$attribute->getId()][$expectedValue])) { $linkField = $this->getLinkField();