From 3cee8536ac776f5e996fcdba737a7785f4e80565 Mon Sep 17 00:00:00 2001 From: Alex Paliarush Date: Mon, 24 Jul 2017 14:16:53 -0500 Subject: [PATCH 01/14] MAGETWO-70816: [Cloud] Unable to get WSDL listing --- .../Api/Data/DesignConfigDataInterface.php | 4 +- .../ServiceDataAttributesGenerator.php | 4 +- .../Module/Di/Code/Scanner/PhpScanner.php | 76 +++++++++++++------ .../Module/Di/Code/Scanner/PhpScannerTest.php | 23 ++++-- .../SomeModule/Api/Data/SomeInterface.php | 15 ++++ 5 files changed, 88 insertions(+), 34 deletions(-) create mode 100644 setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/Api/Data/SomeInterface.php diff --git a/app/code/Magento/Theme/Api/Data/DesignConfigDataInterface.php b/app/code/Magento/Theme/Api/Data/DesignConfigDataInterface.php index 54dce9803a4a6..97dfe37eeaf79 100644 --- a/app/code/Magento/Theme/Api/Data/DesignConfigDataInterface.php +++ b/app/code/Magento/Theme/Api/Data/DesignConfigDataInterface.php @@ -57,14 +57,14 @@ public function setFieldConfig(array $config); /** * Retrieve existing extension attributes object or create a new one. * - * @return DesignConfigDataExtensionInterface|null + * @return \Magento\Theme\Api\Data\DesignConfigDataExtensionInterface|null */ public function getExtensionAttributes(); /** * Set an extension attributes object. * - * @param DesignConfigDataExtensionInterface $extensionAttributes + * @param \Magento\Theme\Api\Data\DesignConfigDataExtensionInterface $extensionAttributes * @return $this */ public function setExtensionAttributes(DesignConfigDataExtensionInterface $extensionAttributes); diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ServiceDataAttributesGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ServiceDataAttributesGenerator.php index 21cf8797f8340..e2bd543ccc77c 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ServiceDataAttributesGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ServiceDataAttributesGenerator.php @@ -54,8 +54,8 @@ public function __construct( public function doOperation() { $files = $this->configurationScanner->scan('extension_attributes.xml'); - $repositories = $this->serviceDataAttributesScanner->collectEntities($files); - foreach ($repositories as $entityName) { + $entities = $this->serviceDataAttributesScanner->collectEntities($files); + foreach ($entities as $entityName) { class_exists($entityName); } } diff --git a/setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php b/setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php index 8c1d6565cd668..ab66a63e24498 100644 --- a/setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php +++ b/setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php @@ -9,6 +9,7 @@ use Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator; use Magento\Framework\ObjectManager\Code\Generator\Factory as FactoryGenerator; use Magento\Setup\Module\Di\Compiler\Log\Log; +use \Magento\Framework\Reflection\TypeProcessor; class PhpScanner implements ScannerInterface { @@ -18,11 +19,21 @@ class PhpScanner implements ScannerInterface protected $_log; /** + * @var TypeProcessor + */ + private $typeProcessor; + + /** + * Initialize dependencies. + * * @param Log $log + * @param TypeProcessor|null $typeProcessor */ - public function __construct(Log $log) + public function __construct(Log $log, TypeProcessor $typeProcessor = null) { $this->_log = $log; + $this->typeProcessor = $typeProcessor + ?: \Magento\Framework\App\ObjectManager::getInstance()->get(TypeProcessor::class); } /** @@ -45,22 +56,9 @@ protected function _findMissingClasses($file, $classReflection, $methodName, $en preg_match('/\[\s\<\w+?>\s([\w\\\\]+)/s', $parameter->__toString(), $matches); if (isset($matches[1]) && substr($matches[1], -strlen($entityType)) == $entityType) { $missingClassName = $matches[1]; - try { - if (class_exists($missingClassName)) { - continue; - } - } catch (\RuntimeException $e) { - } - $sourceClassName = $this->getSourceClassName($missingClassName, $entityType); - if (!class_exists($sourceClassName) && !interface_exists($sourceClassName)) { - $this->_log->add( - Log::CONFIGURATION_ERROR, - $missingClassName, - "Invalid {$entityType} for nonexistent class {$sourceClassName} in file {$file}" - ); - continue; + if ($this->shouldGenerateClass($missingClassName, $entityType, $file)) { + $missingClasses[] = $missingClassName; } - $missingClasses[] = $missingClassName; } } } @@ -137,12 +135,18 @@ protected function _fetchFactories($reflectionClass, $file) */ protected function _fetchMissingExtensionAttributesClasses($reflectionClass, $file) { - $missingExtensionInterfaces = $this->_findMissingClasses( - $file, - $reflectionClass, - 'setExtensionAttributes', - ucfirst(\Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator::ENTITY_TYPE) - ); + $missingExtensionInterfaces = []; + $methodName = 'getExtensionAttributes'; + $entityType = ucfirst(\Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator::ENTITY_TYPE); + if ($reflectionClass->hasMethod($methodName) && $reflectionClass->isInterface()) { + $returnType = $this->typeProcessor->getGetterReturnType( + (new \Zend\Code\Reflection\ClassReflection($reflectionClass->getName()))->getMethod($methodName) + ); + $missingClassName = $returnType['type']; + if ($this->shouldGenerateClass($missingClassName, $entityType, $file)) { + $missingExtensionInterfaces[] = $missingClassName; + } + } $missingExtensionClasses = []; $missingExtensionFactories = []; foreach ($missingExtensionInterfaces as $missingExtensionInterface) { @@ -244,4 +248,32 @@ protected function _getDeclaredClasses($file) } return array_unique($classes); } + + /** + * Check if specified class is missing and if it can be generated. + * + * @param string $missingClassName + * @param string $entityType + * @param string $file + * @return bool + */ + private function shouldGenerateClass($missingClassName, $entityType, $file) + { + try { + if (class_exists($missingClassName)) { + return false; + } + } catch (\RuntimeException $e) { + } + $sourceClassName = $this->getSourceClassName($missingClassName, $entityType); + if (!class_exists($sourceClassName) && !interface_exists($sourceClassName)) { + $this->_log->add( + Log::CONFIGURATION_ERROR, + $missingClassName, + "Invalid {$entityType} for nonexistent class {$sourceClassName} in file {$file}" + ); + return false; + } + return true; + } } diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Scanner/PhpScannerTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Scanner/PhpScannerTest.php index d526ead41c2b0..64f8d83565450 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Scanner/PhpScannerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Scanner/PhpScannerTest.php @@ -8,6 +8,9 @@ require_once __DIR__ . '/../../_files/app/code/Magento/SomeModule/Helper/Test.php'; require_once __DIR__ . '/../../_files/app/code/Magento/SomeModule/ElementFactory.php'; require_once __DIR__ . '/../../_files/app/code/Magento/SomeModule/Model/DoubleColon.php'; +require_once __DIR__ . '/../../_files/app/code/Magento/SomeModule/Api/Data/SomeInterface.php'; + +use Magento\Framework\Reflection\TypeProcessor; class PhpScannerTest extends \PHPUnit_Framework_TestCase { @@ -33,18 +36,19 @@ class PhpScannerTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->_model = new \Magento\Setup\Module\Di\Code\Scanner\PhpScanner( - $this->_logMock = $this->getMock(\Magento\Setup\Module\Di\Compiler\Log\Log::class, [], [], '', false) - ); + $this->_logMock = $this->getMock(\Magento\Setup\Module\Di\Compiler\Log\Log::class, [], [], '', false); + $this->_model = new \Magento\Setup\Module\Di\Code\Scanner\PhpScanner($this->_logMock, new TypeProcessor()); $this->_testDir = str_replace('\\', '/', realpath(__DIR__ . '/../../') . '/_files'); - $this->_testFiles = [ - $this->_testDir . '/app/code/Magento/SomeModule/Helper/Test.php', - $this->_testDir . '/app/code/Magento/SomeModule/Model/DoubleColon.php' - ]; } public function testCollectEntities() { + $this->_testFiles = [ + $this->_testDir . '/app/code/Magento/SomeModule/Helper/Test.php', + $this->_testDir . '/app/code/Magento/SomeModule/Model/DoubleColon.php', + $this->_testDir . '/app/code/Magento/SomeModule/Api/Data/SomeInterface.php' + ]; + $this->_logMock->expects( $this->at(0) )->method( @@ -64,6 +68,9 @@ public function testCollectEntities() 'Invalid Factory declaration for class Magento\SomeModule\Element in file ' . $this->_testFiles[0] ); - $this->assertEquals([], $this->_model->collectEntities($this->_testFiles)); + $this->assertEquals( + ['\Magento\Eav\Api\Data\AttributeExtensionInterface'], + $this->_model->collectEntities($this->_testFiles) + ); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/Api/Data/SomeInterface.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/Api/Data/SomeInterface.php new file mode 100644 index 0000000000000..0e2cbcfb8d827 --- /dev/null +++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/_files/app/code/Magento/SomeModule/Api/Data/SomeInterface.php @@ -0,0 +1,15 @@ + Date: Wed, 9 Aug 2017 17:18:28 -0500 Subject: [PATCH 02/14] MAGETWO-63175: Layered navigation price step range displays in the base currency --- .../Model/Layer/Filter/Price.php | 8 +-- .../Unit/Model/Layer/Filter/PriceTest.php | 1 + .../Model/Layer/Filter/PriceTest.php | 52 ++++++++++++++----- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php b/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php index 9f54bd279d906..108f1b9f4fd8d 100644 --- a/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php +++ b/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php @@ -175,6 +175,9 @@ public function getCurrencyRate() */ protected function _renderRangeLabel($fromPrice, $toPrice) { + $fromPrice = empty($fromPrice) ? 0 : $fromPrice * $this->getCurrencyRate(); + $toPrice = empty($toPrice) ? $toPrice : $toPrice * $this->getCurrencyRate(); + $formattedFromPrice = $this->priceCurrency->format($fromPrice); if ($toPrice === '') { return __('%1 and above', $formattedFromPrice); @@ -261,10 +264,7 @@ private function prepareData($key, $count) if ($to == '*') { $to = $this->getTo($to); } - $label = $this->_renderRangeLabel( - empty($from) ? 0 : $from * $this->getCurrencyRate(), - empty($to) ? $to : $to * $this->getCurrencyRate() - ); + $label = $this->_renderRangeLabel($from, $to); $value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData(); $data = [ diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/PriceTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/PriceTest.php index 9631773cad2c9..abad58a6876d3 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/PriceTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/PriceTest.php @@ -225,6 +225,7 @@ function ($field) use ($requestVar, $priceId) { ->with('price') ->will($this->returnSelf()); + $this->target->setCurrencyRate(1); $this->target->apply($this->request); } diff --git a/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Layer/Filter/PriceTest.php b/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Layer/Filter/PriceTest.php index cd4ee02616b3a..451553113af2c 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Layer/Filter/PriceTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Layer/Filter/PriceTest.php @@ -5,6 +5,8 @@ */ namespace Magento\CatalogSearch\Model\Layer\Filter; +use Magento\TestFramework\Helper\Bootstrap; + /** * Test class for \Magento\CatalogSearch\Model\Layer\Filter\Price. * @@ -19,26 +21,31 @@ class PriceTest extends \PHPUnit\Framework\TestCase */ protected $_model; + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + private $objectManager; + protected function setUp() { - $category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + $this->objectManager = Bootstrap::getObjectManager(); + $category = $this->objectManager->create( \Magento\Catalog\Model\Category::class ); $category->load(4); - $layer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->get(\Magento\Catalog\Model\Layer\Category::class); + $layer = $this->objectManager->get(\Magento\Catalog\Model\Layer\Category::class); $layer->setCurrentCategory($category); - $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\CatalogSearch\Model\Layer\Filter\Price::class, ['layer' => $layer]); + $this->_model = $this->objectManager->create( + \Magento\CatalogSearch\Model\Layer\Filter\Price::class, + ['layer' => $layer] + ); } public function testApplyNothing() { $this->assertEmpty($this->_model->getData('price_range')); - /** @var $objectManager \Magento\TestFramework\ObjectManager */ - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var $request \Magento\TestFramework\Request */ - $request = $objectManager->get(\Magento\TestFramework\Request::class); + $request = $this->objectManager->get(\Magento\TestFramework\Request::class); $this->_model->apply($request); $this->assertEmpty($this->_model->getData('price_range')); @@ -47,10 +54,8 @@ public function testApplyNothing() public function testApplyInvalid() { $this->assertEmpty($this->_model->getData('price_range')); - /** @var $objectManager \Magento\TestFramework\ObjectManager */ - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var $request \Magento\TestFramework\Request */ - $request = $objectManager->get(\Magento\TestFramework\Request::class); + $request = $this->objectManager->get(\Magento\TestFramework\Request::class); $request->setParam('price', 'non-numeric'); $this->_model->apply($request); @@ -62,12 +67,31 @@ public function testApplyInvalid() */ public function testApplyManual() { - /** @var $objectManager \Magento\TestFramework\ObjectManager */ - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var $request \Magento\TestFramework\Request */ - $request = $objectManager->get(\Magento\TestFramework\Request::class); + $request = $this->objectManager->get(\Magento\TestFramework\Request::class); + $request->setParam('price', '10-20'); + $this->_model->apply($request); + } + + /** + * Make sure that currency rate is used to calculate label for applied price filter + */ + public function testApplyWithCustomCurrencyRate() + { + /** @var $request \Magento\TestFramework\Request */ + $request = $this->objectManager->get(\Magento\TestFramework\Request::class); + $request->setParam('price', '10-20'); + $this->_model->setCurrencyRate(10); + $this->_model->apply($request); + + $filters = $this->_model->getLayer()->getState()->getFilters(); + $this->assertArrayHasKey(0, $filters); + $this->assertEquals( + '$100.00 - $199.99', + (string)$filters[0]->getLabel() + ); } public function testGetSetCustomerGroupId() From 348d5130151f798829727b2eff3431e118f6fcbc Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Thu, 10 Aug 2017 16:51:49 -0500 Subject: [PATCH 03/14] MAGETWO-71257: Need to disable module output --- app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php index 4124cb1cd3156..f88a4e6738c3b 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php @@ -128,6 +128,7 @@ public function testGetRssData() ); $customerServiceMock = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class); $wishlistSharingUrl = 'wishlist/shared/index/1'; + $locale = 'en_US'; $productUrl = 'http://product.url/'; $productName = 'Product name'; From 366b3adb9b7a953609a8b038fd69f2fd8f7cd614 Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Thu, 10 Aug 2017 16:56:27 -0500 Subject: [PATCH 04/14] MAGETWO-71257: Need to disable module output by configuration --- .../Test/Unit/Block/Info/SubstitutionTest.php | 2 +- .../Test/Unit/Block/Header/AdditionalTest.php | 3 ++- .../Wishlist/Test/Unit/Model/Rss/WishlistTest.php | 13 +++++++++++++ lib/internal/Magento/Framework/Module/Manager.php | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php b/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php index 9db5475bd65e4..182a9a7951205 100644 --- a/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php +++ b/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php @@ -79,7 +79,7 @@ public function testBeforeToHtml() ->willReturn($abstractBlock); $infoMock = $this->getMockBuilder(\Magento\Payment\Model\Info::class) - ->disableOriginalConstructor() + ->disableOriginalConstructor()->setMethods([]) ->getMock(); $methodMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class) ->getMockForAbstractClass(); diff --git a/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php b/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php index a8c4c46829b2a..35eb297c97ce3 100644 --- a/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php +++ b/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php @@ -134,7 +134,8 @@ protected function setUp() '', false, true, - true + true, + ['getValue'] ); $this->cacheStateMock = $this->getMockForAbstractClass( \Magento\Framework\App\Cache\StateInterface::class, diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php index f88a4e6738c3b..b90f94a125004 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php @@ -152,6 +152,19 @@ public function testGetRssData() $this->urlBuilderMock->expects($this->once()) ->method('getUrl') ->will($this->returnValue($wishlistSharingUrl)); + $this->scopeConfig->expects($this->any()) + ->method('getValue') + ->will($this->returnValueMap( + [ + [ + Data::XML_PATH_DEFAULT_LOCALE, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + null, + $locale + ], + ] + ) + ); $staticArgs = [ 'productName' => $productName, diff --git a/lib/internal/Magento/Framework/Module/Manager.php b/lib/internal/Magento/Framework/Module/Manager.php index dc07ec493e8f0..45db7345ac77d 100644 --- a/lib/internal/Magento/Framework/Module/Manager.php +++ b/lib/internal/Magento/Framework/Module/Manager.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework\Module; /** From 980159b06a88212d0c3357435127dbfd22f0535b Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Thu, 10 Aug 2017 16:56:41 -0500 Subject: [PATCH 05/14] MAGETWO-71257: Need to disable module output --- .../Unit/Block/Adminhtml/Product/Options/AjaxTest.php | 8 ++++++++ .../Test/Unit/Block/Product/Widget/NewWidgetTest.php | 2 ++ .../Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php | 4 ++++ .../Payment/Test/Unit/Block/Info/SubstitutionTest.php | 3 +-- .../Paypal/Test/Unit/Block/Billing/AgreementsTest.php | 4 ++++ .../Widget/Instance/Edit/Chooser/ContainerTest.php | 4 ++++ .../Magento/Framework/View/Element/AbstractBlock.php | 1 - 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php index 3a7db614e7f68..7f1b4a8ea7ee7 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Options/AjaxTest.php @@ -58,6 +58,12 @@ public function testToHtml() ->getMock(); $eventManager->expects($this->exactly(2))->method('dispatch')->will($this->returnValue(true)); + $scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class) + ->setMethods(['getValue']) + ->disableOriginalConstructor()->getMock(); + $scopeConfig->expects($this->once())->method('getValue')->withAnyParameters() + ->will($this->returnValue(false)); + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor() ->setMethods(['setStoreId', 'load', 'getId', '__wakeup', '__sleep']) ->getMock(); @@ -90,6 +96,8 @@ public function testToHtml() $this->context->expects($this->once())->method('getEventManager') ->will($this->returnValue($eventManager)); + $this->context->expects($this->once())->method('getScopeConfig') + ->will($this->returnValue($scopeConfig)); $this->context->expects($this->once())->method('getLayout') ->will($this->returnValue($layout)); $this->context->expects($this->once())->method('getRequest') diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php index c629f797bdc3f..9868213967f7f 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/Widget/NewWidgetTest.php @@ -186,6 +186,8 @@ protected function generalGetProductCollection() { $this->eventManager->expects($this->exactly(2))->method('dispatch') ->will($this->returnValue(true)); + $this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters() + ->willReturn(false); $this->cacheState->expects($this->atLeastOnce())->method('isEnabled')->withAnyParameters() ->willReturn(false); $this->catalogConfig->expects($this->once())->method('getProductAttributes') diff --git a/app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php b/app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php index eefb256b6238b..bcec37e0c7bf0 100644 --- a/app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Block/Cart/Item/Renderer/ActionsTest.php @@ -68,6 +68,10 @@ public function testToHtml() $childNameTwo = 'child.2'; $childNames = [$childNameOne, $childNameTwo]; + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->willReturn(false); + /** * @var Item|\PHPUnit_Framework_MockObject_MockObject $itemMock */ diff --git a/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php b/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php index 182a9a7951205..15468d02a5070 100644 --- a/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php +++ b/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php @@ -93,8 +93,7 @@ public function testBeforeToHtml() $this->layout->expects($this->any()) ->method('createBlock') ->with( - \Magento\Framework\View\Element\Template::class, - '', + \Magento\Framework\View\Element\Template::class, '', ['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']] )->willReturn($fakeBlock); diff --git a/app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php b/app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php index 14be9852e41b1..9808126636a4e 100644 --- a/app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Block/Billing/AgreementsTest.php @@ -231,6 +231,10 @@ public function testToHtml() ->expects($this->at(1)) ->method('dispatch') ->with('view_block_abstract_to_html_after', ['block' => $this->block, 'transport' => $transport]); + $this->scopeConfig + ->expects($this->once()) + ->method('getValue') + ->willReturn(false); $this->urlBuilder->expects($this->once())->method('getUrl')->with('paypal/billing_agreement/startWizard', []); $this->block->toHtml(); } diff --git a/app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php b/app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php index 346d93a9a8536..540bcd1aa43c6 100644 --- a/app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php +++ b/app/code/Magento/Widget/Test/Unit/Block/Adminhtml/Widget/Instance/Edit/Chooser/ContainerTest.php @@ -67,6 +67,7 @@ public function testToHtmlCatalogProductsListGroupedProduct() . ''; $this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true); + $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->themeCollectionFactoryMock->expects($this->once()) ->method('create') @@ -153,6 +154,7 @@ public function testToHtmlCatalogCategoryLinkSimpleProduct() . ''; $this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true); + $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->themeCollectionFactoryMock->expects($this->once()) ->method('create') @@ -283,6 +285,7 @@ public function testToHtmlCmsStaticBlockAllProductTypes() . ''; $this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true); + $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->themeCollectionFactoryMock->expects($this->once()) ->method('create') @@ -400,6 +403,7 @@ public function testToHtmlOrderBySkuAllPages() . 'Sidebar Main'; $this->eventManagerMock->expects($this->exactly(2))->method('dispatch')->willReturn(true); + $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->themeCollectionFactoryMock->expects($this->once()) ->method('create') diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index e977e8a2da2d5..3087bf8809a71 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -650,7 +650,6 @@ protected function _beforeToHtml() public function toHtml() { $this->_eventManager->dispatch('view_block_abstract_to_html_before', ['block' => $this]); - $this->getModuleName(); $html = $this->_loadCache(); if ($html === false) { From bd65ca4e816c3be949760fcce07dc612afa70bed Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Thu, 10 Aug 2017 16:58:42 -0500 Subject: [PATCH 06/14] MAGETWO-71257: Need to disable module output by configuration --- app/code/Magento/Backend/Block/Template.php | 11 +- .../Test/Unit/Block/Info/SubstitutionTest.php | 161 ++++++++++++------ .../Test/Unit/Block/Express/ReviewTest.php | 11 ++ .../Test/Unit/Block/Header/AdditionalTest.php | 6 + .../Test/Unit/Model/Rss/WishlistTest.php | 6 + .../Magento/Backend/Block/TemplateTest.php | 22 +++ .../Framework/View/Element/AbstractBlock.php | 6 + .../Test/Unit/Element/AbstractBlockTest.php | 18 +- 8 files changed, 182 insertions(+), 59 deletions(-) diff --git a/app/code/Magento/Backend/Block/Template.php b/app/code/Magento/Backend/Block/Template.php index 3c8d3a1135565..de1d852e6f244 100644 --- a/app/code/Magento/Backend/Block/Template.php +++ b/app/code/Magento/Backend/Block/Template.php @@ -84,12 +84,17 @@ public function getFormKey() * * @param string $moduleName Full module name * @return boolean - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function isOutputEnabled($moduleName = null) { - return true; + if ($moduleName === null) { + $moduleName = $this->getModuleName(); + } + + return !$this->_scopeConfig->isSetFlag( + 'advanced/modules_disable_output/' . $moduleName, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); } /** diff --git a/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php b/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php index 15468d02a5070..729da9eb8196d 100644 --- a/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php +++ b/app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php @@ -3,6 +3,9 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +// @codingStandardsIgnoreFile + namespace Magento\Payment\Test\Unit\Block\Info; /** @@ -31,23 +34,71 @@ class SubstitutionTest extends \PHPUnit\Framework\TestCase protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->layout = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class) - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $eventManager = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class) - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class) - ->disableOriginalConstructor() - ->setMethods(['getLayout', 'getEventManager', 'getScopeConfig']) - ->getMock(); - $context->expects($this->any()) - ->method('getLayout') - ->willReturn($this->layout); - $context->expects($this->any())->method('getEventManager') - ->willReturn($eventManager); + + $this->layout = $this->getMockBuilder( + \Magento\Framework\View\LayoutInterface::class + )->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + + $eventManager = $this->getMockBuilder( + \Magento\Framework\Event\ManagerInterface::class + )->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + + $scopeConfig = $this->getMockBuilder( + \Magento\Framework\App\Config\ScopeConfigInterface::class + )->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + $scopeConfig->expects( + $this->any() + )->method( + 'getValue' + )->with( + $this->stringContains( + 'advanced/modules_disable_output/' + ), + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + )->will( + $this->returnValue( + false + ) + ); + + $context = $this->getMockBuilder( + \Magento\Framework\View\Element\Template\Context::class + )->disableOriginalConstructor()->setMethods( + ['getLayout', 'getEventManager', 'getScopeConfig'] + )->getMock(); + $context->expects( + $this->any() + )->method( + 'getLayout' + )->will( + $this->returnValue( + $this->layout + ) + ); + $context->expects( + $this->any() + )->method( + 'getEventManager' + )->will( + $this->returnValue( + $eventManager + ) + ); + $context->expects( + $this->any() + )->method( + 'getScopeConfig' + )->will( + $this->returnValue( + $scopeConfig + ) + ); $this->block = $this->objectManager->getObject( \Magento\Payment\Block\Info\Substitution::class, @@ -62,44 +113,52 @@ protected function setUp() public function testBeforeToHtml() { - $abstractBlock = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class) - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $childAbstractBlock = clone $abstractBlock; - - $abstractBlock->expects($this->any()) - ->method('getParentBlock') - ->willReturn($childAbstractBlock); - $this->layout->expects($this->any()) - ->method('getParentName') - ->willReturn('parentName'); - $this->layout->expects($this->any()) - ->method('getBlock') - ->willReturn($abstractBlock); - - $infoMock = $this->getMockBuilder(\Magento\Payment\Model\Info::class) - ->disableOriginalConstructor()->setMethods([]) - ->getMock(); - $methodMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class) - ->getMockForAbstractClass(); - $infoMock->expects($this->once()) - ->method('getMethodInstance') - ->willReturn($methodMock); + $abstractBlock = $this->getMockBuilder( + \Magento\Framework\View\Element\AbstractBlock::class + )->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + $childAbstractBlock = clone($abstractBlock); + + $abstractBlock->expects($this->any())->method('getParentBlock')->will($this->returnValue($childAbstractBlock)); + $this->layout->expects($this->any())->method('getParentName')->will($this->returnValue('parentName')); + $this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($abstractBlock)); + + $infoMock = $this->getMockBuilder( + \Magento\Payment\Model\Info::class + )->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + $methodMock = $this->getMockBuilder( + \Magento\Payment\Model\MethodInterface::class + )->getMockForAbstractClass(); + $infoMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($methodMock)); $this->block->setInfo($infoMock); $fakeBlock = new \StdClass(); - $this->layout->expects($this->any()) - ->method('createBlock') - ->with( - \Magento\Framework\View\Element\Template::class, '', - ['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']] - )->willReturn($fakeBlock); - - $childAbstractBlock->expects($this->any()) - ->method('setChild') - ->with('order_payment_additional', $fakeBlock); + $this->layout->expects( + $this->any() + )->method( + 'createBlock' + )->with( + \Magento\Framework\View\Element\Template::class, + '', + ['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']] + )->will( + $this->returnValue( + $fakeBlock + ) + ); + + $childAbstractBlock->expects( + $this->any() + )->method( + 'setChild' + )->with( + 'order_payment_additional', + $fakeBlock + ); $this->block->toHtml(); } diff --git a/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php b/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php index 9d5d636598767..9b72e8aefead6 100644 --- a/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php @@ -3,9 +3,11 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Paypal\Test\Unit\Block\Express; use Magento\Paypal\Block\Express\Review; +use Magento\Quote\Model\Quote\Address\Rate; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -36,6 +38,14 @@ protected function setUp() $layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class); $eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); + $scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class, [], [], '', false); + + $scopeConfig->expects($this->any()) + ->method('getValue') + ->with( + $this->stringContains('advanced/modules_disable_output/'), + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + )->will($this->returnValue(false)); $urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class); $urlBuilder->expects($this->any())->method('getUrl')->will($this->returnArgument(0)); @@ -50,6 +60,7 @@ protected function setUp() $context->expects($this->any())->method('getLayout')->will($this->returnValue($layout)); $context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager)); + $context->expects($this->any())->method('getScopeConfig')->will($this->returnValue($scopeConfig)); $context->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $context->expects($this->any())->method('getAssetRepository')->will($this->returnValue($this->assetRepo)); $context->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilder)); diff --git a/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php b/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php index 35eb297c97ce3..b88b02ab4cfb5 100644 --- a/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php +++ b/app/code/Magento/Persistent/Test/Unit/Block/Header/AdditionalTest.php @@ -252,6 +252,12 @@ public function testToHtml($customerId) $this->eventManagerMock->expects($this->at(1)) ->method('dispatch') ->with('view_block_abstract_to_html_after'); + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with( + 'advanced/modules_disable_output/Magento_Persistent', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + )->willReturn(false); // get cache $this->cacheStateMock->expects($this->at(0)) diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php index b90f94a125004..f550fb58a991b 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php @@ -156,6 +156,12 @@ public function testGetRssData() ->method('getValue') ->will($this->returnValueMap( [ + [ + 'advanced/modules_disable_output/Magento_Rss', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + null, + null, + ], [ Data::XML_PATH_DEFAULT_LOCALE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, diff --git a/dev/tests/integration/testsuite/Magento/Backend/Block/TemplateTest.php b/dev/tests/integration/testsuite/Magento/Backend/Block/TemplateTest.php index 9c19355095264..82503f6456919 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Block/TemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Block/TemplateTest.php @@ -34,4 +34,26 @@ public function testGetFormKey() { $this->assertGreaterThan(15, strlen($this->_block->getFormKey())); } + + /** + * @magentoAppArea adminhtml + * @covers \Magento\Backend\Block\Template::isOutputEnabled + * @magentoConfigFixture current_store advanced/modules_disable_output/dummy 1 + */ + public function testIsOutputEnabledTrue() + { + $this->_block->setData('module_name', 'dummy'); + $this->assertFalse($this->_block->isOutputEnabled('dummy')); + } + + /** + * @magentoAppArea adminhtml + * @covers \Magento\Backend\Block\Template::isOutputEnabled + * @magentoConfigFixture current_store advanced/modules_disable_output/dummy 0 + */ + public function testIsOutputEnabledFalse() + { + $this->_block->setData('module_name', 'dummy'); + $this->assertTrue($this->_block->isOutputEnabled('dummy')); + } } diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index 3087bf8809a71..0ffa9dce7f730 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -650,6 +650,12 @@ protected function _beforeToHtml() public function toHtml() { $this->_eventManager->dispatch('view_block_abstract_to_html_before', ['block' => $this]); + if ($this->_scopeConfig->getValue( + 'advanced/modules_disable_output/' . $this->getModuleName(), + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + )) { + return ''; + } $html = $this->_loadCache(); if ($html === false) { diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php index a12d18befa69d..710b42af3e23f 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php @@ -3,6 +3,9 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +// @codingStandardsIgnoreFile + namespace Magento\Framework\View\Test\Unit\Element; use Magento\Framework\View\Element\AbstractBlock; @@ -204,12 +207,13 @@ public function testToHtmlWhenModuleIsDisabled() $moduleName = 'Test'; $this->block->setData('module_name', $moduleName); - $this->eventManagerMock->expects($this->exactly(2)) + $this->eventManagerMock->expects($this->any()) ->method('dispatch') - ->willReturnMap([ - ['view_block_abstract_to_html_before', ['block' => $this->block]], - ['view_block_abstract_to_html_after', ['block' => $this->block]], - ]); + ->with('view_block_abstract_to_html_before', ['block' => $this->block]); + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with('advanced/modules_disable_output/' . $moduleName, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->willReturn(true); $this->assertSame('', $this->block->toHtml()); } @@ -242,6 +246,10 @@ public function testGetCacheLifetimeViaToHtml( $this->eventManagerMock->expects($expectsDispatchEvent) ->method('dispatch'); + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with('advanced/modules_disable_output/' . $moduleName, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->willReturn(false); $this->cacheStateMock->expects($this->any()) ->method('isEnabled') ->with(AbstractBlock::CACHE_GROUP) From 15eeba84e63a4d14515546f1b25f730fe4552fdf Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Thu, 10 Aug 2017 17:00:19 -0500 Subject: [PATCH 07/14] MAGETWO-71257: Need to disable module output by configuration --- .../Magento/Framework/Module/Manager.php | 69 ++++++++++--------- .../Module/Output/ConfigInterface.php | 5 -- .../Module/Test/Unit/ManagerTest.php | 59 ++++++++-------- 3 files changed, 63 insertions(+), 70 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/Manager.php b/lib/internal/Magento/Framework/Module/Manager.php index 45db7345ac77d..a28a43633d226 100644 --- a/lib/internal/Magento/Framework/Module/Manager.php +++ b/lib/internal/Magento/Framework/Module/Manager.php @@ -4,6 +4,9 @@ * See COPYING.txt for license details. */ +/** + * Module statuses manager + */ namespace Magento\Framework\Module; /** @@ -17,84 +20,82 @@ class Manager { /** - * The checker of output modules. - * - * @var Output\ConfigInterface the config checker of output modules. + * @var Output\ConfigInterface * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version. * The property can be removed in a future major release */ - private $outputConfig; + private $_outputConfig; /** - * The list of all modules. - * - * @var ModuleListInterface the list of all modules. + * @var ModuleListInterface */ - private $moduleList; + private $_moduleList; /** - * The list of config paths to ignore. - * - * @var array the list of config paths to ignore. + * @var array * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version. * The property can be removed in a future major release */ - private $outputConfigPaths; + private $_outputConfigPaths; /** - * Constructor. - * - * @param Output\ConfigInterface $outputConfig the checker of output modules - * @param ModuleListInterface $moduleList the list of all modules - * @param array $outputConfigPaths the list of config paths to ignore + * @param Output\ConfigInterface $outputConfig + * @param ModuleListInterface $moduleList + * @param array $outputConfigPaths */ public function __construct( Output\ConfigInterface $outputConfig, ModuleListInterface $moduleList, array $outputConfigPaths = [] ) { - $this->outputConfig = $outputConfig; - $this->moduleList = $moduleList; - $this->outputConfigPaths = $outputConfigPaths; + $this->_outputConfig = $outputConfig; + $this->_moduleList = $moduleList; + $this->_outputConfigPaths = $outputConfigPaths; } /** - * Checks whether a module is enabled in the configuration or not. + * Whether a module is enabled in the configuration or not * - * @param string $moduleName the fully-qualified module name - * - * @return boolean true if module is enabled, false otherwise + * @param string $moduleName Fully-qualified module name + * @return boolean */ public function isEnabled($moduleName) { - return $this->moduleList->has($moduleName); + return $this->_moduleList->has($moduleName); } /** - * Checks whether a module output is permitted by the configuration or not. - * - * @param string $moduleName the fully-qualified module name. + * Whether a module output is permitted by the configuration or not * + * @param string $moduleName Fully-qualified module name * @return boolean * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version */ public function isOutputEnabled($moduleName) { - return $this->isEnabled($moduleName); + if (!$this->isEnabled($moduleName)) { + return false; + } + + return true; } /** - * Checks whether a configuration switch for a module output permits output. + * Whether a configuration switch for a module output permits output or not * * @param string $moduleName Fully-qualified module name - * * @return boolean - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version. - * The method can be removed in a future major release - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @deprecated */ protected function _isCustomOutputConfigEnabled($moduleName) { + if (isset($this->_outputConfigPaths[$moduleName])) { + $configPath = $this->_outputConfigPaths[$moduleName]; + if (defined($configPath)) { + $configPath = constant($configPath); + } + return $this->_outputConfig->isSetFlag($configPath); + } return true; } } diff --git a/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php b/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php index cce4691d041be..fc4ca36f777a9 100644 --- a/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php +++ b/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php @@ -5,11 +5,6 @@ */ namespace Magento\Framework\Module\Output; -/** - * Checks whether the module is enabled in the configuration. - * - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version - */ interface ConfigInterface { /** diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php index 4e137514e0e2f..bc71feb4c4750 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php @@ -5,63 +5,60 @@ */ namespace Magento\Framework\Module\Test\Unit; -use Magento\Framework\Module\Manager; -use Magento\Framework\Module\ModuleListInterface; -use Magento\Framework\Module\Output\ConfigInterface; -use \PHPUnit_Framework_MockObject_MockObject as Mock; +use Magento\Framework\Module\Plugin\DbStatusValidator; class ManagerTest extends \PHPUnit\Framework\TestCase { /** * XPath in the configuration of a module output flag - * @deprecated */ const XML_PATH_OUTPUT_ENABLED = 'custom/is_module_output_enabled'; /** - * @var Manager + * @var \Magento\Framework\Module\Manager */ - private $model; + private $_model; /** - * @var ModuleListInterface|Mock + * @var \PHPUnit_Framework_MockObject_MockObject */ - private $moduleList; + private $_moduleList; /** - * @var ConfigInterface|Mock - * @deprecated + * @var \PHPUnit_Framework_MockObject_MockObject */ - private $outputConfig; + private $_outputConfig; /** * @inheritdoc */ protected function setUp() { - $this->moduleList = $this->getMockBuilder(ModuleListInterface::class) - ->getMockForAbstractClass(); - $this->outputConfig = $this->getMockBuilder(ConfigInterface::class) - ->getMockForAbstractClass(); - - $this->model = new Manager( - $this->outputConfig, - $this->moduleList + $this->_moduleList = $this->getMockForAbstractClass(\Magento\Framework\Module\ModuleListInterface::class); + $this->_moduleList->expects($this->any()) + ->method('getOne') + ->will($this->returnValueMap([ + ['Module_One', ['name' => 'One_Module', 'setup_version' => '1']], + ['Module_Two', ['name' => 'Two_Module', 'setup_version' => '2']], + ['Module_Three', ['name' => 'Two_Three']], + ])); + $this->_outputConfig = $this->getMockForAbstractClass(\Magento\Framework\Module\Output\ConfigInterface::class); + $this->_model = new \Magento\Framework\Module\Manager( + $this->_outputConfig, + $this->_moduleList, + [ + 'Module_Two' => self::XML_PATH_OUTPUT_ENABLED, + ] ); } public function testIsEnabled() { - $this->moduleList->expects($this->exactly(2)) - ->method('has') - ->willReturnMap( - [ - ['Module_Exists', true], - ['Module_NotExists', false], - ] - ); - - $this->assertTrue($this->model->isEnabled('Module_Exists')); - $this->assertFalse($this->model->isEnabled('Module_NotExists')); + $this->_moduleList->expects($this->exactly(2))->method('has')->will($this->returnValueMap([ + ['Module_Exists', true], + ['Module_NotExists', false], + ])); + $this->assertTrue($this->_model->isEnabled('Module_Exists')); + $this->assertFalse($this->_model->isEnabled('Module_NotExists')); } } From 5d1c9a2727bf5456c8e6bd38bb25957f4a534482 Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Thu, 10 Aug 2017 17:01:10 -0500 Subject: [PATCH 08/14] MAGETWO-71257: Need to disable module output by configuration --- .../Module/Test/Unit/ManagerTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php index bc71feb4c4750..44185b52b19a4 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/ManagerTest.php @@ -61,4 +61,53 @@ public function testIsEnabled() $this->assertTrue($this->_model->isEnabled('Module_Exists')); $this->assertFalse($this->_model->isEnabled('Module_NotExists')); } + + public function testIsOutputEnabledReturnsFalseForDisabledModule() + { + $this->_outputConfig->expects($this->any())->method('isSetFlag')->will($this->returnValue(true)); + $this->assertFalse($this->_model->isOutputEnabled('Disabled_Module')); + } + + /** + * @param bool $configValue + * @param bool $expectedResult + * @dataProvider isOutputEnabledGenericConfigPathDataProvider + */ + public function testIsOutputEnabledGenericConfigPath($configValue, $expectedResult) + { + $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true)); + $this->_outputConfig->expects($this->once()) + ->method('isEnabled') + ->with('Module_One') + ->will($this->returnValue($configValue)); + $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_One')); + } + + public function isOutputEnabledGenericConfigPathDataProvider() + { + return ['output disabled' => [true, false], 'output enabled' => [false, true]]; + } + + /** + * @param bool $configValue + * @param bool $expectedResult + * @dataProvider isOutputEnabledCustomConfigPathDataProvider + */ + public function testIsOutputEnabledCustomConfigPath($configValue, $expectedResult) + { + $this->_moduleList->expects($this->once())->method('has')->will($this->returnValue(true)); + $this->_outputConfig->expects($this->at(0)) + ->method('isSetFlag') + ->with(self::XML_PATH_OUTPUT_ENABLED) + ->will($this->returnValue($configValue)); + $this->assertEquals($expectedResult, $this->_model->isOutputEnabled('Module_Two')); + } + + public function isOutputEnabledCustomConfigPathDataProvider() + { + return [ + 'path literal, output disabled' => [false, false], + 'path literal, output enabled' => [true, true], + ]; + } } From ff4840e616f26f88abb3f12c5e1c1d288745f35f Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Thu, 10 Aug 2017 17:03:21 -0500 Subject: [PATCH 09/14] MAGETWO-71257: Need to disable module output by configuration --- app/code/Magento/Backend/etc/adminhtml/system.xml | 2 +- .../Form/Fieldset/Modules/DisableOutputTest.php | 1 - lib/internal/Magento/Framework/Module/Manager.php | 13 ++++++------- .../Magento/Framework/Module/Output/Config.php | 9 ++------- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Backend/etc/adminhtml/system.xml b/app/code/Magento/Backend/etc/adminhtml/system.xml index 27fd16cc920dc..e5abdf69daaf0 100644 --- a/app/code/Magento/Backend/etc/adminhtml/system.xml +++ b/app/code/Magento/Backend/etc/adminhtml/system.xml @@ -20,7 +20,7 @@ @deprecated Magento does not support custom disabling/enabling modules output since 2.2.0 version. Section 'Advanced' was disabled. This section will be removed from code in one release. --> -
+
advanced Magento_Backend::advanced diff --git a/app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php b/app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php index f274e7a1fa428..9d76363213d0b 100644 --- a/app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php +++ b/app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Fieldset/Modules/DisableOutputTest.php @@ -7,7 +7,6 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @deprecated because \Magento\Config\Block\System\Config\Form\Fieldset\Modules\DisableOutput is deprecated */ class DisableOutputTest extends \PHPUnit\Framework\TestCase { diff --git a/lib/internal/Magento/Framework/Module/Manager.php b/lib/internal/Magento/Framework/Module/Manager.php index a28a43633d226..b176549138a37 100644 --- a/lib/internal/Magento/Framework/Module/Manager.php +++ b/lib/internal/Magento/Framework/Module/Manager.php @@ -21,8 +21,6 @@ class Manager { /** * @var Output\ConfigInterface - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version. - * The property can be removed in a future major release */ private $_outputConfig; @@ -33,8 +31,6 @@ class Manager /** * @var array - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version. - * The property can be removed in a future major release */ private $_outputConfigPaths; @@ -69,14 +65,18 @@ public function isEnabled($moduleName) * * @param string $moduleName Fully-qualified module name * @return boolean - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version */ public function isOutputEnabled($moduleName) { if (!$this->isEnabled($moduleName)) { return false; } - + if (!$this->_isCustomOutputConfigEnabled($moduleName)) { + return false; + } + if ($this->_outputConfig->isEnabled($moduleName)) { + return false; + } return true; } @@ -85,7 +85,6 @@ public function isOutputEnabled($moduleName) * * @param string $moduleName Fully-qualified module name * @return boolean - * @deprecated */ protected function _isCustomOutputConfigEnabled($moduleName) { diff --git a/lib/internal/Magento/Framework/Module/Output/Config.php b/lib/internal/Magento/Framework/Module/Output/Config.php index 2577ec07422a0..aa4e05efa14a0 100644 --- a/lib/internal/Magento/Framework/Module/Output/Config.php +++ b/lib/internal/Magento/Framework/Module/Output/Config.php @@ -7,11 +7,6 @@ */ namespace Magento\Framework\Module\Output; -/** - * Checks whether the module is enabled in the configuration. - * - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version - */ class Config implements \Magento\Framework\Module\Output\ConfigInterface { /** @@ -53,7 +48,7 @@ public function __construct( */ public function isEnabled($moduleName) { - return false; + return $this->isSetFlag(sprintf(self::XML_PATH_MODULE_OUTPUT_STATUS, $moduleName)); } /** @@ -65,6 +60,6 @@ public function isEnabled($moduleName) */ public function isSetFlag($path) { - return false; + return $this->_scopeConfig->isSetFlag($path, $this->_storeType); } } From 206379a68390495cd4ded9805f91ca56bf7e26ec Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Fri, 11 Aug 2017 10:30:56 -0500 Subject: [PATCH 10/14] MAGETWO-71257: Need to disable module output by configuration - Fix deprecation tags --- app/code/Magento/Backend/Block/Template.php | 5 ++ .../Magento/Framework/Module/Manager.php | 53 ++++++++++++------- .../Framework/Module/Output/Config.php | 37 +++++++++++-- .../Module/Output/ConfigInterface.php | 16 +++++- 4 files changed, 84 insertions(+), 27 deletions(-) diff --git a/app/code/Magento/Backend/Block/Template.php b/app/code/Magento/Backend/Block/Template.php index de1d852e6f244..c87dae47e640e 100644 --- a/app/code/Magento/Backend/Block/Template.php +++ b/app/code/Magento/Backend/Block/Template.php @@ -84,6 +84,11 @@ public function getFormKey() * * @param string $moduleName Full module name * @return boolean + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ public function isOutputEnabled($moduleName = null) { diff --git a/lib/internal/Magento/Framework/Module/Manager.php b/lib/internal/Magento/Framework/Module/Manager.php index b176549138a37..d720c75ba8f47 100644 --- a/lib/internal/Magento/Framework/Module/Manager.php +++ b/lib/internal/Magento/Framework/Module/Manager.php @@ -21,18 +21,28 @@ class Manager { /** * @var Output\ConfigInterface + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ - private $_outputConfig; + private $outputConfig; /** * @var ModuleListInterface */ - private $_moduleList; + private $moduleList; /** * @var array + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ - private $_outputConfigPaths; + private $outputConfigPaths; /** * @param Output\ConfigInterface $outputConfig @@ -44,9 +54,9 @@ public function __construct( ModuleListInterface $moduleList, array $outputConfigPaths = [] ) { - $this->_outputConfig = $outputConfig; - $this->_moduleList = $moduleList; - $this->_outputConfigPaths = $outputConfigPaths; + $this->outputConfig = $outputConfig; + $this->moduleList = $moduleList; + $this->outputConfigPaths = $outputConfigPaths; } /** @@ -57,7 +67,7 @@ public function __construct( */ public function isEnabled($moduleName) { - return $this->_moduleList->has($moduleName); + return $this->moduleList->has($moduleName); } /** @@ -65,19 +75,17 @@ public function isEnabled($moduleName) * * @param string $moduleName Fully-qualified module name * @return boolean + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ public function isOutputEnabled($moduleName) { - if (!$this->isEnabled($moduleName)) { - return false; - } - if (!$this->_isCustomOutputConfigEnabled($moduleName)) { - return false; - } - if ($this->_outputConfig->isEnabled($moduleName)) { - return false; - } - return true; + return $this->isEnabled($moduleName) + && $this->_isCustomOutputConfigEnabled($moduleName) + && !$this->outputConfig->isEnabled($moduleName); } /** @@ -85,15 +93,20 @@ public function isOutputEnabled($moduleName) * * @param string $moduleName Fully-qualified module name * @return boolean + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ protected function _isCustomOutputConfigEnabled($moduleName) { - if (isset($this->_outputConfigPaths[$moduleName])) { - $configPath = $this->_outputConfigPaths[$moduleName]; + if (isset($this->outputConfigPaths[$moduleName])) { + $configPath = $this->outputConfigPaths[$moduleName]; if (defined($configPath)) { $configPath = constant($configPath); } - return $this->_outputConfig->isSetFlag($configPath); + return $this->outputConfig->isSetFlag($configPath); } return true; } diff --git a/lib/internal/Magento/Framework/Module/Output/Config.php b/lib/internal/Magento/Framework/Module/Output/Config.php index aa4e05efa14a0..fd56626381a40 100644 --- a/lib/internal/Magento/Framework/Module/Output/Config.php +++ b/lib/internal/Magento/Framework/Module/Output/Config.php @@ -7,23 +7,42 @@ */ namespace Magento\Framework\Module\Output; +/** + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. + */ class Config implements \Magento\Framework\Module\Output\ConfigInterface { /** * XPath in the configuration where module statuses are stored - * @deprecated Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ const XML_PATH_MODULE_OUTPUT_STATUS = 'advanced/modules_disable_output/%s'; /** * @var \Magento\Framework\App\Config\ScopeConfigInterface - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ protected $_scopeConfig; /** * @var string - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ protected $_storeType; @@ -43,7 +62,11 @@ public function __construct( * Whether a module is enabled in the configuration or not * * @param string $moduleName Fully-qualified module name - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @return boolean */ public function isEnabled($moduleName) @@ -55,7 +78,11 @@ public function isEnabled($moduleName) * Retrieve module enabled specific path * * @param string $path Fully-qualified config path - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @return boolean */ public function isSetFlag($path) diff --git a/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php b/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php index fc4ca36f777a9..6813691b9c906 100644 --- a/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php +++ b/lib/internal/Magento/Framework/Module/Output/ConfigInterface.php @@ -5,13 +5,21 @@ */ namespace Magento\Framework\Module\Output; +/** + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. + */ interface ConfigInterface { /** * Whether a module is enabled in the configuration or not * * @param string $moduleName Fully-qualified module name - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @return boolean */ public function isEnabled($moduleName); @@ -20,7 +28,11 @@ public function isEnabled($moduleName); * Retrieve module enabled specific path * * @param string $path Fully-qualified config path - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @return boolean */ public function isSetFlag($path); From 2e1981b86ef6f2e3aac4e9c3096fb2d92b0442fe Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Fri, 11 Aug 2017 10:51:43 -0500 Subject: [PATCH 11/14] MAGETWO-71257: Need to disable module output by configuration - Fix DisableOutput deprecation tags and hide advanced config in UI. --- .../Magento/Backend/etc/adminhtml/system.xml | 2 +- .../Form/Fieldset/Modules/DisableOutput.php | 60 +++++++++++++++---- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Backend/etc/adminhtml/system.xml b/app/code/Magento/Backend/etc/adminhtml/system.xml index e5abdf69daaf0..27fd16cc920dc 100644 --- a/app/code/Magento/Backend/etc/adminhtml/system.xml +++ b/app/code/Magento/Backend/etc/adminhtml/system.xml @@ -20,7 +20,7 @@ @deprecated Magento does not support custom disabling/enabling modules output since 2.2.0 version. Section 'Advanced' was disabled. This section will be removed from code in one release. --> -
+
advanced Magento_Backend::advanced diff --git a/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index 7d12cc81b4696..088c1b0ec5714 100644 --- a/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -10,32 +10,52 @@ * on the store settings page. * * @method \Magento\Config\Block\System\Config\Form getForm() - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @api */ class DisableOutput extends \Magento\Config\Block\System\Config\Form\Fieldset { /** * @var \Magento\Framework\DataObject - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ protected $_dummyElement; /** * @var \Magento\Config\Block\System\Config\Form\Field - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ protected $_fieldRenderer; /** * @var array - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ protected $_values; /** * @var \Magento\Framework\Module\ModuleListInterface - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ protected $_moduleList; @@ -59,7 +79,11 @@ public function __construct( /** * {@inheritdoc} - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. */ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) { @@ -88,7 +112,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele } /** - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @return \Magento\Framework\DataObject */ protected function _getDummyElement() @@ -100,7 +128,11 @@ protected function _getDummyElement() } /** - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @return \Magento\Config\Block\System\Config\Form\Field */ protected function _getFieldRenderer() @@ -114,7 +146,11 @@ protected function _getFieldRenderer() } /** - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @return array */ protected function _getValues() @@ -131,7 +167,11 @@ protected function _getValues() /** * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset * @param string $moduleName - * @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version + * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 + * version. Module output can still be enabled/disabled in configuration files. However, this functionality should + * not be used in future development. Module design should explicitly state dependencies to avoid requiring output + * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity + * issues that will be addressed in future releases. * @return mixed */ protected function _getFieldHtml($fieldset, $moduleName) From c160414d612c2fce39076925b8e0ea14f4889049 Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Fri, 11 Aug 2017 10:54:41 -0500 Subject: [PATCH 12/14] MAGETWO-71257: Need to disable module output by configuration - Fix unit test. --- app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php b/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php index 9b72e8aefead6..9a7a87b366fcf 100644 --- a/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Block/Express/ReviewTest.php @@ -38,7 +38,7 @@ protected function setUp() $layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class); $eventManager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); - $scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class, [], [], '', false); + $scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); $scopeConfig->expects($this->any()) ->method('getValue') From 8f2f48cc08340fffdb9ca8fc183f1d3745a6055b Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Fri, 11 Aug 2017 13:44:34 -0500 Subject: [PATCH 13/14] MAGETWO-71257: Need to disable module output by configuration --- .../Magento/Robots/Test/Unit/Block/DataTest.php | 14 ++++++++++++++ .../Magento/Sitemap/Test/Unit/Block/RobotsTest.php | 14 ++++++++++++++ .../Wishlist/Test/Unit/Model/Rss/WishlistTest.php | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Robots/Test/Unit/Block/DataTest.php b/app/code/Magento/Robots/Test/Unit/Block/DataTest.php index edc701f438a1b..10d2595832a48 100644 --- a/app/code/Magento/Robots/Test/Unit/Block/DataTest.php +++ b/app/code/Magento/Robots/Test/Unit/Block/DataTest.php @@ -32,11 +32,19 @@ class DataTest extends \PHPUnit\Framework\TestCase */ private $eventManagerMock; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $scopeConfigMock; + protected function setUp() { $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class) ->getMockForAbstractClass(); + $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class) + ->getMockForAbstractClass(); + $this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Context::class) ->disableOriginalConstructor() ->getMock(); @@ -45,6 +53,10 @@ protected function setUp() ->method('getEventManager') ->willReturn($this->eventManagerMock); + $this->context->expects($this->any()) + ->method('getScopeConfig') + ->willReturn($this->scopeConfigMock); + $this->robots = $this->getMockBuilder(\Magento\Robots\Model\Robots::class) ->disableOriginalConstructor() ->getMock(); @@ -69,6 +81,8 @@ public function testToHtml() $this->initEventManagerMock($data); + $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); + $this->robots->expects($this->once()) ->method('getData') ->willReturn($data); diff --git a/app/code/Magento/Sitemap/Test/Unit/Block/RobotsTest.php b/app/code/Magento/Sitemap/Test/Unit/Block/RobotsTest.php index d78f87ad925be..6fcd247ab1f0f 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Block/RobotsTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Block/RobotsTest.php @@ -40,6 +40,11 @@ class RobotsTest extends \PHPUnit\Framework\TestCase */ private $eventManagerMock; + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $scopeConfigMock; + /** * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -50,6 +55,9 @@ protected function setUp() $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class) ->getMockForAbstractClass(); + $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class) + ->getMockForAbstractClass(); + $this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Context::class) ->disableOriginalConstructor() ->getMock(); @@ -58,6 +66,10 @@ protected function setUp() ->method('getEventManager') ->willReturn($this->eventManagerMock); + $this->context->expects($this->any()) + ->method('getScopeConfig') + ->willReturn($this->scopeConfigMock); + $this->storeResolver = $this->getMockBuilder(\Magento\Store\Model\StoreResolver::class) ->disableOriginalConstructor() ->getMock(); @@ -95,6 +107,7 @@ public function testToHtmlRobotsSubmissionIsDisabled() $expected = ''; $this->initEventManagerMock($expected); + $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->storeResolver->expects($this->once()) ->method('getCurrentStoreId') @@ -150,6 +163,7 @@ public function testAfterGetDataRobotsSubmissionIsEnabled() . PHP_EOL; $this->initEventManagerMock($expected); + $this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(false); $this->storeResolver->expects($this->once()) ->method('getCurrentStoreId') diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php index f550fb58a991b..98d36dea28a2a 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php @@ -154,7 +154,8 @@ public function testGetRssData() ->will($this->returnValue($wishlistSharingUrl)); $this->scopeConfig->expects($this->any()) ->method('getValue') - ->will($this->returnValueMap( + ->will( + $this->returnValueMap( [ [ 'advanced/modules_disable_output/Magento_Rss', From 1eb1fcb84d34e27896925c4bb47a03168ce98ddd Mon Sep 17 00:00:00 2001 From: Eric Bohanon Date: Fri, 11 Aug 2017 14:29:36 -0500 Subject: [PATCH 14/14] MAGETWO-71257: Need to disable module output by configuration --- .../Form/Fieldset/Modules/DisableOutput.php | 48 ++++--------------- .../Magento/Framework/Module/Manager.php | 18 ++----- .../Framework/Module/Output/Config.php | 18 ++----- 3 files changed, 14 insertions(+), 70 deletions(-) diff --git a/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php b/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php index 088c1b0ec5714..8741f1ae8f612 100644 --- a/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php +++ b/app/code/Magento/Config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.php @@ -21,41 +21,25 @@ class DisableOutput extends \Magento\Config\Block\System\Config\Form\Fieldset { /** * @var \Magento\Framework\DataObject - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ protected $_dummyElement; /** * @var \Magento\Config\Block\System\Config\Form\Field - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ protected $_fieldRenderer; /** * @var array - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ protected $_values; /** * @var \Magento\Framework\Module\ModuleListInterface - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ protected $_moduleList; @@ -112,11 +96,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele } /** - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 * @return \Magento\Framework\DataObject */ protected function _getDummyElement() @@ -128,11 +108,7 @@ protected function _getDummyElement() } /** - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 * @return \Magento\Config\Block\System\Config\Form\Field */ protected function _getFieldRenderer() @@ -146,11 +122,7 @@ protected function _getFieldRenderer() } /** - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 * @return array */ protected function _getValues() @@ -167,11 +139,7 @@ protected function _getValues() /** * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset * @param string $moduleName - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 * @return mixed */ protected function _getFieldHtml($fieldset, $moduleName) diff --git a/lib/internal/Magento/Framework/Module/Manager.php b/lib/internal/Magento/Framework/Module/Manager.php index d720c75ba8f47..a9a3d2294a90f 100644 --- a/lib/internal/Magento/Framework/Module/Manager.php +++ b/lib/internal/Magento/Framework/Module/Manager.php @@ -21,11 +21,7 @@ class Manager { /** * @var Output\ConfigInterface - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ private $outputConfig; @@ -36,11 +32,7 @@ class Manager /** * @var array - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ private $outputConfigPaths; @@ -93,11 +85,7 @@ public function isOutputEnabled($moduleName) * * @param string $moduleName Fully-qualified module name * @return boolean - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ protected function _isCustomOutputConfigEnabled($moduleName) { diff --git a/lib/internal/Magento/Framework/Module/Output/Config.php b/lib/internal/Magento/Framework/Module/Output/Config.php index fd56626381a40..48afc97dc5336 100644 --- a/lib/internal/Magento/Framework/Module/Output/Config.php +++ b/lib/internal/Magento/Framework/Module/Output/Config.php @@ -18,31 +18,19 @@ class Config implements \Magento\Framework\Module\Output\ConfigInterface { /** * XPath in the configuration where module statuses are stored - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ const XML_PATH_MODULE_OUTPUT_STATUS = 'advanced/modules_disable_output/%s'; /** * @var \Magento\Framework\App\Config\ScopeConfigInterface - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ protected $_scopeConfig; /** * @var string - * @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0 - * version. Module output can still be enabled/disabled in configuration files. However, this functionality should - * not be used in future development. Module design should explicitly state dependencies to avoid requiring output - * disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity - * issues that will be addressed in future releases. + * @deprecated 100.2.0 */ protected $_storeType;