From 80811fcfeab152106788b9029ed2de18051c9898 Mon Sep 17 00:00:00 2001 From: Nadiya Syvokonenko Date: Mon, 21 Aug 2017 13:35:35 +0300 Subject: [PATCH 1/8] MAGETWO-49796: Catalog top nav, CSS class not set to active when using Varnish --- lib/web/mage/menu.js | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/web/mage/menu.js b/lib/web/mage/menu.js index fdb796addbcf0..01708c092f1ab 100644 --- a/lib/web/mage/menu.js +++ b/lib/web/mage/menu.js @@ -59,6 +59,8 @@ define([ } this._assignControls()._listen(); + + this._setActiveMenu(); }, /** @@ -108,6 +110,49 @@ define([ } }, + /** + * Sets 'active' CSS class to menu item for active category if it was not set before. + * If menu item has parent categories, sets 'has-active' class to all af them + * + * @private + * + * @return void + */ + _setActiveMenu: function () { + var currentUrl = window.location.href.split('?')[0], + activeCategoryLink = this.element.find('a[href="' + currentUrl + '"]'); + + if (activeCategoryLink && activeCategoryLink.parent().hasClass('active') !== true + && activeCategoryLink.hasClass('ui-corner-all') + ) { + activeCategoryLink.parent().addClass('active'); + var classes = activeCategoryLink.parent().attr('class'), + classStartPosition = classes.indexOf('nav-'), + classNav = classes.substring(classStartPosition, classes.indexOf(' ', classStartPosition)); + + this._setActiveParent(classNav); + } + }, + + /** + * Sets 'has-active' CSS class to all parent categories in menu has active category + * + * @private + * + * @param {String} childClassName - Class name of active category
  • element + * @return void + */ + _setActiveParent: function (childClassName) { + var parentClass = childClassName.substr(0, childClassName.lastIndexOf('-')); + if (parentClass.lastIndexOf('-') !== -1) { + var parent = this.element.find('.' + parentClass); + if (parent) { + parent.addClass('has-active'); + } + this._setActiveParent(parentClass); + } + }, + /** * Add class for expanded option. */ From 4d9be10cefe65bd3181dc182b3fbffc88e513c7c Mon Sep 17 00:00:00 2001 From: Nadiya Syvokonenko Date: Mon, 21 Aug 2017 18:29:50 +0300 Subject: [PATCH 2/8] MAGETWO-49796: Catalog top nav, CSS class not set to active when using Varnish - cover case for product view page --- lib/web/mage/menu.js | 98 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 21 deletions(-) diff --git a/lib/web/mage/menu.js b/lib/web/mage/menu.js index 01708c092f1ab..b9fefb8f706f1 100644 --- a/lib/web/mage/menu.js +++ b/lib/web/mage/menu.js @@ -59,7 +59,6 @@ define([ } this._assignControls()._listen(); - this._setActiveMenu(); }, @@ -111,48 +110,105 @@ define([ }, /** - * Sets 'active' CSS class to menu item for active category if it was not set before. - * If menu item has parent categories, sets 'has-active' class to all af them + * Tries to figure out the active category for current page and add appropriate classes: + * - 'active' class for active category + * - 'has-active' class for all parents of active category * - * @private + * First, checks whether current URL is URL of category page, + * otherwise tries to retrieve category URL in case of current URL is product view page URL + * which has category tree path in it. * * @return void + * @private */ _setActiveMenu: function () { - var currentUrl = window.location.href.split('?')[0], - activeCategoryLink = this.element.find('a[href="' + currentUrl + '"]'); - - if (activeCategoryLink && activeCategoryLink.parent().hasClass('active') !== true - && activeCategoryLink.hasClass('ui-corner-all') - ) { - activeCategoryLink.parent().addClass('active'); - var classes = activeCategoryLink.parent().attr('class'), - classStartPosition = classes.indexOf('nav-'), - classNav = classes.substring(classStartPosition, classes.indexOf(' ', classStartPosition)); - - this._setActiveParent(classNav); + var currentUrl = window.location.href.split('?')[0]; + + if (!this._setActiveMenuForCategory(currentUrl)) { + this._setActiveMenuForProduct(currentUrl); } }, /** - * Sets 'has-active' CSS class to all parent categories in menu has active category + * Looks for category with provided URL and adds 'active' CSS class to it if it was not set before. + * If menu item has parent categories, sets 'has-active' class to all af them. * + * @param {String} url - possible category URL + * @returns {boolean} - true if active category was founded by provided URL, otherwise return false * @private + */ + _setActiveMenuForCategory: function (url) { + var activeCategoryLink = this.element.find('a[href="' + url + '"]'), + classes, + classNav; + + if (activeCategoryLink && activeCategoryLink.hasClass('ui-corner-all')) { + + if (!activeCategoryLink.parent().hasClass('active')) { + activeCategoryLink.parent().addClass('active'); + classes = activeCategoryLink.parent().attr('class'); + classNav = classes.match(/(nav\-)[0-9]+(\-[0-9]+)+/gi); + + if (classNav) { + this._setActiveParent(classNav[0]); + } + } + return true; + } + return false; + }, + + /** + * Sets 'has-active' CSS class to all parent categories which have part of provided class in childClassName + * + * @example: + * childClassName - 'nav-1-2-3' + * CSS class 'has-active' will be added to categories have 'nav-1-2' and 'nav-1' classes * * @param {String} childClassName - Class name of active category
  • element * @return void + * @private */ _setActiveParent: function (childClassName) { - var parentClass = childClassName.substr(0, childClassName.lastIndexOf('-')); + var parentElement, + parentClass = childClassName.substr(0, childClassName.lastIndexOf('-')); + if (parentClass.lastIndexOf('-') !== -1) { - var parent = this.element.find('.' + parentClass); - if (parent) { - parent.addClass('has-active'); + parentElement = this.element.find('.' + parentClass); + + if (parentElement) { + parentElement.addClass('has-active'); } this._setActiveParent(parentClass); } }, + /** + * Tries to retrieve category URL from current URL and mark this category as active + * @see _setActiveMenuForCategory(url) + * + * @example: + * currentUrl - http://magento.com/category1/category12/product.html, + * category URLs has extensions .phtml - http://magento.com/category1.phtml + * method sets active category which has URL http://magento.com/category1/category12.phtml + * + * @param {String} currentUrl - current page URL without parameters + * @return void + * @private + */ + _setActiveMenuForProduct: function (currentUrl) { + var categoryUrlExtension, + possibleCategoryUrl, + //retrieve first category URL to know what extension is used for category URLs + firstCategoryUrl = this.element.find('> li a').attr('href'); + + if (firstCategoryUrl) { + categoryUrlExtension = firstCategoryUrl.substr(firstCategoryUrl.lastIndexOf('.')); + possibleCategoryUrl = currentUrl.substr(0, currentUrl.lastIndexOf('/')) + categoryUrlExtension; + this._setActiveMenuForCategory(possibleCategoryUrl); + } + }, + /** * Add class for expanded option. */ From 15c586a06bf9b0fea4baa07a76335b7d3126c5d9 Mon Sep 17 00:00:00 2001 From: Nadiya Syvokonenko Date: Tue, 22 Aug 2017 11:57:11 +0300 Subject: [PATCH 3/8] MAGETWO-49796: Catalog top nav, CSS class not set to active when using Varnish - fix code style errors --- lib/web/mage/menu.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/web/mage/menu.js b/lib/web/mage/menu.js index b9fefb8f706f1..667c86cec6454 100644 --- a/lib/web/mage/menu.js +++ b/lib/web/mage/menu.js @@ -134,7 +134,7 @@ define([ * If menu item has parent categories, sets 'has-active' class to all af them. * * @param {String} url - possible category URL - * @returns {boolean} - true if active category was founded by provided URL, otherwise return false + * @returns {Boolean} - true if active category was founded by provided URL, otherwise return false * @private */ _setActiveMenuForCategory: function (url) { @@ -142,26 +142,27 @@ define([ classes, classNav; - if (activeCategoryLink && activeCategoryLink.hasClass('ui-corner-all')) { + if (!activeCategoryLink || !activeCategoryLink.hasClass('ui-corner-all')) { - if (!activeCategoryLink.parent().hasClass('active')) { - activeCategoryLink.parent().addClass('active'); - classes = activeCategoryLink.parent().attr('class'); - classNav = classes.match(/(nav\-)[0-9]+(\-[0-9]+)+/gi); + //category was not found by provided URL + return false; + } else if (!activeCategoryLink.parent().hasClass('active')) { + activeCategoryLink.parent().addClass('active'); + classes = activeCategoryLink.parent().attr('class'); + classNav = classes.match(/(nav\-)[0-9]+(\-[0-9]+)+/gi); - if (classNav) { - this._setActiveParent(classNav[0]); - } + if (classNav) { + this._setActiveParent(classNav[0]); } - return true; } - return false; + + return true; }, /** * Sets 'has-active' CSS class to all parent categories which have part of provided class in childClassName * - * @example: + * @example * childClassName - 'nav-1-2-3' * CSS class 'has-active' will be added to categories have 'nav-1-2' and 'nav-1' classes * @@ -187,7 +188,7 @@ define([ * Tries to retrieve category URL from current URL and mark this category as active * @see _setActiveMenuForCategory(url) * - * @example: + * @example * currentUrl - http://magento.com/category1/category12/product.html, * category URLs has extensions .phtml - http://magento.com/category1.phtml * method sets active category which has URL http://magento.com/category1/category12.phtml From e41f6ccdc12ddab53c9b9436ca30a0dda5918fc3 Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Thu, 31 Aug 2017 09:08:47 +0300 Subject: [PATCH 4/8] MAGETWO-49796: Catalog top nav, CSS class not set to active when using Varnish --- lib/web/mage/menu.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/web/mage/menu.js b/lib/web/mage/menu.js index 667c86cec6454..5a51dcb26583e 100644 --- a/lib/web/mage/menu.js +++ b/lib/web/mage/menu.js @@ -199,12 +199,17 @@ define([ */ _setActiveMenuForProduct: function (currentUrl) { var categoryUrlExtension, + lastUrlSection, possibleCategoryUrl, //retrieve first category URL to know what extension is used for category URLs firstCategoryUrl = this.element.find('> li a').attr('href'); if (firstCategoryUrl) { - categoryUrlExtension = firstCategoryUrl.substr(firstCategoryUrl.lastIndexOf('.')); + lastUrlSection = firstCategoryUrl.substr(firstCategoryUrl.lastIndexOf('/')); + categoryUrlExtension = (lastUrlSection.lastIndexOf('.') !== -1) + ? lastUrlSection.substr(lastUrlSection.lastIndexOf('.')) : ''; + + //categoryUrlExtension = lastUrlSection.substr(lastUrlSection.lastIndexOf('.')); possibleCategoryUrl = currentUrl.substr(0, currentUrl.lastIndexOf('/')) + categoryUrlExtension; this._setActiveMenuForCategory(possibleCategoryUrl); } From 72f831b1f4143418bb207646972c996cc1df979e Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Thu, 31 Aug 2017 09:53:03 +0300 Subject: [PATCH 5/8] MAGETWO-49796: Catalog top nav, CSS class not set to active when using Varnish --- lib/web/mage/menu.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/web/mage/menu.js b/lib/web/mage/menu.js index 5a51dcb26583e..8a212b2bd445d 100644 --- a/lib/web/mage/menu.js +++ b/lib/web/mage/menu.js @@ -209,7 +209,6 @@ define([ categoryUrlExtension = (lastUrlSection.lastIndexOf('.') !== -1) ? lastUrlSection.substr(lastUrlSection.lastIndexOf('.')) : ''; - //categoryUrlExtension = lastUrlSection.substr(lastUrlSection.lastIndexOf('.')); possibleCategoryUrl = currentUrl.substr(0, currentUrl.lastIndexOf('/')) + categoryUrlExtension; this._setActiveMenuForCategory(possibleCategoryUrl); } From c00303f7cbe6677b67280084a9d3e614f2ed5cad Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Fri, 1 Sep 2017 15:45:21 +0300 Subject: [PATCH 6/8] MAGETWO-71890: Magento fails with deploymentConfig present on new install --- .../Magento/Deploy/Console/CommandList.php | 58 +++++++++++++++++ .../Test/Unit/Console/CommandListTest.php | 51 +++++++++++++++ app/code/Magento/Deploy/cli_commands.php | 8 +++ app/code/Magento/Deploy/composer.json | 1 + .../Setup/Console/Command/InstallCommand.php | 7 ++ .../Console/Command/InstallCommandTest.php | 65 ++++++++++++++++++- 6 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/Deploy/Console/CommandList.php create mode 100644 app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php create mode 100644 app/code/Magento/Deploy/cli_commands.php diff --git a/app/code/Magento/Deploy/Console/CommandList.php b/app/code/Magento/Deploy/Console/CommandList.php new file mode 100644 index 0000000000000..2470737b19217 --- /dev/null +++ b/app/code/Magento/Deploy/Console/CommandList.php @@ -0,0 +1,58 @@ +objectManager = $objectManager; + } + + /** + * Gets list of command classes + * + * @return string[] + */ + private function getCommandsClasses() + { + return [ + \Magento\Deploy\Console\Command\App\ConfigImportCommand::class, + ]; + } + + /** + * @inheritdoc + */ + public function getCommands() + { + $commands = []; + foreach ($this->getCommandsClasses() as $class) { + if (class_exists($class)) { + $commands[] = $this->objectManager->get($class); + } else { + throw new \Exception('Class ' . $class . ' does not exist'); + } + } + + return $commands; + } +} diff --git a/app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php b/app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php new file mode 100644 index 0000000000000..41052b2760c78 --- /dev/null +++ b/app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php @@ -0,0 +1,51 @@ +objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->getMockForAbstractClass(); + + $this->model = new CommandList( + $this->objectManagerMock + ); + } + + public function testGetCommands() + { + $this->objectManagerMock->expects($this->once()) + ->method('get') + ->withConsecutive([ + ConfigImportCommand::class, + ]); + + $this->model->getCommands(); + } +} diff --git a/app/code/Magento/Deploy/cli_commands.php b/app/code/Magento/Deploy/cli_commands.php new file mode 100644 index 0000000000000..dd111b479e2ce --- /dev/null +++ b/app/code/Magento/Deploy/cli_commands.php @@ -0,0 +1,8 @@ +installerFactory->create($consoleLogger); $installer->install($input->getOptions()); + + $importConfigCommand = $this->getApplication()->find(ConfigImportCommand::COMMAND_NAME); + $arrayInput = new ArrayInput([]); + $arrayInput->setInteractive($input->isInteractive()); + $importConfigCommand->run($arrayInput, $output); } /** diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php index 46e93486d6def..5b7b6c1626911 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/InstallCommandTest.php @@ -6,7 +6,11 @@ namespace Magento\Setup\Test\Unit\Console\Command; +use Magento\Deploy\Console\Command\App\ConfigImportCommand; use Magento\Setup\Console\Command\InstallCommand; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Tester\CommandTester; use Magento\Setup\Model\AdminAccount; use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; @@ -38,6 +42,26 @@ class InstallCommandTest extends \PHPUnit\Framework\TestCase */ private $installer; + /** + * @var Application|\PHPUnit_Framework_MockObject_MockObject + */ + private $applicationMock; + + /** + * @var HelperSet|\PHPUnit_Framework_MockObject_MockObject + */ + private $helperSetMock; + + /** + * @var InputDefinition|\PHPUnit_Framework_MockObject_MockObject + */ + private $definitionMock; + + /** + * @var ConfigImportCommand|\PHPUnit_Framework_MockObject_MockObject + */ + private $configImportMock; + public function setUp() { $this->input = [ @@ -88,12 +112,42 @@ public function setUp() $this->installerFactory = $this->createMock(\Magento\Setup\Model\InstallerFactory::class); $this->installer = $this->createMock(\Magento\Setup\Model\Installer::class); + $this->applicationMock = $this->getMockBuilder(Application::class) + ->disableOriginalConstructor() + ->getMock(); + $this->helperSetMock = $this->getMockBuilder(HelperSet::class) + ->disableOriginalConstructor() + ->getMock(); + $this->definitionMock = $this->getMockBuilder(InputDefinition::class) + ->disableOriginalConstructor() + ->getMock(); + $this->configImportMock = $this->getMockBuilder(ConfigImportCommand::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->applicationMock->expects($this->any()) + ->method('getHelperSet') + ->willReturn($this->helperSetMock); + $this->applicationMock->expects($this->any()) + ->method('getDefinition') + ->willReturn($this->definitionMock); + $this->definitionMock->expects($this->any()) + ->method('getOptions') + ->willReturn([]); + $this->applicationMock->expects($this->any()) + ->method('find') + ->with(ConfigImportCommand::COMMAND_NAME) + ->willReturn($this->configImportMock); + $this->command = new InstallCommand( $this->installerFactory, $configModel, $userConfig, $adminUser ); + $this->command->setApplication( + $this->applicationMock + ); } public function testExecute() @@ -102,6 +156,8 @@ public function testExecute() ->method('create') ->will($this->returnValue($this->installer)); $this->installer->expects($this->once())->method('install'); + $this->configImportMock->expects($this->once()) + ->method('run'); $commandTester = new CommandTester($this->command); $commandTester->execute($this->input); @@ -134,6 +190,7 @@ private function getOptionsListDeployConfig() ->expects($this->any()) ->method('getName') ->will($this->returnValue(BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME)); + return [$option1, $option2, $option3, $option4]; } @@ -164,6 +221,7 @@ private function getOptionsListUserConfig() ->expects($this->any()) ->method('getName') ->will($this->returnValue(StoreConfigurationDataMapper::KEY_CURRENCY)); + return [$option1, $option2, $option3, $option4]; } @@ -199,6 +257,7 @@ private function getOptionsListAdminUser() ->expects($this->any()) ->method('getName') ->will($this->returnValue(AdminAccount::KEY_LAST_NAME)); + return [$option1, $option2, $option3, $option4, $option5]; } @@ -246,8 +305,8 @@ public function validateDataProvider() { return [ 'without option' => ['', ''], - 'normal case' => ['abcde', ''], - '20 chars' => ['12345678901234567890', ''] + 'normal case' => ['abcde', ''], + '20 chars' => ['12345678901234567890', ''], ]; } @@ -258,7 +317,7 @@ public function validateWithExceptionDataProvider() { return [ ['123456789012345678901', 'InvalidArgumentException'], - ['abcdefghijk12345678fdgsdfgsdfgsdfsgsdfg90abcdefgdfddgsdfg', 'InvalidArgumentException'] + ['abcdefghijk12345678fdgsdfgsdfgsdfsgsdfg90abcdefgdfddgsdfg', 'InvalidArgumentException'], ]; } } From dda3e02790fa2e32ec28630df570a8426ad395a9 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Mon, 4 Sep 2017 10:02:06 +0300 Subject: [PATCH 7/8] MAGETWO-71890: Magento fails with deploymentConfig present on new install --- .../Deploy/Test/Unit/Console/CommandListTest.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php b/app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php index 41052b2760c78..0d305551e0af2 100644 --- a/app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php +++ b/app/code/Magento/Deploy/Test/Unit/Console/CommandListTest.php @@ -40,12 +40,19 @@ protected function setUp() public function testGetCommands() { + $configImportCommand = $this->getMockBuilder(ConfigImportCommand::class) + ->disableOriginalConstructor() + ->getMock(); + $this->objectManagerMock->expects($this->once()) ->method('get') - ->withConsecutive([ - ConfigImportCommand::class, + ->willReturnMap([ + [ConfigImportCommand::class, $configImportCommand], ]); - $this->model->getCommands(); + $this->assertSame( + [$configImportCommand], + $this->model->getCommands() + ); } } From cebb3a334f3703d10d2d4091d5701d38fd40d7f4 Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Mon, 4 Sep 2017 13:24:32 +0300 Subject: [PATCH 8/8] MAGETWO-49796: Catalog top nav, CSS class not set to active when using Varnish --- lib/web/mage/menu.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web/mage/menu.js b/lib/web/mage/menu.js index 8a212b2bd445d..05d3217414883 100644 --- a/lib/web/mage/menu.js +++ b/lib/web/mage/menu.js @@ -206,8 +206,8 @@ define([ if (firstCategoryUrl) { lastUrlSection = firstCategoryUrl.substr(firstCategoryUrl.lastIndexOf('/')); - categoryUrlExtension = (lastUrlSection.lastIndexOf('.') !== -1) - ? lastUrlSection.substr(lastUrlSection.lastIndexOf('.')) : ''; + categoryUrlExtension = lastUrlSection.lastIndexOf('.') !== -1 ? + lastUrlSection.substr(lastUrlSection.lastIndexOf('.')) : ''; possibleCategoryUrl = currentUrl.substr(0, currentUrl.lastIndexOf('/')) + categoryUrlExtension; this._setActiveMenuForCategory(possibleCategoryUrl);