function 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\HandlerCode
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']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.