View source
<?php
namespace Drupal\Tests\views_ui\Functional;
class CachedDataUITest extends UITestBase {
public static $testViews = [
'test_view',
];
protected $defaultTheme = 'stark';
public function testCacheData() {
$views_admin_user_uid = $this->fullAdminUser
->id();
$temp_store = $this->container
->get('tempstore.shared')
->get('views');
$this
->assertEqual($temp_store
->getMetadata('test_view'), NULL, 'The view is not locked.');
$this
->drupalGet('admin/structure/views/view/test_view/edit');
$this
->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
$this
->assertText('You have unsaved changes.');
$this
->assertEqual($temp_store
->getMetadata('test_view')
->getOwnerId(), $views_admin_user_uid, 'View cache has been saved.');
$view_cache = $temp_store
->get('test_view');
$this
->assertTrue($view_cache
->status(), 'The view is enabled.');
$this
->assertEqual($temp_store
->getMetadata('test_view')
->getOwnerId(), $views_admin_user_uid, 'The view is locked.');
$this
->drupalPostForm(NULL, [], t('Cancel'));
$this
->assertEqual($temp_store
->getMetadata('test_view'), NULL, 'Shared tempstore data has been removed.');
$this
->assertUrl('admin/structure/views', [], 'Redirected back to the view listing page.');
$this
->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/structure/views/view/test_view/edit');
$this
->assertNoFieldById('edit-actions-submit', t('Save'));
$this
->assertNoFieldById('edit-actions-cancel', t('Cancel'));
$this
->assertLinkByHref('admin/structure/views/view/test_view/break-lock');
$this
->clickLink(t('break this lock'));
$this
->drupalPostForm(NULL, [], t('Break lock'));
$this
->assertFieldById('edit-actions-submit', t('Save'));
$this
->assertFieldById('edit-actions-cancel', t('Cancel'));
$this
->drupalPostForm('admin/structure/views/view/test_view/edit', [], t('Save'));
$this
->assertRaw(t('The view %view has been saved.', [
'%view' => 'Test view',
]));
$this
->drupalPostForm('admin/structure/views/nojs/display/test_view/default/title', [], t('Apply'));
$this
->drupalPostForm('admin/structure/views/view/test_view/delete', [], t('Delete'));
$this
->assertEqual($temp_store
->getMetadata('test_view'), NULL, 'View tempstore data has been removed after deletion.');
}
}