function ManageDisplayTest::assertNodeViewTextHelper
Same name in other branches
- 9 core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::assertNodeViewTextHelper()
- 8.9.x core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::assertNodeViewTextHelper()
- 10 core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_ui\Functional\ManageDisplayTest::assertNodeViewTextHelper()
Asserts that a string is (not) found in the rendered node in a view mode.
This helper function is used by assertNodeViewText() and assertNodeViewNoText().
@internal
Parameters
\Drupal\Core\Entity\EntityInterface $node: The node.
string $view_mode: The view mode in which the node should be displayed.
string $text: Plain text to look for.
string $message: Message to display.
bool $not_exists: TRUE if this text should not exist, FALSE if it should.
2 calls to ManageDisplayTest::assertNodeViewTextHelper()
- ManageDisplayTest::assertNodeViewNoText in core/
modules/ field_ui/ tests/ src/ Functional/ ManageDisplayTest.php - Asserts that a string is not found in the rendered node in a view mode.
- ManageDisplayTest::assertNodeViewText in core/
modules/ field_ui/ tests/ src/ Functional/ ManageDisplayTest.php - Asserts that a string is found in the rendered node in a view mode.
File
-
core/
modules/ field_ui/ tests/ src/ Functional/ ManageDisplayTest.php, line 345
Class
- ManageDisplayTest
- Tests the Field UI "Manage display" and "Manage form display" screens.
Namespace
Drupal\Tests\field_ui\FunctionalCode
public function assertNodeViewTextHelper(EntityInterface $node, string $view_mode, string $text, string $message, bool $not_exists) : void {
// Make sure caches on the tester side are refreshed after changes
// submitted on the tested side.
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Render a cloned node, so that we do not alter the original.
$clone = clone $node;
$element = \Drupal::entityTypeManager()->getViewBuilder('node')
->view($clone, $view_mode);
$output = (string) \Drupal::service('renderer')->renderRoot($element);
if ($not_exists) {
$this->assertStringNotContainsString((string) $text, $output, $message);
}
else {
$this->assertStringContainsString((string) $text, $output, $message);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.