Same name and namespace in other branches
- 8.9.x core/modules/system/tests/src/Unit/Pager/PreprocessPagerTest.php \Drupal\Tests\system\Unit\Pager\PreprocessPagerTest
- 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, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, RandomGeneratorTrait, PhpUnitWarnings
- class \Drupal\Tests\system\Unit\Pager\PreprocessPagerTest
Expanded class hierarchy of PreprocessPagerTest
File
- core/
modules/ system/ tests/ src/ Unit/ Pager/ PreprocessPagerTest.php, line 16
Namespace
Drupal\Tests\system\Unit\PagerView 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);
// template_preprocess_pager() renders translatable attribute values.
$container
->set('string_translation', $this
->getStringTranslationStub());
\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']));
}
/**
* Tests template_preprocess_pager() when a #quantity value is passed.
*
* @covers ::template_preprocess_pager
*/
public function testQuantitySet() {
require_once $this->root . '/core/includes/theme.inc';
$variables = [
'pager' => [
'#element' => '2',
'#parameters' => [],
'#quantity' => '2',
'#route_name' => '',
'#tags' => '',
],
];
template_preprocess_pager($variables);
$this
->assertEquals([
'first',
'previous',
'pages',
], array_keys($variables['items']));
/** @var \Drupal\Core\Template\AttributeString $attribute */
$attribute = $variables['items']['pages']['2']['attributes']
->offsetGet('aria-current');
$this
->assertInstanceOf(AttributeString::class, $attribute);
$this
->assertEquals('page', $attribute
->value());
}
/**
* Tests template_preprocess_pager() when an empty #pagination_heading_level value is passed.
*
* @covers ::template_preprocess_pager
*/
public function testEmptyPaginationHeadingLevelSet() {
require_once $this->root . '/core/includes/theme.inc';
$variables = [
'pager' => [
'#element' => '2',
'#pagination_heading_level' => '',
'#parameters' => [],
'#quantity' => '2',
'#route_name' => '',
'#tags' => '',
],
];
template_preprocess_pager($variables);
$this
->assertEquals('h4', $variables['pagination_heading_level']);
}
/**
* Tests template_preprocess_pager() when no #pagination_heading_level is passed.
*
* @covers ::template_preprocess_pager
*/
public function testPaginationHeadingLevelNotSet() {
require_once $this->root . '/core/includes/theme.inc';
$variables = [
'pager' => [
'#element' => '',
'#parameters' => [],
'#quantity' => '',
'#route_name' => '',
'#tags' => '',
],
];
template_preprocess_pager($variables);
$this
->assertEquals('h4', $variables['pagination_heading_level']);
}
/**
* Tests template_preprocess_pager() when a #pagination_heading_level value is passed.
*
* @covers ::template_preprocess_pager
*/
public function testPaginationHeadingLevelSet() {
require_once $this->root . '/core/includes/theme.inc';
$variables = [
'pager' => [
'#element' => '2',
'#pagination_heading_level' => 'h5',
'#parameters' => [],
'#quantity' => '2',
'#route_name' => '',
'#tags' => '',
],
];
template_preprocess_pager($variables);
$this
->assertEquals('h5', $variables['pagination_heading_level']);
}
/**
* Test template_preprocess_pager() with an invalid #pagination_heading_level.
*
* @covers ::template_preprocess_pager
*/
public function testPaginationHeadingLevelInvalid() {
require_once $this->root . '/core/includes/theme.inc';
$variables = [
'pager' => [
'#element' => '2',
'#pagination_heading_level' => 'not-a-heading-element',
'#parameters' => [],
'#quantity' => '2',
'#route_name' => '',
'#tags' => '',
],
];
template_preprocess_pager($variables);
$this
->assertEquals('h4', $variables['pagination_heading_level']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
PreprocessPagerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PreprocessPagerTest:: |
public | function | Tests template_preprocess_pager() when an empty #pagination_heading_level value is passed. | |
PreprocessPagerTest:: |
public | function | Test template_preprocess_pager() with an invalid #pagination_heading_level. | |
PreprocessPagerTest:: |
public | function | Tests template_preprocess_pager() when no #pagination_heading_level is passed. | |
PreprocessPagerTest:: |
public | function | Tests template_preprocess_pager() when a #pagination_heading_level value is passed. | |
PreprocessPagerTest:: |
public | function | Tests template_preprocess_pager() when an empty #quantity is passed. | |
PreprocessPagerTest:: |
public | function | Tests template_preprocess_pager() when a #quantity value is passed. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. | |
UnitTestCase:: |
protected | property | The app root. | 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:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public static | function | ||
UnitTestCase:: |
public | function |