19 declare(strict_types=1);
33 $this->assertInstanceOf(Sorting::class, $sort);
40 public function testSorting(array $input,
string $key,
string $label,
string $what,
string $method, array $equal, array $less, array $greater): void
43 $this->assertEquals($key, $sort->key());
44 $this->assertEquals($label, $sort->label());
45 $this->assertEquals(0, $sort->compare($this->pair($what, $method, $equal[0]), $this->
pair($what, $method, $equal[1])));
46 $this->assertEquals(-1, $this->
sign($sort->compare($this->pair($what, $method, $less[0]), $this->
pair($what, $method, $less[1]))));
47 $this->assertEquals(1, $this->
sign($sort->compare($this->pair($what, $method, $greater[0]), $this->
pair($what, $method, $greater[1]))));
60 ], array_keys((
new Sorting())->options()));
66 'Default sort is title_asc' => [[],
'title_asc',
'sort_by_title_asc',
'badge',
'getTitle', [
'A',
'a'], [
'f',
'G'], [
'd',
'c']],
67 'Descending title' => [[
'title_desc'],
'title_desc',
'sort_by_title_desc',
'badge',
'getTitle', [
'A',
'a'], [
'd',
'c'], [
'f',
'G']],
68 'Ascending date' => [[
'date_asc'],
'date_asc',
'sort_by_date_asc',
'assignment',
'getTimestamp', [
'7',
'7'], [8, 30], [20, 6]],
69 'Ascending date' => [[
'date_desc'],
'date_desc',
'sort_by_date_desc',
'assignment',
'getTimestamp', [7, 7], [20, 6], [8, 30]],
70 'Random input results in title_asc' => [[
'Lorem ipsum'],
'title_asc',
'sort_by_title_asc',
'badge',
'getTitle', [
'A',
'a'], [
'f',
'G'], [
'd',
'c']]
74 private function pair(
string $what,
string $method, $value): array
76 $badge = $this->getMockBuilder(ilBadge::class)->disableOriginalConstructor()->getMock();
77 $assignment = $this->getMockBuilder(ilBadgeAssignment::class)->disableOriginalConstructor()->getMock();
81 'assignment' => $assignment,
84 $pair[$what]->method($method)->willReturn($value);
91 return !$x ? 0 : $x / abs($x);
pair(string $what, string $method, $value)
testSorting(array $input, string $key, string $label, string $what, string $method, array $equal, array $less, array $greater)
testConstruct sortProvider
testOptions()
testConstruct