Skip to content

Commit

Permalink
remove duplication of tests (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
semteacher committed Feb 18, 2025
1 parent 18c1fb5 commit 6eaa66b
Showing 1 changed file with 0 additions and 233 deletions.
233 changes: 0 additions & 233 deletions tests/base_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,239 +263,6 @@ public function test_filter_callback(): void {
$this->assertEquals(15, $nrofrows);
}

/**
* Test wb datepicker filter functionality via webservice external class.
*
* @covers \local_wunderbyte_table\filters\types\datepicker
*
* @throws \coding_exception
* @throws \dml_exception
*
*/
public function test_filter_datepicker(): void {

// First, we create default test courses.
$courses = $this->create_test_courses(10);
// Create 3 courses for end date filtering.
$this->create_test_courses(1, [
'fullname' => 'ended1',
'startdate' => strtotime('2 May 2010'),
'enddate' => strtotime('20 May 2010'),
]);
$this->create_test_courses(1, [
'fullname' => 'ended2',
'startdate' => strtotime('5 Jun 2020 14:00'),
'enddate' => strtotime('15 Jun 2020 15:00'),
]);
$plusfifftymonth = strtotime('+50 month');
$plussixtymonth = strtotime('+60 month');
$this->create_test_courses(1, [
'fullname' => 'future1',
'startdate' => $plusfifftymonth,
'enddate' => $plussixtymonth,
]);

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

$table = $this->create_demo2_table();
$table->pagesize = 20;

$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
'{"enddate":{"Course end date":{">":' . $plusfifftymonth . '}}}'
);
$this->assertEquals(1, $nrofrows);

$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
'{"enddate":{"Course end date":{"<":' . strtotime('1 January 2020') . '}}}'
);
$this->assertEquals(11, $nrofrows);

$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
'{"enddate":{"Course end date":{"<":' . strtotime('+1 year') . '}}}'
);
$this->assertEquals(12, $nrofrows);
}

/**
* Test wb base full text search.
*
* @covers \local_wunderbyte_table\filters\types\standardfilter
*
* @throws \coding_exception
* @throws \dml_exception
*
*/
public function test_filter_standardfilter(): void {
// First, we create ten courses.
$this->create_test_courses(10);
// Now we create another six courses for basic searching and filtering.
$this->create_test_courses(3, ['fullname' => 'filtercourse']);
$this->create_test_courses(1, ['fullname' => 'ended1']);
$this->create_test_courses(1, ['fullname' => 'ended2']);
$this->create_test_courses(1, ['fullname' => 'future1']);

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

$table = $this->create_demo2_table();
$table->pagesize = 20;

$nrofrows = $this->get_rowscount_for_table($table);
$this->assertEquals(16, $nrofrows);

// Validate basic filtering by course fullname.
$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
'{"fullname":["filtercourse"]}'
);
$this->assertEquals(3, $nrofrows);

$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
'{"fullname":["ended2"]}'
);
$this->assertEquals(1, $nrofrows);

$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
'{"fullname":["ended%"]}'
);
$this->assertEquals(2, $nrofrows);
}

/**
* Test wb base full text search.
*
* @covers \wunderbyte_table::query_db_cached
* @covers \wunderbyte_table::define_fulltextsearchcolumns
*
* @throws \coding_exception
* @throws \dml_exception
*
*/
public function test_fulltextsearchcolumns(): void {
// First, we create ten courses.
$this->create_test_courses(10);
// Now we create another six courses for basic searching and filtering.
$this->create_test_courses(3, ['fullname' => 'filtercourse']);
$this->create_test_courses(1, ['fullname' => 'ended1']);
$this->create_test_courses(1, ['fullname' => 'ended2']);
$this->create_test_courses(1, ['fullname' => 'future1']);

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

$table = $this->create_demo2_table();

$nrofrows = $this->get_rowscount_for_table($table);
$this->assertEquals(16, $nrofrows);

// Search for courses by name.
$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
null,
'filtercourse'
);
$this->assertEquals(3, $nrofrows);

$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
null,
'Test course 9'
);
$this->assertEquals(1, $nrofrows);

$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
null,
'ended'
);
$this->assertEquals(2, $nrofrows);

// Validate basic filtering by course fullname.
$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
'{"fullname":["filtercourse"]}'
);
$this->assertEquals(3, $nrofrows);

$nrofrows = $this->get_rowscount_for_table(
$table,
0,
null,
null,
null,
null,
null,
'{"fullname":["ended2"]}'
);
$this->assertEquals(1, $nrofrows);
}

/**
* Function to create and return wunderbyte table class.
*
Expand Down

0 comments on commit 6eaa66b

Please sign in to comment.