CachedDataUITest.php in Drupal 10
File
core/modules/views_ui/tests/src/Functional/CachedDataUITest.php
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
->assertNull($temp_store
->getMetadata('test_view'), 'The view is not locked.');
$this
->drupalGet('admin/structure/views/view/test_view/edit');
$this
->drupalGet('admin/structure/views/nojs/display/test_view/default/title');
$this
->submitForm([], 'Apply');
$this
->assertSession()
->pageTextContains('You have unsaved changes.');
$this
->assertEquals($views_admin_user_uid, $temp_store
->getMetadata('test_view')
->getOwnerId(), 'View cache has been saved.');
$view_cache = $temp_store
->get('test_view');
$this
->assertTrue($view_cache
->status(), 'The view is enabled.');
$this
->assertEquals($views_admin_user_uid, $temp_store
->getMetadata('test_view')
->getOwnerId(), 'The view is locked.');
$this
->submitForm([], 'Cancel');
$this
->assertNull($temp_store
->getMetadata('test_view'), 'Shared tempstore data has been removed.');
$this
->assertSession()
->addressEquals('admin/structure/views');
$this
->drupalGet('admin/structure/views/nojs/display/test_view/default/title');
$this
->submitForm([], 'Apply');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/structure/views/view/test_view/edit');
$this
->assertSession()
->buttonNotExists('Save');
$this
->assertSession()
->buttonNotExists('Cancel');
$this
->assertSession()
->linkByHrefExists('admin/structure/views/view/test_view/break-lock');
$this
->clickLink('break this lock');
$this
->submitForm([], 'Break lock');
$this
->assertSession()
->buttonExists('Save');
$this
->assertSession()
->buttonExists('Cancel');
$this
->drupalGet('admin/structure/views/view/test_view/edit');
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains("The view Test view has been saved.");
$this
->drupalGet('admin/structure/views/nojs/display/test_view/default/title');
$this
->submitForm([], 'Apply');
$this
->drupalGet('admin/structure/views/view/test_view/delete');
$this
->submitForm([], 'Delete');
$this
->assertNull($temp_store
->getMetadata('test_view'), 'View tempstore data has been removed after deletion.');
}
}