class ControllerBaseTest in MongoDB 8.2
Test the ControllerBase mechanisms.
@coversDefaultClass \Drupal\mongodb_watchdog\Controller\ControllerBase
@group mongodb
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\mongodb_watchdog\Unit\ControllerBaseTest
Expanded class hierarchy of ControllerBaseTest
File
- modules/
mongodb_watchdog/ tests/ src/ Unit/ ControllerBaseTest.php, line 17
Namespace
Drupal\Tests\mongodb_watchdog\UnitView source
class ControllerBaseTest extends UnitTestCase {
const ITEMS_PER_PAGE = 50;
/**
* Test page generation for various data set shapes.
*
* @covers ::getPage
*
* @dataProvider pageGenerationData
*/
public function testPageGeneration(int $requestedPage, int $count, int $expected) {
$actual = ControllerBase::getPage($count, $requestedPage, static::ITEMS_PER_PAGE);
$this
->assertEquals($expected, $actual);
}
/**
* Data provider for testPageGeneration().
*
* @see \Drupal\Tests\mongodb_watchdog\Unit\ControllerBaseTest::testPageGeneration()
*
* Coding standards are ignored for the data list for the sake of readability.
*/
public function pageGenerationData() {
// One partial available page.
$one = static::ITEMS_PER_PAGE;
// Part of one page.
$partial = (int) floor($one * 0.6);
// More than one available page.
$oneplus = $one + $partial;
// Exactly two pages.
$two = (int) ($one * 2);
$twoplus = $two + $partial;
$expectations = [
// @codingStandardsIgnoreStart
// page, count, result
[
-1,
0,
0,
],
[
-1,
$partial,
0,
],
[
-1,
$one,
0,
],
[
-1,
$oneplus,
0,
],
[
-1,
$two,
0,
],
[
0,
0,
0,
],
[
0,
$partial,
0,
],
[
0,
$one,
0,
],
[
0,
$oneplus,
0,
],
[
0,
$two,
0,
],
[
1,
0,
0,
],
[
1,
$partial,
0,
],
[
1,
$one,
0,
],
[
1,
$oneplus,
1,
],
[
1,
$two,
1,
],
[
2,
0,
0,
],
[
2,
$partial,
0,
],
[
2,
$one,
0,
],
[
2,
$oneplus,
1,
],
[
2,
$two,
1,
],
[
2,
$twoplus,
2,
],
];
return $expectations;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBaseTest:: |
constant | |||
ControllerBaseTest:: |
public | function | Data provider for testPageGeneration(). | |
ControllerBaseTest:: |
public | function | Test page generation for various data set shapes. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |