class EntityListBuilderTest
Same name in this branch
- 9 core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Entity/EntityListBuilderTest.php \Drupal\Tests\system\Functional\Entity\EntityListBuilderTest
- 11.x core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest
- 10 core/modules/system/tests/src/Functional/Entity/EntityListBuilderTest.php \Drupal\Tests\system\Functional\Entity\EntityListBuilderTest
- 10 core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest
- 8.9.x core/modules/system/tests/src/Functional/Entity/EntityListBuilderTest.php \Drupal\Tests\system\Functional\Entity\EntityListBuilderTest
- 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest
Tests entity list builder functionality.
@group Entity
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\system\Functional\Entity\EntityListBuilderTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of EntityListBuilderTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityListBuilderTest.php, line 14
Namespace
Drupal\Tests\system\Functional\EntityView source
class EntityListBuilderTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'entity_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create and log in user.
$this->drupalLogin($this->drupalCreateUser([
'administer entity_test content',
]));
}
/**
* Tests paging.
*/
public function testPager() {
// Create 51 test entities.
for ($i = 1; $i < 52; $i++) {
EntityTest::create([
'name' => 'Test entity ' . $i,
])->save();
}
// Load the listing page.
$this->drupalGet('entity_test/list');
// Item 51 should not be present.
$this->assertSession()
->pageTextContains('Test entity 50');
$this->assertSession()
->responseNotContains('Test entity 51');
// Browse to the next page, test entity 51 is shown.
$this->clickLink('Page 2');
$this->assertSession()
->responseNotContains('Test entity 50');
$this->assertSession()
->pageTextContains('Test entity 51');
}
/**
* Tests that the correct cache contexts are set.
*/
public function testCacheContexts() {
/** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */
$list_builder = $this->container
->get('entity_type.manager')
->getListBuilder('entity_test');
$build = $list_builder->render();
$this->container
->get('renderer')
->renderRoot($build);
$this->assertEqualsCanonicalizing([
'entity_test_view_grants',
'languages:' . LanguageInterface::TYPE_INTERFACE,
'theme',
'url.query_args.pagers:0',
'user.permissions',
], $build['#cache']['contexts']);
}
/**
* Tests if the list cache tags are set.
*/
public function testCacheTags() {
$this->drupalGet('entity_test/list');
$this->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'entity_test_list');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.