You are here

public function FieldFieldTest::testAttachedRender in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php \Drupal\Tests\views\Kernel\Handler\FieldFieldTest::testAttachedRender()
  2. 9 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 279

Class

FieldFieldTest
Provides some integration tests for the Field handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testAttachedRender() {
  $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']);
}