EntityListBuilderTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/Entity/EntityListBuilderTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Entity;
use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\BrowserTestBase;
class EntityListBuilderTest extends BrowserTestBase {
protected static $modules = [
'entity_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([
'administer entity_test content',
]);
$this
->drupalLogin($this->webUser);
}
public function testPager() {
for ($i = 1; $i < 52; $i++) {
EntityTest::create([
'name' => 'Test entity ' . $i,
])
->save();
}
$this
->drupalGet('entity_test/list');
$this
->assertSession()
->pageTextContains('Test entity 50');
$this
->assertSession()
->responseNotContains('Test entity 51');
$this
->clickLink('Page 2');
$this
->assertSession()
->responseNotContains('Test entity 50');
$this
->assertSession()
->pageTextContains('Test entity 51');
}
public function testCacheContexts() {
$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']);
}
public function testCacheTags() {
$this
->drupalGet('entity_test/list');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'entity_test_list');
}
}