ColorBackgroundFormatterTest.php in Examples for Developers 3.x
File
modules/field_example/tests/src/Functional/ColorBackgroundFormatterTest.php
View source
<?php
namespace Drupal\Tests\field_example\Functional;
use Drupal\Component\Render\FormattableMarkup;
class ColorBackgroundFormatterTest extends FieldExampleBrowserTestBase {
public function testSingleValueField() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->administratorAccount);
$this->fieldName = $this
->createField('field_example_rgb', 'field_example_colorpicker', '1', 'field_example_color_background');
$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 content area color has been changed to #00ff00');
}
public function testMultiValueField() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->administratorAccount);
$this->fieldName = $this
->createField('field_example_rgb', 'field_example_colorpicker', '-1', 'field_example_color_background');
$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]' => '#ffff4f',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$assert
->pageTextContains((string) new FormattableMarkup('@type @title has been created', [
'@type' => $this->contentTypeName,
'@title' => $title,
]));
$assert
->pageTextContains('The content area color has been changed to #00ff00');
$assert
->pageTextContains('The content area color has been changed to #ffff4f');
}
}