1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Drupal\Tests\mongodb_watchdog\Unit; |
6
|
|
|
|
7
|
|
|
use Drupal\mongodb_watchdog\Controller\ControllerBase; |
8
|
|
|
use Drupal\Tests\UnitTestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Test the ControllerBase mechanisms. |
12
|
|
|
* |
13
|
|
|
* @coversDefaultClass \Drupal\mongodb_watchdog\Controller\ControllerBase |
14
|
|
|
* |
15
|
|
|
* @group mongodb |
16
|
|
|
*/ |
17
|
|
|
class ControllerBaseTest extends UnitTestCase { |
18
|
|
|
|
19
|
|
|
const ITEMS_PER_PAGE = 50; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Test page generation for various data set shapes. |
23
|
|
|
* |
24
|
|
|
* @covers ::getPage |
25
|
|
|
* |
26
|
|
|
* @dataProvider pageGenerationData |
27
|
|
|
*/ |
28
|
|
|
public function testPageGeneration(int $requestedPage, int $count, int $expected) { |
29
|
|
|
$actual = ControllerBase::getPage($count, $requestedPage, static::ITEMS_PER_PAGE); |
30
|
|
|
$this->assertEquals($expected, $actual); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Data provider for testPageGeneration(). |
35
|
|
|
* |
36
|
|
|
* @see \Drupal\Tests\mongodb_watchdog\Unit\ControllerBaseTest::testPageGeneration() |
37
|
|
|
* |
38
|
|
|
* Coding standards are ignored for the data list for the sake of readability. |
39
|
|
|
*/ |
40
|
|
|
public function pageGenerationData() { |
41
|
|
|
// One partial available page. |
42
|
|
|
$one = static::ITEMS_PER_PAGE; |
43
|
|
|
// Part of one page. |
44
|
|
|
$partial = floor($one * 0.6); |
45
|
|
|
// More than one available page. |
46
|
|
|
$oneplus = $one + $partial; |
47
|
|
|
// Exactly two pages. |
48
|
|
|
$two = $one * 2; |
49
|
|
|
$twoplus = $two + $partial; |
50
|
|
|
|
51
|
|
|
$expectations = [ |
52
|
|
|
// @codingStandardsIgnoreStart |
53
|
|
|
// page, count, result |
54
|
|
|
[-1, 0, 0], |
55
|
|
|
[-1, $partial, 0], |
56
|
|
|
[-1, $one, 0], |
57
|
|
|
[-1, $oneplus, 0], |
58
|
|
|
[-1, $two, 0], |
59
|
|
|
|
60
|
|
|
[ 0, 0, 0], |
61
|
|
|
[ 0, $partial, 0], |
62
|
|
|
[ 0, $one, 0], |
63
|
|
|
[ 0, $oneplus, 0], |
64
|
|
|
[ 0, $two, 0], |
65
|
|
|
|
66
|
|
|
[ 1, 0, 0], |
67
|
|
|
[ 1, $partial, 0], |
68
|
|
|
[ 1, $one, 0], |
69
|
|
|
[ 1, $oneplus, 1], |
70
|
|
|
[ 1, $two, 1], |
71
|
|
|
|
72
|
|
|
[ 2, 0, 0], |
73
|
|
|
[ 2, $partial, 0], |
74
|
|
|
[ 2, $one, 0], |
75
|
|
|
[ 2, $oneplus, 1], |
76
|
|
|
[ 2, $two, 1], |
77
|
|
|
[ 2, $twoplus, 2], |
78
|
|
|
// @codingStandardsIgnoreEnd |
79
|
|
|
]; |
80
|
|
|
return $expectations; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|