|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tempest\Support\Tests; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Stringable; |
| 9 | +use Tempest\Support\HtmlString; |
| 10 | +use Tempest\Support\StringHelper; |
| 11 | + |
| 12 | +/** |
| 13 | + * @internal |
| 14 | + */ |
| 15 | +final class HtmlStringTest extends TestCase |
| 16 | +{ |
| 17 | + public function test_convertions(): void |
| 18 | + { |
| 19 | + $this->assertInstanceOf(HtmlString::class, HtmlString::createTag('div')); |
| 20 | + $this->assertInstanceOf(Stringable::class, HtmlString::createTag('div')); |
| 21 | + $this->assertInstanceOf(StringHelper::class, HtmlString::createTag('div')->toStringHelper()); |
| 22 | + $this->assertSame('<div></div>', HtmlString::createTag('div')->toStringHelper()->toString()); |
| 23 | + } |
| 24 | + |
| 25 | + public function test_create_tag(): void |
| 26 | + { |
| 27 | + $this->assertSame( |
| 28 | + expected: '<div></div>', |
| 29 | + actual: (string) HtmlString::createTag('div'), |
| 30 | + ); |
| 31 | + |
| 32 | + $this->assertSame( |
| 33 | + expected: '<button type="submit">OK</button>', |
| 34 | + actual: (string) HtmlString::createTag('button', ['type' => 'submit'], 'OK'), |
| 35 | + ); |
| 36 | + |
| 37 | + $this->assertSame( |
| 38 | + expected: '<a href="https://example.com">Link</a>', |
| 39 | + actual: (string) HtmlString::createTag('a', ['href' => 'https://example.com'], 'Link'), |
| 40 | + ); |
| 41 | + |
| 42 | + $this->assertSame( |
| 43 | + expected: '<script src="https://example.com/script.js"></script>', |
| 44 | + actual: (string) HtmlString::createTag('script', ['src' => 'https://example.com/script.js']), |
| 45 | + ); |
| 46 | + |
| 47 | + $this->assertSame( |
| 48 | + expected: '<link href="https://example.com/style.css" rel="stylesheet" />', |
| 49 | + actual: (string) HtmlString::createTag('link', ['href' => 'https://example.com/style.css', 'rel' => 'stylesheet']), |
| 50 | + ); |
| 51 | + |
| 52 | + $this->assertSame( |
| 53 | + expected: '<img src="https://example.com/image.jpg" alt="An image" />', |
| 54 | + actual: (string) HtmlString::createTag('img', ['src' => 'https://example.com/image.jpg', 'alt' => 'An image']), |
| 55 | + ); |
| 56 | + |
| 57 | + $this->assertSame( |
| 58 | + expected: '<input type="checkbox" checked />', |
| 59 | + actual: (string) HtmlString::createTag('input', ['type' => 'checkbox', 'checked' => true]), |
| 60 | + ); |
| 61 | + |
| 62 | + $this->assertSame( |
| 63 | + expected: '<input type="checkbox" />', |
| 64 | + actual: (string) HtmlString::createTag('input', ['type' => 'checkbox', 'checked' => false]), |
| 65 | + ); |
| 66 | + } |
| 67 | +} |
0 commit comments