Add PHP unit tests and page tests.

Run "composer install", then "composer test".
This commit is contained in:
tim
2026-09-26 03:48:09 +02:00
parent 848c447c5b
commit ed959888b4
42 changed files with 5522 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace Xxx\Tests\Unit;
use Xxx\Tests\Support\TestCase;
// html_entity_decode_full() and convert_entity() in lib/convert_entities.inc.php
class EntitiesTest extends TestCase {
public function testNamedEntitiesAreDecoded(): void {
$this->assertSame("Wait\u{2026} \u{2014} \u{201C}yes\u{201D}", html_entity_decode_full('Wait&hellip; &mdash; &ldquo;yes&rdquo;'));
}
public function testNumericEntitiesAreDecoded(): void {
$this->assertSame("\u{2013} A", html_entity_decode_full('&#8211; &#x41;'));
}
public function testTheXmlEntitiesAreDecoded(): void {
$this->assertSame('<a> & "b"', html_entity_decode_full('&lt;a&gt; &amp; &quot;b&quot;'));
}
public function testSingleQuotesStayEncodedByDefault(): void {
$this->assertSame('&#039;', html_entity_decode_full('&#039;'));
$this->assertSame("'", html_entity_decode_full('&#039;', ENT_QUOTES));
}
public function testUnknownEntitiesAreDropped(): void {
$this->assertSame('ab', html_entity_decode_full('a&bogus;b'));
}
public function testEntityNamesAreCaseSensitive(): void {
$this->assertSame("\u{00E8}\u{00C8}", html_entity_decode_full('&egrave;&Egrave;'));
}
public function testConvertEntity(): void {
$this->assertSame('&#8230;', convert_entity(array('&hellip;', 'hellip')));
$this->assertSame('', convert_entity(array('&bogus;', 'bogus')));
$this->assertSame('&bogus;', convert_entity(array('&bogus;', 'bogus'), FALSE));
}
public function testTextWithoutEntitiesIsUnchanged(): void {
$this->assertSame('Plain & simple? No: plain.', html_entity_decode_full('Plain & simple? No: plain.'));
}
}