function RowEntityRenderersTest::assertTranslations

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php \Drupal\Tests\views\Kernel\Entity\RowEntityRenderersTest::assertTranslations()
  2. 8.9.x core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php \Drupal\Tests\views\Kernel\Entity\RowEntityRenderersTest::assertTranslations()
  3. 11.x core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php \Drupal\Tests\views\Kernel\Entity\RowEntityRenderersTest::assertTranslations()

Checks that the view results match the expected values.

@internal

Parameters

string $display: Name of display to test with.

string $renderer_id: The id of the renderer to be tested.

array $expected: An array of expected title translation values, one for each result row.

string $message: (optional) A message to display with the assertion.

2 calls to RowEntityRenderersTest::assertTranslations()
RowEntityRenderersTest::checkLanguageRenderers in core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php
Checks that the language renderer configurations work as expected.
RowEntityRenderersTest::checkLanguageRenderersRelationship in core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php
Checks language renderer configurations work with relationships.

File

core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php, line 378

Class

RowEntityRenderersTest
Tests the entity row renderers.

Namespace

Drupal\Tests\views\Kernel\Entity

Code

protected function assertTranslations(string $display, string $renderer_id, array $expected, string $message = '') : void {
    $view = Views::getView('test_entity_row_renderers');
    $view->storage
        ->invalidateCaches();
    $view->setDisplay($display);
    $view->getDisplay()
        ->setOption('rendering_language', $renderer_id);
    $view->preview();
    $result = FALSE;
    foreach ($expected as $index => $expected_output) {
        if (!empty($view->result[$index])) {
            $build = $view->rowPlugin
                ->render($view->result[$index]);
            $output = (string) \Drupal::service('renderer')->renderRoot($build);
            $result = str_contains($output, $expected_output);
            if (!$result) {
                break;
            }
        }
        else {
            $result = FALSE;
            break;
        }
    }
    $this->assertTrue($result, $message);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.