|
| 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 | +} |
0 commit comments