|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Qameta\Allure\Test\Attribute; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Qameta\Allure\Attribute; |
| 9 | +use Qameta\Allure\Attribute\AttributeParser; |
| 10 | +use Qameta\Allure\Setup\LinkTemplateCollectionInterface; |
| 11 | + |
| 12 | +use function json_encode; |
| 13 | + |
| 14 | +/** |
| 15 | + * @covers \Qameta\Allure\Attribute\AttributeParser |
| 16 | + */ |
| 17 | +class AttributeParserTest extends TestCase |
| 18 | +{ |
| 19 | + public function testGetLinks_ConstructedWithoutLinkAttributes_ReturnsEmptyList(): void |
| 20 | + { |
| 21 | + $parser = new AttributeParser( |
| 22 | + attributes: [ |
| 23 | + ], |
| 24 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 25 | + ); |
| 26 | + |
| 27 | + self::assertEmpty($parser->getLinks()); |
| 28 | + } |
| 29 | + |
| 30 | + public function testGetLinks_ConstructedWithLinkAttributes_ReturnsMatchingLinkModels(): void |
| 31 | + { |
| 32 | + $parser = new AttributeParser( |
| 33 | + attributes: [ |
| 34 | + new Attribute\Link('a', 'b', Attribute\Link::TMS), |
| 35 | + new Attribute\Link('c', 'd', Attribute\Link::ISSUE), |
| 36 | + ], |
| 37 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 38 | + ); |
| 39 | + |
| 40 | + $expectedValue = <<<EOF |
| 41 | +[ |
| 42 | + {"name": "a", "url": "b", "type": "tms"}, |
| 43 | + {"name": "c", "url": "d", "type": "issue"} |
| 44 | +] |
| 45 | +EOF; |
| 46 | + self::assertJsonStringEqualsJsonString( |
| 47 | + $expectedValue, |
| 48 | + json_encode($parser->getLinks()), |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + public function testGetLabels_ConstructedWithoutLabelAttributes_ReturnsEmptyList(): void |
| 53 | + { |
| 54 | + $parser = new AttributeParser( |
| 55 | + attributes: [ |
| 56 | + ], |
| 57 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 58 | + ); |
| 59 | + |
| 60 | + self::assertEmpty($parser->getLabels()); |
| 61 | + } |
| 62 | + |
| 63 | + public function testGetLabels_ConstructedWithLabelAttributes_ReturnsMatchingLabelModelsInReverseOrder(): void |
| 64 | + { |
| 65 | + $parser = new AttributeParser( |
| 66 | + attributes: [ |
| 67 | + new Attribute\Label('a', 'b'), |
| 68 | + new Attribute\Label('c', 'd'), |
| 69 | + ], |
| 70 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 71 | + ); |
| 72 | + |
| 73 | + $expectedValue = <<<EOF |
| 74 | +[ |
| 75 | + {"name": "c", "value": "d"}, |
| 76 | + {"name": "a", "value": "b"} |
| 77 | +] |
| 78 | +EOF; |
| 79 | + self::assertJsonStringEqualsJsonString( |
| 80 | + $expectedValue, |
| 81 | + json_encode($parser->getLabels()), |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function testGetParameters_ConstructedWithoutParameterAttributes_ReturnsEmptyList(): void |
| 86 | + { |
| 87 | + $parser = new AttributeParser( |
| 88 | + attributes: [ |
| 89 | + ], |
| 90 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 91 | + ); |
| 92 | + |
| 93 | + self::assertEmpty($parser->getParameters()); |
| 94 | + } |
| 95 | + |
| 96 | + public function testGetParameters_ConstructedWithParameterAttributes_ReturnsMatchingParamsInReverseOrder(): void |
| 97 | + { |
| 98 | + $parser = new AttributeParser( |
| 99 | + attributes: [ |
| 100 | + new Attribute\Parameter('a', 'b', mode: Attribute\ParameterMode::HIDDEN), |
| 101 | + new Attribute\Parameter('c', 'd', excluded: true), |
| 102 | + ], |
| 103 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 104 | + ); |
| 105 | + |
| 106 | + $expectedValue = <<<EOF |
| 107 | +[ |
| 108 | + {"name": "a", "value": "b", "excluded": null, "mode": "hidden"}, |
| 109 | + {"name": "c", "value": "d", "excluded": true, "mode": null} |
| 110 | +] |
| 111 | +EOF; |
| 112 | + self::assertJsonStringEqualsJsonString( |
| 113 | + $expectedValue, |
| 114 | + json_encode($parser->getParameters()), |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + public function testGetDisplayName_ConstructedWithoutDisplayNameAttribute_ReturnsNull(): void |
| 119 | + { |
| 120 | + $parser = new AttributeParser( |
| 121 | + attributes: [ |
| 122 | + ], |
| 123 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 124 | + ); |
| 125 | + |
| 126 | + self::assertNull($parser->getDisplayName()); |
| 127 | + } |
| 128 | + |
| 129 | + public function testGetDisplayName_ConstructedWithDisplayNameAttribute_ReturnsMatchingValue(): void |
| 130 | + { |
| 131 | + $parser = new AttributeParser( |
| 132 | + attributes: [ |
| 133 | + new Attribute\DisplayName('a'), |
| 134 | + ], |
| 135 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 136 | + ); |
| 137 | + |
| 138 | + self::assertSame('a', $parser->getDisplayName()); |
| 139 | + } |
| 140 | + |
| 141 | + |
| 142 | + public function testGetDescription_ConstructedWithoutDescriptionAttribute_ReturnsNull(): void |
| 143 | + { |
| 144 | + $parser = new AttributeParser( |
| 145 | + attributes: [ |
| 146 | + ], |
| 147 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 148 | + ); |
| 149 | + |
| 150 | + self::assertNull($parser->getDescription()); |
| 151 | + } |
| 152 | + |
| 153 | + public function testGetDescription_ConstructedWithDescriptionAttribute_ReturnsMatchingValue(): void |
| 154 | + { |
| 155 | + $parser = new AttributeParser( |
| 156 | + attributes: [ |
| 157 | + new Attribute\Description('a'), |
| 158 | + ], |
| 159 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 160 | + ); |
| 161 | + |
| 162 | + self::assertSame('a', $parser->getDescription()); |
| 163 | + } |
| 164 | + |
| 165 | + public function testGetDescription_ConstructedWithDescriptionHtmlAttribute_ReturnsNull(): void |
| 166 | + { |
| 167 | + $parser = new AttributeParser( |
| 168 | + attributes: [ |
| 169 | + new Attribute\Description('a', isHtml: true), |
| 170 | + ], |
| 171 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 172 | + ); |
| 173 | + |
| 174 | + self::assertNull($parser->getDescription()); |
| 175 | + } |
| 176 | + |
| 177 | + public function testGetDescriptionHtml_ConstructedWithoutDescriptionAttribute_ReturnsNull(): void |
| 178 | + { |
| 179 | + $parser = new AttributeParser( |
| 180 | + attributes: [ |
| 181 | + ], |
| 182 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 183 | + ); |
| 184 | + |
| 185 | + self::assertNull($parser->getDescriptionHtml()); |
| 186 | + } |
| 187 | + |
| 188 | + public function testGetDescriptionHtml_ConstructedWithDescriptionHtmlAttribute_ReturnsMatchingValue(): void |
| 189 | + { |
| 190 | + $parser = new AttributeParser( |
| 191 | + attributes: [ |
| 192 | + new Attribute\Description('a', isHtml: true), |
| 193 | + ], |
| 194 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 195 | + ); |
| 196 | + |
| 197 | + self::assertSame('a', $parser->getDescriptionHtml()); |
| 198 | + } |
| 199 | + |
| 200 | + public function testGetDescriptionHtml_ConstructedWithDescriptionAttribute_ReturnsNull(): void |
| 201 | + { |
| 202 | + $parser = new AttributeParser( |
| 203 | + attributes: [ |
| 204 | + new Attribute\Description('a', isHtml: false), |
| 205 | + ], |
| 206 | + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), |
| 207 | + ); |
| 208 | + |
| 209 | + self::assertNull($parser->getDescriptionHtml()); |
| 210 | + } |
| 211 | +} |
0 commit comments