HTMLTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // {{{ License
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. // }}}
  18. namespace App\Tests\Util;
  19. use App\Util\HTML;
  20. use Jchook\AssertThrows\AssertThrows;
  21. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  22. class HTMLTest extends WebTestCase
  23. {
  24. use AssertThrows;
  25. public function testHTML()
  26. {
  27. static::assertSame('', HTML::html(''));
  28. static::assertSame("<a>\n\n</a>\n", HTML::html(['a' => '']));
  29. static::assertSame("<a>\n <p>\n </p>\n</a>\n", HTML::html(['a' => ['p' => '']]));
  30. static::assertSame("<a href=\"test\">\n <p>\n </p>\n</a>\n", HTML::html(['a' => ['attrs' => ['href' => 'test'], 'p' => '']]));
  31. static::assertSame("<a>\n <p>\n foo\n </p>\n <br/>\n</a>\n", HTML::html(['a' => ['p' => 'foo', 'br' => 'empty']]));
  32. static::assertThrows(\InvalidArgumentException::class, fn () => HTML::html(1));
  33. static::assertSame("<a href=\"test\">\n foo\n</a>", implode("\n", HTML::tag('a', ['href' => 'test'], content: 'foo', empty_tag: false)));
  34. static::assertSame('<br/>', implode("\n", HTML::tag('br', attrs: null, content: null, empty_tag: true)));
  35. }
  36. }