PrefetchCacheTest.php in Content locking (anti-concurrent editing) 8.2
File
tests/src/FunctionalJavascript/Integration/PrefetchCacheTest.php
View source
<?php
namespace Drupal\Tests\content_lock\FunctionalJavascript\Integration;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\content_lock\FunctionalJavascript\ContentLockJavascriptTestBase;
class PrefetchCacheTest extends ContentLockJavascriptTestBase {
use BlockCreationTrait;
public static $modules = [
'block',
'prefetch_cache_test',
];
protected $defaultTheme = 'stark';
public function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block', [
'primary' => TRUE,
]);
}
public function testPrefetchCacheJsLocking() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalLogin($this->admin);
$this
->drupalGet('admin/config/content/content_lock');
$this
->click('#edit-entity-types-entity-test-mul-changed');
$this
->click('#edit-entity-test-mul-changed-settings-js-lock');
$page
->pressButton('Save configuration');
$lockService = \Drupal::service('content_lock');
$this
->drupalLogin($this->user1);
$this
->drupalGet($this->entity
->toUrl());
$this
->assertFalse($lockService
->fetchLock($this->entity
->id(), $this->entity
->language()
->getId(), NULL, 'entity_test_mul_changed'));
$this
->drupalGet($this->entity
->toUrl('edit-form'));
$assert_session
->waitForElement('css', 'messages messages--status');
$this
->assertNotFalse($lockService
->fetchLock($this->entity
->id(), $this->entity
->language()
->getId(), NULL, 'entity_test_mul_changed'));
$page
->pressButton(t('Save'));
$this
->assertFalse($lockService
->fetchLock($this->entity
->id(), $this->entity
->language()
->getId(), NULL, 'entity_test_mul_changed'));
}
public function testPrefetchCacheNormalLocking() {
$page = $this
->getSession()
->getPage();
$this
->drupalLogin($this->admin);
$this
->drupalGet('admin/config/content/content_lock');
$this
->click('#edit-entity-types-entity-test-mul-changed');
$page
->pressButton('Save configuration');
$lockService = \Drupal::service('content_lock');
$this
->drupalLogin($this->user1);
$this
->drupalGet($this->entity
->toUrl());
sleep(3);
$this
->assertNotFalse($lockService
->fetchLock($this->entity
->id(), $this->entity
->language()
->getId(), NULL, 'entity_test_mul_changed'));
}
}