assertEquals($expected, Text::full_format($bbcode), $name); } public function dataTeX(): array { return [ ['text-tex-basic', '[tex]some formula[/tex]', 'some formula'], ['text-tex-outer', '[size=4][tex]some formula[/tex][/size]', 'some formula'], ['text-tex-nested', '[tex]some [b]formula[/b][/tex]', 'some [b]formula[/b]'], ]; } // for phpunit v10: #[DataProvider('dataBB')] /** * @dataProvider dataBB */ public function testBB(string $name, string $bbcode, string $expected): void { global $Viewer; $Viewer = (new Gazelle\Manager\User)->find('@user'); Text::setViewer($Viewer); $this->assertEquals($expected, Text::full_format($bbcode), $name); } public static function dataBB(): array { $image = 'https://www.example.com/a.jpg'; $htmlImage = "\"$image\""; $url = 'https://www.example.com/'; $user = (new Gazelle\Manager\User)->find('@user'); return [ ["text-align-l", "[align=left]o[/align]", "
o
"], ["text-artist", "[artist]Frank Zappa[/artist]", "Frank Zappa"], ["text-b", "[b]o[/b]", "o"], ["text-br", "a\nb", "a
\nb"], ["text-box", "[box]jellyfish[/box]", "
jellyfish
"], ["text-code", "[code]ab\ncd[/code]", "ab
\ncd
"], ["text-color-name", "[color=cornsilk]pink[/color]", "pink"], ["text-color-hash", "[color=#c0ffee]black[/color]", "black"], ["text-colour", "[colour=gold]pink[/colour]", "pink"], ["text-headline", "[headline]abc[/headline]", "=abc="], ["text-hr", "[hr]", "
"], ["text-i", "[i]am[/i]", "am"], ["text-img-1", "[img={$image}]", $htmlImage], ["text-img-2", "[img]{$image}[/img]", $htmlImage], ["text-important", "[important]x[/important]", "x"], ["text-inlinesize", "[inlinesize=7]b[/inlinesize]", "b"], ["text-n", "[[n]i]am[[n]/i]", "[i]am[/i]"], ["text-pad", "[pad=2|4|6|8]text[/pad]", "text"], ["text-plain", "[plain]a[b]c[/plain]", "a[b]c"], ["text-pre", "[pre]a\nb[/pre]", "
a
\nb
"], ["text-quote-n", "[quote]a[/quote]", "
a
"], ["text-quote-y", "[quote=phpunit]a[/quote]", "phpunit wrote:
a
"], ["text-rule", "[rule]1[/rule]", "1"], ["text-s", "[s]sss[/s]", "sss"], ["text-size", "[size=4]big[/size]", "big"], ["text-s", "[s]sss[/s]", "sss"], ["text-u", "[u]uuu[/u]", "uuu"], ["text-url", $url, "https://www.example.com/"], ["text-hide", "[hide]secret[/hide]", "Hidden text: Show
secret
" ], ["text-mature", "[mature]titties[/mature]", "Mature content has been blocked. You can choose to view mature content by editing your id()}\">settings." ], ["text-spoiler", "[spoiler]surprise[/spoiler]", "Hidden text: Show
surprise
" ], ["text-user-1", "[user]user[/user]", "user"], ["text-user-2", "@user", "id()}\">@user"], ["text-user-3", "@user.", "id()}\">@user."], ["text-emoji", ":nod:", "\"\""], ["text-nest-1", "[size=3][i]z[/i][/size]", "z"], ["text-nest-2", "[quote=user]abc [b]xyz[/b] def[/quote] [b][i][s][u]ghi[/u][/s][/i][/b]", "user wrote:
abc xyz def
ghi" ], ]; } public function testCollage(): void { $admin = (new Gazelle\Manager\User)->find('@admin'); $name = 'collage ' . randomString(6); $collage = (new Gazelle\Manager\Collage)->create($admin, 1, $name, 'phpunit collage', 'jazz,disco', new Gazelle\Log); $this->assertInstanceOf(Gazelle\Collage::class, $collage, 'text-create-collage'); $this->assertEquals( "id()}\">{$collage->name()}", Text::full_format("[collage]{$collage->id()}[/collage]"), 'text-collage-bb' ); $this->assertEquals( "id()}\">{$collage->name()}", Text::full_format(SITE_URL . '/' . $collage->url()), 'text-collage-url' ); $this->assertEquals(1, $collage->remove(), 'text-remove-collage'); } public function testForum(): void { Text::setViewer((new Gazelle\Manager\User)->find('@admin')); $name = 'forum ' . randomString(6); $forum = (new Gazelle\Manager\Forum)->create( sequence: 999, categoryId: 1, name: $name, description: 'phpunit forum test', minRead: 100, minWrite: 100, minCreate: 100, autoLock: false, autoLockWeeks: 52, ); $this->assertInstanceOf(Gazelle\Forum::class, $forum, 'text-create-forum'); $this->assertEquals( "id()}\">{$forum->name()}", Text::full_format("[forum]{$forum->id()}[/forum]"), 'text-forum' ); $this->assertEquals(1, $forum->remove(), 'text-remove-forum'); } public function testForumThread(): void { $postId = (int)Gazelle\DB::DB()->scalar(" SELECT min(fp.ID) FROM forums_posts fp INNER JOIN forums_topics ft ON (ft.ID = fp.TopicID) "); $post = (new Gazelle\Manager\ForumPost)->findById($postId); $threadId = $post->thread()->id(); $title = $post->thread()->title(); $this->assertMatchesRegularExpression( "@^\Q{$title}\E$@", Text::full_format("[thread]{$threadId}[/thread]"), 'text-forum-thread' ); $this->assertMatchesRegularExpression( "@^\Q{$title}\E \(Post #{$postId}\)$@", Text::full_format("[thread]{$threadId}:{$postId}[/thread]"), 'text-forum-post' ); } public function dataList(): array { return [ ['text-list-a', <<
  • one
  • two
  • END_HTML], ['text-list-b', <<
    outro END_HTML], ['text-list-c', <<
  • one [*]
  • two
  • END_HTML], ['text-list-d', <<
  • one [#]
  • two
  • END_HTML], ['text-list-e', <<
  • one
  • two [*]
  • END_HTML], ['text-list-f', <<
  • two [*]

  • outro END_HTML], ['text-list-g', <<
  • alpha
  • beta
  • delta
  • END_HTML], ['text-list-g', <<
  • alpha
  • beta
  • delta
  • END_HTML], ]; } // for phpunit v10: #[DataProvider('dataList')] /** * @dataProvider dataList */ public function testList(string $name, string $bbcode, string $expected): void { $this->assertEquals($expected, Text::full_format($bbcode), $name); } public function testStrip(): void { $url = 'https://www.example.com'; $this->assertEquals( 'https://www.example.com/a.png https://www.example.com/b.png https://www.example.com here', Text::strip_bbcode("[img]{$url}/a.png[/img] [img={$url}/b.png] [url]{$url}[/url] [url={$url}]here[/url]"), 'text-strip-bb' ); } public function testTOC(): void { Text::$TOC = true; $html = Text::full_format(<<
      1. BIG
    1. Big
    2. Also Big
  • Smaller
  • Small
  • END_HTML; $this->assertEquals($expected, Text::parse_toc(), 'text-toc-default'); $expected = <<
  • Smaller
  • Small
  • END_HTML; $this->assertEquals($expected, Text::parse_toc(3, true), 'text-toc-3-true'); Text::$TOC = false; } public function testTorrent(): void { $id = (int)Gazelle\DB::DB()->scalar(" SELECT min(t.ID) FROM torrents t INNER JOIN torrents_group tg ON (tg.ID = t.GroupID) INNER JOIN category c ON (c.category_id = tg.CategoryID) WHERE c.name = ? ", 'Music' ); $torrent = (new Gazelle\Manager\Torrent)->findById($id); $torrentId = $torrent->id(); $tgroupId = $torrent->group()->id(); $torrentRegexp = "^.*.* \[\d+ .*?\]"; $this->assertMatchesRegularExpression("@{$torrentRegexp} .*$@", Text::full_format("[pl]{$torrentId}[/pl]"), 'text-pl' ); // FIXME: we generate torrent urls in two different ways $torrentRegexp = "^.*.* \[\d+ .*?\]"; $this->assertMatchesRegularExpression("@{$torrentRegexp}@", Text::full_format(SITE_URL . "/{$torrent->url()}"), "text-torrent-url tg={$tgroupId} t={$torrentId}" ); $tgroupRegexp = ".*?.*? \[\d+ \S+\]"; $this->assertMatchesRegularExpression("@{$tgroupRegexp}@", Text::full_format("[torrent]{$tgroupId}[/torrent]"), 'text-tgroup-id' ); $this->assertMatchesRegularExpression("@{$tgroupRegexp}@", Text::full_format(SITE_URL . "/{$torrent->group()->url()}"), 'text-tgroup-url' ); } }