diff --git a/.github/workflows/php70.yml b/.github/workflows/php70.yml index 64b0684..36bc51d 100644 --- a/.github/workflows/php70.yml +++ b/.github/workflows/php70.yml @@ -36,4 +36,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php71.yml b/.github/workflows/php71.yml index cce136d..6d38d9c 100644 --- a/.github/workflows/php71.yml +++ b/.github/workflows/php71.yml @@ -36,4 +36,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php72.yml b/.github/workflows/php72.yml index 22b1910..9677225 100644 --- a/.github/workflows/php72.yml +++ b/.github/workflows/php72.yml @@ -36,6 +36,8 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php73.yml b/.github/workflows/php73.yml index 647e46b..c3928f9 100644 --- a/.github/workflows/php73.yml +++ b/.github/workflows/php73.yml @@ -36,7 +36,9 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php74.yml b/.github/workflows/php74.yml index 0d719c9..cfdae1c 100644 --- a/.github/workflows/php74.yml +++ b/.github/workflows/php74.yml @@ -36,7 +36,9 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php80.yml b/.github/workflows/php80.yml index 224ed55..f423f35 100644 --- a/.github/workflows/php80.yml +++ b/.github/workflows/php80.yml @@ -38,4 +38,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php81.yml b/.github/workflows/php81.yml index 56afd6b..282254f 100644 --- a/.github/workflows/php81.yml +++ b/.github/workflows/php81.yml @@ -37,7 +37,9 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} - name: SonarCloud uses: SonarSource/sonarcloud-github-action@master diff --git a/.github/workflows/php82.yml b/.github/workflows/php82.yml index f965a41..ec4b0e8 100644 --- a/.github/workflows/php82.yml +++ b/.github/workflows/php82.yml @@ -39,4 +39,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 \ No newline at end of file + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/tests/webfiori/test/ui/HTMLTableTest.php b/tests/webfiori/test/ui/HTMLTableTest.php index cc428df..3fb88bd 100644 --- a/tests/webfiori/test/ui/HTMLTableTest.php +++ b/tests/webfiori/test/ui/HTMLTableTest.php @@ -3,7 +3,8 @@ namespace webfiori\test\ui; use PHPUnit\Framework\TestCase; -use InvalidArgumentException; +use webfiori\ui\Anchor; +use webfiori\ui\HTMLNode; use webfiori\ui\HTMLTable; /** @@ -60,7 +61,7 @@ public function test01() { . '' . '', $table->toHTML()); $this->assertEquals('Hello', $table->getValue(0, 0)); - $table->setValue(0, 1, new \webfiori\ui\HTMLNode()); + $table->setValue(0, 1, new HTMLNode()); $this->assertEquals('
', $table->getValue(0, 1).''); $this->assertNull($table->getValue(88, 99)); $table->setIsQuotedAttribute(false); @@ -83,4 +84,184 @@ public function test03() { $this->expectExceptionMessage("Column index must be less than 5 and greater than -1."); $table->setValue(2, 5, 'Hello'); } + /** + * @test + */ + public function testAddColumn00() { + $table = new HTMLTable(1, 1); + $table->setValue(0, 0, 'Hello'); + $table->addColumn(['world']); + $this->assertEquals('world', $table->getValue(0, 1)); + } + /** + * @test + */ + public function testAddColumn01() { + $table = new HTMLTable(1, 1); + $table->setValue(0, 0, 'Hello'); + $table->addColumn([new Anchor('http://localhost', 'world')]); + $this->assertTrue($table->getValue(0, 1) instanceof Anchor ); + } + /** + * @test + */ + public function testAddColumn02() { + $table = new HTMLTable(4, 1); + + $table->addColumn([new Anchor('http://localhost', 'world'), 'test']); + $this->assertTrue($table->getValue(0, 1) instanceof Anchor ); + $this->assertEquals($table->getValue(1, 1), 'test'); + $this->assertEquals($table->getValue(2, 1), ''); + $this->assertEquals($table->getValue(3, 1), ''); + } + /** + * @test + */ + public function testAddRow00() { + $table = new HTMLTable(1, 1); + $table->setValue(0, 0, 'Hello'); + $table->addRow(['world']); + $this->assertEquals('world', $table->getValue(1, 0)); + } + /** + * @test + */ + public function testAddRow01() { + $table = new HTMLTable(1, 2); + $table->setValue(0, 0, 'Hello'); + $table->addRow([new Anchor('http://localhost', 'world'), 'world']); + $this->assertTrue($table->getValue(1, 0) instanceof Anchor ); + $this->assertEquals('world', $table->getValue(1, 1)); + } + /** + * @test + */ + public function testAddRow02() { + $table = new HTMLTable(4, 5); + + $table->addRow([new Anchor('http://localhost', 'world'), 'test']); + $this->assertTrue($table->getValue(4, 0) instanceof Anchor ); + $this->assertEquals($table->getValue(4, 1), 'test'); + $this->assertEquals($table->getValue(4, 2), ''); + $this->assertEquals($table->getValue(4, 3), ''); + $this->assertEquals($table->getValue(4, 4), ''); + } + /** + * @test + */ + public function testRemoveCol00() { + $table = new HTMLTable(4, 5); + for ($x = 0 ; $x < $table->rows() ; $x++) { + for ($y = 0 ; $y < $table->cols() ; $y++) { + $table->setValue($x, $y, 'Row '.$x.' Col '.$y); + } + } + $this->assertEquals(5, $table->cols()); + $this->assertEquals('Row 0 Col 0', $table->getValue(0, 0)); + + $table->removeCol(0); + + $this->assertEquals(4, $table->cols()); + $this->assertEquals('Row 0 Col 1', $table->getValue(0, 0)); + + $this->assertEquals('Row 0 Col 4', $table->getValue(0, 3)); + $table->removeCol(3); + + $this->assertEquals(3, $table->cols()); + $this->assertEquals('Row 0 Col 3', $table->getValue(0, 2)); + + $table->removeCol(0); + + $this->assertEquals(2, $table->cols()); + $this->assertEquals('Row 0 Col 2', $table->getValue(0, 0)); + + $table->removeCol(1); + + $this->assertEquals(1, $table->cols()); + $this->assertEquals('Row 0 Col 2', $table->getValue(0, 0)); + + $table->removeCol(0); + + $this->assertEquals(1, $table->cols()); + $this->assertEquals('Row 0 Col 2', $table->getValue(0, 0)); + } + /** + * @test + */ + public function testRemoveRow00() { + $table = new HTMLTable(4, 5); + for ($x = 0 ; $x < $table->rows() ; $x++) { + for ($y = 0 ; $y < $table->cols() ; $y++) { + $table->setValue($x, $y, 'Row '.$x.' Col '.$y); + } + } + $this->assertEquals(4, $table->rows()); + $this->assertEquals('Row 0 Col 0', $table->getValue(0, 0)); + + $table->removeRow(0); + + $this->assertEquals(3, $table->rows()); + $this->assertEquals('Row 1 Col 0', $table->getValue(0, 0)); + + $this->assertEquals('Row 3 Col 3', $table->getValue(2, 3)); + $table->removeRow(2); + + $this->assertEquals(2, $table->rows()); + $this->assertEquals('Row 2 Col 3', $table->getValue(1, 3)); + + $table->removeRow(0); + + $this->assertEquals(1, $table->rows()); + $this->assertEquals('Row 2 Col 0', $table->getValue(0, 0)); + + $table->removeRow(0); + + $this->assertEquals(1, $table->rows()); + $this->assertEquals('Row 2 Col 0', $table->getValue(0, 0)); + + } + /** + * @test + */ + public function testSetColAttributes00() { + $table = new HTMLTable(5, 5); + $table->setColAttributes(0, [ + 'class' => 'first-col' + ]); + $table->setColAttributes(1, [ + 'class' => 'second-col' + ]); + $table->setColAttributes(4, [ + 'class' => 'last-col' + ]); + for ($x = 0 ; $x < $table->rows() ; $x++) { + $this->assertEquals('first-col', $table->getCell($x, 0)->getAttribute('class')); + $this->assertEquals('second-col', $table->getCell($x, 1)->getAttribute('class')); + $this->assertEquals('last-col', $table->getCell($x, 4)->getAttribute('class')); + } + } + /** + * @test + */ + public function testSetRowAttributes00() { + $table = new HTMLTable(5, 5); + $table->setRowAttributes(0, [ + 'class' => 'first-row' + ]); + $table->setRowAttributes(1, [ + 'class' => 'second-row' + ]); + $table->setRowAttributes(4, [ + 'class' => 'last-row' + ]); + for ($x = 0 ; $x < $table->cols() ; $x++) { + $this->assertEquals('first-row', $table->getCell(0, $x)->getAttribute('class')); + } + for ($x = 0 ; $x < $table->cols() ; $x++) { + $this->assertEquals('second-row', $table->getCell(1, $x)->getAttribute('class')); + } + for ($x = 0 ; $x < $table->cols() ; $x++) { + $this->assertEquals('last-row', $table->getCell(4, $x)->getAttribute('class')); + } + } } diff --git a/tests/webfiori/test/ui/LoadTemplateTest.php b/tests/webfiori/test/ui/LoadTemplateTest.php index 1bb25fa..bed0a38 100644 --- a/tests/webfiori/test/ui/LoadTemplateTest.php +++ b/tests/webfiori/test/ui/LoadTemplateTest.php @@ -201,6 +201,13 @@ public function testHeadTemplate01() { $this->assertEquals('{{title}}', $node->getPageTitle()); $this->assertEquals('UTF-8', $node->getCharSet()); } + /** + * @test + */ + public function test11() { + $this->expectException(\webfiori\ui\exceptions\TemplateNotFoundException::class); + $compiler = new TemplateCompiler(self::TEST_TEMPLATES_PATH.'not-exist.php'); + } /** * @test */ diff --git a/webfiori/ui/HTMLDoc.php b/webfiori/ui/HTMLDoc.php index 21c276c..ec60955 100644 --- a/webfiori/ui/HTMLDoc.php +++ b/webfiori/ui/HTMLDoc.php @@ -348,7 +348,6 @@ public function saveToHTMLFile(string $path, string $fileName, bool $wellFormatt public function setHeadNode(HeadNode $node) { $this->getDocumentRoot()->replaceChild($this->headNode, $node); $this->headNode = $node; - } /** * Sets the language of the document. diff --git a/webfiori/ui/HTMLTable.php b/webfiori/ui/HTMLTable.php index 97b6e81..74e6386 100644 --- a/webfiori/ui/HTMLTable.php +++ b/webfiori/ui/HTMLTable.php @@ -159,7 +159,7 @@ public function getValue(int $rowIndex, int $colIndex) { if ($cell != null) { $ch = $cell->getChild(0); - if ($ch->getName() == '#TEXT') { + if ($ch->getNodeName() == '#TEXT') { return $ch->getText(); } @@ -170,6 +170,8 @@ public function getValue(int $rowIndex, int $colIndex) { /** * Removes a column from the table given column index. * + * Note that if the table has one column, the method will not remove it. + * * @param int $colIndex The index of the column. * * @return array The method will return an array that holds objects that @@ -179,10 +181,11 @@ public function getValue(int $rowIndex, int $colIndex) { public function removeCol(int $colIndex) : array { $colCells = []; - if ($colIndex < $this->cols()) { + if ($colIndex < $this->cols() && $this->cols() > 1) { foreach ($this as $row) { $colCells[] = $row->children()->remove($colIndex); } + $this->cols--; } return $colCells; @@ -190,6 +193,8 @@ public function removeCol(int $colIndex) : array { /** * Removes a row given its index. * + * Note that if the table has only one row, the method will not remove it. + * * @param int $rowIndex The index of the row. * * @return TableRow|null If the row is removed, the method will return @@ -197,7 +202,15 @@ public function removeCol(int $colIndex) : array { * will return null. */ public function removeRow(int $rowIndex) { - return $this->removeChild($rowIndex); + if ($this->rows() > 1) { + $row = $this->removeChild($rowIndex); + + if ($row !== null) { + $this->rows--; + } + + return $row; + } } /** * Returns number of rows in the table.