You are here

class ControllerBaseTest in MongoDB 8.2

Test the ControllerBase mechanisms.

@coversDefaultClass \Drupal\mongodb_watchdog\Controller\ControllerBase

@group mongodb

Hierarchy

Expanded class hierarchy of ControllerBaseTest

File

modules/mongodb_watchdog/tests/src/Unit/ControllerBaseTest.php, line 17

Namespace

Drupal\Tests\mongodb_watchdog\Unit
View 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

Namesort descending Modifiers Type Description Overrides
ControllerBaseTest::ITEMS_PER_PAGE constant
ControllerBaseTest::pageGenerationData public function Data provider for testPageGeneration().
ControllerBaseTest::testPageGeneration public function Test page generation for various data set shapes.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340