Skip to content

Commit

Permalink
Merge pull request #17 from WebFiori/dev
Browse files Browse the repository at this point in the history
Refactoring + Small Bugs Fixes
  • Loading branch information
usernane authored May 17, 2022
2 parents f629ebf + bd3a892 commit f4f3606
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php81.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [8.2]
php: [8.1]

name: PHP${{matrix.php}} - ${{matrix.os}}

Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="tests/test.php">
<phpunit colors="true" bootstrap="tests/bootstrap.php">
<php>
</php>
<filter>
Expand All @@ -16,7 +16,7 @@
</logging>
<testsuites>
<testsuite name="HTML Elements Tests">
<directory>./tests</directory>
<directory>./tests/webfiori/test/ui</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/HTMLList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/HTMLNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace webfiori\ui\test;
namespace webfiori\test\ui;

use webfiori\ui\HTMLDoc;
use webfiori\ui\HTMLNode;
Expand All @@ -23,6 +23,29 @@ public function testgetChildrenByAttrVal00() {
$this->assertEquals(1, $list->size());
$this->assertEquals('a', $list->get(0)->getNodeName());
}
/**
*
* @param HTMLDoc $doc
* @depends testConstructor00
*/
public function testAsCode00(HTMLDoc $doc) {
$this->assertEquals(""
."&lt;!DOCTYPE html&gt;\r\n"
."&lt;html&gt;\r\n"
." &lt;head&gt;\r\n"
." &lt;title&gt;\r\n"
." Default\r\n"
." &lt;/title&gt;\r\n"
." &lt;meta name = \"viewport\" content = \"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"&gt;\r\n"
." &lt;/head&gt;\r\n"
." &lt;body itemscope itemtype = \"http://schema.org/WebPage\"&gt;\r\n"
." &lt;/body&gt;\r\n"
."&lt;/html&gt;\r\n"
.""
."", $doc->asCode([
'with-colors' => false
]));
}
/**
* @test
*/
Expand Down Expand Up @@ -144,6 +167,7 @@ public function testConstructor00() {
."</html>\r\n"
.""
."",$doc->toHTML());
return $doc;
}
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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('<div></div>', $node.'');
$node->table()->tr(['Hello', 'World']);
$this->assertEquals('<div><table><tr><td>Hello</td><td>World</td></tr></table></div>', $node.'');
}
/**
* @test
*/
public function testAddChild16() {
$node = new HTMLNode('tr');
$node->cell('Hello');
$this->assertEquals('<tr><td>Hello</td></tr>', $node.'');
$this->assertEquals('&lt;tr&gt;'.HTMLDoc::NL
. ' &lt;td&gt;'.HTMLDoc::NL
. ' Hello'.HTMLDoc::NL
. ' &lt;/td&gt;'.HTMLDoc::NL
. '&lt;/tr&gt;'.HTMLDoc::NL, $node->asCode([
'with-colors' => false
]));
}
/**
* @test
*/
public function testAddChild17() {
$node = new HTMLNode('html');
$node->addChild('body')
->img([
'src' => 'image.png'
]);
$this->assertEquals('<html><body><img src=image.png></body></html>', $node.'');
$node->setIsQuotedAttribute(true);
$this->assertEquals('<html><body><img src="image.png"></body></html>', $node.'');
$this->assertEquals('&lt;!DOCTYPE html&gt;'.HTMLDoc::NL
. '&lt;html&gt;'.HTMLDoc::NL
. ' &lt;body&gt;'.HTMLDoc::NL
. ' &lt;img src = "image.png"&gt;'.HTMLDoc::NL
. ' &lt;/body&gt;'.HTMLDoc::NL
. '&lt;/html&gt;'.HTMLDoc::NL, $node->asCode([
'with-colors' => false
]));
}
/**
* @test
*/
Expand Down Expand Up @@ -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', "")
Expand Down Expand Up @@ -1968,6 +2014,38 @@ public function testRemoveChild09() {
. '<section id="my-sec"><h1>Hello Sec</h1></section>'
. '</div>', $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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace webfiori\test\ui;

namespace webfiori\ui\test;
use PHPUnit\Framework\TestCase;
use InvalidArgumentException;
use webfiori\ui\HTMLTable;
Expand All @@ -16,15 +11,16 @@
*
* @author Ibrahim
*/
class TestHTMLTable extends TestCase {
class HTMLTableTest extends TestCase {
/**
* @test
*/
public function test00() {
$table = new HTMLTable(3, 5);
$table->setIsQuotedAttribute(true);
$this->assertEquals(5, $table->cols());
$this->assertEquals(3, $table->rows());
$this->assertEquals('<table border="1" style="border-collapse:collapse">'
$this->assertEquals('<table border="1" style="border-collapse:collapse;">'
. '<tr>'
. '<td></td><td></td><td></td><td></td><td></td>'
. '</tr>'
Expand All @@ -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 border="1" style="border-collapse:collapse">'
$table->setIsQuotedAttribute(true);
$this->assertEquals('<table border="1" style="border-collapse:collapse;">'
. '<tr>'
. '<td>Hello</td><td></td><td></td><td></td><td></td>'
. '</tr>'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace webfiori\ui\test;
namespace webfiori\test\ui;

use webfiori\ui\HTMLNode;
use webfiori\ui\HeadNode;
Expand Down Expand Up @@ -789,4 +789,17 @@ public function testSetTitle00() {
$this->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());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace webfiori\ui\test;
namespace webfiori\test\ui;

use webfiori\ui\Input;
use webfiori\ui\HTMLNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<?php
namespace webfiori\test\ui;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace webfiori\ui\test;
use webfiori\ui\HTMLNode;
use webfiori\ui\HeadNode;
use webfiori\ui\HTMLDoc;
Expand Down

0 comments on commit f4f3606

Please sign in to comment.