You are here

class PreprocessPagerTest in Drupal 10

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

Tests pager preprocessing.

@group system

Hierarchy

  • class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitWarnings

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() : void {
    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/theme.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
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
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::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::setUpBeforeClass public static function