public function LinkAllyFormatterTest::testLinkAllyFormatterStringField in Element Class Formatter 8
Test formatter with string field.
@dataProvider providerLinkText
File
- tests/
src/ Functional/ LinkAllyFormatterTest.php, line 56
Class
- LinkAllyFormatterTest
- Defines a class for testing LinkAllyFormatter.
Namespace
Drupal\Tests\element_class_formatter\FunctionalCode
public function testLinkAllyFormatterStringField(string $link_text = NULL, string $wrapper = '') {
$field_config = $this
->createEntityField('link_ally_class', 'string', [
'class' => self::TEST_CLASS,
'link_text' => $link_text,
'screenreader_text' => 'about [entity_test:name]',
'tag' => $wrapper,
]);
$field_value = $this
->randomMachineName();
$entity = EntityTest::create([
$field_config
->getName() => $field_value,
]);
$entity
->save();
$this
->drupalGet($entity
->toUrl());
$assert_session = $this
->assertSession();
$selector = 'a.' . self::TEST_CLASS;
if ($wrapper) {
$selector = "{$wrapper} {$selector}";
}
$element = $assert_session
->elementExists('css', $selector);
$assert_session
->elementTextContains('css', $selector, $link_text ?: $field_value);
$assert_session
->elementExists('css', sprintf('span.visually-hidden:contains("about %s")', $entity
->label()), $element);
}