Same name and namespace in other branches
- 8.x-2.x tests/src/Functional/ColorFieldFormatterTest.php \Drupal\Tests\color_field\Functional\ColorFieldFormatterTest::testColorFieldFormatterSwatch() 1 comment
Test color_field_formatter_swatch formatter.
File
-
tests/
src/ Functional/ ColorFieldFormatterTest.php, line 114
Class
- ColorFieldFormatterTest
- Tests color field formatters.
Namespace
Drupal\Tests\color_field\FunctionalCode
public function testColorFieldFormatterSwatch() : 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_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->drupalGet('node/add/article');
$this->submitForm($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->drupalGet('node/add/article');
$this->submitForm($edit, t('Save'));
$this->assertSession()
->responseContains('background-color: rgb(118,0,137)');
$this->assertSession()
->responseContains('color_field__swatch--circle');
}