Skip to content

Commit 97bd34c

Browse files
authored
ENGCOM-6668: Add frontend template hints status command #26451
2 parents ba8fae3 + 93905ea commit 97bd34c

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Developer\Console\Command;
9+
10+
use Magento\Framework\App\Config\ReinitableConfigInterface;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\Console\Cli;
13+
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
17+
/**
18+
* Command to show frontend template hints status
19+
*/
20+
class TemplateHintsStatusCommand extends Command
21+
{
22+
const COMMAND_NAME = 'dev:template-hints:status';
23+
const TEMPLATE_HINTS_STOREFRONT_PATH = 'dev/debug/template_hints_storefront';
24+
25+
/**
26+
* @var ScopeConfigInterface
27+
*/
28+
private $scopeConfig;
29+
30+
/**
31+
* @var ReinitableConfigInterface
32+
*/
33+
private $reinitableConfig;
34+
35+
/**
36+
* Initialize dependencies.
37+
*
38+
* @param ScopeConfigInterface $scopeConfig
39+
* @param ReinitableConfigInterface $reinitableConfig
40+
*/
41+
public function __construct(
42+
ScopeConfigInterface $scopeConfig,
43+
ReinitableConfigInterface $reinitableConfig
44+
) {
45+
parent::__construct();
46+
$this->scopeConfig = $scopeConfig;
47+
$this->reinitableConfig = $reinitableConfig;
48+
}
49+
50+
/**
51+
* @inheritdoc
52+
*/
53+
public function configure()
54+
{
55+
$this->setName(self::COMMAND_NAME)
56+
->setDescription('Show frontend template hints status.');
57+
58+
parent::configure();
59+
}
60+
61+
/**
62+
* @inheritdoc
63+
* @throws \InvalidArgumentException
64+
*/
65+
public function execute(InputInterface $input, OutputInterface $output)
66+
{
67+
$this->reinitableConfig->reinit();
68+
$templateHintsStatus =
69+
($this->isTemplateHintsEnabled())
70+
? 'enabled'
71+
: 'disabled';
72+
$templateHintsMessage = __("Template hints are %status", ['status' => $templateHintsStatus]);
73+
$output->writeln("<info>$templateHintsMessage</info>");
74+
75+
return Cli::RETURN_SUCCESS;
76+
}
77+
78+
/**
79+
* Check if template hints enabled
80+
*
81+
* @return bool
82+
*/
83+
private function isTemplateHintsEnabled(): bool
84+
{
85+
return $this->scopeConfig->isSetFlag(self::TEMPLATE_HINTS_STOREFRONT_PATH, 'default');
86+
}
87+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Developer\Test\Unit\Console\Command;
9+
10+
use Magento\Developer\Console\Command\TemplateHintsStatusCommand;
11+
use Magento\Framework\App\Config\ReinitableConfigInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\Console\Cli;
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Tester\CommandTester;
16+
17+
/**
18+
* Class TemplateHintsStatusCommandTest
19+
*
20+
* Tests dev:template-hints:status command.
21+
*/
22+
class TemplateHintsStatusCommandTest extends TestCase
23+
{
24+
/**
25+
* @var TemplateHintsStatusCommand
26+
*/
27+
private $command;
28+
/**
29+
* @var ScopeConfigInterface
30+
*/
31+
private $scopeConfigMock;
32+
/**
33+
* @var ReinitableConfigInterface
34+
*/
35+
private $reinitableConfigMock;
36+
37+
/**
38+
* @inheritDoc
39+
*/
40+
protected function setUp()
41+
{
42+
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
43+
$this->reinitableConfigMock = $this->getMockForAbstractClass(ReinitableConfigInterface::class);
44+
45+
$this->command = new TemplateHintsStatusCommand(
46+
$this->scopeConfigMock,
47+
$this->reinitableConfigMock
48+
);
49+
}
50+
51+
/**
52+
* Verify ScopeConfigInterface instance
53+
*/
54+
public function testScopeConfigInterfaceInstance()
55+
{
56+
$this->assertInstanceOf(ScopeConfigInterface::class, $this->scopeConfigMock);
57+
}
58+
59+
/**
60+
* Verify ReinitableConfigInterface instance
61+
*/
62+
public function testReinitableConfigInterfaceInstance()
63+
{
64+
$this->assertInstanceOf(ReinitableConfigInterface::class, $this->reinitableConfigMock);
65+
}
66+
67+
/**
68+
* Verify TemplateHintsStatusCommand instance
69+
*/
70+
public function testCommandInstance()
71+
{
72+
$this->assertInstanceOf(TemplateHintsStatusCommand::class, $this->command);
73+
}
74+
}

app/code/Magento/Developer/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<item name="dev_query_log_disable" xsi:type="object">Magento\Developer\Console\Command\QueryLogDisableCommand</item>
106106
<item name="dev_template_hints_disable" xsi:type="object">Magento\Developer\Console\Command\TemplateHintsDisableCommand</item>
107107
<item name="dev_template_hints_enable" xsi:type="object">Magento\Developer\Console\Command\TemplateHintsEnableCommand</item>
108+
<item name="dev_template_hints_status" xsi:type="object">Magento\Developer\Console\Command\TemplateHintsStatusCommand</item>
108109
<item name="dev_profiler_disable" xsi:type="object">Magento\Developer\Console\Command\ProfilerDisableCommand</item>
109110
<item name="dev_profiler_enable" xsi:type="object">Magento\Developer\Console\Command\ProfilerEnableCommand</item>
110111
<item name="dev_generate_patch" xsi:type="object">Magento\Developer\Console\Command\GeneratePatchCommand</item>

0 commit comments

Comments
 (0)