You are here

class PreprocessPagerTest in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php \Drupal\Tests\system\Unit\Pager\PreprocessPagerTest
  2. 10 core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php \Drupal\Tests\system\Unit\Pager\PreprocessPagerTest

Tests pager preprocessing.

@group system

Hierarchy

Expanded class hierarchy of PreprocessPagerTest

File

core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php, line 13

Namespace

Drupal\Tests\system\Unit\Pager
View source
class PreprocessPagerTest extends UnitTestCase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $pager_manager = $this
      ->getMockBuilder('Drupal\\Core\\Pager\\PagerManager')
      ->disableOriginalConstructor()
      ->getMock();
    $pager = $this
      ->getMockBuilder('Drupal\\Core\\Pager\\Pager')
      ->disableOriginalConstructor()
      ->getMock();
    $url_generator = $this
      ->getMockBuilder('Drupal\\Core\\Routing\\UrlGenerator')
      ->disableOriginalConstructor()
      ->getMock();
    $pager
      ->method('getTotalPages')
      ->willReturn(2);
    $pager
      ->method('getCurrentPage')
      ->willReturn(1);
    $url_generator
      ->method('generateFromRoute')
      ->willReturn('');
    $pager_manager
      ->method('getPager')
      ->willReturn($pager);
    $pager_manager
      ->method('getUpdatedParameters')
      ->willReturn('');
    $container = new ContainerBuilder();
    $container
      ->set('pager.manager', $pager_manager);
    $container
      ->set('url_generator', $url_generator);
    \Drupal::setContainer($container);
  }

  /**
   * Tests template_preprocess_pager() when an empty #quantity is passed.
   *
   * @covers ::template_preprocess_pager
   */
  public function testQuantityNotSet() {
    require_once $this->root . '/core/includes/pager.inc';
    $variables = [
      'pager' => [
        '#element' => '',
        '#parameters' => [],
        '#quantity' => '',
        '#route_name' => '',
        '#tags' => '',
      ],
    ];
    template_preprocess_pager($variables);
    $this
      ->assertEquals([
      'first',
      'previous',
    ], array_keys($variables['items']));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
PreprocessPagerTest::setUp protected function Overrides UnitTestCase::setUp
PreprocessPagerTest::testQuantityNotSet public function Tests template_preprocess_pager() when an empty #quantity is passed.
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.