You are here

public function ColorFieldWidgetTest::testColorFieldWidgetHtml5 in Color Field 8.2

Test color_field_widget_html5.

File

tests/src/Functional/ColorFieldWidgetTest.php, line 15

Class

ColorFieldWidgetTest
Tests color field widgets.

Namespace

Drupal\Tests\color_field\Functional

Code

public function testColorFieldWidgetHtml5() {
  $this->form
    ->setComponent('field_color', [
    'type' => 'color_field_widget_html5',
  ])
    ->save();
  $this->display
    ->setComponent('field_color', [
    'type' => 'color_field_formatter_text',
    'weight' => 1,
  ])
    ->save();
  $session = $this
    ->assertSession();

  // Confirm field label and description are rendered.
  $this
    ->drupalGet('node/add/article');
  $session
    ->fieldExists("field_color[0][color]");
  $session
    ->fieldExists("field_color[0][opacity]");
  $session
    ->responseContains('Freeform Color');
  $session
    ->responseContains('Color field description');

  // Test basic entry of color field.
  $edit = [
    'title[0][value]' => $this
      ->randomMachineName(),
    'field_color[0][color]' => "#E70000",
    'field_color[0][opacity]' => 1,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $session
    ->responseContains('#E70000 1</div>');
}