-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-6668: Add frontend template hints status command #26451
- Loading branch information
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
app/code/Magento/Developer/Console/Command/TemplateHintsStatusCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Developer\Console\Command; | ||
|
||
use Magento\Framework\App\Config\ReinitableConfigInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Console\Cli; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command to show frontend template hints status | ||
*/ | ||
class TemplateHintsStatusCommand extends Command | ||
{ | ||
const COMMAND_NAME = 'dev:template-hints:status'; | ||
const TEMPLATE_HINTS_STOREFRONT_PATH = 'dev/debug/template_hints_storefront'; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var ReinitableConfigInterface | ||
*/ | ||
private $reinitableConfig; | ||
|
||
/** | ||
* Initialize dependencies. | ||
* | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param ReinitableConfigInterface $reinitableConfig | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
ReinitableConfigInterface $reinitableConfig | ||
) { | ||
parent::__construct(); | ||
$this->scopeConfig = $scopeConfig; | ||
$this->reinitableConfig = $reinitableConfig; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function configure() | ||
{ | ||
$this->setName(self::COMMAND_NAME) | ||
->setDescription('Show frontend template hints status.'); | ||
|
||
parent::configure(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->reinitableConfig->reinit(); | ||
$templateHintsStatus = | ||
($this->isTemplateHintsEnabled()) | ||
? 'enabled' | ||
: 'disabled'; | ||
$templateHintsMessage = __("Template hints are %status", ['status' => $templateHintsStatus]); | ||
$output->writeln("<info>$templateHintsMessage</info>"); | ||
|
||
return Cli::RETURN_SUCCESS; | ||
} | ||
|
||
/** | ||
* Check if template hints enabled | ||
* | ||
* @return bool | ||
*/ | ||
private function isTemplateHintsEnabled(): bool | ||
{ | ||
return $this->scopeConfig->isSetFlag(self::TEMPLATE_HINTS_STOREFRONT_PATH, 'default'); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
app/code/Magento/Developer/Test/Unit/Console/Command/TemplateHintsStatusCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Developer\Test\Unit\Console\Command; | ||
|
||
use Magento\Developer\Console\Command\TemplateHintsStatusCommand; | ||
use Magento\Framework\App\Config\ReinitableConfigInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Console\Cli; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
/** | ||
* Class TemplateHintsStatusCommandTest | ||
* | ||
* Tests dev:template-hints:status command. | ||
*/ | ||
class TemplateHintsStatusCommandTest extends TestCase | ||
{ | ||
/** | ||
* @var TemplateHintsStatusCommand | ||
*/ | ||
private $command; | ||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfigMock; | ||
/** | ||
* @var ReinitableConfigInterface | ||
*/ | ||
private $reinitableConfigMock; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class); | ||
$this->reinitableConfigMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class); | ||
|
||
$this->command = new TemplateHintsStatusCommand( | ||
$this->scopeConfigMock, | ||
$this->reinitableConfigMock | ||
); | ||
} | ||
|
||
/** | ||
* Verify ScopeConfigInterface instance | ||
*/ | ||
public function testScopeConfigInterfaceInstance() | ||
{ | ||
$this->assertInstanceOf(ScopeConfigInterface::class, $this->scopeConfigMock); | ||
} | ||
|
||
/** | ||
* Verify ReinitableConfigInterface instance | ||
*/ | ||
public function testReinitableConfigInterfaceInstance() | ||
{ | ||
$this->assertInstanceOf(ReinitableConfigInterface::class, $this->reinitableConfigMock); | ||
} | ||
|
||
/** | ||
* Verify TemplateHintsStatusCommand instance | ||
*/ | ||
public function testCommandInstance() | ||
{ | ||
$this->assertInstanceOf(TemplateHintsStatusCommand::class, $this->command); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters