Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / src / Tests / CachedDataUITest.php
1 <?php
2
3 namespace Drupal\views_ui\Tests;
4
5 /**
6  * Tests the user tempstore cache in the UI.
7  *
8  * @group views_ui
9  */
10 class CachedDataUITest extends UITestBase {
11
12   /**
13    * Views used by this test.
14    *
15    * @var array
16    */
17   public static $testViews = ['test_view'];
18
19   /**
20    * Tests the user tempstore views data in the UI.
21    */
22   public function testCacheData() {
23     $views_admin_user_uid = $this->fullAdminUser->id();
24
25     $temp_store = $this->container->get('user.shared_tempstore')->get('views');
26     // The view should not be locked.
27     $this->assertEqual($temp_store->getMetadata('test_view'), NULL, 'The view is not locked.');
28
29     $this->drupalGet('admin/structure/views/view/test_view/edit');
30     // Make sure we have 'changes' to the view.
31     $this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
32     $this->assertText('You have unsaved changes.');
33     $this->assertEqual($temp_store->getMetadata('test_view')->owner, $views_admin_user_uid, 'View cache has been saved.');
34
35     $view_cache = $temp_store->get('test_view');
36     // The view should be enabled.
37     $this->assertTrue($view_cache->status(), 'The view is enabled.');
38     // The view should now be locked.
39     $this->assertEqual($temp_store->getMetadata('test_view')->owner, $views_admin_user_uid, 'The view is locked.');
40
41     // Cancel the view edit and make sure the cache is deleted.
42     $this->drupalPostForm(NULL, [], t('Cancel'));
43     $this->assertEqual($temp_store->getMetadata('test_view'), NULL, 'User tempstore data has been removed.');
44     // Test we are redirected to the view listing page.
45     $this->assertUrl('admin/structure/views', [], 'Redirected back to the view listing page.');
46
47     // Log in with another user and make sure the view is locked and break.
48     $this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
49     $this->drupalLogin($this->adminUser);
50
51     $this->drupalGet('admin/structure/views/view/test_view/edit');
52     // Test that save and cancel buttons are not shown.
53     $this->assertNoFieldById('edit-actions-submit', t('Save'));
54     $this->assertNoFieldById('edit-actions-cancel', t('Cancel'));
55     // Test we have the break lock link.
56     $this->assertLinkByHref('admin/structure/views/view/test_view/break-lock');
57     // Break the lock.
58     $this->clickLink(t('break this lock'));
59     $this->drupalPostForm(NULL, [], t('Break lock'));
60     // Test that save and cancel buttons are shown.
61     $this->assertFieldById('edit-actions-submit', t('Save'));
62     $this->assertFieldById('edit-actions-cancel', t('Cancel'));
63     // Test we can save the view.
64     $this->drupalPostForm('admin/structure/views/view/test_view/edit', [], t('Save'));
65     $this->assertRaw(t('The view %view has been saved.', ['%view' => 'Test view']));
66
67     // Test that a deleted view has no tempstore data.
68     $this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
69     $this->drupalPostForm('admin/structure/views/view/test_view/delete', [], t('Delete'));
70     // No view tempstore data should be returned for this view after deletion.
71     $this->assertEqual($temp_store->getMetadata('test_view'), NULL, 'View tempstore data has been removed after deletion.');
72   }
73
74 }