Skip to content

Commit a6e8695

Browse files
authored
Merge pull request #41 from magento-l3/ACP2E-932
ACP2E-932: [Infra] Integrate EAT and Jenkins SVC
2 parents 1e5a267 + 95e0629 commit a6e8695

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Reporter;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
8+
class HtmlTargetDecoratorTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider dataProviderTestUrl
12+
*/
13+
public function testUrl(bool $hasOption, string $target, string $context, string $urlJson, string $expected): void
14+
{
15+
$input = $this->getMockBuilder(InputInterface::class)->getMockForAbstractClass();
16+
$input->expects($this->once())->method('hasOption')->with('report-html-target-url')->willReturn($hasOption);
17+
if ($hasOption) {
18+
$input->expects($this->once())->method('getOption')->with('report-html-target-url')->willReturn($urlJson);
19+
} else {
20+
$input->expects($this->never())->method('getOption');
21+
}
22+
$result = HtmlTargetDecorator::url($target, $context, $input);
23+
$this->assertEquals($expected, $result);
24+
}
25+
26+
public function dataProviderTestUrl()
27+
{
28+
return [
29+
'target-context-class' => [
30+
true,
31+
'Magento\Framework\Registry',
32+
'class',
33+
'[{"reportTypes": ["interface", "class"], "url": "https://localhost/?target=%s"}]',
34+
'<a href="https://localhost/?target=TWFnZW50b1xGcmFtZXdvcmtcUmVnaXN0cnk=" target="_blank">Magento\Framework\Registry</a>'
35+
],
36+
'target-context-class-array' => [
37+
true,
38+
'Magento\Framework\Registry',
39+
'class',
40+
'[{"reportTypes": ["mftf"], "url": "https://localhost/?target=%s"}, {"reportTypes": ["class"], "url": "https://localhost/?target=%s"}]',
41+
'<a href="https://localhost/?target=TWFnZW50b1xGcmFtZXdvcmtcUmVnaXN0cnk=" target="_blank">Magento\Framework\Registry</a>'
42+
],
43+
'target-context-mftf' => [
44+
true,
45+
'Magento\Framework\Registry',
46+
'mftf',
47+
'[{"reportTypes": ["interface", "class"], "url": "https://localhost/?target=%s"}]',
48+
'Magento\Framework\Registry'
49+
],
50+
'empty-json' => [
51+
true,
52+
'Magento\Framework\Registry::$someProperty',
53+
'class',
54+
'',
55+
'Magento\Framework\Registry::$someProperty'
56+
],
57+
'broken-json' => [
58+
true,
59+
'Magento\Framework\Registry',
60+
'class',
61+
'[{"reportTypes": ["interface", "class"]',
62+
'Magento\Framework\Registry'
63+
],
64+
'has-no-option' => [
65+
false,
66+
'Magento\Framework\Registry',
67+
'class',
68+
'',
69+
'Magento\Framework\Registry'
70+
],
71+
];
72+
}
73+
}

src/Console/Command/CompareSourceCommand.php

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ protected function configure()
9797
. '. Example: --report-type=' . ReportTypes::MFTF . PHP_EOL,
9898
[]
9999
),
100+
new InputOption(
101+
'report-html-target-url',
102+
'',
103+
InputOption::VALUE_OPTIONAL,
104+
'Json data to create url for Target field in HTML report of a specific type. Example: [{"reportTypes": ["interface", "class"], "url": "https://example.com/?target=%s"}]',
105+
''
106+
),
100107
]);
101108
}
102109

src/Reporter/HtmlDbSchemaReporter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function outputTable(OutputInterface $output, Report $report, $context
137137
} elseif (substr($location, 0, strlen($sourceAfterDir)) == $sourceAfterDir) {
138138
$location = substr($location, strlen($sourceAfterDir));
139139
}
140-
140+
$target = HtmlTargetDecorator::url($target, $context, $this->input);
141141
$output->writeln(
142142
'<tr class="text-' . ($level > $allowedChangeLevel ? 'danger' : 'success') .
143143
'"><td>' . $levelStr . '</td><td>' . $target . '<br/>' . $location . '</td><td>' . $code . ' ' .

src/Reporter/HtmlTargetDecorator.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Magento\SemanticVersionChecker\Reporter;
4+
5+
use Symfony\Component\Console\Input\InputInterface;
6+
7+
/**
8+
* Html decorator for Target field of the report
9+
*/
10+
class HtmlTargetDecorator
11+
{
12+
private static string $optionName = 'report-html-target-url';
13+
14+
/**
15+
* Create a link tag for specific report types
16+
*
17+
* @param string $target
18+
* @param string $context
19+
* @param InputInterface $input
20+
* @return string
21+
*/
22+
public static function url(string $target, string $context, InputInterface $input): string
23+
{
24+
if (!$input->hasOption(self::$optionName)) {
25+
return $target;
26+
}
27+
$urlContextJson = $input->getOption(self::$optionName);
28+
foreach (@json_decode($urlContextJson, true) ?? [] as $urlContext) {
29+
if (!in_array($context, $urlContext['reportTypes']) || !$urlContext['url']) {
30+
continue;
31+
}
32+
$href = sprintf($urlContext['url'], base64_encode($target));
33+
$target = sprintf('<a href="%s" target="_blank">%s</a>', $href, $target);
34+
}
35+
return $target;
36+
}
37+
}

0 commit comments

Comments
 (0)