Skip to content

Commit c6d0b13

Browse files
authored
Merge pull request #43 from WebFiori/dev
refactor: Added More Tests and Fixed Bugs
2 parents 052ffa7 + 7063250 commit c6d0b13

File tree

12 files changed

+230
-14
lines changed

12 files changed

+230
-14
lines changed

.github/workflows/php70.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ jobs:
3636
run: phpunit
3737

3838
- name: CodeCov
39-
uses: codecov/codecov-action@v1
39+
uses: codecov/codecov-action@v4
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/php71.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ jobs:
3636
run: phpunit
3737

3838
- name: CodeCov
39-
uses: codecov/codecov-action@v1
39+
uses: codecov/codecov-action@v4
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/php72.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
run: phpunit
3737

3838
- name: CodeCov
39-
uses: codecov/codecov-action@v1
39+
uses: codecov/codecov-action@v4
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
4042

4143

.github/workflows/php73.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ jobs:
3636
run: phpunit
3737

3838
- name: CodeCov
39-
uses: codecov/codecov-action@v1
39+
uses: codecov/codecov-action@v4
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
4042

4143

4244

.github/workflows/php74.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ jobs:
3636
run: phpunit
3737

3838
- name: CodeCov
39-
uses: codecov/codecov-action@v1
39+
uses: codecov/codecov-action@v4
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
4042

4143

4244

.github/workflows/php80.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ jobs:
3838
run: phpunit
3939

4040
- name: CodeCov
41-
uses: codecov/codecov-action@v1
41+
uses: codecov/codecov-action@v4
42+
with:
43+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/php81.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ jobs:
3737
run: phpunit
3838

3939
- name: CodeCov
40-
uses: codecov/codecov-action@v1
40+
uses: codecov/codecov-action@v4
41+
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}
4143

4244
- name: SonarCloud
4345
uses: SonarSource/sonarcloud-github-action@master

.github/workflows/php82.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ jobs:
3939
run: phpunit
4040

4141
- name: CodeCov
42-
uses: codecov/codecov-action@v1
42+
uses: codecov/codecov-action@v4
43+
with:
44+
token: ${{ secrets.CODECOV_TOKEN }}

tests/webfiori/test/ui/HTMLTableTest.php

Lines changed: 183 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace webfiori\test\ui;
44

55
use PHPUnit\Framework\TestCase;
6-
use InvalidArgumentException;
6+
use webfiori\ui\Anchor;
7+
use webfiori\ui\HTMLNode;
78
use webfiori\ui\HTMLTable;
89

