class PagerTest
Same name in this branch
- 9 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest
- 9 core/modules/system/tests/src/Functional/Pager/PagerTest.php \Drupal\Tests\system\Functional\Pager\PagerTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Functional/Wizard/PagerTest.php \Drupal\Tests\views\Functional\Wizard\PagerTest
- 11.x core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest
- 11.x core/modules/system/tests/src/Functional/Pager/PagerTest.php \Drupal\Tests\system\Functional\Pager\PagerTest
Tests the ability of the views wizard to create views without a pager.
@group views
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\views\Functional\Wizard\WizardTestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\Wizard\PagerTest implements \Drupal\Tests\views\Functional\Wizard\WizardTestBase
- class \Drupal\Tests\views\Functional\Wizard\WizardTestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of PagerTest
File
-
core/
modules/ views/ tests/ src/ Functional/ Wizard/ PagerTest.php, line 10
Namespace
Drupal\Tests\views\Functional\WizardView source
class PagerTest extends WizardTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests the pager option.
*/
public function testPager() {
// Create nodes, each with a different creation time so that we have
// conditions that are meaningful for the use of a pager.
$this->drupalCreateContentType([
'type' => 'page',
]);
for ($i = 0; $i < 12; $i++) {
$this->drupalCreateNode([
'created' => REQUEST_TIME - $i,
]);
}
// Make a View that uses a pager.
$path_with_pager = 'test-view-with-pager';
$this->createViewAtPath($path_with_pager, TRUE);
$this->drupalGet($path_with_pager);
// This technique for finding the existence of a pager
// matches that used in Drupal\views_ui\Tests\PreviewTest.php.
$this->assertSession()
->elementExists('xpath', '//ul[contains(@class, "pager__items")]/li');
// Make a View that does not have a pager.
$path_with_no_pager = 'test-view-without-pager';
$this->createViewAtPath($path_with_no_pager, FALSE);
$this->drupalGet($path_with_no_pager);
$this->assertSession()
->elementNotExists('xpath', '//ul[contains(@class, "pager__items")]/li');
}
/**
* Create a simple View of nodes at a given path.
*
* @param string $path
* The path at which the View should be created.
* @param bool $pager
* A boolean for whether the View created should use a pager.
*/
protected function createViewAtPath($path, $pager = TRUE) {
$view = [];
$view['label'] = $this->randomMachineName(16);
$view['id'] = strtolower($this->randomMachineName(16));
$view['show[sort]'] = 'node_field_data-created:ASC';
$view['page[create]'] = 1;
$view['page[title]'] = $this->randomMachineName(16);
$view['page[path]'] = $path;
$view['page[pager]'] = $pager;
$this->drupalGet('admin/structure/views/add');
$this->submitForm($view, 'Save and edit');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.