From a3b5a187ea9368b12ee146317284e3515dd2f04f Mon Sep 17 00:00:00 2001 From: as7469 Date: Wed, 8 Feb 2017 14:56:42 +0100 Subject: [PATCH 01/12] Fix for https://github.com/magento/magento2/issues/8392 --- .../Catalog/Model/ProductLink/CollectionProvider.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php index 917a47b637cea..80d625fcb95f5 100644 --- a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php @@ -48,9 +48,14 @@ public function getCollection(\Magento\Catalog\Model\Product $product, $type) $products = $this->providers[$type]->getLinkedProducts($product); $converter = $this->converterPool->getConverter($type); $output = []; + $realoutput = []; foreach ($products as $item) { $output[$item->getId()] = $converter->convert($item); } - return $output; + foreach ($output as $item) { + $realoutput[$item["position"]] = $item; + } + ksort($realoutput); + return $realoutput; } } From 207b160150b020f64b2f9139f973ca2528587bea Mon Sep 17 00:00:00 2001 From: as7469 Date: Wed, 8 Feb 2017 16:42:09 +0100 Subject: [PATCH 02/12] Fix for https://github.com/magento/magento2/issues/8392 --- .../Catalog/Model/ProductLink/CollectionProvider.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php index 80d625fcb95f5..d495da310df00 100644 --- a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php @@ -48,14 +48,14 @@ public function getCollection(\Magento\Catalog\Model\Product $product, $type) $products = $this->providers[$type]->getLinkedProducts($product); $converter = $this->converterPool->getConverter($type); $output = []; - $realoutput = []; + $realoutput = []; foreach ($products as $item) { $output[$item->getId()] = $converter->convert($item); } - foreach ($output as $item) { - $realoutput[$item["position"]] = $item; - } - ksort($realoutput); + foreach ($output as $item) { + $realoutput[$item["position"]] = $item; + } + ksort($realoutput); return $realoutput; } } From 5d42cef32e04f516abfefe6f570bff780258def7 Mon Sep 17 00:00:00 2001 From: dmanners Date: Fri, 10 Feb 2017 11:31:29 +0000 Subject: [PATCH 03/12] Update the Adminhtml image tree to use the new Serializer Json rather than Zend_Json --- .../Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php b/app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php index 1b5e4f54f552c..7e52e2bdb4702 100644 --- a/app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php +++ b/app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Tree.php @@ -26,20 +26,30 @@ class Tree extends \Magento\Backend\Block\Template */ protected $_cmsWysiwygImages = null; + /** + * @var \Magento\Framework\Serialize\Serializer\Json + */ + private $serializer; + /** * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages * @param \Magento\Framework\Registry $registry * @param array $data + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @throws \RuntimeException */ public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Cms\Helper\Wysiwyg\Images $cmsWysiwygImages, \Magento\Framework\Registry $registry, - array $data = [] + array $data = [], + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->_coreRegistry = $registry; $this->_cmsWysiwygImages = $cmsWysiwygImages; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\Serializer\Json::class); parent::__construct($context, $data); } @@ -65,7 +75,7 @@ public function getTreeJson() 'cls' => 'folder', ]; } - return \Zend_Json::encode($jsonArray); + return $this->serializer->serialize($jsonArray); } /** From 991a54d6d3b40e4151fe4f798044aa94253f121d Mon Sep 17 00:00:00 2001 From: as7469 Date: Mon, 13 Feb 2017 16:07:23 +0100 Subject: [PATCH 04/12] Issue 8392 fix improved --- .../Catalog/Model/ProductLink/CollectionProvider.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php index d495da310df00..47174062488da 100644 --- a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php @@ -53,7 +53,14 @@ public function getCollection(\Magento\Catalog\Model\Product $product, $type) $output[$item->getId()] = $converter->convert($item); } foreach ($output as $item) { - $realoutput[$item["position"]] = $item; + $itemPosition = $item["position"]; + if (!isset($realoutput[$itemposition])) { + $realoutput[$itemPosition] = $item; + } + else { + $newPosition = $itemPosition+1; + $realoutput[$newPosition] = $item; + } } ksort($realoutput); return $realoutput; From acfce4eedf09ba119f5fb4c9f179876a8a3ead02 Mon Sep 17 00:00:00 2001 From: as7469 Date: Mon, 13 Feb 2017 16:09:08 +0100 Subject: [PATCH 05/12] Issue 8392 fix improved --- .../Magento/Catalog/Model/ProductLink/CollectionProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php index 47174062488da..bd27dd473c69c 100644 --- a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php @@ -54,7 +54,7 @@ public function getCollection(\Magento\Catalog\Model\Product $product, $type) } foreach ($output as $item) { $itemPosition = $item["position"]; - if (!isset($realoutput[$itemposition])) { + if (!isset($realoutput[$itemPosition])) { $realoutput[$itemPosition] = $item; } else { From 0002f6d3c4624f660d151d73bcb321f93eb8c032 Mon Sep 17 00:00:00 2001 From: as7469 Date: Mon, 13 Feb 2017 18:16:24 +0100 Subject: [PATCH 06/12] Issue 8392 - formatting wanking --- .../Magento/Catalog/Model/ProductLink/CollectionProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php index bd27dd473c69c..1536c982b40d2 100644 --- a/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php +++ b/app/code/Magento/Catalog/Model/ProductLink/CollectionProvider.php @@ -56,7 +56,7 @@ public function getCollection(\Magento\Catalog\Model\Product $product, $type) $itemPosition = $item["position"]; if (!isset($realoutput[$itemPosition])) { $realoutput[$itemPosition] = $item; - } + } else { $newPosition = $itemPosition+1; $realoutput[$newPosition] = $item; From a60ed27ce41c36120588cfecac15e7d3aa1b75ff Mon Sep 17 00:00:00 2001 From: dmanners Date: Mon, 20 Feb 2017 12:18:04 +0000 Subject: [PATCH 07/12] Remove Zend_Json from Customer module in the auth-pop-up block and add tests for the new test function --- .../Block/Account/AuthenticationPopup.php | 22 ++++++- .../Block/Account/AuthenticationPopupTest.php | 58 ++++++++++++++++++- .../account/authentication-popup.phtml | 2 +- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Customer/Block/Account/AuthenticationPopup.php b/app/code/Magento/Customer/Block/Account/AuthenticationPopup.php index a0f94e1b8f733..efada54438c8c 100644 --- a/app/code/Magento/Customer/Block/Account/AuthenticationPopup.php +++ b/app/code/Magento/Customer/Block/Account/AuthenticationPopup.php @@ -15,16 +15,26 @@ class AuthenticationPopup extends \Magento\Framework\View\Element\Template */ protected $jsLayout; + /** + * @var \Magento\Framework\Serialize\Serializer\Json + */ + private $serializer; + /** * @param \Magento\Framework\View\Element\Template\Context $context * @param array $data + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @throws \RuntimeException */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, - array $data = [] + array $data = [], + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { parent::__construct($context, $data); $this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : []; + $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** @@ -32,7 +42,7 @@ public function __construct( */ public function getJsLayout() { - return \Zend_Json::encode($this->jsLayout); + return $this->serializer->serialize($this->jsLayout); } /** @@ -50,6 +60,14 @@ public function getConfig() ]; } + /** + * @return bool|string + */ + public function getSerializedConfig() + { + return $this->serializer->serialize($this->getConfig()); + } + /** * Is autocomplete enabled for storefront * diff --git a/app/code/Magento/Customer/Test/Unit/Block/Account/AuthenticationPopupTest.php b/app/code/Magento/Customer/Test/Unit/Block/Account/AuthenticationPopupTest.php index 67a3fb8f3a576..476111f8253ea 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Account/AuthenticationPopupTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Account/AuthenticationPopupTest.php @@ -31,6 +31,9 @@ class AuthenticationPopupTest extends \PHPUnit_Framework_TestCase /** @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ private $urlBuilderMock; + /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */ + private $serilizerMock; + protected function setUp() { $this->contextMock = $this->getMockBuilder(Context::class) @@ -72,8 +75,13 @@ function ($string) { ->method('getEscaper') ->willReturn($escaperMock); + $this->serilizerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) + ->getMock(); + $this->model = new AuthenticationPopup( - $this->contextMock + $this->contextMock, + [], + $this->serilizerMock ); } @@ -83,6 +91,7 @@ function ($string) { * @param string $registerUrl * @param string $forgotUrl * @param array $result + * @throws \PHPUnit_Framework_Exception * * @dataProvider dataProviderGetConfig */ @@ -172,4 +181,51 @@ public function dataProviderGetConfig() ], ]; } + + /** + * @param mixed $isAutocomplete + * @param string $baseUrl + * @param string $registerUrl + * @param string $forgotUrl + * @param array $result + * @throws \PHPUnit_Framework_Exception + * + * @dataProvider dataProviderGetConfig + */ + public function testGetSerializedConfig($isAutocomplete, $baseUrl, $registerUrl, $forgotUrl, array $result) + { + $this->scopeConfigMock->expects($this->any()) + ->method('getValue') + ->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE, null) + ->willReturn($isAutocomplete); + + /** @var StoreInterface||\PHPUnit_Framework_MockObject_MockObject $storeMock */ + $storeMock = $this->getMockBuilder(StoreInterface::class) + ->setMethods(['getBaseUrl']) + ->getMockForAbstractClass(); + + $this->storeManagerMock->expects($this->any()) + ->method('getStore') + ->with(null) + ->willReturn($storeMock); + + $storeMock->expects($this->any()) + ->method('getBaseUrl') + ->willReturn($baseUrl); + + $this->urlBuilderMock->expects($this->any()) + ->method('getUrl') + ->willReturnMap( + [ + ['customer/account/create', [], $registerUrl], + ['customer/account/forgotpassword', [], $forgotUrl], + ] + ); + $this->serilizerMock->expects($this->any())->method('serialize') + ->willReturn( + json_encode($this->model->getConfig()) + ); + + $this->assertEquals(json_encode($result), $this->model->getSerializedConfig()); + } } diff --git a/app/code/Magento/Customer/view/frontend/templates/account/authentication-popup.phtml b/app/code/Magento/Customer/view/frontend/templates/account/authentication-popup.phtml index bcf0cc92bc912..20ea488931398 100644 --- a/app/code/Magento/Customer/view/frontend/templates/account/authentication-popup.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/account/authentication-popup.phtml @@ -10,7 +10,7 @@ ?>