View source
<?php
namespace Drupal\simplify\Tests;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Tests\BrowserTestBase;
class PerCommentTypeSettingsTest extends BrowserTestBase {
use CommentTestTrait;
protected $adminUser;
public static $modules = [
'node',
'comment',
'field_ui',
'simplify',
];
public static function getInfo() {
return [
'name' => 'Simplify per comment-type settings test.',
'description' => 'Test the Simplify per comment-type settings.',
'group' => 'Simplify',
];
}
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer content types',
'administer comments',
'administer comment types',
'administer comment fields',
'administer comment display',
'administer simplify',
'skip comment approval',
'post comments',
'access comments',
'access content',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalCreateContentType([
'type' => 'content_type',
'name' => 'Testing content type',
]);
$this
->addDefaultCommentField('node', 'content_type');
}
public function testSettingSaving() {
$node = $this
->drupalCreateNode([
'type' => 'content_type',
'promote' => 1,
'uid' => $this->adminUser
->id(),
]);
$this
->drupalGet("/node/" . $node
->id());
$this
->assertRaw('About text formats', 'Comment text format option is defined.');
$this
->drupalGet('/admin/config/user-interface/simplify');
$options = [
'simplify_admin' => TRUE,
'simplify_comments_global[format]' => 'format',
];
$this
->drupalPostForm(NULL, $options, $this
->t('Save configuration'));
$this
->drupalGet('/admin/structure/comment/manage/comment');
$this
->assertFieldChecked('edit-simplify-comments-format', 'Comment text fomat selection option is checked.');
$text_format = $this
->xpath('//input[@name="simplify_comments[format]" and @disabled="disabled"]');
$this
->assertTrue(count($text_format) === 1, 'Comment text format option is disabled.');
$this
->drupalGet('/admin/config/user-interface/simplify');
$options = [
'simplify_admin' => TRUE,
'simplify_comments_global[format]' => FALSE,
];
$this
->drupalPostForm(NULL, $options, $this
->t('Save configuration'));
$this
->drupalGet('/admin/structure/comment/manage/comment');
$this
->assertNoFieldChecked('edit-simplify-comments-format', 'Comment text fomat selection option is not checked.');
$options = [
'simplify_comments[format]' => 'format',
];
$this
->drupalPostForm(NULL, $options, $this
->t('Save'));
$this
->drupalGet('/admin/structure/comment/manage/comment');
$this
->assertFieldChecked('edit-simplify-comments-format', 'Comment text fomat selection option is checked.');
$this
->drupalGet("/node/" . $node
->id());
$this
->assertNoRaw('About text formats', 'Comment text format option is not defined.');
}
}