Skip to content

Commit 7efcd4f

Browse files
semteachereynimeni
authored andcommitted
refactoring. 2 phpunit created test_filter_standardfilter() and test_fulltextsearchcolumns() (#69)
1 parent f50abe8 commit 7efcd4f

File tree

1 file changed

+77
-24
lines changed

1 file changed

+77
-24
lines changed

tests/base_test.php

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function test_query_db_cached(): void {
125125
* Test wb filter functionality via webservice external class.
126126
*
127127
* @covers \wunderbyte_table::query_db_cached
128+
* @covers \wunderbyte_table::define_sortablecolumns
129+
* @covers \local_wunderbyte_table\local\sortables\types\standardsortable
128130
*
129131
* @throws \coding_exception
130132
* @throws \dml_exception
@@ -198,7 +200,7 @@ public function test_sortable(): void {
198200
/**
199201
* Test wb filter functionality via webservice external class.
200202
*
201-
* @covers \wunderbyte_table\filters\types\callback
203+
* @covers \local_wunderbyte_table\filters\types\callback
202204
*
203205
* @throws \coding_exception
204206
* @throws \dml_exception
@@ -264,7 +266,7 @@ public function test_filter_callback(): void {
264266
/**
265267
* Test wb datepicker filter functionality via webservice external class.
266268
*
267-
* @covers \wunderbyte_table\filters\types\datepicker
269+
* @covers \local_wunderbyte_table\filters\types\datepicker
268270
*
269271
* @throws \coding_exception
270272
* @throws \dml_exception
@@ -297,6 +299,7 @@ public function test_filter_datepicker(): void {
297299
$this->setUser($user);
298300

299301
$table = $this->create_demo2_table();
302+
$table->pagesize = 20;
300303

301304
$nrofrows = $this->get_rowscount_for_table(
302305
$table,
@@ -336,38 +339,88 @@ public function test_filter_datepicker(): void {
336339
}
337340

338341
/**
339-
* Test wb base search and filtering functionality via webservice external class.
342+
* Test wb base full text search.
343+
*
344+
* @covers \local_wunderbyte_table\filters\types\standardfilter
345+
*
346+
* @throws \coding_exception
347+
* @throws \dml_exception
348+
*
349+
*/
350+
public function test_filter_standardfilter(): void {
351+
// First, we create ten courses.
352+
$this->create_test_courses(10);
353+
// Now we create another six courses for basic searching and filtering.
354+
$this->create_test_courses(3, ['fullname' => 'filtercourse']);
355+
$this->create_test_courses(1, ['fullname' => 'ended1']);
356+
$this->create_test_courses(1, ['fullname' => 'ended2']);
357+
$this->create_test_courses(1, ['fullname' => 'future1']);
358+
359+
$user = $this->getDataGenerator()->create_user();
360+
$this->setUser($user);
361+
362+
$table = $this->create_demo2_table();
363+
$table->pagesize = 20;
364+
365+
$nrofrows = $this->get_rowscount_for_table($table);
366+
$this->assertEquals(16, $nrofrows);
367+
368+
// Validate basic filtering by course fullname.
369+
$nrofrows = $this->get_rowscount_for_table(
370+
$table,
371+
0,
372+
null,
373+
null,
374+
null,
375+
null,
376+
null,
377+
'{"fullname":["filtercourse"]}'
378+
);
379+
$this->assertEquals(3, $nrofrows);
380+
381+
$nrofrows = $this->get_rowscount_for_table(
382+
$table,
383+
0,
384+
null,
385+
null,
386+
null,
387+
null,
388+
null,
389+
'{"fullname":["ended2"]}'
390+
);
391+
$this->assertEquals(1, $nrofrows);
392+
393+
$nrofrows = $this->get_rowscount_for_table(
394+
$table,
395+
0,
396+
null,
397+
null,
398+
null,
399+
null,
400+
null,
401+
'{"fullname":["ended%"]}'
402+
);
403+
$this->assertEquals(2, $nrofrows);
404+
}
405+
406+
/**
407+
* Test wb base full text search.
340408
*
341409
* @covers \wunderbyte_table::query_db_cached
342-
* // @runInSeparateProcess
410+
* @covers \wunderbyte_table::define_fulltextsearchcolumns
343411
*
344412
* @throws \coding_exception
345413
* @throws \dml_exception
346414
*
347415
*/
348-
public function test_basic_search_filtering_cached(): void {
416+
public function test_fulltextsearchcolumns(): void {
349417
// First, we create ten courses.
350418
$this->create_test_courses(10);
351-
// Now we create another three courses for basic searching and filtering.
419+
// Now we create another six courses for basic searching and filtering.
352420
$this->create_test_courses(3, ['fullname' => 'filtercourse']);
353-
// Create 2 courses for end date filtering.
354-
$this->create_test_courses(1, [
355-
'fullname' => 'ended1',
356-
'startdate' => strtotime('2 May 2010'),
357-
'enddate' => strtotime('20 May 2010'),
358-
]);
359-
$this->create_test_courses(1, [
360-
'fullname' => 'ended2',
361-
'startdate' => strtotime('5 Jun 2020 14:00'),
362-
'enddate' => strtotime('15 Jun 2020 15:00'),
363-
]);
364-
$plusfifftymonth = strtotime('+50 month');
365-
$plussixtymonth = strtotime('+60 month');
366-
$this->create_test_courses(1, [
367-
'fullname' => 'future1',
368-
'startdate' => $plusfifftymonth,
369-
'enddate' => $plussixtymonth,
370-
]);
421+
$this->create_test_courses(1, ['fullname' => 'ended1']);
422+
$this->create_test_courses(1, ['fullname' => 'ended2']);
423+
$this->create_test_courses(1, ['fullname' => 'future1']);
371424

372425
$user = $this->getDataGenerator()->create_user();
373426
$this->setUser($user);

0 commit comments

Comments
 (0)