diff --git a/.github/workflows/php81.yml b/.github/workflows/php81.yml index 3918541..5a8b65d 100644 --- a/.github/workflows/php81.yml +++ b/.github/workflows/php81.yml @@ -14,7 +14,7 @@ jobs: fail-fast: true matrix: os: [ ubuntu-latest ] - php: [8.2] + php: [8.1] name: PHP${{matrix.php}} - ${{matrix.os}} diff --git a/phpunit.xml b/phpunit.xml index 9da74d3..c83e005 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + @@ -16,7 +16,7 @@ - ./tests + ./tests/webfiori/test/ui \ No newline at end of file diff --git a/src/HTMLList.php b/src/HTMLList.php index 9725d0d..325976e 100644 --- a/src/HTMLList.php +++ b/src/HTMLList.php @@ -190,7 +190,7 @@ public function addSubList($ul) { * * @since 1.0.2 */ - public function getChild($index) { + public function getChild(int $index) { $ch = parent::getChild($index); if ($ch instanceof ListItem) { diff --git a/src/HTMLNode.php b/src/HTMLNode.php index d1d4fd9..58a5011 100644 --- a/src/HTMLNode.php +++ b/src/HTMLNode.php @@ -1895,7 +1895,7 @@ public function removeAttributes() { /** * Removes a direct child node. * - * @param HTMLNode|string $nodeInstOrId The node that will be removed. This also can + * @param HTMLNode|string|int $nodeInstOrId The node that will be removed. This also can * be the ID of the child that will be removed. In addition to that, this can * be the index of the element that will be removed starting from 0. * diff --git a/tests/test.php b/tests/bootstrap.php similarity index 100% rename from tests/test.php rename to tests/bootstrap.php diff --git a/tests/html/HTMLDocTest.php b/tests/webfiori/test/ui/HTMLDocTest.php similarity index 93% rename from tests/html/HTMLDocTest.php rename to tests/webfiori/test/ui/HTMLDocTest.php index 0fae91b..118a3eb 100644 --- a/tests/html/HTMLDocTest.php +++ b/tests/webfiori/test/ui/HTMLDocTest.php @@ -1,5 +1,5 @@ assertEquals(1, $list->size()); $this->assertEquals('a', $list->get(0)->getNodeName()); } + /** + * + * @param HTMLDoc $doc + * @depends testConstructor00 + */ + public function testAsCode00(HTMLDoc $doc) { + $this->assertEquals("" + ."<!DOCTYPE html>\r\n" + ."<html>\r\n" + ." <head>\r\n" + ." <title>\r\n" + ." Default\r\n" + ." </title>\r\n" + ." <meta name = \"viewport\" content = \"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">\r\n" + ." </head>\r\n" + ." <body itemscope itemtype = \"http://schema.org/WebPage\">\r\n" + ." </body>\r\n" + ."</html>\r\n" + ."" + ."", $doc->asCode([ + 'with-colors' => false + ])); + } /** * @test */ @@ -144,6 +167,7 @@ public function testConstructor00() { ."\r\n" ."" ."",$doc->toHTML()); + return $doc; } /** * @test diff --git a/tests/html/HTMLNodeTest.php b/tests/webfiori/test/ui/HTMLNodeTest.php similarity index 96% rename from tests/html/HTMLNodeTest.php rename to tests/webfiori/test/ui/HTMLNodeTest.php index 442ce76..763839f 100644 --- a/tests/html/HTMLNodeTest.php +++ b/tests/webfiori/test/ui/HTMLNodeTest.php @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -namespace webfiori\ui\test; +namespace webfiori\test\ui; use webfiori\ui\Anchor; use webfiori\ui\HTMLDoc; @@ -299,6 +299,52 @@ public function testAddChild14() { $x = $node->addChild('v-row'); $this->assertEquals('v-row', $x->getNodeName()); } + /** + * @test + */ + public function testAddChild15() { + $node = new HTMLNode(); + $node->tr([1, 2, 3]); + $this->assertEquals('
', $node.''); + $node->table()->tr(['Hello', 'World']); + $this->assertEquals('
HelloWorld
', $node.''); + } + /** + * @test + */ + public function testAddChild16() { + $node = new HTMLNode('tr'); + $node->cell('Hello'); + $this->assertEquals('Hello', $node.''); + $this->assertEquals('<tr>'.HTMLDoc::NL + . ' <td>'.HTMLDoc::NL + . ' Hello'.HTMLDoc::NL + . ' </td>'.HTMLDoc::NL + . '</tr>'.HTMLDoc::NL, $node->asCode([ + 'with-colors' => false + ])); + } + /** + * @test + */ + public function testAddChild17() { + $node = new HTMLNode('html'); + $node->addChild('body') + ->img([ + 'src' => 'image.png' + ]); + $this->assertEquals('', $node.''); + $node->setIsQuotedAttribute(true); + $this->assertEquals('', $node.''); + $this->assertEquals('<!DOCTYPE html>'.HTMLDoc::NL + . '<html>'.HTMLDoc::NL + . ' <body>'.HTMLDoc::NL + . ' <img src = "image.png">'.HTMLDoc::NL + . ' </body>'.HTMLDoc::NL + . '</html>'.HTMLDoc::NL, $node->asCode([ + 'with-colors' => false + ])); + } /** * @test */ @@ -507,7 +553,7 @@ public function testChaining01() { */ public function testCount00() { $node = new HTMLNode(); - $node->section('Hello') + $node->section(new HTMLNode()) ->getParent() ->br() ->codeSnippit('PHP Code', "") @@ -1968,6 +2014,38 @@ public function testRemoveChild09() { . '

Hello Sec

' . '', $node->toHTML()); } + /** + * @test + */ + public function testRemoveChild10() { + $node = new HTMLNode(); + $node->text('Hello') + ->paragraph('Super Paragraph', ['id'=>'p-1']) + ->div(['id'=>'empty-div']) + ->getParent() + ->section('Hello Sec', 1, [ + 'id' => 'my-sec' + ]); + $removed = $node->removeChild(0); + $this->assertEquals('Hello', $removed->getText()); + $removed2 = $node->removeChild(1); + $this->assertEquals('div', $removed2->getNodeName()); + } + /** + * @test + */ + public function testReplace00() { + $div = new HTMLNode(); + $div->img(); + $div->paragraph('Hello'); + $div->text('Super'); + $table = $div->table(); + $another = new HTMLNode('input'); + + $this->assertTrue($div->replaceChild($table, $another)); + $this->assertEquals('input', $div->getLastChild()->getNodeName()); + $this->assertFalse($div->replaceChild(new HTMLNode(), $table)); + } /** * @test */ diff --git a/tests/html/TestHTMLTable.php b/tests/webfiori/test/ui/HTMLTableTest.php similarity index 88% rename from tests/html/TestHTMLTable.php rename to tests/webfiori/test/ui/HTMLTableTest.php index 61f2a11..62d5897 100644 --- a/tests/html/TestHTMLTable.php +++ b/tests/webfiori/test/ui/HTMLTableTest.php @@ -1,12 +1,7 @@ setIsQuotedAttribute(true); $this->assertEquals(5, $table->cols()); $this->assertEquals(3, $table->rows()); - $this->assertEquals('' + $this->assertEquals('
' . '' . '' . '' @@ -42,7 +38,8 @@ public function test01() { $this->assertEquals(5, $table->cols()); $this->assertEquals(3, $table->rows()); $table->setValue(0, 0, 'Hello'); - $this->assertEquals('
' + $table->setIsQuotedAttribute(true); + $this->assertEquals('
' . '' . '' . '' diff --git a/tests/html/HeadNodeTest.php b/tests/webfiori/test/ui/HeadNodeTest.php similarity index 98% rename from tests/html/HeadNodeTest.php rename to tests/webfiori/test/ui/HeadNodeTest.php index 32f1eeb..3722a37 100644 --- a/tests/html/HeadNodeTest.php +++ b/tests/webfiori/test/ui/HeadNodeTest.php @@ -1,5 +1,5 @@ assertEquals(1,$node->childrenCount()); $this->assertEquals('',$node->getPageTitle()); } + /** + * @test + */ + public function testSetTitle01() { + $node = new HeadNode('Hello'); + $this->assertEquals(2,$node->childrenCount()); + $this->assertNotNull($node->getTitleNode()); + $this->assertEquals('Hello',$node->getPageTitle()); + $node->setTitle(''); + $this->assertEquals(1,$node->childrenCount()); + $this->assertEquals('',$node->getPageTitle()); + $this->assertNotNull($node->getTitleNode()); + } } diff --git a/tests/html/InputTest.php b/tests/webfiori/test/ui/InputTest.php similarity index 99% rename from tests/html/InputTest.php rename to tests/webfiori/test/ui/InputTest.php index 34ec564..40c66a1 100644 --- a/tests/html/InputTest.php +++ b/tests/webfiori/test/ui/InputTest.php @@ -1,5 +1,5 @@
Hello