Same name and namespace in other branches
- 8.x-2.x tests/src/Functional/ColorFieldFormatterTokenTest.php \Drupal\Tests\color_field\Functional\ColorFieldFormatterTokenTest 1 comment
Tests color field formatters.
@group color_field
Hierarchy
- class \Drupal\Tests\color_field\Functional\ColorFieldFunctionalTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\color_field\Functional\ColorFieldFormatterTokenTest extends \Drupal\Tests\color_field\Functional\ColorFieldFunctionalTestBase
Expanded class hierarchy of ColorFieldFormatterTokenTest
File
-
tests/
src/ Functional/ ColorFieldFormatterTokenTest.php, line 15
Namespace
Drupal\Tests\color_field\FunctionalView source
class ColorFieldFormatterTokenTest extends ColorFieldFunctionalTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'field',
'node',
'color_field',
'token',
];
/**
* Test color_field_formatter_css formatter.
*/
public function testTokens() : void {
$this->form
->setComponent('field_color', [
'type' => 'color_field_widget_default',
])
->save();
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_color[0][color]' => "#9C59D1",
'field_color[0][opacity]' => 0.95,
];
$this->display
->setComponent('field_color', [
'type' => 'color_field_formatter_css',
'weight' => 1,
'settings' => [
'selector' => '.node-[node:content-type]',
'property' => 'background-color',
'important' => FALSE,
'opacity' => TRUE,
],
'label' => 'hidden',
])
->save();
$this->drupalGet('node/add/article');
$this->submitForm($edit, t('Save'));
$this->assertSession()
->responseContains('.node-article { background-color: rgba(156,89,209,0.95); }');
// Ensure 2 fields on the same entity are both rendered properly.
FieldStorageConfig::create([
'field_name' => 'field_text_color',
'entity_type' => 'node',
'type' => 'color_field_type',
])->save();
FieldConfig::create([
'field_name' => 'field_text_color',
'label' => 'Text Color',
'entity_type' => 'node',
'bundle' => 'article',
])->save();
$this->display
->setComponent('field_text_color', [
'type' => 'color_field_formatter_css',
'weight' => 1,
'settings' => [
'selector' => '.node-[node:content-type]',
'property' => 'color',
'important' => FALSE,
'opacity' => TRUE,
],
'label' => 'hidden',
])
->save();
$this->form
->setComponent('field_text_color', [
'type' => 'color_field_widget_default',
])
->save();
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_color[0][color]' => "#000000",
'field_color[0][opacity]' => 0.1,
'field_text_color[0][color]' => "#000000",
'field_text_color[0][opacity]' => 1,
];
$this->drupalGet('node/add/article');
$this->submitForm($edit, t('Save'));
$this->assertSession()
->responseContains('.node-article { background-color: rgba(0,0,0,0.1); }');
$this->assertSession()
->responseContains('.node-article { color: rgba(0,0,0,1); }');
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ColorFieldFormatterTokenTest::$modules | protected static | property | Modules to enable. | Overrides ColorFieldFunctionalTestBase::$modules |
ColorFieldFormatterTokenTest::testTokens | public | function | Test color_field_formatter_css formatter. | |
ColorFieldFunctionalTestBase::$defaultTheme | protected | property | ||
ColorFieldFunctionalTestBase::$display | protected | property | The Entity View Display for the article node type. | |
ColorFieldFunctionalTestBase::$form | protected | property | The Entity Form Display for the article node type. | |
ColorFieldFunctionalTestBase::setUp | protected | function |