You are here

public function ColorFieldFormatterTest::testColorFieldFormatterCss in Color Field 8.2

Test color_field_formatter_css formatter.

File

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

Class

ColorFieldFormatterTest
Tests color field formatters.

Namespace

Drupal\Tests\color_field\Functional

Code

public function testColorFieldFormatterCss() {
  $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_css',
    'weight' => 1,
    'label' => 'hidden',
  ])
    ->save();

  // Test default options.
  $edit = [
    'title[0][value]' => $this
      ->randomMachineName(),
    'field_color[0][color]' => "#FFF430",
    'field_color[0][opacity]' => 0.9,
  ];
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save'));
  $this
    ->assertSession()
    ->responseContains('body { background-color: rgba(255,244,48,0.9) !important; }');

  // Test without opacity and not important.
  $edit = [
    'title[0][value]' => $this
      ->randomMachineName(),
    'field_color[0][color]' => "#FFFFFF",
    'field_color[0][opacity]' => 1,
  ];
  $this->display
    ->setComponent('field_color', [
    'type' => 'color_field_formatter_css',
    'weight' => 1,
    'settings' => [
      'selector' => 'body',
      'property' => 'background-color',
      'important' => FALSE,
      'opacity' => FALSE,
    ],
    'label' => 'hidden',
  ])
    ->save();
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save'));
  $this
    ->assertSession()
    ->responseContains('body { background-color: rgb(255,255,255); }');
}