ContentLockTermTest.php in Content locking (anti-concurrent editing) 8.2
File
tests/src/Functional/ContentLockTermTest.php
View source
<?php
namespace Drupal\Tests\content_lock\Functional;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\Tests\BrowserTestBase;
class ContentLockTermTest extends BrowserTestBase {
use TaxonomyTestTrait;
public static $modules = [
'taxonomy',
'content_lock',
];
protected $defaultTheme = 'stark';
public function testContentLockTerm() {
$vocabulary = $this
->createVocabulary();
$term1 = $this
->createTerm($vocabulary);
$admin = $this
->drupalCreateUser([
'administer taxonomy',
'administer content lock',
]);
$user1 = $this
->drupalCreateUser([
'administer taxonomy',
'access content',
]);
$user2 = $this
->drupalCreateUser([
'administer taxonomy',
'break content lock',
]);
$this
->drupalLogin($admin);
$edit = [
'taxonomy_term[bundles][' . $term1
->bundle() . ']' => 1,
];
$this
->drupalPostForm('admin/config/content/content_lock', $edit, t('Save configuration'));
$this
->drupalLogin($user1);
$this
->drupalGet("taxonomy/term/{$term1->id()}/edit");
$assert_session = $this
->assertSession();
$assert_session
->pageTextContains(t('This content is now locked against simultaneous editing.'));
$this
->drupalLogin($user2);
$this
->drupalGet("taxonomy/term/{$term1->id()}/edit");
$assert_session
->pageTextContains(t('This content is being edited by the user @name and is therefore locked to prevent other users changes.', [
'@name' => $user1
->getDisplayName(),
]));
$assert_session
->linkExists(t('Break lock'));
$submit = $assert_session
->buttonExists('edit-submit');
$this
->assertTrue($submit
->hasAttribute('disabled'));
$this
->drupalLogin($user1);
$this
->drupalGet("taxonomy/term/{$term1->id()}/edit");
$assert_session
->pageTextContains(t('This content is now locked by you against simultaneous editing.'));
$this
->drupalPostForm('/taxonomy/term/' . $term1
->id() . '/edit', [], t('Save'));
$this
->drupalLogin($user2);
$this
->drupalGet("taxonomy/term/{$term1->id()}/edit");
$assert_session
->pageTextContains(t('This content is now locked against simultaneous editing.'));
$this
->drupalLogin($user1);
$this
->drupalGet("taxonomy/term/{$term1->id()}/edit");
$assert_session
->pageTextContains(t('This content is being edited by the user @name and is therefore locked to prevent other users changes.', [
'@name' => $user2
->getDisplayName(),
]));
$assert_session
->linkNotExists(t('Break lock'));
$submit = $assert_session
->buttonExists('edit-submit');
$this
->assertTrue($submit
->hasAttribute('disabled'));
$this
->drupalLogin($user2);
$this
->drupalGet("taxonomy/term/{$term1->id()}/edit");
$assert_session
->pageTextContains(t('This content is now locked by you against simultaneous editing.'));
$this
->drupalPostForm('/taxonomy/term/' . $term1
->id() . '/edit', [], t('Save'));
}
}