Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity / tests / src / Functional / RevisionRouteAccessTest.php
1 <?php
2
3 namespace Drupal\Tests\entity\Functional;
4
5 use Drupal\entity_module_test\Entity\EnhancedEntity;
6 use Drupal\Tests\block\Traits\BlockCreationTrait;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Tests the revision route access check.
11  *
12  * @group entity
13  *
14  * @runTestsInSeparateProcesses
15  *
16  * @preserveGlobalState disabled
17  */
18 class RevisionRouteAccessTest extends BrowserTestBase {
19
20   use BlockCreationTrait;
21
22   /**
23    * The current user.
24    *
25    * @var \Drupal\Core\Session\AccountInterface
26    */
27   protected $account;
28
29   /**
30    * Modules to enable.
31    *
32    * @var array
33    */
34   public static $modules = ['entity_module_test', 'user', 'entity', 'block'];
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function setUp() {
40     parent::setUp();
41
42     $this->placeBlock('local_tasks_block');
43     $this->placeBlock('system_breadcrumb_block');
44
45     $this->account = $this->drupalCreateUser([
46       'administer entity_test_enhanced',
47       'view all entity_test_enhanced revisions',
48     ]);
49
50     $this->drupalLogin($this->account);
51   }
52
53   /**
54    * Test enhanced entity revision routes access.
55    */
56   public function testRevisionRouteAccess() {
57     $entity = EnhancedEntity::create([
58       'name' => 'rev 1',
59       'type' => 'default',
60     ]);
61     $entity->save();
62
63     $revision = clone $entity;
64     $revision->name->value = 'rev 2';
65     $revision->setNewRevision(TRUE);
66     $revision->isDefaultRevision(FALSE);
67     $revision->save();
68
69     $this->drupalGet('/entity_test_enhanced/1/revisions');
70     $this->assertSession()->statusCodeEquals(200);
71     $this->assertSession()->responseContains('Revisions');
72     $collection_link = $this->getSession()->getPage()->findLink('Enhanced entities');
73     $collection_link->click();
74     $this->assertSession()->addressEquals('/entity_test_enhanced');
75     $this->assertSession()->responseContains('Edit');
76     $edit_link = $this->getSession()->getPage()->findLink('Edit');
77     $edit_link->click();
78     $this->assertSession()->addressEquals('/entity_test_enhanced/1/edit');
79     // Check if we have revision tab link on edit page.
80     $this->getSession()->getPage()->findLink('Revisions')->click();
81     $this->assertSession()->addressEquals('/entity_test_enhanced/1/revisions');
82     $this->drupalGet('/entity_test_enhanced/1/revisions/2/view');
83     $this->assertSession()->statusCodeEquals(200);
84     $this->assertSession()->responseContains('rev 2');
85     $revisions_link = $this->getSession()->getPage()->findLink('Revisions');
86     $revisions_link->click();
87     $this->assertSession()->addressEquals('/entity_test_enhanced/1/revisions');
88     $this->assertSession()->statusCodeEquals(200);
89   }
90
91 }