function FieldFieldTest::testAttachedRender

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php \Drupal\Tests\views\Kernel\Handler\FieldFieldTest::testAttachedRender()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php \Drupal\Tests\views\Kernel\Handler\FieldFieldTest::testAttachedRender()
  3. 10 core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php \Drupal\Tests\views\Kernel\Handler\FieldFieldTest::testAttachedRender()

Tests that formatter's #attached assets are correctly preserved.

See also

\Drupal\views_test_formatter\Plugin\Field\FieldFormatter\AttachmentTestFormatter::viewElements()

File

core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php, line 284

Class

FieldFieldTest
Provides some integration tests for the Field handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testAttachedRender() : void {
    $executable = Views::getView('test_field_field_attachment_test');
    $executable->execute();
    // Check that the attachments added by AttachmentTestFormatter have been
    // preserved in the render array.
    $render = $executable->display_handler
        ->render();
    $expected_attachments = [
        'library' => [
            'views/views.module',
        ],
    ];
    foreach ($this->entities as $entity) {
        $expected_attachments['library'][] = 'foo/fake_library';
        $expected_attachments['drupalSettings']['AttachmentIntegerFormatter'][$entity->id()] = $entity->id();
    }
    $this->assertEquals($expected_attachments, $render['#attached']);
}

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