|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHPDraft\Model\Elements\Tests; |
| 4 | + |
| 5 | +use Lunr\Halo\LunrBaseTest; |
| 6 | +use PHPDraft\Model\Elements\ElementStructureElement; |
| 7 | +use ReflectionClass; |
| 8 | + |
| 9 | +/** |
| 10 | + * Class ElementStructureElementTest |
| 11 | + * @covers \PHPDraft\Model\Elements\ElementStructureElement |
| 12 | + */ |
| 13 | +class ElementStructureElementTest extends LunrBaseTest |
| 14 | +{ |
| 15 | + |
| 16 | + /** |
| 17 | + * Set up |
| 18 | + */ |
| 19 | + public function setUp(): void |
| 20 | + { |
| 21 | + $this->class = new ElementStructureElement(); |
| 22 | + $this->reflection = new ReflectionClass('PHPDraft\Model\Elements\ElementStructureElement'); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Tear down |
| 27 | + */ |
| 28 | + public function tearDown(): void |
| 29 | + { |
| 30 | + unset($this->class); |
| 31 | + unset($this->reflection); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @covers \PHPDraft\Model\Elements\ElementStructureElement::parse |
| 36 | + */ |
| 37 | + public function testParse() |
| 38 | + { |
| 39 | + $json = '{"element": "Cow", "content": "stuff", "meta": {"description": {"content": "desc"}}}'; |
| 40 | + $dep = []; |
| 41 | + $this->class->parse(json_decode($json), $dep); |
| 42 | + |
| 43 | + $this->assertPropertySame('type', 'Cow'); |
| 44 | + $this->assertPropertySame('value', 'stuff'); |
| 45 | + $this->assertPropertySame('description', 'desc'); |
| 46 | + $this->assertSame(['Cow'], $dep); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @covers \PHPDraft\Model\Elements\ElementStructureElement::string_value |
| 51 | + */ |
| 52 | + public function testStringValue() |
| 53 | + { |
| 54 | + $this->assertSame('<li class="list-group-item mdl-list__item"><a class="code" title="" href="#object-"></a></li>', $this->class->string_value()); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @covers \PHPDraft\Model\Elements\ElementStructureElement::__toString |
| 59 | + */ |
| 60 | + public function testToString() |
| 61 | + { |
| 62 | + $this->set_reflection_property_value('type', 'string'); |
| 63 | + |
| 64 | + $this->assertSame('<li class="list-group-item mdl-list__item"><code>string</code></li>', $this->class->__toString()); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @covers \PHPDraft\Model\Elements\ElementStructureElement::__toString |
| 69 | + */ |
| 70 | + public function testToStringCustomType() |
| 71 | + { |
| 72 | + $this->set_reflection_property_value('type', 'Cow'); |
| 73 | + |
| 74 | + $this->assertSame('<li class="list-group-item mdl-list__item"><a class="code" title="Cow" href="#object-cow">Cow</a></li>', $this->class->__toString()); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @covers \PHPDraft\Model\Elements\ElementStructureElement::__toString |
| 79 | + */ |
| 80 | + public function testToStringDescription() |
| 81 | + { |
| 82 | + $this->set_reflection_property_value('type', 'Cow'); |
| 83 | + $this->set_reflection_property_value('description', 'Something'); |
| 84 | + |
| 85 | + $this->assertSame('<li class="list-group-item mdl-list__item"><a class="code" title="Cow" href="#object-cow">Cow</a> - <span class="description">Something</span></li>', $this->class->__toString()); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @covers \PHPDraft\Model\Elements\ElementStructureElement::__toString |
| 90 | + */ |
| 91 | + public function testToStringValue() |
| 92 | + { |
| 93 | + $this->set_reflection_property_value('type', 'Cow'); |
| 94 | + $this->set_reflection_property_value('value', 'stuff'); |
| 95 | + |
| 96 | + $this->assertSame('<li class="list-group-item mdl-list__item"><a class="code" title="Cow" href="#object-cow">Cow</a> - <span class="example-value pull-right">stuff</span></li>', $this->class->__toString()); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * @covers \PHPDraft\Model\Elements\ElementStructureElement::__toString |
| 101 | + */ |
| 102 | + public function testToStringDescriptionAndValue() |
| 103 | + { |
| 104 | + $this->set_reflection_property_value('type', 'Cow'); |
| 105 | + $this->set_reflection_property_value('value', 'stuff'); |
| 106 | + $this->set_reflection_property_value('description', 'Something'); |
| 107 | + |
| 108 | + $this->assertSame('<li class="list-group-item mdl-list__item"><a class="code" title="Cow" href="#object-cow">Cow</a> - <span class="description">Something</span> - <span class="example-value pull-right">stuff</span></li>', $this->class->__toString()); |
| 109 | + } |
| 110 | +} |
0 commit comments