View source
<?php
namespace Drupal\Tests\comment_alter\Functional;
use Drupal\Tests\comment_alter\Functional\CommentAlterTestBase;
class CommentAlterListStringTest extends CommentAlterTestBase {
public static $modules = [
'options',
];
protected function addOptionField($widget_type, $cardinality) {
return $this
->addField('list_string', $widget_type, [
'settings' => [
'allowed_values' => [
1 => 'One',
2 => 'Two',
],
],
'cardinality' => $cardinality,
]);
}
public function testOptionsSelectSingle() {
$field_name = $this
->addOptionField('options_select', 1);
$this
->createEntityObject([
$field_name => [
'value' => 1,
],
]);
$this
->assertAlterableField($field_name);
$this
->postComment([
"comment_alter_fields[{$field_name}]" => 2,
]);
$this
->assertCommentDiff([
$field_name => [
[
1,
2,
],
],
]);
$this
->assertCommentSettings($field_name);
$this
->assertRevisionDelete();
}
public function testOptionsSelectMultiple() {
$field_name = $this
->addOptionField('options_select', -1);
$this
->createEntityObject([
$field_name => [
0 => [
'value' => 1,
],
],
]);
$this
->assertAlterableField($field_name);
$this
->postComment([
"comment_alter_fields[{$field_name}][]" => [
1,
2,
],
]);
$this
->assertCommentDiff([
$field_name => [
[
1,
1,
],
[
NULL,
2,
],
],
]);
$this
->assertCommentSettings($field_name);
$this
->assertRevisionDelete();
}
public function testOptionsButtonSingle() {
$field_name = $this
->addOptionField('options_buttons', 1);
$this
->createEntityObject([
$field_name => [
'value' => 1,
],
]);
$this
->postComment([
"comment_alter_fields[{$field_name}]" => 2,
]);
$this
->assertCommentDiff([
$field_name => [
[
1,
2,
],
],
]);
$this
->assertRevisionDelete();
}
public function testOptionsButtonMultiple() {
$field_name = $this
->addOptionField('options_buttons', -1);
$this
->createEntityObject([
$field_name => [
0 => [
'value' => 1,
],
],
]);
$this
->postComment([
"comment_alter_fields[{$field_name}][2]" => TRUE,
]);
$this
->assertCommentDiff([
$field_name => [
[
1,
1,
],
[
NULL,
2,
],
],
]);
$this
->assertRevisionDelete();
}
}