Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / tests / src / Functional / Entity / EntityListBuilderTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Entity;
4
5 use Drupal\Core\Language\LanguageInterface;
6 use Drupal\entity_test\Entity\EntityTest;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Tests entity list builder functionality.
11  *
12  * @group Entity
13  */
14 class EntityListBuilderTest extends BrowserTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = ['entity_test'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26
27     // Create and log in user.
28     $this->webUser = $this->drupalCreateUser([
29       'administer entity_test content',
30     ]);
31     $this->drupalLogin($this->webUser);
32   }
33
34   /**
35    * Test paging.
36    */
37   public function testPager() {
38     // Create 51 test entities.
39     for ($i = 1; $i < 52; $i++) {
40       EntityTest::create(['name' => 'Test entity ' . $i])->save();
41     }
42
43     // Load the listing page.
44     $this->drupalGet('entity_test/list');
45
46     // Item 51 should not be present.
47     $this->assertRaw('Test entity 50', 'Item 50 is shown.');
48     $this->assertNoRaw('Test entity 51', 'Item 51 is on the next page.');
49
50     // Browse to the next page.
51     $this->clickLink(t('Page 2'));
52     $this->assertNoRaw('Test entity 50', 'Test entity 50 is on the previous page.');
53     $this->assertRaw('Test entity 51', 'Test entity 51 is shown.');
54   }
55
56   /**
57    * Tests that the correct cache contexts are set.
58    */
59   public function testCacheContexts() {
60     /** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */
61     $list_builder = $this->container->get('entity.manager')->getListBuilder('entity_test');
62
63     $build = $list_builder->render();
64     $this->container->get('renderer')->renderRoot($build);
65
66     $this->assertEqual(['entity_test_view_grants', 'languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url.query_args.pagers:0', 'user.permissions'], $build['#cache']['contexts']);
67   }
68
69   /**
70    * Tests if the list cache tags are set.
71    */
72   public function testCacheTags() {
73     $this->drupalGet('entity_test/list');
74     $this->assertCacheTag('entity_test_list');
75   }
76
77 }