protected function NodeDisplayConfigurableTest::assertNodeHtml in Drupal 9
Asserts that the node HTML is as expected.
Parameters
\Drupal\node\NodeInterface $node: The node being tested.
\Drupal\user\UserInterface $user: The logged in user.
string $html_element: Either 'div' or 'span'
string $metadata_region: The region of the node html content where meta data is expected.
bool $field_classes: If TRUE, check for field--name-XXX classes.
1 call to NodeDisplayConfigurableTest::assertNodeHtml()
- NodeDisplayConfigurableTest::testDisplayConfigurable in core/
modules/ node/ tests/ src/ Functional/ NodeDisplayConfigurableTest.php - Sets base fields to configurable display and check settings are respected.
File
- core/
modules/ node/ tests/ src/ Functional/ NodeDisplayConfigurableTest.php, line 117
Class
- NodeDisplayConfigurableTest
- Tests making node base fields' displays configurable.
Namespace
Drupal\Tests\node\FunctionalCode
protected function assertNodeHtml(NodeInterface $node, UserInterface $user, string $html_element, string $metadata_region, bool $field_classes) {
$assert = $this
->assertSession();
$title_selector = 'h1 span' . ($field_classes ? '.field--name-title' : '') . '[data-quickedit-field-id="node/1/title/en/full"]';
$created_selector = 'article[data-quickedit-entity-id="node/1"] ' . $html_element . ($field_classes ? '.field--name-created' : '') . '[data-quickedit-field-id="node/1/created/en/full"]';
$uid_selector = 'article[data-quickedit-entity-id="node/1"] ' . $html_element . ($field_classes ? '.field--name-uid' : '') . '[data-quickedit-field-id="node/1/uid/en/full"]';
$assert
->elementTextContains('css', $title_selector, $node
->getTitle());
$assert
->elementTextContains('css', $created_selector, \Drupal::service('date.formatter')
->format($node
->getCreatedTime()));
if ($html_element === 'div') {
$assert
->elementTextContains('css', "{$uid_selector} {$html_element}" . '[rel="schema:author"]', $user
->getAccountName());
$assert
->elementNotExists('css', "{$uid_selector} a");
$assert
->elementTextContains('css', "{$uid_selector} {$html_element}", 'Authored by');
$assert
->elementExists('css', 'span[property="schema:dateCreated"]');
}
else {
$assert
->elementTextContains('css', $uid_selector . ' a[property="schema:name"]', $user
->getAccountName());
$assert
->elementTextContains('css', 'article[data-quickedit-entity-id="node/1"] ' . $metadata_region, 'Submitted by');
}
}