910
/**
@@ -60,7 +61,7 @@ public function test01() {
6061
. '</tr>'
6162
. '</table>', $table->toHTML());
6263
$this->assertEquals('Hello', $table->getValue(0, 0));
63-
$table->setValue(0, 1, new \webfiori\ui\HTMLNode());
64+
$table->setValue(0, 1, new HTMLNode());
6465
$this->assertEquals('<div></div>', $table->getValue(0, 1).'');
6566
$this->assertNull($table->getValue(88, 99));
6667
$table->setIsQuotedAttribute(false);
@@ -83,4 +84,184 @@ public function test03() {
8384
$this->expectExceptionMessage("Column index must be less than 5 and greater than -1.");
8485
$table->setValue(2, 5, 'Hello');
8586
}
87+
/**
88+
* @test
89+
*/
90+
public function testAddColumn00() {
91+
$table = new HTMLTable(1, 1);
92+
$table->setValue(0, 0, 'Hello');
93+
$table->addColumn(['world']);
94+
$this->assertEquals('world', $table->getValue(0, 1));
95+
}
96+
/**
97+
* @test
98+
*/
99+
public function testAddColumn01() {
100+
$table = new HTMLTable(1, 1);
101+
$table->setValue(0, 0, 'Hello');
102+
$table->addColumn([new Anchor('http://localhost', 'world')]);
103+
$this->assertTrue($table->getValue(0, 1) instanceof Anchor );
104+
}
105+
/**
106+
* @test
107+
*/
108+
public function testAddColumn02() {
109+
$table = new HTMLTable(4, 1);
110+
111+
$table->addColumn([new Anchor('http://localhost', 'world'), 'test']);
112+
$this->assertTrue($table->getValue(0, 1) instanceof Anchor );
113+
$this->assertEquals($table->getValue(1, 1), 'test');
114+
$this->assertEquals($table->getValue(2, 1), '');
115+
$this->assertEquals($table->getValue(3, 1), '');
116+
}
117+
/**
118+
* @test
119+
*/
120+
public function testAddRow00() {
121+
$table = new HTMLTable(1, 1);
122+
$table->setValue(0, 0, 'Hello');
123+
$table->addRow(['world']);
124+
$this->assertEquals('world', $table->getValue(1, 0));
125+
}
126+
/**
127+
* @test
128+
*/
129+
public function testAddRow01() {
130+
$table = new HTMLTable(1, 2);
131+
$table->setValue(0, 0, 'Hello');
132+
$table->addRow([new Anchor('http://localhost', 'world'), 'world']);
133+
$this->assertTrue($table->getValue(1, 0) instanceof Anchor );
134+
$this->assertEquals('world', $table->getValue(1, 1));
135+
}
136+
/**
137+
* @test
138+
*/
139+
public function testAddRow02() {
140+
$table = new HTMLTable(4, 5);
141+
142+
$table->addRow([new Anchor('http://localhost', 'world'), 'test']);
143+
$this->assertTrue($table->getValue(4, 0) instanceof Anchor );
144+
$this->assertEquals($table->getValue(4, 1), 'test');
145+
$this->assertEquals($table->getValue(4, 2), '');
146+
$this->assertEquals($table->getValue(4, 3), '');
147+
$this->assertEquals($table->getValue(4, 4), '');
148+
}
149+
/**
150+
* @test
151+
*/
152+
public function testRemoveCol00() {
153+
$table = new HTMLTable(4, 5);
154+
for ($x = 0 ; $x < $table->rows() ; $x++) {
155+
for ($y = 0 ; $y < $table->cols() ; $y++) {
156+
$table->setValue($x, $y, 'Row '.$x.' Col '.$y);
157+
}
158+
}
159+
$this->assertEquals(5, $table->cols());
160+
$this->assertEquals('Row 0 Col 0', $table->getValue(0, 0));
161+
162+
$table->removeCol(0);
163+
164+
$this->assertEquals(4, $table->cols());
165+
$this->assertEquals('Row 0 Col 1', $table->getValue(0, 0));
166+
167+
$this->assertEquals('Row 0 Col 4', $table->getValue(0, 3));
168+
$table->removeCol(3);
169+
170+
$this->assertEquals(3, $table->cols());
171+
$this->assertEquals('Row 0 Col 3', $table->getValue(0, 2));
172+
173+
$table->removeCol(0);
174+
175+
$this->assertEquals(2, $table->cols());
176+
$this->assertEquals('Row 0 Col 2', $table->getValue(0, 0));
177+
178+
$table->removeCol(1);
179+
180+
$this->assertEquals(1, $table->cols());
181+
$this->assertEquals('Row 0 Col 2', $table->getValue(0, 0));
182+
183+
$table->removeCol(0);
184+
185+
$this->assertEquals(1, $table->cols());
186+
$this->assertEquals('Row 0 Col 2', $table->getValue(0, 0));
187+
}
188+
/**
189+
* @test
190+
*/
191+
public function testRemoveRow00() {
192+
$table = new HTMLTable(4, 5);
193+
for ($x = 0 ; $x < $table->rows() ; $x++) {
194+
for ($y = 0 ; $y < $table->cols() ; $y++) {
195+
$table->setValue($x, $y, 'Row '.$x.' Col '.$y);
196+
}
197+
}
198+
$this->assertEquals(4, $table->rows());
199+
$this->assertEquals('Row 0 Col 0', $table->getValue(0, 0));
200+
201+
$table->removeRow(0);
202+
203+
$this->assertEquals(3, $table->rows());
204+
$this->assertEquals('Row 1 Col 0', $table->getValue(0, 0));
205+
206+
$this->assertEquals('Row 3 Col 3', $table->getValue(2, 3));
207+
$table->removeRow(2);
208+
209+
$this->assertEquals(2, $table->rows());
210+
$this->assertEquals('Row 2 Col 3', $table->getValue(1, 3));
211+
212+
$table->removeRow(0);
213+
214+
$this->assertEquals(1, $table->rows());
215+
$this->assertEquals('Row 2 Col 0', $table->getValue(0, 0));
216+
217+
$table->removeRow(0);
218+
219+
$this->assertEquals(1, $table->rows());
220+
$this->assertEquals('Row 2 Col 0', $table->getValue(0, 0));
221+
222+
}
223+
/**
224+
* @test
225+
*/
226+
public function testSetColAttributes00() {
227+
$table = new HTMLTable(5, 5);
228+
$table->setColAttributes(0, [
229+
'class' => 'first-col'
230+
]);
231+
$table->setColAttributes(1, [
232+
'class' => 'second-col'
233+
]);
234+
$table->setColAttributes(4, [
235+
'class' => 'last-col'
236+
]);
237+
for ($x = 0 ; $x < $table->rows() ; $x++) {
238+
$this->assertEquals('first-col', $table->getCell($x, 0)->getAttribute('class'));
239+
$this->assertEquals('second-col', $table->getCell($x, 1)->getAttribute('class'));
240+
$this->assertEquals('last-col', $table->getCell($x, 4)->getAttribute('class'));
241+
}
242+
}
243+
/**
244+
* @test
245+
*/
246+
public function testSetRowAttributes00() {
247+
$table = new HTMLTable(5, 5);
248+
$table->setRowAttributes(0, [
249+
'class' => 'first-row'
250+
]);
251+
$table->setRowAttributes(1, [
252+
'class' => 'second-row'
253+
]);
254+
$table->setRowAttributes(4, [
255+
'class' => 'last-row'
256+
]);
257+
for ($x = 0 ; $x < $table->cols() ; $x++) {
258+
$this->assertEquals('first-row', $table->getCell(0, $x)->getAttribute('class'));
259+
}
260+
for ($x = 0 ; $x < $table->cols() ; $x++) {
261+
$this->assertEquals('second-row', $table->getCell(1, $x)->getAttribute('class'));
262+
}
263+
for ($x = 0 ; $x < $table->cols() ; $x++) {
264+
$this->assertEquals('last-row', $table->getCell(4, $x)->getAttribute('class'));
265+
}
266+
}
86267
}

tests/webfiori/test/ui/LoadTemplateTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ public function testHeadTemplate01() {
201201
$this->assertEquals('{{title}}', $node->getPageTitle());
202202
$this->assertEquals('UTF-8', $node->getCharSet());
203203
}
204+
/**
205+
* @test
206+
*/
207+
public function test11() {
208+
$this->expectException(\webfiori\ui\exceptions\TemplateNotFoundException::class);
209+
$compiler = new TemplateCompiler(self::TEST_TEMPLATES_PATH.'not-exist.php');
210+
}
204211
/**
205212
* @test
206213
*/

0 commit comments

Comments
 (0)