ColorPickerWidgetTest.php in Examples for Developers 8
File
field_example/tests/src/Functional/ColorPickerWidgetTest.php
View source
<?php
namespace Drupal\Tests\field_example\Functional;
use Drupal\Component\Render\FormattableMarkup;
class ColorPickerWidgetTest extends FieldExampleBrowserTestBase {
public function testSingleValueField() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->administratorAccount);
$this->fieldName = $this
->createField('field_example_rgb', 'field_example_colorpicker', '1');
$this
->drupalLogin($this->authorAccount);
$this
->drupalGet('node/add/' . $this->contentTypeName);
$title = $this
->randomMachineName(20);
$edit = [
'title[0][value]' => $title,
'field_' . $this->fieldName . '[0][value]' => '#00ff00',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$assert
->pageTextContains((string) new FormattableMarkup('@type @title has been created', [
'@type' => $this->contentTypeName,
'@title' => $title,
]));
$assert
->pageTextContains('The color code in this field is #00ff00');
}
public function testMultiValueField() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->administratorAccount);
$this->fieldName = $this
->createField('field_example_rgb', 'field_example_colorpicker', '-1');
$this
->drupalLogin($this->authorAccount);
$this
->drupalGet('node/add/' . $this->contentTypeName);
$title = $this
->randomMachineName(20);
$edit = [
'title[0][value]' => $title,
'field_' . $this->fieldName . '[0][value]' => '#00ff00',
];
$this
->drupalPostForm(NULL, $edit, 'Add another item');
$edit = [
'field_' . $this->fieldName . '[1][value]' => '#ffffff',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$assert
->pageTextContains((string) new FormattableMarkup('@type @title has been created', [
'@type' => $this->contentTypeName,
'@title' => $title,
]));
$assert
->pageTextContains('The color code in this field is #00ff00');
$assert
->pageTextContains('The color code in this field is #ffffff');
}
}