Same name and namespace in other branches
  1. 8.x-2.x tests/src/Functional/ColorFieldFormatterTest.php \Drupal\Tests\color_field\Functional\ColorFieldFormatterTest::testColorFieldFormatterCss() 1 comment

Test color_field_formatter_css formatter.

File

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

Class

ColorFieldFormatterTest
Tests color field formatters.

Namespace

Drupal\Tests\color_field\Functional

Code

public function testColorFieldFormatterCss() : void {
    $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->drupalGet('node/add/article');
    $this->submitForm($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->drupalGet('node/add/article');
    $this->submitForm($edit, t('Save'));
    $this->assertSession()
        ->responseContains('body { background-color: rgb(255,255,255); }');
}