|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MadeByDenis\PhpMjmlRenderer\Tests\Unit\Elements\BodyComponents; |
| 4 | + |
| 5 | +use MadeByDenis\PhpMjmlRenderer\Elements\BodyComponents\MjSpacer; |
| 6 | +use MadeByDenis\PhpMjmlRenderer\Elements\ElementFactory; |
| 7 | +use MadeByDenis\PhpMjmlRenderer\Parser\MjmlNode; |
| 8 | +use OutOfBoundsException; |
| 9 | + |
| 10 | +beforeEach(function () { |
| 11 | + $this->element = new MjSpacer(); |
| 12 | +}); |
| 13 | + |
| 14 | +it('is not ending tag', function () { |
| 15 | + expect($this->element->isEndingTag())->toBe(false); |
| 16 | +}); |
| 17 | + |
| 18 | +it('returns the correct component name', function () { |
| 19 | + expect($this->element->getTagName())->toBe('mj-spacer'); |
| 20 | +}); |
| 21 | + |
| 22 | +it('returns the correct default attributes', function () { |
| 23 | + $attributes = [ |
| 24 | + 'height' => '20px', |
| 25 | + ]; |
| 26 | + |
| 27 | + foreach ($attributes as $key => $value) { |
| 28 | + expect($this->element->getAttribute($key))->toBe($value); |
| 29 | + } |
| 30 | +}); |
| 31 | + |
| 32 | +it('will throw out of bounds exception if the allowed attribute is not existing', function () { |
| 33 | + $this->element->getAllowedAttributeData('invalid-attribute'); |
| 34 | +})->throws(OutOfBoundsException::class); |
| 35 | + |
| 36 | +it('will return allowed attribute data', function () { |
| 37 | + $data = $this->element->getAllowedAttributeData('height'); |
| 38 | + expect($data)->toBeArray(); |
| 39 | + expect($data)->toHaveKey('type'); |
| 40 | + expect($data)->toHaveKey('unit'); |
| 41 | +}); |
| 42 | + |
| 43 | +it('will correctly render a simple spacer', function () { |
| 44 | + $spacerNode = new MjmlNode( |
| 45 | + 'mj-spacer', |
| 46 | + null, |
| 47 | + null, |
| 48 | + false, |
| 49 | + null |
| 50 | + ); |
| 51 | + |
| 52 | + $factory = new ElementFactory(); |
| 53 | + $mjSpacerElement = $factory->create($spacerNode); |
| 54 | + |
| 55 | + expect($mjSpacerElement)->toBeInstanceOf(MjSpacer::class); |
| 56 | + |
| 57 | + $out = $mjSpacerElement->render(); |
| 58 | + |
| 59 | + expect($out)->toContain('<div'); |
| 60 | + expect($out)->toContain('height'); |
| 61 | + expect($out)->toContain('20px'); |
| 62 | + expect($out)->not->toBeEmpty(); |
| 63 | +}); |
| 64 | + |
| 65 | +it('will correctly render a spacer with custom height', function () { |
| 66 | + $spacerNode = new MjmlNode( |
| 67 | + 'mj-spacer', |
| 68 | + ['height' => '50px'], |
| 69 | + null, |
| 70 | + false, |
| 71 | + null |
| 72 | + ); |
| 73 | + |
| 74 | + $factory = new ElementFactory(); |
| 75 | + $mjSpacerElement = $factory->create($spacerNode); |
| 76 | + |
| 77 | + $out = $mjSpacerElement->render(); |
| 78 | + |
| 79 | + expect($out)->toContain('50px'); |
| 80 | + expect($out)->not->toBeEmpty(); |
| 81 | +}); |
| 82 | + |
| 83 | +it('will correctly render a spacer with small height', function () { |
| 84 | + $spacerNode = new MjmlNode( |
| 85 | + 'mj-spacer', |
| 86 | + ['height' => '10px'], |
| 87 | + null, |
| 88 | + false, |
| 89 | + null |
| 90 | + ); |
| 91 | + |
| 92 | + $factory = new ElementFactory(); |
| 93 | + $mjSpacerElement = $factory->create($spacerNode); |
| 94 | + |
| 95 | + $out = $mjSpacerElement->render(); |
| 96 | + |
| 97 | + expect($out)->toContain('10px'); |
| 98 | + expect($out)->not->toBeEmpty(); |
| 99 | +}); |
| 100 | + |
| 101 | +it('will correctly render a spacer with large height', function () { |
| 102 | + $spacerNode = new MjmlNode( |
| 103 | + 'mj-spacer', |
| 104 | + ['height' => '100px'], |
| 105 | + null, |
| 106 | + false, |
| 107 | + null |
| 108 | + ); |
| 109 | + |
| 110 | + $factory = new ElementFactory(); |
| 111 | + $mjSpacerElement = $factory->create($spacerNode); |
| 112 | + |
| 113 | + $out = $mjSpacerElement->render(); |
| 114 | + |
| 115 | + expect($out)->toContain('100px'); |
| 116 | + expect($out)->not->toBeEmpty(); |
| 117 | +}); |
0 commit comments