assertEquals(
"bolditalic",
$this->filter("[b]bold[/b][i]italic[/i]")
);
}
public function testStacking(): void
{
$this->assertEquals(
"BIB",
$this->filter("[b]B[/b][i]I[/i][b]B[/b]")
);
$this->assertEquals(
"boldbolditalicbold",
$this->filter("[b]bold[i]bolditalic[/i]bold[/b]")
);
}
public function testFailure(): void
{
$this->assertEquals(
"[b]bold[i]italic",
$this->filter("[b]bold[i]italic")
);
}
public function testCode(): void
{
$this->assertEquals(
"
[b]bold[/b]
",
$this->filter("[code][b]bold[/b][/code]")
);
}
public function testNestedList(): void
{
$this->assertEquals(
"",
$this->filter("[list][*]a[list][*]a[*]b[/list][*]b[/list]")
);
$this->assertEquals(
"",
$this->filter("[ul][*]a[ol][*]a[*]b[/ol][*]b[/ul]")
);
}
public function testSpoiler(): void
{
$this->assertEquals(
"ShishNet",
$this->filter("[spoiler]ShishNet[/spoiler]")
);
$this->assertEquals(
"FuvfuArg",
$this->strip("[spoiler]ShishNet[/spoiler]")
);
#$this->assertEquals(
# $this->filter("[spoiler]ShishNet"),
# "[spoiler]ShishNet");
}
public function testURL(): void
{
$this->assertEquals(
"https://shishnet.org",
$this->filter("[url]https://shishnet.org[/url]")
);
$this->assertEquals(
"ShishNet",
$this->filter("[url=https://shishnet.org]ShishNet[/url]")
);
$this->assertEquals(
"[url=javascript:alert(\"owned\")]click to fail[/url]",
$this->filter("[url=javascript:alert(\"owned\")]click to fail[/url]")
);
}
public function testEmailURL(): void
{
$this->assertEquals(
"spam@shishnet.org",
$this->filter("[email]spam@shishnet.org[/email]")
);
}
public function testAnchor(): void
{
$this->assertEquals(
'Rules ΒΆ ',
$this->filter("[anchor=rules]Rules[/anchor]")
);
}
private function filter(string $in): string
{
$bb = new BBCode();
return $bb->_format($in);
}
private function strip(string $in): string
{
$bb = new BBCode();
return $bb->strip($in);
}
public function testSiteLinks(): void
{
$this->assertEquals(
'>>123',
$this->filter(">>123")
);
$this->assertEquals(
'>>123#c456',
$this->filter(">>123#c456")
);
$this->assertEquals(
'foo/bar',
$this->filter("[url]site://foo/bar[/url]")
);
$this->assertEquals(
'foo/bar#c123',
$this->filter("[url]site://foo/bar#c123[/url]")
);
$this->assertEquals(
'look at my post',
$this->filter("[url=site://foo/bar]look at my post[/url]")
);
$this->assertEquals(
'look at my comment',
$this->filter("[url=site://foo/bar#c123]look at my comment[/url]")
);
}
}