public function ColorFieldWidgetJavascriptTests::testColorFieldWidgetBox in Color Field 8.2
Test color_field_widget_box.
File
- tests/
src/ FunctionalJavascript/ ColorFieldWidgetJavascriptTests.php, line 97
Class
- ColorFieldWidgetJavascriptTests
- Tests for form grouping elements.
Namespace
Drupal\Tests\color_field\FunctionalJavascriptCode
public function testColorFieldWidgetBox() {
$this->form
->setComponent('field_color_repeat', [
'type' => 'color_field_widget_box',
'settings' => [
'default_colors' => '#FF0000,#FFFFFF',
],
])
->setComponent('field_color', [
'type' => 'color_field_widget_box',
'settings' => [
'default_colors' => '#007749,#000000,#FFFFFF,#FFB81C,#E03C31,#001489,#ffafc8,#74d7ee',
],
])
->save();
$session = $this
->getSession();
$web_assert = $this
->assertSession();
$this
->drupalGet('node/add/article');
$page = $session
->getPage();
// Wait for elements to be generated.
$web_assert
->waitForElementVisible('css', '#color-field-field-color_repeat button');
$boxes = $page
->findAll('css', '#color-field-field-color-repeat button');
$this
->assertEquals(3, count($boxes));
// Confirm that help text/label are present.
$web_assert
->responseContains('Freeform Color');
$web_assert
->responseContains('Color field description');
// Confirm that two fields aren't sharing settings.
$boxes = $page
->findAll('css', '#color-field-field-color button');
$this
->assertEquals(8, count($boxes));
/** @var \Behat\Mink\Element\NodeElement $box */
$box = $boxes[0];
$this
->assertEquals('#007749', $box
->getAttribute('color'));
// Only one of the fields has a default, so it is the only one that should
// have a box that is selected. This also confirms that even if the storage
// setting isn't uppercase hash prefixed hex that it still correctly selects
// the right color in the color box widget.
$active = $page
->findAll('css', 'button.color_field_widget_box__square.active');
$this
->assertEquals(1, count($active));
// Confirm that clicking the swatch sets the field value.
$box
->click();
$field = $page
->findField('field_color[0][color]');
$this
->assertEquals('#007749', $field
->getValue());
}