View source
<?php
namespace Drupal\Tests\hide_revision_field\Functional;
use Drupal\Tests\BrowserTestBase;
class RevisionLogWidgetTest extends BrowserTestBase {
protected static $modules = [
'node',
'user',
'hide_revision_field',
];
protected $adminUser;
protected $webUser;
protected $defaultTheme = 'stark';
protected $form;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'bypass node access',
'administer revision field personalization',
'access revision field',
]);
$this->webUser = $this
->drupalCreateUser([
'bypass node access',
]);
$this
->drupalCreateContentType([
'type' => 'article',
'new_revision' => TRUE,
]);
$entityTypeManager = $this->container
->get('entity_type.manager');
$this->form = $entityTypeManager
->getStorage('entity_form_display')
->load('node.article.default');
}
public function testWidget() {
$this
->drupalLogin($this->webUser);
$this
->drupalGet('node/add/article');
$session = $this
->assertSession();
$session
->fieldExists('revision_log[0][value]');
$session
->fieldValueEquals('revision_log[0][value]', '');
$this->form
->setComponent('revision_log', [
'type' => 'hide_revision_field_log_widget',
'settings' => [
'show' => FALSE,
],
])
->save();
$this
->drupalGet('node/add/article');
$session
->fieldNotExists('revision_log[0][value]');
$this->form
->setComponent('revision_log', [
'type' => 'hide_revision_field_log_widget',
'settings' => [
'show' => TRUE,
'permission_based' => TRUE,
'default' => 'A new log message',
],
])
->save();
$this
->drupalGet('node/add/article');
$session
->fieldNotExists('revision_log[0][value]');
$session
->hiddenFieldValueEquals('revision_log[0][value]', 'A new log message');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('node/add/article');
$session
->fieldExists('revision_log[0][value]');
$session
->fieldValueEquals('revision_log[0][value]', 'A new log message');
}
public function testUserPersonalization() {
$this
->drupalLogin($this->webUser);
$this
->drupalGet("user/{$this->webUser->id()}/edit");
$session = $this
->assertSession();
$session
->fieldNotExists('hide_revision_field[node][article]');
$session
->pageTextNotContains('Revision Field Settings');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("user/{$this->adminUser->id()}/edit");
$session = $this
->assertSession();
$session
->fieldExists('hide_revision_field[node][article]');
$session
->fieldValueEquals('hide_revision_field[node][article]', TRUE);
$session
->pageTextContains('Revision Field Settings');
$edit = [
'hide_revision_field[node][article]' => FALSE,
];
$this
->submitForm($edit, 'op');
$this
->drupalGet('node/add/article');
$session
->fieldNotExists('revision_log[0][value]');
$this->form
->setComponent('revision_log', [
'type' => 'hide_revision_field_log_widget',
'settings' => [
'allow_user_settings' => FALSE,
],
])
->save();
$this
->drupalGet("user/{$this->adminUser->id()}/edit");
$session
->fieldNotExists('hide_revision_field[node][article]');
$session
->pageTextNotContains('Revision Field Settings');
}
}