You are here

public function ColorFieldFormatterTest::testColorFieldFormatterSwatch in Color Field 8.2

Test color_field_formatter_swatch formatter.

File

tests/src/Functional/ColorFieldFormatterTest.php, line 109

Class

ColorFieldFormatterTest
Tests color field formatters.

Namespace

Drupal\Tests\color_field\Functional

Code

public function testColorFieldFormatterSwatch() {
  $this->form
    ->setComponent('field_color', [
    'type' => 'color_field_widget_default',
    'settings' => [
      'placeholder_color' => '#ABC123',
      'placeholder_opacity' => '1.0',
    ],
  ])
    ->save();
  $this->display
    ->setComponent('field_color', [
    'type' => 'color_field_formatter_swatch',
    'weight' => 1,
    'label' => 'hidden',
  ])
    ->save();

  // Test square with opacity.
  $edit = [
    'title[0][value]' => $this
      ->randomMachineName(),
    'field_color[0][color]' => "#0044FF",
    'field_color[0][opacity]' => 0.9,
  ];
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save'));
  $this
    ->assertSession()
    ->responseContains('background-color: rgba(0,68,255,0.9)');
  $this
    ->assertSession()
    ->responseContains('color_field__swatch--square');

  // Test circle without opacity.
  $edit = [
    'title[0][value]' => $this
      ->randomMachineName(),
    'field_color[0][color]' => "#760089",
    'field_color[0][opacity]' => 1,
  ];
  $this->display
    ->setComponent('field_color', [
    'type' => 'color_field_formatter_swatch',
    'weight' => 1,
    'settings' => [
      'shape' => 'circle',
      'opacity' => FALSE,
    ],
  ])
    ->save();
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save'));
  $this
    ->assertSession()
    ->responseContains('background-color: rgb(118,0,137)');
  $this
    ->assertSession()
    ->responseContains('color_field__swatch--circle');
}