33namespace webfiori \test \ui ;
44
55use PHPUnit \Framework \TestCase ;
6- use InvalidArgumentException ;
6+ use webfiori \ui \Anchor ;
7+ use webfiori \ui \HTMLNode ;
78use 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}
0 commit comments