public function EntityReferenceLabelClassFormatterTest::testClassFormatter in Element Class Formatter 8
Tests element reference label class formatter.
@dataProvider providerFormatterCases
File
- tests/
src/ Functional/ EntityReferenceLabelClassFormatterTest.php, line 21
Class
- EntityReferenceLabelClassFormatterTest
- Functional tests for the entity reference label with class formatter.
Namespace
Drupal\Tests\element_class_formatter\FunctionalCode
public function testClassFormatter($link = TRUE, $tag = 'a') {
$formatter_settings = [
'class' => self::TEST_CLASS,
'tag' => 'div',
'link' => $link,
];
$field_config = $this
->createEntityField('entity_reference_label_class', 'entity_reference', $formatter_settings);
$referenced_node = $this
->drupalCreateNode([
'type' => 'referenced_content',
]);
$referenced_node2 = $this
->drupalCreateNode([
'type' => 'referenced_content',
'status' => 0,
]);
$entity = EntityTest::create([
$field_config
->getName() => [
$referenced_node,
$referenced_node2,
],
]);
$entity
->save();
$this
->drupalGet($entity
->toUrl());
$assert_session = $this
->assertSession();
$assert_session
->elementExists('css', $tag . '.' . self::TEST_CLASS);
$assert_session
->pageTextContains($referenced_node
->label());
$assert_session
->pageTextNotContains($referenced_node2
->label());
}