nur-sery/tests/php/content/contentTest.php

40 lines
1.3 KiB
PHP
Raw Normal View History

2023-12-30 18:40:23 +04:00
<?php
2023-12-31 18:54:10 +04:00
namespace nur\sery\php\content;
2023-12-30 18:40:23 +04:00
2023-12-31 18:54:10 +04:00
use nur\sery\php\content\content;
use nur\sery\php\content\impl\html;
2023-12-30 18:40:23 +04:00
use PHPUnit\Framework\TestCase;
class contentTest extends TestCase {
function testFlattern() {
self::assertSame([], content::flatten(null));
self::assertSame([], content::flatten([null]));
self::assertSame([""], content::flatten(""));
self::assertSame([""], content::flatten([""]));
self::assertSame(["a", "b", "c", "d"], content::flatten(["a", ["b", ["c"], "d"]]));
}
function testResolve_static() {
self::assertSame([], content::resolve_static(null, null));
self::assertSame([], content::resolve_static([null], [null]));
self::assertSame([""], content::resolve_static("", ""));
self::assertSame([""], content::resolve_static([""], [""]));
self::assertSame(["&lt;quoted&gt;"], content::resolve_static("<quoted>", "<quoted>"));
self::assertSame(["<non-quoted>"], content::resolve_static(["<non-quoted>"], ["<non-quoted>"]));
self::assertSame(
"<h1>title&lt;q/&gt;</h1><p>hello<nq/><span>brave&lt;q/&gt;</span><span>world<nq/></span></p>",
content::to_string([
[html::H1, "title<q/>"],
[html::P, [
"hello<nq/>",
[html::SPAN, "brave<q/>"],
[html::SPAN, ["world<nq/>"]],
]],
]));
}
}