124 lines
2.6 KiB
PHP
124 lines
2.6 KiB
PHP
<?php
|
|
namespace nulib\web\content;
|
|
|
|
use nulib\cl;
|
|
use nulib\php\content\c;
|
|
use nulib\tests\TestCase;
|
|
|
|
class vTest extends TestCase {
|
|
function testStatic() {
|
|
self::assertSame(<<<EOT
|
|
<h1>title</h1>
|
|
<p>text</p>
|
|
EOT, c::to_string([
|
|
[v::H1, "title"],
|
|
[v::P, "text"],
|
|
]));
|
|
|
|
self::assertSame(<<<EOT
|
|
<h1>title</h1>
|
|
<p>the<b>bold</b>text<br/>linefeed</p><hr/>
|
|
EOT, c::to_string([
|
|
[v::H1, "title"],
|
|
[v::P, [
|
|
"the",
|
|
[v::B, "bold"],
|
|
"text",
|
|
[v::BR],
|
|
"linefeed",
|
|
]],
|
|
[v::HR],
|
|
]));
|
|
|
|
self::assertSame(<<<EOT
|
|
<div class="div" checked="checked">before<span>spanned</span><span class="black">blacked</span>after</div>
|
|
EOT, c::to_string([
|
|
[v::DIV, [
|
|
"before",
|
|
"class" => "div",
|
|
[v::SPAN, "spanned"],
|
|
[v::SPAN, ["class" => "black", "blacked"]],
|
|
"disabled" => false,
|
|
"checked" => true,
|
|
"after",
|
|
]],
|
|
]));
|
|
}
|
|
|
|
function testDynamic() {
|
|
self::assertSame(<<<EOT
|
|
<h1>title</h1>
|
|
<p>text</p>
|
|
EOT, c::to_string([
|
|
v::h1("title"),
|
|
v::p("text"),
|
|
]));
|
|
|
|
self::assertSame(<<<EOT
|
|
<h1>title</h1>
|
|
<p>the<b>bold</b>text<br/>linefeed</p><hr/>
|
|
EOT, c::to_string([
|
|
v::h1("title"),
|
|
v::p([
|
|
"the",
|
|
v::b("bold"),
|
|
"text",
|
|
v::br(),
|
|
"linefeed",
|
|
]),
|
|
v::hr(),
|
|
]));
|
|
|
|
self::assertSame(<<<EOT
|
|
<div class="div" checked="checked">before<span>spanned</span><span class="black">blacked</span>after</div>
|
|
EOT, c::to_string([
|
|
v::div([
|
|
"before",
|
|
"class" => "div",
|
|
v::span("spanned"),
|
|
v::span(["class" => "black", "blacked"]),
|
|
"disabled" => false,
|
|
"checked" => true,
|
|
"after",
|
|
]),
|
|
]));
|
|
}
|
|
|
|
function testDynamic2() {
|
|
$rows = [
|
|
["a" => 1, "b" => 2, "c" => 3],
|
|
["a" => "un", "b" => "deux", "c" => "trois"],
|
|
["a" => "one", "b" => "two", "c" => "three"],
|
|
];
|
|
self::assertSame(<<<EOT
|
|
<table>
|
|
<thead>
|
|
<tr><th>a</th><th>b</th><th>c</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr><td>1</td><td>2</td><td>3</td></tr>
|
|
<tr><td>un</td><td>deux</td><td>trois</td></tr>
|
|
<tr><td>one</td><td>two</td><td>three</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
EOT, c::to_string(v::table([
|
|
v::thead(v::tr(function() use ($rows) {
|
|
$headers = array_keys(cl::first($rows));
|
|
foreach ($headers as $header) {
|
|
yield v::th($header);
|
|
}
|
|
})),
|
|
v::tbody(function() use ($rows) {
|
|
foreach ($rows as $row) {
|
|
yield v::tr(function () use ($row) {
|
|
foreach ($row as $col) {
|
|
yield v::td($col);
|
|
}
|
|
});
|
|
}
|
|
}),
|
|
])));
|
|
}
|
|
}
|