CommentAlterTextTest.php in Comment Alter 8
File
tests/src/Functional/CommentAlterTextTest.php
View source
<?php
namespace Drupal\Tests\comment_alter\Functional;
use Drupal\Tests\comment_alter\Functional\CommentAlterTestBase;
class CommentAlterTextTest extends CommentAlterTestBase {
public static $modules = [
'text',
];
protected function addTextField($cardinality) {
return $this
->addField('text', 'text_textfield', [
'cardinality' => $cardinality,
]);
}
public function testTextFieldSingle() {
$field_name = $this
->addTextField(1);
$old_value = $this
->randomMachineName(5);
$new_value = $this
->randomMachineName(6);
$this
->createEntityObject([
$field_name => [
'value' => $old_value,
],
]);
$this
->assertAlterableField($field_name);
$this
->postComment([
"comment_alter_fields[{$field_name}][0][value]" => $new_value,
]);
$this
->assertCommentDiff([
$field_name => [
[
$old_value,
$new_value,
],
],
]);
$this
->assertCommentSettings($field_name);
$this
->assertRevisionDelete();
}
public function testTextFieldMultiple() {
$field_name = $this
->addTextField(-1);
$old_value = $this
->randomMachineName(5);
$new_value = $this
->randomMachineName(6);
$this
->createEntityObject([
$field_name => [
0 => [
'value' => $old_value,
],
],
]);
$this
->assertAlterableField($field_name);
$this
->postComment([
"comment_alter_fields[{$field_name}][1][value]" => $new_value,
]);
$this
->assertCommentDiff([
$field_name => [
[
$old_value,
$old_value,
],
[
NULL,
$new_value,
],
],
]);
$this
->assertCommentSettings($field_name);
$this
->assertRevisionDelete();
}
}