From 7bd5e25d290bf905fbf8254b66bedae01a5c6717 Mon Sep 17 00:00:00 2001 From: Fabian Schmengler Date: Fri, 8 May 2020 15:19:48 +0200 Subject: [PATCH 01/45] Prevent side effect on category objects store_id and url_key on save --- .../CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php index a86604672e2b4..5775d6dffee4a 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php @@ -124,6 +124,9 @@ protected function generateForGlobalScope( $mergeDataProvider = clone $this->mergeDataProviderPrototype; $categoryId = $category->getId(); foreach ($category->getStoreIds() as $storeId) { + if ($storeId !== Store::DEFAULT_STORE_ID) { + $category = clone $category; // prevent undesired side effects on original object + } $category->setStoreId($storeId); if (!$this->isGlobalScope($storeId) && $this->isOverrideUrlsForStore($storeId, $categoryId, $overrideStoreUrls) From 8bcd2fa8839cd3f0fb659d49ee1590b664b9687c Mon Sep 17 00:00:00 2001 From: Fabian Schmengler Date: Fri, 8 May 2020 15:54:36 +0200 Subject: [PATCH 02/45] Refactor: remove redundant check --- .../CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php index 5775d6dffee4a..f32cd77433c17 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php @@ -124,13 +124,11 @@ protected function generateForGlobalScope( $mergeDataProvider = clone $this->mergeDataProviderPrototype; $categoryId = $category->getId(); foreach ($category->getStoreIds() as $storeId) { - if ($storeId !== Store::DEFAULT_STORE_ID) { - $category = clone $category; // prevent undesired side effects on original object - } - $category->setStoreId($storeId); if (!$this->isGlobalScope($storeId) && $this->isOverrideUrlsForStore($storeId, $categoryId, $overrideStoreUrls) ) { + $category = clone $category; // prevent undesired side effects on original object + $category->setStoreId($storeId); $this->updateCategoryUrlForStore($storeId, $category); $mergeDataProvider->merge($this->generateForSpecificStoreView($storeId, $category, $rootCategoryId)); } From 87c5c609769388433a127ca0999addb4cb841691 Mon Sep 17 00:00:00 2001 From: Fabian Schmengler Date: Fri, 8 May 2020 16:23:34 +0200 Subject: [PATCH 03/45] Add missing categoryRepository property --- .../CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php index f32cd77433c17..5972982ff41ce 100644 --- a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php +++ b/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php @@ -54,6 +54,11 @@ class CategoryUrlRewriteGenerator */ private $mergeDataProviderPrototype; + /** + * @var CategoryRepositoryInterface + */ + private $categoryRepository; + /** * @var bool */ From 31c5963f8e21008e799598fc34b26e0728ba56f0 Mon Sep 17 00:00:00 2001 From: Fabian Schmengler Date: Fri, 8 May 2020 18:48:38 +0200 Subject: [PATCH 04/45] Add integration test for bugfix --- .../Model/CategoryUrlRewriteGeneratorTest.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryUrlRewriteGeneratorTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryUrlRewriteGeneratorTest.php index 1353dbff17b0b..d0b7d49ebccd7 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryUrlRewriteGeneratorTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryUrlRewriteGeneratorTest.php @@ -9,37 +9,35 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; /** - * Class CategoryUrlRewriteGeneratorTest - * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CategoryUrlRewriteGeneratorTest extends \PHPUnit\Framework\TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit\Framework\MockObject\MockObject */ private $canonicalUrlRewriteGenerator; - /** @var \PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit\Framework\MockObject\MockObject */ private $currentUrlRewritesRegenerator; - /** @var \PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit\Framework\MockObject\MockObject */ private $childrenUrlRewriteGenerator; /** @var \Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator */ private $categoryUrlRewriteGenerator; - /** @var \Magento\CatalogUrlRewrite\Service\V1\StoreViewService|\PHPUnit_Framework_MockObject_MockObject */ + /** @var \Magento\CatalogUrlRewrite\Service\V1\StoreViewService|\PHPUnit\Framework\MockObject\MockObject */ private $storeViewService; - /** @var \Magento\Catalog\Model\Category|\PHPUnit_Framework_MockObject_MockObject */ + /** @var \Magento\Catalog\Model\Category|\PHPUnit\Framework\MockObject\MockObject */ private $category; - /** @var \Magento\Catalog\Api\CategoryRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** @var \Magento\Catalog\Api\CategoryRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject */ private $categoryRepository; - /** @var \PHPUnit_Framework_MockObject_MockObject */ + /** @var \PHPUnit\Framework\MockObject\MockObject */ private $mergeDataProvider; - /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */ + /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit\Framework\MockObject\MockObject */ protected $serializer; /** @@ -141,6 +139,7 @@ public function testGenerationForGlobalScope() ], $this->categoryUrlRewriteGenerator->generate($this->category, false, $categoryId) ); + $this->assertEquals(0, $this->category->getStoreId(), 'Store ID should not have been modified'); } /** From 0118d484509c06254bbc8f392ab2eb6ca06ea18a Mon Sep 17 00:00:00 2001 From: Tymoteusz Motylewski Date: Fri, 24 Apr 2020 23:14:15 +0200 Subject: [PATCH 05/45] Fix SQL query quoting/casting when type is passed to where function The $type variable can be both string or int, so before comparing it to 'TYPE_CONDITION' string it has to be casted to avoid comparing integer zero with string (0 == 'TYPE_CONDITION') which will wrongly return true, and remove the information about type. Pass type provided to where function down the chain to allow automatic casting of arrays of values e.g. to int. This fixes following cases: 1) ->where('attr_table.store_id IN (?)', $storeIds, Zend_Db::INT_TYPE); 2) ->where('attr_table.store_id = ?', $storeId, Zend_Db::INT_TYPE); In both cases now passed value is correctly casted to int (either single value, or each value from array) Co-authored-by: Ihor Sviziev --- .../Magento/Framework/DB/Adapter/Pdo/Mysql.php | 7 ++++--- lib/internal/Magento/Framework/DB/Select.php | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index 7db91c06d9649..e4b2dad4a8108 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -21,6 +21,7 @@ use Magento\Framework\DB\Query\Generator as QueryGenerator; use Magento\Framework\DB\Select; use Magento\Framework\DB\SelectFactory; +use Magento\Framework\DB\Sql\Expression; use Magento\Framework\DB\Statement\Parameter; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Phrase; @@ -1511,10 +1512,10 @@ public function select() * Method revrited for handle empty arrays in value param * * @param string $text The text with a placeholder. - * @param mixed $value The value to quote. - * @param string $type OPTIONAL SQL datatype + * @param array|null|int|string|float|Expression|Select|\DateTimeInterface $value The value to quote. + * @param int|string|null $type OPTIONAL SQL datatype of the given value e.g. Zend_Db::FLOAT_TYPE or "INT" * @param integer $count OPTIONAL count of placeholders to replace - * @return string An SQL-safe quoted value placed into the orignal text. + * @return string An SQL-safe quoted value placed into the original text. */ public function quoteInto($text, $value, $type = null, $count = null) { diff --git a/lib/internal/Magento/Framework/DB/Select.php b/lib/internal/Magento/Framework/DB/Select.php index 075aa6b24faa7..4f79b0d314f1d 100644 --- a/lib/internal/Magento/Framework/DB/Select.php +++ b/lib/internal/Magento/Framework/DB/Select.php @@ -7,6 +7,7 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\DB\Sql\Expression; /** * Class for SQL SELECT generation and results. @@ -107,19 +108,19 @@ public function __construct( * * * @param string $cond The WHERE condition. - * @param string|array|null $value OPTIONAL An optional single or array value to quote into the condition. - * @param string|int|null $type OPTIONAL The type of the given value - * @return \Magento\Framework\DB\Select + * @param array|null|int|string|float|Expression|Select|\DateTimeInterface $value The value to quote. + * @param int|string|null $type OPTIONAL SQL datatype of the given value e.g. Zend_Db::FLOAT_TYPE or "INT" + * @return Select */ public function where($cond, $value = null, $type = null) { if ($value === null && $type === null) { $value = ''; - } elseif ($type == self::TYPE_CONDITION) { + } elseif ((string)$type === self::TYPE_CONDITION) { $type = null; } if (is_array($value)) { - $cond = $this->getConnection()->quoteInto($cond, $value); + $cond = $this->getConnection()->quoteInto($cond, $value, $type); $value = null; } return parent::where($cond, $value, $type); From f2468b5680879d3b50fed47fd766d1f074e6ffda Mon Sep 17 00:00:00 2001 From: Svyatoslav Date: Fri, 19 Jun 2020 22:21:23 +0300 Subject: [PATCH 06/45] Improvement PageLayout Config Builder. Added save in cache config files. --- .../Theme/Model/PageLayout/Config/Builder.php | 27 +++++++++++++++---- .../Model/PageLayout/Config/BuilderTest.php | 20 ++++++++++++-- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Theme/Model/PageLayout/Config/Builder.php b/app/code/Magento/Theme/Model/PageLayout/Config/Builder.php index 13b8aa23073ce..a982d6f6fd68f 100644 --- a/app/code/Magento/Theme/Model/PageLayout/Config/Builder.php +++ b/app/code/Magento/Theme/Model/PageLayout/Config/Builder.php @@ -12,6 +12,8 @@ */ class Builder implements \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface { + const CACHE_KEY_LAYOUTS = 'THEME_LAYOUTS_FILES_MERGED'; + /** * @var \Magento\Framework\View\PageLayout\ConfigFactory */ @@ -32,19 +34,27 @@ class Builder implements \Magento\Framework\View\Model\PageLayout\Config\Builder */ private $configFiles = []; + /** + * @var \Magento\Framework\App\Cache\Type\Layout + */ + protected $cacheModel; + /** * @param \Magento\Framework\View\PageLayout\ConfigFactory $configFactory * @param \Magento\Framework\View\PageLayout\File\Collector\Aggregated $fileCollector * @param \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection + * @param \Magento\Framework\App\Cache\Type\Layout $cacheModel */ public function __construct( \Magento\Framework\View\PageLayout\ConfigFactory $configFactory, \Magento\Framework\View\PageLayout\File\Collector\Aggregated $fileCollector, - \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection + \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection, + \Magento\Framework\App\Cache\Type\Layout $cacheModel ) { $this->configFactory = $configFactory; $this->fileCollector = $fileCollector; $this->themeCollection = $themeCollection; + $this->cacheModel = $cacheModel; $this->themeCollection->setItemObjectClass(\Magento\Theme\Model\Theme\Data::class); } @@ -57,7 +67,7 @@ public function getPageLayoutsConfig() } /** - * Retrieve configuration files. + * Retrieve configuration files. Caches merged layouts.xml XML files. * * @return array */ @@ -65,10 +75,17 @@ protected function getConfigFiles() { if (!$this->configFiles) { $configFiles = []; - foreach ($this->themeCollection->loadRegisteredThemes() as $theme) { - $configFiles[] = $this->fileCollector->getFilesContent($theme, 'layouts.xml'); + $this->configFiles = $this->cacheModel->load(self::CACHE_KEY_LAYOUTS); + if (!empty($this->configFiles)) { + $this->configFiles = @unserialize($this->configFiles);//if value in cache is corrupted. + } + if (empty($this->configFiles)) { + foreach ($this->themeCollection->loadRegisteredThemes() as $theme) { + $configFiles[] = $this->fileCollector->getFilesContent($theme, 'layouts.xml'); + } + $this->configFiles = array_merge(...$configFiles); + $this->cacheModel->save(serialize($this->configFiles), self::CACHE_KEY_LAYOUTS); } - $this->configFiles = array_merge(...$configFiles); } return $this->configFiles; diff --git a/app/code/Magento/Theme/Test/Unit/Model/PageLayout/Config/BuilderTest.php b/app/code/Magento/Theme/Test/Unit/Model/PageLayout/Config/BuilderTest.php index d9eccdb871222..f8975172a87b1 100644 --- a/app/code/Magento/Theme/Test/Unit/Model/PageLayout/Config/BuilderTest.php +++ b/app/code/Magento/Theme/Test/Unit/Model/PageLayout/Config/BuilderTest.php @@ -10,14 +10,19 @@ */ namespace Magento\Theme\Test\Unit\Model\PageLayout\Config; +use Magento\Framework\App\Cache\Type\FrontendPool; +use Magento\Framework\App\Cache\Type\Layout as LayoutCache; +use Magento\Framework\Cache\FrontendInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\View\PageLayout\Config; use Magento\Framework\View\PageLayout\File\Collector\Aggregated; +use Magento\TestFramework\Helper\Bootstrap; use Magento\Theme\Model\PageLayout\Config\Builder; use Magento\Theme\Model\ResourceModel\Theme\Collection; use Magento\Theme\Model\Theme\Data; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Magento\Framework\App\Cache\Type\Layout; class BuilderTest extends TestCase { @@ -41,6 +46,11 @@ class BuilderTest extends TestCase */ protected $themeCollection; + /** + * @var Layout|MockObject + */ + protected $cacheModel; + /** * SetUp method * @@ -58,21 +68,26 @@ protected function setUp(): void )->disableOriginalConstructor() ->getMock(); + $helper = new ObjectManager($this); $this->themeCollection = $this->getMockBuilder(Collection::class) ->disableOriginalConstructor() ->getMock(); + $this->cacheModel = $this->getMockBuilder(Layout::class) + ->disableOriginalConstructor() + ->getMock(); + $this->themeCollection->expects($this->once()) ->method('setItemObjectClass') ->with(Data::class) ->willReturnSelf(); - $helper = new ObjectManager($this); $this->builder = $helper->getObject( Builder::class, [ 'configFactory' => $this->configFactory, 'fileCollector' => $this->fileCollector, - 'themeCollection' => $this->themeCollection + 'themeCollection' => $this->themeCollection, + 'cacheModel' => $this->cacheModel, ] ); } @@ -84,6 +99,7 @@ protected function setUp(): void */ public function testGetPageLayoutsConfig() { + $this->cacheModel->clean(); $files1 = ['content layouts_1.xml', 'content layouts_2.xml']; $files2 = ['content layouts_3.xml', 'content layouts_4.xml']; From 09b63c7e378eea2db2453653b1348eb33e45600d Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Fri, 3 Jul 2020 09:48:44 +0200 Subject: [PATCH 07/45] Set up operation_key as nullable for support B2B implementations --- app/code/Magento/AsynchronousOperations/etc/db_schema.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/AsynchronousOperations/etc/db_schema.xml b/app/code/Magento/AsynchronousOperations/etc/db_schema.xml index 5d49d71ee46b0..ab482d2e2c761 100644 --- a/app/code/Magento/AsynchronousOperations/etc/db_schema.xml +++ b/app/code/Magento/AsynchronousOperations/etc/db_schema.xml @@ -34,7 +34,7 @@ - Date: Sun, 12 Jul 2020 12:12:56 -0400 Subject: [PATCH 08/45] Fix for wildcard section reload being broken by section-config refactor in 2bd4cb5 --- app/code/Magento/Customer/view/frontend/web/js/customer-data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js index 770ea47d754d3..1e4b9050dc2b3 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js +++ b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js @@ -86,7 +86,7 @@ define([ var parameters; sectionNames = sectionConfig.filterClientSideSections(sectionNames); - parameters = _.isArray(sectionNames) ? { + parameters = _.isArray(sectionNames) && sectionNames.indexOf('*') < 0 ? { sections: sectionNames.join(',') } : []; parameters['force_new_section_timestamp'] = forceNewSectionTimestamp; From 1505a36a8b21c0660e1cf519b7bd703e581789c1 Mon Sep 17 00:00:00 2001 From: Greg Harvell Date: Mon, 20 Jul 2020 15:08:18 -0400 Subject: [PATCH 09/45] Added Jasmine tests for Magento_Customer customer-data.js --- .../frontend/js/customer-data.test.js | 272 ++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js new file mode 100644 index 0000000000000..398d48f2e3a08 --- /dev/null +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -0,0 +1,272 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +/* eslint max-nested-callbacks: 0 */ + +define([ + 'squire' +], function (Squire) { + 'use strict'; + + var injector = new Squire(), + originalGetJSON, + storage, + storageInvalidation = {}, + obj; + + beforeEach(function (done) { + injector.require(['Magento_Customer/js/customer-data'], function (Constr) { + originalGetJSON = $.getJSON; + obj = Constr; + done(); + }); + }); + + afterEach(function () { + try { + injector.clean(); + injector.remove(); + $.getJSON = originalGetJSON; + } catch (e) { + } + }); + + describe('Magento_Customer/js/customer-data', function () { + + describe('"init" method', function () { + beforeEach(function () { + spyOn(obj, "reload").and.returnValue(true); + + storageInvalidation = { + keys: function () { + return ['section']; + } + } + + var dataProvider = { + getFromStorage: function (sections) { + return ['section']; + } + }; + + storage = { + keys: function () { + return ['section']; + } + }; + + spyOn(dataProvider, "getFromStorage"); + spyOn(storage, "keys").and.returnValue(['section']); + spyOn(storageInvalidation, "keys").and.returnValue(['section']); + }); + + it('Should be defined', function () { + expect(obj.hasOwnProperty('init')).toBeDefined(); + }); + + it('Does not throw before component is initialized', function () { + expect(function () { + obj.init(); + }).not.toThrow(); + }); + + it('Calls "getExpiredSectionNames" method', function () { + spyOn(obj, "getExpiredSectionNames").and.returnValue([]); + obj.init(); + expect(obj.getExpiredSectionNames).toHaveBeenCalled(); + }); + + it('Calls "reload" method when expired sections exist', function () { + spyOn(obj, "getExpiredSectionNames").and.returnValue(['section']); + obj.init(); + expect(obj.reload).toHaveBeenCalled(); + }); + + it('Calls "reload" method when expired sections do not exist', function () { + spyOn(obj, "getExpiredSectionNames").and.returnValue([]); + + _.isEmpty = jasmine.createSpy().and.returnValue(false); + + obj.init(); + expect(obj.reload).toHaveBeenCalled(); + }); + }); + + describe('"getExpiredSectionNames" method', function () { + it('Should be defined', function () { + expect(obj.hasOwnProperty('getExpiredSectionNames')).toBeDefined(); + }); + + it('Does not throw before component is initialized', function () { + expect(function () { + obj.getExpiredSectionNames(); + }).not.toThrow(); + }); + }); + + describe('"get" method', function () { + it('Should be defined', function () { + expect(obj.hasOwnProperty('get')).toBeDefined(); + }); + + it('Does not throw before component is initialized', function () { + expect(function () { + obj.get(); + }).not.toThrow(); + }); + }); + + describe('"set" method', function () { + it('Should be defined', function () { + expect(obj.hasOwnProperty('set')).toBeDefined(); + }); + + it('Does not throw before component is initialized', function () { + expect(function () { + obj.set('cart', {}); + }).not.toThrow(); + }); + }); + + describe('"reload" method', function () { + beforeEach(function () { + $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + var deferred = $.Deferred(); + + deferred.promise().done = function () { + return { + responseJSON: { + section: {} + } + }; + }; + + return deferred.promise(); + }); + }); + + it('Should be defined', function () { + expect(obj.hasOwnProperty('reload')).toBeDefined(); + }); + + it('Does not throw before component is initialized', function () { + expect(function () { + obj.reload(); + }).not.toThrow(); + }); + + it('Returns proper sections object when passed array with a single section name', function () { + var result; + + $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + var deferred = $.Deferred(); + + deferred.promise().done = function () { + return { + responseJSON: { + section: {} + } + }; + }; + + expect(parameters).toEqual(jasmine.objectContaining({ + "sections": "section" + })); + + return deferred.promise(); + }); + + result = obj.reload(['section'], true); + + expect(result).toEqual(jasmine.objectContaining({ + responseJSON: { + section: {} + } + })); + }); + + it('Returns proper sections object when passed array with a multiple section names', function () { + var result; + + $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + var deferred = $.Deferred(); + + expect(parameters).toEqual(jasmine.objectContaining({ + "sections": "cart,customer,messages" + })); + + deferred.promise().done = function () { + return { + responseJSON: { + cart: {}, + customer: {}, + messages: {} + } + }; + }; + + return deferred.promise(); + }); + + result = obj.reload(['cart', 'customer', 'messages'], true); + + expect(result).toEqual(jasmine.objectContaining({ + responseJSON: { + cart: {}, + customer: {}, + messages: {} + } + })); + }); + + it('Returns all sections when passed wildcard string', function () { + var result; + + $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + var deferred = $.Deferred(); + + expect(parameters).toEqual(jasmine.objectContaining({ + "force_new_section_timestamp": true + })); + + deferred.promise().done = function () { + return { + responseJSON: { + cart: {}, + customer: {}, + messages: {} + } + }; + }; + + return deferred.promise(); + }); + + result = obj.reload('*', true); + + expect($.getJSON).toHaveBeenCalled(); + expect(result).toEqual(jasmine.objectContaining({ + responseJSON: { + cart: {}, + customer: {}, + messages: {} + } + })); + }); + }); + + describe('"invalidate" method', function () { + it('Should be defined', function () { + expect(obj.hasOwnProperty('invalidate')).toBeDefined(); + }); + }); + + describe('"Magento_Customer/js/customer-data" method', function () { + it('Should be defined', function () { + expect(obj.hasOwnProperty('Magento_Customer/js/customer-data')).toBeDefined(); + }); + }); + }); +}); From ff99146565f414f23a4105b3f8926d31fe4a39e8 Mon Sep 17 00:00:00 2001 From: Greg Harvell Date: Thu, 23 Jul 2020 10:00:54 -0400 Subject: [PATCH 10/45] Updated customerData jasmine test to work when whole test suite is run and fixed an issue with jquery/jquery-storageapi where object may not exist yet. --- .../frontend/js/customer-data.test.js | 86 +++++++++++-------- lib/web/jquery/jquery.storageapi.min.js | 2 +- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js index 398d48f2e3a08..d973d3a1bd9c0 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -6,57 +6,57 @@ /* eslint max-nested-callbacks: 0 */ define([ - 'squire' -], function (Squire) { + 'squire', + 'jquery', + 'jquery/jquery-storageapi' +], function (Squire, $) { 'use strict'; var injector = new Squire(), - originalGetJSON, - storage, - storageInvalidation = {}, + sectionConfig, obj; - beforeEach(function (done) { - injector.require(['Magento_Customer/js/customer-data'], function (Constr) { - originalGetJSON = $.getJSON; - obj = Constr; - done(); - }); - }); + describe('Magento_Customer/js/customer-data', function () { - afterEach(function () { - try { - injector.clean(); - injector.remove(); - $.getJSON = originalGetJSON; - } catch (e) { - } - }); + beforeEach(function (done) { + injector.require([ + 'Magento_Customer/js/customer-data', + 'Magento_Customer/js/section-config' + ], function (Constr, sectionConfiguration) { + obj = Constr; + sectionConfig = sectionConfiguration; + done(); + }); + }); - describe('Magento_Customer/js/customer-data', function () { + afterEach(function () { + try { + injector.clean(); + injector.remove(); + } catch (e) { + } + }); describe('"init" method', function () { - beforeEach(function () { - spyOn(obj, "reload").and.returnValue(true); - - storageInvalidation = { + var storageInvalidation = { keys: function () { return ['section']; } - } - - var dataProvider = { - getFromStorage: function (sections) { + }, + dataProvider = { + getFromStorage: function () { return ['section']; } - }; - + }, storage = { keys: function () { return ['section']; } }; + beforeEach(function () { + spyOn(obj, "reload").and.returnValue(true); + spyOn($, 'initNamespaceStorage').and.returnValue(true); spyOn(dataProvider, "getFromStorage"); spyOn(storage, "keys").and.returnValue(['section']); spyOn(storageInvalidation, "keys").and.returnValue(['section']); @@ -124,15 +124,17 @@ define([ }); it('Does not throw before component is initialized', function () { + _.each = jasmine.createSpy().and.returnValue(true); + expect(function () { - obj.set('cart', {}); + obj.set(); }).not.toThrow(); }); }); describe('"reload" method', function () { beforeEach(function () { - $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { var deferred = $.Deferred(); deferred.promise().done = function () { @@ -160,7 +162,9 @@ define([ it('Returns proper sections object when passed array with a single section name', function () { var result; - $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + spyOn(sectionConfig, 'filterClientSideSections').and.returnValue(['section']); + + jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { var deferred = $.Deferred(); deferred.promise().done = function () { @@ -190,7 +194,9 @@ define([ it('Returns proper sections object when passed array with a multiple section names', function () { var result; - $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + spyOn(sectionConfig, 'filterClientSideSections').and.returnValue(['cart,customer,messages']); + + jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { var deferred = $.Deferred(); expect(parameters).toEqual(jasmine.objectContaining({ @@ -224,7 +230,7 @@ define([ it('Returns all sections when passed wildcard string', function () { var result; - $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { var deferred = $.Deferred(); expect(parameters).toEqual(jasmine.objectContaining({ @@ -246,7 +252,7 @@ define([ result = obj.reload('*', true); - expect($.getJSON).toHaveBeenCalled(); + expect(jQuery.getJSON).toHaveBeenCalled(); expect(result).toEqual(jasmine.objectContaining({ responseJSON: { cart: {}, @@ -261,6 +267,12 @@ define([ it('Should be defined', function () { expect(obj.hasOwnProperty('invalidate')).toBeDefined(); }); + + it('Does not throw before component is initialized', function () { + expect(function () { + obj.invalidate(); + }).not.toThrow(); + }); }); describe('"Magento_Customer/js/customer-data" method', function () { diff --git a/lib/web/jquery/jquery.storageapi.min.js b/lib/web/jquery/jquery.storageapi.min.js index 886c3d847ed3b..5f39773343663 100644 --- a/lib/web/jquery/jquery.storageapi.min.js +++ b/lib/web/jquery/jquery.storageapi.min.js @@ -1,2 +1,2 @@ /* jQuery Storage API Plugin 1.7.3 https://github.com/julien-maurel/jQuery-Storage-API */ -!function(e){"function"==typeof define&&define.amd?define(["jquery", "jquery/jquery.cookie"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t){var r,i,n,o=arguments.length,s=window[t],a=arguments,u=a[1];if(2>o)throw Error("Minimum 2 arguments must be given");if(e.isArray(u)){i={};for(var f in u){r=u[f];try{i[r]=JSON.parse(s.getItem(r))}catch(c){i[r]=s.getItem(r)}}return i}if(2!=o){try{i=JSON.parse(s.getItem(u))}catch(c){throw new ReferenceError(u+" is not defined in this storage")}for(var f=2;o-1>f;f++)if(i=i[a[f]],void 0===i)throw new ReferenceError([].slice.call(a,1,f+1).join(".")+" is not defined in this storage");if(e.isArray(a[f])){n=i,i={};for(var m in a[f])i[a[f][m]]=n[a[f][m]];return i}return i[a[f]]}try{return JSON.parse(s.getItem(u))}catch(c){return s.getItem(u)}}function r(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1],u=s[2],f={};if(2>n||!e.isPlainObject(a)&&3>n)throw Error("Minimum 3 arguments must be given or second parameter must be an object");if(e.isPlainObject(a)){for(var c in a)r=a[c],e.isPlainObject(r)?o.setItem(c,JSON.stringify(r)):o.setItem(c,r);return a}if(3==n)return"object"==typeof u?o.setItem(a,JSON.stringify(u)):o.setItem(a,u),u;try{i=o.getItem(a),null!=i&&(f=JSON.parse(i))}catch(m){}i=f;for(var c=2;n-2>c;c++)r=s[c],i[r]&&e.isPlainObject(i[r])||(i[r]={}),i=i[r];return i[s[c]]=s[c+1],o.setItem(a,JSON.stringify(f)),f}function i(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1];if(2>n)throw Error("Minimum 2 arguments must be given");if(e.isArray(a)){for(var u in a)o.removeItem(a[u]);return!0}if(2==n)return o.removeItem(a),!0;try{r=i=JSON.parse(o.getItem(a))}catch(f){throw new ReferenceError(a+" is not defined in this storage")}for(var u=2;n-1>u;u++)if(i=i[s[u]],void 0===i)throw new ReferenceError([].slice.call(s,1,u).join(".")+" is not defined in this storage");if(e.isArray(s[u]))for(var c in s[u])delete i[s[u][c]];else delete i[s[u]];return o.setItem(a,JSON.stringify(r)),!0}function n(t,r){var n=a(t);for(var o in n)i(t,n[o]);if(r)for(var o in e.namespaceStorages)u(o)}function o(r){var i=arguments.length,n=arguments,s=(window[r],n[1]);if(1==i)return 0==a(r).length;if(e.isArray(s)){for(var u=0;ui)throw Error("Minimum 2 arguments must be given");if(e.isArray(o)){for(var a=0;a1?t.apply(this,o):n,a._cookie)for(var u in e.cookie())""!=u&&s.push(u.replace(a._prefix,""));else for(var f in a)s.push(f);return s}function u(t){if(!t||"string"!=typeof t)throw Error("First parameter must be a string");g?(window.localStorage.getItem(t)||window.localStorage.setItem(t,"{}"),window.sessionStorage.getItem(t)||window.sessionStorage.setItem(t,"{}")):(window.localCookieStorage.getItem(t)||window.localCookieStorage.setItem(t,"{}"),window.sessionCookieStorage.getItem(t)||window.sessionCookieStorage.setItem(t,"{}"));var r={localStorage:e.extend({},e.localStorage,{_ns:t}),sessionStorage:e.extend({},e.sessionStorage,{_ns:t})};return e.cookie&&(window.cookieStorage.getItem(t)||window.cookieStorage.setItem(t,"{}"),r.cookieStorage=e.extend({},e.cookieStorage,{_ns:t})),e.namespaceStorages[t]=r,r}function f(e){if(!window[e])return!1;var t="jsapi";try{return window[e].setItem(t,t),window[e].removeItem(t),!0}catch(r){return!1}}var c="ls_",m="ss_",g=f("localStorage"),h={_type:"",_ns:"",_callMethod:function(e,t){var r=[this._type],t=Array.prototype.slice.call(t),i=t[0];return this._ns&&r.push(this._ns),"string"==typeof i&&-1!==i.indexOf(".")&&(t.shift(),[].unshift.apply(t,i.split("."))),[].push.apply(r,t),e.apply(this,r)},get:function(){return this._callMethod(t,arguments)},set:function(){var t=arguments.length,i=arguments,n=i[0];if(1>t||!e.isPlainObject(n)&&2>t)throw Error("Minimum 2 arguments must be given or first parameter must be an object");if(e.isPlainObject(n)&&this._ns){for(var o in n)r(this._type,this._ns,o,n[o]);return n}var s=this._callMethod(r,i);return this._ns?s[n.split(".")[0]]:s},remove:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(i,arguments)},removeAll:function(e){return this._ns?(r(this._type,this._ns,{}),!0):n(this._type,e)},isEmpty:function(){return this._callMethod(o,arguments)},isSet:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(s,arguments)},keys:function(){return this._callMethod(a,arguments)}};if(e.cookie){window.name||(window.name=Math.floor(1e8*Math.random()));var l={_cookie:!0,_prefix:"",_expires:null,_path:null,_domain:null,setItem:function(t,r){e.cookie(this._prefix+t,r,{expires:this._expires,path:this._path,domain:this._domain})},getItem:function(t){return e.cookie(this._prefix+t)},removeItem:function(t){return e.removeCookie(this._prefix+t)},clear:function(){for(var t in e.cookie())""!=t&&(!this._prefix&&-1===t.indexOf(c)&&-1===t.indexOf(m)||this._prefix&&0===t.indexOf(this._prefix))&&e.removeCookie(t)},setExpires:function(e){return this._expires=e,this},setPath:function(e){return this._path=e,this},setDomain:function(e){return this._domain=e,this},setConf:function(e){return e.path&&(this._path=e.path),e.domain&&(this._domain=e.domain),e.expires&&(this._expires=e.expires),this},setDefaultConf:function(){this._path=this._domain=this._expires=null}};g||(window.localCookieStorage=e.extend({},l,{_prefix:c,_expires:3650}),window.sessionCookieStorage=e.extend({},l,{_prefix:m+window.name+"_"})),window.cookieStorage=e.extend({},l),e.cookieStorage=e.extend({},h,{_type:"cookieStorage",setExpires:function(e){return window.cookieStorage.setExpires(e),this},setPath:function(e){return window.cookieStorage.setPath(e),this},setDomain:function(e){return window.cookieStorage.setDomain(e),this},setConf:function(e){return window.cookieStorage.setConf(e),this},setDefaultConf:function(){return window.cookieStorage.setDefaultConf(),this}})}e.initNamespaceStorage=function(e){return u(e)},g?(e.localStorage=e.extend({},h,{_type:"localStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionStorage"})):(e.localStorage=e.extend({},h,{_type:"localCookieStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionCookieStorage"})),e.namespaceStorages={},e.removeAllStorages=function(t){e.localStorage.removeAll(t),e.sessionStorage.removeAll(t),e.cookieStorage&&e.cookieStorage.removeAll(t),t||(e.namespaceStorages={})}}); \ No newline at end of file +!function(e){"function"==typeof define&&define.amd?define(["jquery", "jquery/jquery.cookie"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t){var r,i,n,o=arguments.length,s=window[t],a=arguments,u=a[1];if(2>o)throw Error("Minimum 2 arguments must be given");if(e.isArray(u)){i={};for(var f in u){r=u[f];try{i[r]=JSON.parse(s.getItem(r))}catch(c){i[r]=s.getItem(r)}}return i}if(2!=o){try{i=JSON.parse(s.getItem(u))}catch(c){throw new ReferenceError(u+" is not defined in this storage")}for(var f=2;o-1>f;f++)if(i=i[a[f]],void 0===i)throw new ReferenceError([].slice.call(a,1,f+1).join(".")+" is not defined in this storage");if(e.isArray(a[f])){n=i,i={};for(var m in a[f])i[a[f][m]]=n[a[f][m]];return i}return i[a[f]]}try{return JSON.parse(s.getItem(u))}catch(c){return s.getItem(u)}}function r(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1],u=s[2],f={};if(2>n||!e.isPlainObject(a)&&3>n)throw Error("Minimum 3 arguments must be given or second parameter must be an object");if(e.isPlainObject(a)){for(var c in a)r=a[c],e.isPlainObject(r)?o.setItem(c,JSON.stringify(r)):o.setItem(c,r);return a}if(3==n)return"object"==typeof u?o.setItem(a,JSON.stringify(u)):o.setItem(a,u),u;try{i=o.getItem(a),null!=i&&(f=JSON.parse(i))}catch(m){}i=f;for(var c=2;n-2>c;c++)r=s[c],i[r]&&e.isPlainObject(i[r])||(i[r]={}),i=i[r];return i[s[c]]=s[c+1],o.setItem(a,JSON.stringify(f)),f}function i(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1];if(2>n)throw Error("Minimum 2 arguments must be given");if(e.isArray(a)){for(var u in a)o.removeItem(a[u]);return!0}if(2==n)return o.removeItem(a),!0;try{r=i=JSON.parse(o.getItem(a))}catch(f){throw new ReferenceError(a+" is not defined in this storage")}for(var u=2;n-1>u;u++)if(i=i[s[u]],void 0===i)throw new ReferenceError([].slice.call(s,1,u).join(".")+" is not defined in this storage");if(e.isArray(s[u]))for(var c in s[u])delete i[s[u][c]];else delete i[s[u]];return o.setItem(a,JSON.stringify(r)),!0}function n(t,r){var n=a(t);for(var o in n)i(t,n[o]);if(r)for(var o in e.namespaceStorages)u(o)}function o(r){var i=arguments.length,n=arguments,s=(window[r],n[1]);if(1==i)return 0==a(r).length;if(e.isArray(s)){for(var u=0;ui)throw Error("Minimum 2 arguments must be given");if(e.isArray(o)){for(var a=0;a1?t.apply(this,o):n,a&&a._cookie)for(var u in e.cookie())""!=u&&s.push(u.replace(a._prefix,""));else for(var f in a)s.push(f);return s}function u(t){if(!t||"string"!=typeof t)throw Error("First parameter must be a string");g?(window.localStorage.getItem(t)||window.localStorage.setItem(t,"{}"),window.sessionStorage.getItem(t)||window.sessionStorage.setItem(t,"{}")):(window.localCookieStorage.getItem(t)||window.localCookieStorage.setItem(t,"{}"),window.sessionCookieStorage.getItem(t)||window.sessionCookieStorage.setItem(t,"{}"));var r={localStorage:e.extend({},e.localStorage,{_ns:t}),sessionStorage:e.extend({},e.sessionStorage,{_ns:t})};return e.cookie&&(window.cookieStorage.getItem(t)||window.cookieStorage.setItem(t,"{}"),r.cookieStorage=e.extend({},e.cookieStorage,{_ns:t})),e.namespaceStorages[t]=r,r}function f(e){if(!window[e])return!1;var t="jsapi";try{return window[e].setItem(t,t),window[e].removeItem(t),!0}catch(r){return!1}}var c="ls_",m="ss_",g=f("localStorage"),h={_type:"",_ns:"",_callMethod:function(e,t){var r=[this._type],t=Array.prototype.slice.call(t),i=t[0];return this._ns&&r.push(this._ns),"string"==typeof i&&-1!==i.indexOf(".")&&(t.shift(),[].unshift.apply(t,i.split("."))),[].push.apply(r,t),e.apply(this,r)},get:function(){return this._callMethod(t,arguments)},set:function(){var t=arguments.length,i=arguments,n=i[0];if(1>t||!e.isPlainObject(n)&&2>t)throw Error("Minimum 2 arguments must be given or first parameter must be an object");if(e.isPlainObject(n)&&this._ns){for(var o in n)r(this._type,this._ns,o,n[o]);return n}var s=this._callMethod(r,i);return this._ns?s[n.split(".")[0]]:s},remove:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(i,arguments)},removeAll:function(e){return this._ns?(r(this._type,this._ns,{}),!0):n(this._type,e)},isEmpty:function(){return this._callMethod(o,arguments)},isSet:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(s,arguments)},keys:function(){return this._callMethod(a,arguments)}};if(e.cookie){window.name||(window.name=Math.floor(1e8*Math.random()));var l={_cookie:!0,_prefix:"",_expires:null,_path:null,_domain:null,setItem:function(t,r){e.cookie(this._prefix+t,r,{expires:this._expires,path:this._path,domain:this._domain})},getItem:function(t){return e.cookie(this._prefix+t)},removeItem:function(t){return e.removeCookie(this._prefix+t)},clear:function(){for(var t in e.cookie())""!=t&&(!this._prefix&&-1===t.indexOf(c)&&-1===t.indexOf(m)||this._prefix&&0===t.indexOf(this._prefix))&&e.removeCookie(t)},setExpires:function(e){return this._expires=e,this},setPath:function(e){return this._path=e,this},setDomain:function(e){return this._domain=e,this},setConf:function(e){return e.path&&(this._path=e.path),e.domain&&(this._domain=e.domain),e.expires&&(this._expires=e.expires),this},setDefaultConf:function(){this._path=this._domain=this._expires=null}};g||(window.localCookieStorage=e.extend({},l,{_prefix:c,_expires:3650}),window.sessionCookieStorage=e.extend({},l,{_prefix:m+window.name+"_"})),window.cookieStorage=e.extend({},l),e.cookieStorage=e.extend({},h,{_type:"cookieStorage",setExpires:function(e){return window.cookieStorage.setExpires(e),this},setPath:function(e){return window.cookieStorage.setPath(e),this},setDomain:function(e){return window.cookieStorage.setDomain(e),this},setConf:function(e){return window.cookieStorage.setConf(e),this},setDefaultConf:function(){return window.cookieStorage.setDefaultConf(),this}})}e.initNamespaceStorage=function(e){return u(e)},g?(e.localStorage=e.extend({},h,{_type:"localStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionStorage"})):(e.localStorage=e.extend({},h,{_type:"localCookieStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionCookieStorage"})),e.namespaceStorages={},e.removeAllStorages=function(t){e.localStorage.removeAll(t),e.sessionStorage.removeAll(t),e.cookieStorage&&e.cookieStorage.removeAll(t),t||(e.namespaceStorages={})}}); From 8047497701d5a332ad692844f12af11f344d9854 Mon Sep 17 00:00:00 2001 From: Greg Harvell Date: Fri, 24 Jul 2020 10:41:48 -0400 Subject: [PATCH 11/45] Fixed eslint & jscs errors with customer-data.test.js, reseting methods to their original context after being mocked. --- .../frontend/js/customer-data.test.js | 76 ++++++++++++++++--- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js index d973d3a1bd9c0..613b70f4c4838 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -3,8 +3,8 @@ * See COPYING.txt for license details. */ +/* global _ */ /* eslint max-nested-callbacks: 0 */ - define([ 'squire', 'jquery', @@ -14,6 +14,10 @@ define([ var injector = new Squire(), sectionConfig, + originalGetJSON, + originalReload, + originalInitNamespaceStorage, + originalEach, obj; describe('Magento_Customer/js/customer-data', function () { @@ -39,27 +43,46 @@ define([ describe('"init" method', function () { var storageInvalidation = { + /** + * Mock Keys Method + * @returns array + */ keys: function () { return ['section']; } }, dataProvider = { + /** + * Mock getFromStorage Method + * @returns array + */ getFromStorage: function () { return ['section']; } }, storage = { + /** + * Mock Keys Method + * @returns array + */ keys: function () { return ['section']; } }; beforeEach(function () { - spyOn(obj, "reload").and.returnValue(true); + originalReload = obj.reload; + originalInitNamespaceStorage = $.initNamespaceStorage; + spyOn(obj, 'reload').and.returnValue(true); spyOn($, 'initNamespaceStorage').and.returnValue(true); - spyOn(dataProvider, "getFromStorage"); - spyOn(storage, "keys").and.returnValue(['section']); - spyOn(storageInvalidation, "keys").and.returnValue(['section']); + spyOn(dataProvider, 'getFromStorage'); + spyOn(storage, 'keys').and.returnValue(['section']); + spyOn(storageInvalidation, 'keys').and.returnValue(['section']); + }); + + afterEach(function () { + obj.reload = originalReload; + $.initNameSpaceStorage = originalInitNamespaceStorage; }); it('Should be defined', function () { @@ -73,19 +96,19 @@ define([ }); it('Calls "getExpiredSectionNames" method', function () { - spyOn(obj, "getExpiredSectionNames").and.returnValue([]); + spyOn(obj, 'getExpiredSectionNames').and.returnValue([]); obj.init(); expect(obj.getExpiredSectionNames).toHaveBeenCalled(); }); it('Calls "reload" method when expired sections exist', function () { - spyOn(obj, "getExpiredSectionNames").and.returnValue(['section']); + spyOn(obj, 'getExpiredSectionNames').and.returnValue(['section']); obj.init(); expect(obj.reload).toHaveBeenCalled(); }); it('Calls "reload" method when expired sections do not exist', function () { - spyOn(obj, "getExpiredSectionNames").and.returnValue([]); + spyOn(obj, 'getExpiredSectionNames').and.returnValue([]); _.isEmpty = jasmine.createSpy().and.returnValue(false); @@ -119,6 +142,14 @@ define([ }); describe('"set" method', function () { + beforeEach(function () { + originalEach = _.each; + }); + + afterEach(function () { + _.each = originalEach; + }); + it('Should be defined', function () { expect(obj.hasOwnProperty('set')).toBeDefined(); }); @@ -134,9 +165,14 @@ define([ describe('"reload" method', function () { beforeEach(function () { - jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + originalGetJSON = jQuery.getJSON; + jQuery.getJSON = jasmine.createSpy().and.callFake(function () { var deferred = $.Deferred(); + /** + * Mock Done Method for getJSON + * @returns object + */ deferred.promise().done = function () { return { responseJSON: { @@ -149,6 +185,10 @@ define([ }); }); + afterEach(function () { + jQuery.getJSON = originalGetJSON; + }); + it('Should be defined', function () { expect(obj.hasOwnProperty('reload')).toBeDefined(); }); @@ -167,6 +207,10 @@ define([ jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { var deferred = $.Deferred(); + /** + * Mock Done Method for getJSON + * @returns object + */ deferred.promise().done = function () { return { responseJSON: { @@ -176,7 +220,7 @@ define([ }; expect(parameters).toEqual(jasmine.objectContaining({ - "sections": "section" + sections: 'section' })); return deferred.promise(); @@ -200,9 +244,13 @@ define([ var deferred = $.Deferred(); expect(parameters).toEqual(jasmine.objectContaining({ - "sections": "cart,customer,messages" + sections: 'cart,customer,messages' })); + /** + * Mock Done Method for getJSON + * @returns object + */ deferred.promise().done = function () { return { responseJSON: { @@ -234,9 +282,13 @@ define([ var deferred = $.Deferred(); expect(parameters).toEqual(jasmine.objectContaining({ - "force_new_section_timestamp": true + 'force_new_section_timestamp': true })); + /** + * Mock Done Method for getJSON + * @returns object + */ deferred.promise().done = function () { return { responseJSON: { From dd862a21c29de46c362a050638b277c7deda34c9 Mon Sep 17 00:00:00 2001 From: Greg Harvell Date: Tue, 28 Jul 2020 08:15:42 -0400 Subject: [PATCH 12/45] Reverting jQuery StorageApi back to original version. --- lib/web/jquery/jquery.storageapi.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web/jquery/jquery.storageapi.min.js b/lib/web/jquery/jquery.storageapi.min.js index 5f39773343663..fcf296a384bce 100644 --- a/lib/web/jquery/jquery.storageapi.min.js +++ b/lib/web/jquery/jquery.storageapi.min.js @@ -1,2 +1,2 @@ /* jQuery Storage API Plugin 1.7.3 https://github.com/julien-maurel/jQuery-Storage-API */ -!function(e){"function"==typeof define&&define.amd?define(["jquery", "jquery/jquery.cookie"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t){var r,i,n,o=arguments.length,s=window[t],a=arguments,u=a[1];if(2>o)throw Error("Minimum 2 arguments must be given");if(e.isArray(u)){i={};for(var f in u){r=u[f];try{i[r]=JSON.parse(s.getItem(r))}catch(c){i[r]=s.getItem(r)}}return i}if(2!=o){try{i=JSON.parse(s.getItem(u))}catch(c){throw new ReferenceError(u+" is not defined in this storage")}for(var f=2;o-1>f;f++)if(i=i[a[f]],void 0===i)throw new ReferenceError([].slice.call(a,1,f+1).join(".")+" is not defined in this storage");if(e.isArray(a[f])){n=i,i={};for(var m in a[f])i[a[f][m]]=n[a[f][m]];return i}return i[a[f]]}try{return JSON.parse(s.getItem(u))}catch(c){return s.getItem(u)}}function r(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1],u=s[2],f={};if(2>n||!e.isPlainObject(a)&&3>n)throw Error("Minimum 3 arguments must be given or second parameter must be an object");if(e.isPlainObject(a)){for(var c in a)r=a[c],e.isPlainObject(r)?o.setItem(c,JSON.stringify(r)):o.setItem(c,r);return a}if(3==n)return"object"==typeof u?o.setItem(a,JSON.stringify(u)):o.setItem(a,u),u;try{i=o.getItem(a),null!=i&&(f=JSON.parse(i))}catch(m){}i=f;for(var c=2;n-2>c;c++)r=s[c],i[r]&&e.isPlainObject(i[r])||(i[r]={}),i=i[r];return i[s[c]]=s[c+1],o.setItem(a,JSON.stringify(f)),f}function i(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1];if(2>n)throw Error("Minimum 2 arguments must be given");if(e.isArray(a)){for(var u in a)o.removeItem(a[u]);return!0}if(2==n)return o.removeItem(a),!0;try{r=i=JSON.parse(o.getItem(a))}catch(f){throw new ReferenceError(a+" is not defined in this storage")}for(var u=2;n-1>u;u++)if(i=i[s[u]],void 0===i)throw new ReferenceError([].slice.call(s,1,u).join(".")+" is not defined in this storage");if(e.isArray(s[u]))for(var c in s[u])delete i[s[u][c]];else delete i[s[u]];return o.setItem(a,JSON.stringify(r)),!0}function n(t,r){var n=a(t);for(var o in n)i(t,n[o]);if(r)for(var o in e.namespaceStorages)u(o)}function o(r){var i=arguments.length,n=arguments,s=(window[r],n[1]);if(1==i)return 0==a(r).length;if(e.isArray(s)){for(var u=0;ui)throw Error("Minimum 2 arguments must be given");if(e.isArray(o)){for(var a=0;a1?t.apply(this,o):n,a&&a._cookie)for(var u in e.cookie())""!=u&&s.push(u.replace(a._prefix,""));else for(var f in a)s.push(f);return s}function u(t){if(!t||"string"!=typeof t)throw Error("First parameter must be a string");g?(window.localStorage.getItem(t)||window.localStorage.setItem(t,"{}"),window.sessionStorage.getItem(t)||window.sessionStorage.setItem(t,"{}")):(window.localCookieStorage.getItem(t)||window.localCookieStorage.setItem(t,"{}"),window.sessionCookieStorage.getItem(t)||window.sessionCookieStorage.setItem(t,"{}"));var r={localStorage:e.extend({},e.localStorage,{_ns:t}),sessionStorage:e.extend({},e.sessionStorage,{_ns:t})};return e.cookie&&(window.cookieStorage.getItem(t)||window.cookieStorage.setItem(t,"{}"),r.cookieStorage=e.extend({},e.cookieStorage,{_ns:t})),e.namespaceStorages[t]=r,r}function f(e){if(!window[e])return!1;var t="jsapi";try{return window[e].setItem(t,t),window[e].removeItem(t),!0}catch(r){return!1}}var c="ls_",m="ss_",g=f("localStorage"),h={_type:"",_ns:"",_callMethod:function(e,t){var r=[this._type],t=Array.prototype.slice.call(t),i=t[0];return this._ns&&r.push(this._ns),"string"==typeof i&&-1!==i.indexOf(".")&&(t.shift(),[].unshift.apply(t,i.split("."))),[].push.apply(r,t),e.apply(this,r)},get:function(){return this._callMethod(t,arguments)},set:function(){var t=arguments.length,i=arguments,n=i[0];if(1>t||!e.isPlainObject(n)&&2>t)throw Error("Minimum 2 arguments must be given or first parameter must be an object");if(e.isPlainObject(n)&&this._ns){for(var o in n)r(this._type,this._ns,o,n[o]);return n}var s=this._callMethod(r,i);return this._ns?s[n.split(".")[0]]:s},remove:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(i,arguments)},removeAll:function(e){return this._ns?(r(this._type,this._ns,{}),!0):n(this._type,e)},isEmpty:function(){return this._callMethod(o,arguments)},isSet:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(s,arguments)},keys:function(){return this._callMethod(a,arguments)}};if(e.cookie){window.name||(window.name=Math.floor(1e8*Math.random()));var l={_cookie:!0,_prefix:"",_expires:null,_path:null,_domain:null,setItem:function(t,r){e.cookie(this._prefix+t,r,{expires:this._expires,path:this._path,domain:this._domain})},getItem:function(t){return e.cookie(this._prefix+t)},removeItem:function(t){return e.removeCookie(this._prefix+t)},clear:function(){for(var t in e.cookie())""!=t&&(!this._prefix&&-1===t.indexOf(c)&&-1===t.indexOf(m)||this._prefix&&0===t.indexOf(this._prefix))&&e.removeCookie(t)},setExpires:function(e){return this._expires=e,this},setPath:function(e){return this._path=e,this},setDomain:function(e){return this._domain=e,this},setConf:function(e){return e.path&&(this._path=e.path),e.domain&&(this._domain=e.domain),e.expires&&(this._expires=e.expires),this},setDefaultConf:function(){this._path=this._domain=this._expires=null}};g||(window.localCookieStorage=e.extend({},l,{_prefix:c,_expires:3650}),window.sessionCookieStorage=e.extend({},l,{_prefix:m+window.name+"_"})),window.cookieStorage=e.extend({},l),e.cookieStorage=e.extend({},h,{_type:"cookieStorage",setExpires:function(e){return window.cookieStorage.setExpires(e),this},setPath:function(e){return window.cookieStorage.setPath(e),this},setDomain:function(e){return window.cookieStorage.setDomain(e),this},setConf:function(e){return window.cookieStorage.setConf(e),this},setDefaultConf:function(){return window.cookieStorage.setDefaultConf(),this}})}e.initNamespaceStorage=function(e){return u(e)},g?(e.localStorage=e.extend({},h,{_type:"localStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionStorage"})):(e.localStorage=e.extend({},h,{_type:"localCookieStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionCookieStorage"})),e.namespaceStorages={},e.removeAllStorages=function(t){e.localStorage.removeAll(t),e.sessionStorage.removeAll(t),e.cookieStorage&&e.cookieStorage.removeAll(t),t||(e.namespaceStorages={})}}); +!function(e){"function"==typeof define&&define.amd?define(["jquery", "jquery/jquery.cookie"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){function t(t){var r,i,n,o=arguments.length,s=window[t],a=arguments,u=a[1];if(2>o)throw Error("Minimum 2 arguments must be given");if(e.isArray(u)){i={};for(var f in u){r=u[f];try{i[r]=JSON.parse(s.getItem(r))}catch(c){i[r]=s.getItem(r)}}return i}if(2!=o){try{i=JSON.parse(s.getItem(u))}catch(c){throw new ReferenceError(u+" is not defined in this storage")}for(var f=2;o-1>f;f++)if(i=i[a[f]],void 0===i)throw new ReferenceError([].slice.call(a,1,f+1).join(".")+" is not defined in this storage");if(e.isArray(a[f])){n=i,i={};for(var m in a[f])i[a[f][m]]=n[a[f][m]];return i}return i[a[f]]}try{return JSON.parse(s.getItem(u))}catch(c){return s.getItem(u)}}function r(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1],u=s[2],f={};if(2>n||!e.isPlainObject(a)&&3>n)throw Error("Minimum 3 arguments must be given or second parameter must be an object");if(e.isPlainObject(a)){for(var c in a)r=a[c],e.isPlainObject(r)?o.setItem(c,JSON.stringify(r)):o.setItem(c,r);return a}if(3==n)return"object"==typeof u?o.setItem(a,JSON.stringify(u)):o.setItem(a,u),u;try{i=o.getItem(a),null!=i&&(f=JSON.parse(i))}catch(m){}i=f;for(var c=2;n-2>c;c++)r=s[c],i[r]&&e.isPlainObject(i[r])||(i[r]={}),i=i[r];return i[s[c]]=s[c+1],o.setItem(a,JSON.stringify(f)),f}function i(t){var r,i,n=arguments.length,o=window[t],s=arguments,a=s[1];if(2>n)throw Error("Minimum 2 arguments must be given");if(e.isArray(a)){for(var u in a)o.removeItem(a[u]);return!0}if(2==n)return o.removeItem(a),!0;try{r=i=JSON.parse(o.getItem(a))}catch(f){throw new ReferenceError(a+" is not defined in this storage")}for(var u=2;n-1>u;u++)if(i=i[s[u]],void 0===i)throw new ReferenceError([].slice.call(s,1,u).join(".")+" is not defined in this storage");if(e.isArray(s[u]))for(var c in s[u])delete i[s[u][c]];else delete i[s[u]];return o.setItem(a,JSON.stringify(r)),!0}function n(t,r){var n=a(t);for(var o in n)i(t,n[o]);if(r)for(var o in e.namespaceStorages)u(o)}function o(r){var i=arguments.length,n=arguments,s=(window[r],n[1]);if(1==i)return 0==a(r).length;if(e.isArray(s)){for(var u=0;ui)throw Error("Minimum 2 arguments must be given");if(e.isArray(o)){for(var a=0;a1?t.apply(this,o):n,a._cookie)for(var u in e.cookie())""!=u&&s.push(u.replace(a._prefix,""));else for(var f in a)s.push(f);return s}function u(t){if(!t||"string"!=typeof t)throw Error("First parameter must be a string");g?(window.localStorage.getItem(t)||window.localStorage.setItem(t,"{}"),window.sessionStorage.getItem(t)||window.sessionStorage.setItem(t,"{}")):(window.localCookieStorage.getItem(t)||window.localCookieStorage.setItem(t,"{}"),window.sessionCookieStorage.getItem(t)||window.sessionCookieStorage.setItem(t,"{}"));var r={localStorage:e.extend({},e.localStorage,{_ns:t}),sessionStorage:e.extend({},e.sessionStorage,{_ns:t})};return e.cookie&&(window.cookieStorage.getItem(t)||window.cookieStorage.setItem(t,"{}"),r.cookieStorage=e.extend({},e.cookieStorage,{_ns:t})),e.namespaceStorages[t]=r,r}function f(e){if(!window[e])return!1;var t="jsapi";try{return window[e].setItem(t,t),window[e].removeItem(t),!0}catch(r){return!1}}var c="ls_",m="ss_",g=f("localStorage"),h={_type:"",_ns:"",_callMethod:function(e,t){var r=[this._type],t=Array.prototype.slice.call(t),i=t[0];return this._ns&&r.push(this._ns),"string"==typeof i&&-1!==i.indexOf(".")&&(t.shift(),[].unshift.apply(t,i.split("."))),[].push.apply(r,t),e.apply(this,r)},get:function(){return this._callMethod(t,arguments)},set:function(){var t=arguments.length,i=arguments,n=i[0];if(1>t||!e.isPlainObject(n)&&2>t)throw Error("Minimum 2 arguments must be given or first parameter must be an object");if(e.isPlainObject(n)&&this._ns){for(var o in n)r(this._type,this._ns,o,n[o]);return n}var s=this._callMethod(r,i);return this._ns?s[n.split(".")[0]]:s},remove:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(i,arguments)},removeAll:function(e){return this._ns?(r(this._type,this._ns,{}),!0):n(this._type,e)},isEmpty:function(){return this._callMethod(o,arguments)},isSet:function(){if(arguments.length<1)throw Error("Minimum 1 argument must be given");return this._callMethod(s,arguments)},keys:function(){return this._callMethod(a,arguments)}};if(e.cookie){window.name||(window.name=Math.floor(1e8*Math.random()));var l={_cookie:!0,_prefix:"",_expires:null,_path:null,_domain:null,setItem:function(t,r){e.cookie(this._prefix+t,r,{expires:this._expires,path:this._path,domain:this._domain})},getItem:function(t){return e.cookie(this._prefix+t)},removeItem:function(t){return e.removeCookie(this._prefix+t)},clear:function(){for(var t in e.cookie())""!=t&&(!this._prefix&&-1===t.indexOf(c)&&-1===t.indexOf(m)||this._prefix&&0===t.indexOf(this._prefix))&&e.removeCookie(t)},setExpires:function(e){return this._expires=e,this},setPath:function(e){return this._path=e,this},setDomain:function(e){return this._domain=e,this},setConf:function(e){return e.path&&(this._path=e.path),e.domain&&(this._domain=e.domain),e.expires&&(this._expires=e.expires),this},setDefaultConf:function(){this._path=this._domain=this._expires=null}};g||(window.localCookieStorage=e.extend({},l,{_prefix:c,_expires:3650}),window.sessionCookieStorage=e.extend({},l,{_prefix:m+window.name+"_"})),window.cookieStorage=e.extend({},l),e.cookieStorage=e.extend({},h,{_type:"cookieStorage",setExpires:function(e){return window.cookieStorage.setExpires(e),this},setPath:function(e){return window.cookieStorage.setPath(e),this},setDomain:function(e){return window.cookieStorage.setDomain(e),this},setConf:function(e){return window.cookieStorage.setConf(e),this},setDefaultConf:function(){return window.cookieStorage.setDefaultConf(),this}})}e.initNamespaceStorage=function(e){return u(e)},g?(e.localStorage=e.extend({},h,{_type:"localStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionStorage"})):(e.localStorage=e.extend({},h,{_type:"localCookieStorage"}),e.sessionStorage=e.extend({},h,{_type:"sessionCookieStorage"})),e.namespaceStorages={},e.removeAllStorages=function(t){e.localStorage.removeAll(t),e.sessionStorage.removeAll(t),e.cookieStorage&&e.cookieStorage.removeAll(t),t||(e.namespaceStorages={})}}); From cdfc6814958dc07fe47c41725b6a0715fce76309 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 14 Aug 2020 10:24:27 +0300 Subject: [PATCH 13/45] Fix js unit test failures --- .../Customer/frontend/js/customer-data.test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js index 613b70f4c4838..55340bfc6fe60 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -74,7 +74,16 @@ define([ originalReload = obj.reload; originalInitNamespaceStorage = $.initNamespaceStorage; spyOn(obj, 'reload').and.returnValue(true); - spyOn($, 'initNamespaceStorage').and.returnValue(true); + spyOn($, 'initNamespaceStorage').and.callFake(function (name) { + let ns = { + localStorage: {cookie: false, _ns: name}, + sessionStorage: {cookie: false, _ns: name} + }; + + $.namespaceStorages[name] = ns; + + return ns; + }); spyOn(dataProvider, 'getFromStorage'); spyOn(storage, 'keys').and.returnValue(['section']); spyOn(storageInvalidation, 'keys').and.returnValue(['section']); @@ -83,6 +92,7 @@ define([ afterEach(function () { obj.reload = originalReload; $.initNameSpaceStorage = originalInitNamespaceStorage; + $.namespaceStorages={}; }); it('Should be defined', function () { From c2e254c868fec04e6d356c25c6b963ea8e02518a Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 14 Aug 2020 11:40:17 +0300 Subject: [PATCH 14/45] Revert not related changes From c4900734f8608cbadd51bb1032c2a8bfad2d0870 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 14 Aug 2020 13:10:50 +0300 Subject: [PATCH 15/45] Fix static test --- .../Customer/frontend/js/customer-data.test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js index 55340bfc6fe60..3e5e274315058 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -76,8 +76,14 @@ define([ spyOn(obj, 'reload').and.returnValue(true); spyOn($, 'initNamespaceStorage').and.callFake(function (name) { let ns = { - localStorage: {cookie: false, _ns: name}, - sessionStorage: {cookie: false, _ns: name} + localStorage: { + cookie: false, + _ns: name + }, + sessionStorage: { + cookie: false, + _ns: name + } }; $.namespaceStorages[name] = ns; @@ -92,7 +98,7 @@ define([ afterEach(function () { obj.reload = originalReload; $.initNameSpaceStorage = originalInitNamespaceStorage; - $.namespaceStorages={}; + $.namespaceStorages = {}; }); it('Should be defined', function () { From 176013fd10f724e2a33998b02c93294ec1772a40 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 14 Aug 2020 17:38:57 +0300 Subject: [PATCH 16/45] Fix static tests --- .../app/code/Magento/Customer/frontend/js/customer-data.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js index 3e5e274315058..e2caa08617ef2 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -75,7 +75,7 @@ define([ originalInitNamespaceStorage = $.initNamespaceStorage; spyOn(obj, 'reload').and.returnValue(true); spyOn($, 'initNamespaceStorage').and.callFake(function (name) { - let ns = { + var ns = { localStorage: { cookie: false, _ns: name From 2922c1c293e41fa1d056d868c816b6f0f2e5c160 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 14 Aug 2020 18:56:47 +0300 Subject: [PATCH 17/45] Fix failing unit test --- .../frontend/js/customer-data.test.js | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js index e2caa08617ef2..20be2cae41be5 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -16,7 +16,6 @@ define([ sectionConfig, originalGetJSON, originalReload, - originalInitNamespaceStorage, originalEach, obj; @@ -72,24 +71,12 @@ define([ beforeEach(function () { originalReload = obj.reload; - originalInitNamespaceStorage = $.initNamespaceStorage; spyOn(obj, 'reload').and.returnValue(true); - spyOn($, 'initNamespaceStorage').and.callFake(function (name) { - var ns = { - localStorage: { - cookie: false, - _ns: name - }, - sessionStorage: { - cookie: false, - _ns: name - } - }; - $.namespaceStorages[name] = ns; + //Init storage api library + $.initNamespaceStorage('mage-cache-storage').localStorage; + $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage; - return ns; - }); spyOn(dataProvider, 'getFromStorage'); spyOn(storage, 'keys').and.returnValue(['section']); spyOn(storageInvalidation, 'keys').and.returnValue(['section']); @@ -97,7 +84,6 @@ define([ afterEach(function () { obj.reload = originalReload; - $.initNameSpaceStorage = originalInitNamespaceStorage; $.namespaceStorages = {}; }); From 5031159fef1c5621f5c8bb0ccbc8e8efb9b70972 Mon Sep 17 00:00:00 2001 From: Daniel Beitler Date: Wed, 19 Aug 2020 21:58:57 -0400 Subject: [PATCH 18/45] UPS Shipment Tracking: Change "Delivered On" title --- .../DataProviders/Tracking/ChangeTitle.php | 34 ++++++++ .../Tracking/ChangeTitleTest.php | 81 +++++++++++++++++++ app/code/Magento/Ups/etc/di.xml | 3 + 3 files changed, 118 insertions(+) create mode 100644 app/code/Magento/Ups/Plugin/Block/DataProviders/Tracking/ChangeTitle.php create mode 100644 app/code/Magento/Ups/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php diff --git a/app/code/Magento/Ups/Plugin/Block/DataProviders/Tracking/ChangeTitle.php b/app/code/Magento/Ups/Plugin/Block/DataProviders/Tracking/ChangeTitle.php new file mode 100644 index 0000000000000..973b199217271 --- /dev/null +++ b/app/code/Magento/Ups/Plugin/Block/DataProviders/Tracking/ChangeTitle.php @@ -0,0 +1,34 @@ +getCarrier() === Carrier::CODE) { + $result = __('Status Updated On:'); + } + return $result; + } +} diff --git a/app/code/Magento/Ups/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php b/app/code/Magento/Ups/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php new file mode 100644 index 0000000000000..fa608584be964 --- /dev/null +++ b/app/code/Magento/Ups/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php @@ -0,0 +1,81 @@ +plugin = $objectManagerHelper->getObject(ChangeTitle::class); + } + + /** + * Check if DeliveryDateTitle was changed if the carrier is UPS + * + * @param string $carrierCode + * @param string $originalResult + * @param Phrase|string $finalResult + * @dataProvider testAfterGetTitleDataProvider + */ + public function testAfterGetTitle(string $carrierCode, string $originalResult, $finalResult) + { + /** @var DeliveryDateTitle|MockObject $subjectMock */ + $subjectMock = $this->getMockBuilder(DeliveryDateTitle::class) + ->disableOriginalConstructor() + ->getMock(); + + /** @var Status|MockObject $trackingStatusMock */ + $trackingStatusMock = $this->getMockBuilder(Status::class) + ->disableOriginalConstructor() + ->setMethods(['getCarrier']) + ->getMock(); + $trackingStatusMock->expects($this::once()) + ->method('getCarrier') + ->willReturn($carrierCode); + + $actual = $this->plugin->afterGetTitle($subjectMock, $originalResult, $trackingStatusMock); + + $this->assertEquals($finalResult, $actual); + } + + /** + * Data provider + * + * @return array + */ + public function testAfterGetTitleDataProvider(): array + { + return [ + [Carrier::CODE, 'Original Title', __('Status Updated On:')], + ['not-fedex', 'Original Title', 'Original Title'], + ]; + } +} diff --git a/app/code/Magento/Ups/etc/di.xml b/app/code/Magento/Ups/etc/di.xml index a04a5eb48bdab..08d751fc3e2c8 100644 --- a/app/code/Magento/Ups/etc/di.xml +++ b/app/code/Magento/Ups/etc/di.xml @@ -28,4 +28,7 @@ + + + From 77d62ef15b1092d8869aa6dfbcd419effd157beb Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 25 Aug 2020 18:01:09 +0300 Subject: [PATCH 19/45] async-opetation-status-issue Added intagration test for testing saving bulk operation with not set 'operation_id' during executing \Magento\Catalog\Model\Attribute\Backend\Consumer::process() method. --- .../Model/Attribute/Backend/ConsumerTest.php | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php new file mode 100644 index 0000000000000..ebba99914d705 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php @@ -0,0 +1,149 @@ +objectManager = Bootstrap::getObjectManager(); + $this->publisherMock = $this->getMockForAbstractClass(BulkPublisherInterface::class); + + $this->bulkManagement = $this->objectManager->create( + BulkManagement::class, + [ + 'publisher' => $this->publisherMock + ] + ); + $this->bulkStatus = $this->objectManager->get(BulkStatus::class); + $catalogProductMock = $this->createMock(\Magento\Catalog\Helper\Product::class); + $productFlatIndexerProcessorMock = $this->createMock( + \Magento\Catalog\Model\Indexer\Product\Flat\Processor::class + ); + $productPriceIndexerProcessorMock = $this->createMock( + \Magento\Catalog\Model\Indexer\Product\Price\Processor::class + ); + $operationManagementMock = $this->createMock( + \Magento\Framework\Bulk\OperationManagementInterface::class + ); + $actionMock = $this->createMock(\Magento\Catalog\Model\Product\Action::class); + $loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class); + $this->serializer = $this->objectManager->get(\Magento\Framework\Serialize\SerializerInterface::class); + $entityManager = $this->objectManager->get(\Magento\Framework\EntityManager\EntityManager::class); + $this->model = $this->objectManager->create( + Consumer::class, + [ + 'catalogProduct' => $catalogProductMock, + 'productFlatIndexerProcessor' => $productFlatIndexerProcessorMock, + 'productPriceIndexerProcessor' => $productPriceIndexerProcessorMock, + 'operationManagement' => $operationManagementMock, + 'action' => $actionMock, + 'logger' => $loggerMock, + 'serializer' => $this->serializer, + 'entityManager' => $entityManager + ] + ); + + parent::setUp(); + } + + /** + * Testing saving bulk operation during processing operation by attribute backend consumer + */ + public function testSaveOperationDuringProcess() + { + $operation = $this->prepareUpdateAttributesBulkAndOperation(); + try { + $this->model->process($operation); + } catch (\Exception $e) { + $this->fail(sprintf('Operation save process failed.: %s', $e->getMessage())); + } + $operationStatus = $operation->getStatus(); + $this->assertEquals( + 1, + $this->bulkStatus->getOperationsCountByBulkIdAndStatus(self::BULK_UUID, $operationStatus) + ); + } + + /** + * Schedules test bulk and returns operation + * @return OperationInterface + */ + private function prepareUpdateAttributesBulkAndOperation(): OperationInterface + { + // general bulk information + $bulkUuid = self::BULK_UUID; + $bulkDescription = 'Update attributes for 2 selected products'; + $topicName = 'product_action_attribute.update'; + $userId = 1; + /** @var OperationInterfaceFactory $operationFactory */ + $operationFactory = $this->objectManager->get(OperationInterfaceFactory::class); + $operation = $operationFactory->create(); + $operation->setBulkUuid($bulkUuid) + ->setTopicName($topicName) + ->setSerializedData($this->serializer->serialize( + ['product_ids' => [1,3], 'attributes' => [], 'store_id' => '0'] + )); + $this->bulkManagement->scheduleBulk($bulkUuid, [$operation], $bulkDescription, $userId); + return $operation; + } + + /** + * Clear created bulk and operation + */ + protected function tearDown(): void + { + $this->bulkManagement->deleteBulk(self::BULK_UUID); + parent::tearDown(); + } +} From 3b397e34ae8e05fbf08b01395bd733f08cf9bb21 Mon Sep 17 00:00:00 2001 From: Greg Harvell Date: Thu, 27 Aug 2020 16:18:20 -0400 Subject: [PATCH 20/45] Fix for customer-data.test failing due to storage not existing yet. --- .../app/code/Magento/Customer/frontend/js/customer-data.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js index 20be2cae41be5..ae497004e59de 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -92,6 +92,8 @@ define([ }); it('Does not throw before component is initialized', function () { + obj.initStorage(); + expect(function () { obj.init(); }).not.toThrow(); From 4da31ea9c11948ca6853524295fa5276c5c5ff9b Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 9 Sep 2020 14:03:54 +0200 Subject: [PATCH 21/45] Fix static tests and small alignments --- .../Model/Attribute/Backend/ConsumerTest.php | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php index ebba99914d705..fd7e01dee6b1e 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php @@ -8,21 +8,34 @@ namespace Magento\Catalog\Model\Attribute\Backend; +use Magento\AsynchronousOperations\Api\Data\OperationInterface; use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory; -use PHPUnit\Framework\TestCase; -use Magento\TestFramework\Helper\Bootstrap; -use Magento\Framework\ObjectManagerInterface; use Magento\AsynchronousOperations\Model\BulkManagement; use Magento\AsynchronousOperations\Model\BulkStatus; -use Magento\AsynchronousOperations\Api\Data\OperationInterface; use Magento\Framework\MessageQueue\BulkPublisherInterface; +use Magento\Framework\ObjectManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\TestCase; +use Magento\Catalog\Helper\Product; +use Magento\Catalog\Model\Indexer\Product\Flat\Processor; +use Magento\Framework\Bulk\OperationManagementInterface; +use Magento\Catalog\Model\Product\Action; +use Psr\Log\LoggerInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\EntityManager\EntityManager; +use Magento\Catalog\Model\Attribute\Backend\Consumer; +/** + * Test for Mysql Consumer execution + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class ConsumerTest extends TestCase { const BULK_UUID = '5a12c1bd-a8b5-41d4-8c00-3f5bcaa6d3c8'; /** - * @var \Magento\Catalog\Model\Attribute\Backend\Consumer + * @var Consumer */ private $model; @@ -47,7 +60,7 @@ class ConsumerTest extends TestCase private $objectManager; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var SerializerInterface */ private $serializer; @@ -66,20 +79,20 @@ protected function setUp(): void ] ); $this->bulkStatus = $this->objectManager->get(BulkStatus::class); - $catalogProductMock = $this->createMock(\Magento\Catalog\Helper\Product::class); + $catalogProductMock = $this->createMock(Product::class); $productFlatIndexerProcessorMock = $this->createMock( - \Magento\Catalog\Model\Indexer\Product\Flat\Processor::class + Processor::class ); $productPriceIndexerProcessorMock = $this->createMock( - \Magento\Catalog\Model\Indexer\Product\Price\Processor::class + Processor::class ); $operationManagementMock = $this->createMock( - \Magento\Framework\Bulk\OperationManagementInterface::class + OperationManagementInterface::class ); - $actionMock = $this->createMock(\Magento\Catalog\Model\Product\Action::class); - $loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class); - $this->serializer = $this->objectManager->get(\Magento\Framework\Serialize\SerializerInterface::class); - $entityManager = $this->objectManager->get(\Magento\Framework\EntityManager\EntityManager::class); + $actionMock = $this->createMock(Action::class); + $loggerMock = $this->createMock(LoggerInterface::class); + $this->serializer = $this->objectManager->get(SerializerInterface::class); + $entityManager = $this->objectManager->get(EntityManager::class); $this->model = $this->objectManager->create( Consumer::class, [ From a0e65ed26f6b31fcff0eec02c72a1da1ffa86938 Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 9 Sep 2020 17:35:38 +0200 Subject: [PATCH 22/45] Align tests --- .../Catalog/Model/Attribute/Backend/ConsumerTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php index fd7e01dee6b1e..8dffcdbdd4582 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php @@ -17,7 +17,8 @@ use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; use Magento\Catalog\Helper\Product; -use Magento\Catalog\Model\Indexer\Product\Flat\Processor; +use Magento\Catalog\Model\Indexer\Product\Flat\Processor as FlatProcessor; +use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceProcessor; use Magento\Framework\Bulk\OperationManagementInterface; use Magento\Catalog\Model\Product\Action; use Psr\Log\LoggerInterface; @@ -81,10 +82,10 @@ protected function setUp(): void $this->bulkStatus = $this->objectManager->get(BulkStatus::class); $catalogProductMock = $this->createMock(Product::class); $productFlatIndexerProcessorMock = $this->createMock( - Processor::class + FlatProcessor::class ); $productPriceIndexerProcessorMock = $this->createMock( - Processor::class + PriceProcessor::class ); $operationManagementMock = $this->createMock( OperationManagementInterface::class From 5de71f6075d312d78dfe2509b412646665919d8f Mon Sep 17 00:00:00 2001 From: Greg Harvell Date: Wed, 9 Sep 2020 11:36:40 -0400 Subject: [PATCH 23/45] Adjustments to customer-data.test.js based off code review. --- .../frontend/js/customer-data.test.js | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js index e82b2261861d4..60c7bdea6a36e 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js @@ -18,6 +18,8 @@ define([ var injector = new Squire(), obj, + _, + originaljQuery, originalGetJSON, originalReload, originalIsEmpty, @@ -103,12 +105,14 @@ define([ }); beforeEach(function (done) { - originalGetJSON = jQuery.getJSON; + originalGetJSON = $.getJSON; sectionConfig['Magento_Customer/js/section-config'](sectionConfigSettings); injector.require([ + 'underscore', 'Magento_Customer/js/customer-data' - ], function (Constr) { + ], function (underscore, Constr) { + _ = underscore; obj = Constr; done(); }); @@ -116,7 +120,7 @@ define([ afterEach(function () { try { - jQuery.getJSON = originalGetJSON; + $.getJSON = originalGetJSON; clearLocalStorage(); injector.clean(); injector.remove(); @@ -125,14 +129,20 @@ define([ }); describe('"init" method', function () { + var storageInvalidation = { + keys: function () { + return ['section']; + } + }; + beforeEach(function () { originalReload = obj.reload; originalIsEmpty = _.isEmpty; - spyOn(obj, 'reload').and.returnValue(true); - $.initNamespaceStorage('mage-cache-storage').localStorage; $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage; + + spyOn(storageInvalidation, 'keys').and.returnValue(['section']); }); afterEach(function () { @@ -161,13 +171,15 @@ define([ it('Calls "reload" method when expired sections exist', function () { spyOn(obj, 'getExpiredSectionNames').and.returnValue(['section']); + spyOn(obj, 'reload').and.returnValue(true); obj.init(); expect(obj.reload).toHaveBeenCalled(); }); it('Calls "reload" method when expired sections do not exist', function () { spyOn(obj, 'getExpiredSectionNames').and.returnValue([]); - _.isEmpty = jasmine.createSpy('_.isEmpty').and.returnValue(false); + spyOn(obj, 'reload').and.returnValue(true); + spyOn(_, 'isEmpty').and.returnValue(false); obj.init(); expect(obj.reload).toHaveBeenCalled(); @@ -180,14 +192,14 @@ define([ } }); - jQuery.getJSON = jasmine.createSpy().and.callFake(function () { + $.getJSON = jasmine.createSpy().and.callFake(function () { var deferred = $.Deferred(); return deferred.promise(); }); init(); - expect(jQuery.getJSON).not.toHaveBeenCalled(); + expect($.getJSON).not.toHaveBeenCalled(); }); it('Check it requests sections from the server if there are expired sections', function () { @@ -246,6 +258,13 @@ define([ 'content': {} } }); + + $.getJSON = jasmine.createSpy('$.getJSON').and.callFake(function () { + var deferred = $.Deferred(); + + return deferred.promise(); + }); + init(); expect(customerData.getExpiredSectionNames()).toEqual(['cart']); }); @@ -268,6 +287,12 @@ define([ } }); + $.getJSON = jasmine.createSpy('$.getJSON').and.callFake(function () { + var deferred = $.Deferred(); + + return deferred.promise(); + }); + init(); expect(customerData.getExpiredSectionNames()).toEqual(['cart']); }); @@ -320,7 +345,10 @@ define([ describe('"reload" method', function () { beforeEach(function () { - jQuery.getJSON = jasmine.createSpy().and.callFake(function () { + originaljQuery = $; + $ = jQuery; + + $.getJSON = jasmine.createSpy().and.callFake(function () { var deferred = $.Deferred(); /** @@ -339,6 +367,10 @@ define([ }); }); + afterEach(function () { + $ = originaljQuery; + }); + it('Should be defined', function () { expect(obj.hasOwnProperty('reload')).toBeDefined(); }); @@ -354,7 +386,7 @@ define([ spyOn(sectionConfig, 'filterClientSideSections').and.returnValue(['section']); - jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { var deferred = $.Deferred(); /** @@ -390,7 +422,7 @@ define([ spyOn(sectionConfig, 'filterClientSideSections').and.returnValue(['cart,customer,messages']); - jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { var deferred = $.Deferred(); expect(parameters).toEqual(jasmine.objectContaining({ @@ -428,7 +460,7 @@ define([ it('Check it returns all sections when passed wildcard string', function () { var result; - jQuery.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { + $.getJSON = jasmine.createSpy().and.callFake(function (url, parameters) { var deferred = $.Deferred(); expect(parameters).toEqual(jasmine.objectContaining({ @@ -454,7 +486,7 @@ define([ result = obj.reload('*', true); - expect(jQuery.getJSON).toHaveBeenCalled(); + expect($.getJSON).toHaveBeenCalled(); expect(result).toEqual(jasmine.objectContaining({ responseJSON: { cart: {}, From 1472740580d7a5b051455c3e62a2233a33545077 Mon Sep 17 00:00:00 2001 From: Marcos Trama Date: Wed, 9 Sep 2020 22:54:43 -0300 Subject: [PATCH 24/45] Update zip_codes.xml Changed regex for zipcodes from Brazil. All zipcode must have 8 positions, with or without dash --- app/code/Magento/Directory/etc/zip_codes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Directory/etc/zip_codes.xml b/app/code/Magento/Directory/etc/zip_codes.xml index 3c540f7ce0ffd..14d250656d28c 100644 --- a/app/code/Magento/Directory/etc/zip_codes.xml +++ b/app/code/Magento/Directory/etc/zip_codes.xml @@ -64,7 +64,7 @@ - ^[0-9]{5}$ + ^[0-9]{8}$ ^[0-9]{5}\-[0-9]{3}$ From fd4a2c7f1759d03f54faa228b66efc7af51dd5a2 Mon Sep 17 00:00:00 2001 From: Greg Harvell Date: Thu, 10 Sep 2020 07:31:49 -0400 Subject: [PATCH 25/45] Fixing a broken multi-shipping test. --- .../Multishipping/frontend/js/multi-shipping.test.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js index 65ee180476f3a..a8ae8ab65e378 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Multishipping/frontend/js/multi-shipping.test.js @@ -68,9 +68,11 @@ define([ var addNewAddressBtn, addressflag, canContinueBtn, - canContinueFlag; + canContinueFlag, + originalGetJSON; beforeEach(function () { + originalGetJSON = $.getJSON; addNewAddressBtn = $('