Skip to content

Commit fa2ba51

Browse files
georgmaisseribernhardf
authored andcommitted
Tests: Improve Unit Test #69
1 parent 70fee2c commit fa2ba51

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

tests/base_tests.php

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function setUp(): void {
5959
* Test wb base functionality via webservice external class.
6060
*
6161
* @covers \wunderbyte_table::query_db_cached
62-
* @runInSeparateProcess
62+
* // @runInSeparateProcess
6363
*
6464
* @throws \coding_exception
6565
* @throws \dml_exception
@@ -75,23 +75,23 @@ public function test_query_db_cached(): void {
7575
$this->setUser($user);
7676

7777
$table = $this->create_demo2_table();
78-
$nrofrows = $this->return_rows_for_table($table);
78+
$nrofrows = $this->get_rowscount_for_table($table);
7979

8080
// Now we get back exactly 10.
8181
$this->assertEquals($nrofrows, 10);
8282

8383
// Now we create another three courses.
8484
$this->create_test_courses(3, ['fullname' => 'filtercourse']);
8585

86-
$nrofrows = $this->return_rows_for_table($table);
86+
$nrofrows = $this->get_rowscount_for_table($table);
8787

8888
// Because of caching kicking in, we still get 10 items.
8989
$this->assertEquals($nrofrows, 10);
9090

9191
// Now we purge the cache.
9292
cache_helper::purge_by_event('changesinwunderbytetable');
9393

94-
$nrofrows = $this->return_rows_for_table($table);
94+
$nrofrows = $this->get_rowscount_for_table($table);
9595

9696
// After purging, we expect 13.
9797
$this->assertEquals($nrofrows, 13);
@@ -102,17 +102,17 @@ public function test_query_db_cached(): void {
102102
// Now we purge the cache.
103103
cache_helper::purge_by_event('changesinwunderbytetable');
104104

105-
$nrofrows = $this->return_rows_for_table($table);
105+
$nrofrows = $this->get_rowscount_for_table($table);
106106

107107
$this->assertEquals($nrofrows, 20);
108108

109109
// Now we fetch the third page. With 43 coures, we expect only three rows now.
110-
$nrofrows = $this->return_rows_for_table($table, 2);
110+
$nrofrows = $this->get_rowscount_for_table($table, 2);
111111

112112
$this->assertEquals($nrofrows, 3);
113113

114114
// Now we fetch the third page. With 43 coures, we expect only three rows now.
115-
$nrofrows = $this->return_rows_for_table(
115+
$nrofrows = $this->get_rowscount_for_table(
116116
$table,
117117
0,
118118
null,
@@ -205,7 +205,7 @@ public function create_test_courses(int $coursestocreate = 1, $options = []): ar
205205
* @return int
206206
*
207207
*/
208-
public function return_rows_for_table(
208+
public function get_rowscount_for_table(
209209
wunderbyte_table $table,
210210
$page = null,
211211
$tsort = null,
@@ -217,6 +217,49 @@ public function return_rows_for_table(
217217
$searchtext = null
218218
): int {
219219

220+
$rows = $this->get_rows_for_table(
221+
$table,
222+
$page,
223+
$tsort,
224+
$thide,
225+
$tshow,
226+
$tdir,
227+
$treset,
228+
$filterobjects,
229+
$searchtext
230+
);
231+
232+
return count($rows);
233+
}
234+
235+
/**
236+
* Returns the actual rows for a table. This only retrieves the rows for the current page.
237+
*
238+
* @param wunderbyte_table $table
239+
* @param int $page
240+
* @param string $tsort
241+
* @param string $thide
242+
* @param string $tshow
243+
* @param int $tdir
244+
* @param int $treset
245+
* @param string $filterobjects
246+
* @param string $searchtext
247+
*
248+
* @return array
249+
*
250+
*/
251+
public function get_rows_for_table(
252+
wunderbyte_table $table,
253+
$page = null,
254+
$tsort = null,
255+
$thide = null,
256+
$tshow = null,
257+
$tdir = null,
258+
$treset = null,
259+
$filterobjects = null,
260+
$searchtext = null
261+
): array {
262+
220263
$encodedtable = $table->return_encoded_table();
221264
$result = load_data::execute(
222265
$encodedtable,
@@ -235,7 +278,6 @@ public function return_rows_for_table(
235278
throw new moodle_exception('test', 'test', '', json_encode($jsonobject));
236279
}
237280
$rows = $jsonobject->table->rows ?? 0;
238-
239-
return count($rows);
281+
return $rows;
240282
}
241283
}

0 commit comments

Comments
 (0)