You are here

public function ExtraFieldsTest::testExtraFieldWeight in Entity Print 8.2

Ensure the weight is correctly assigned during rendering.

File

tests/src/Kernel/ExtraFieldsTest.php, line 95

Class

ExtraFieldsTest
Tests the hook_extra_fields() implementation.

Namespace

Drupal\Tests\entity_print\Kernel

Code

public function testExtraFieldWeight() {
  $controller = NodeViewController::create($this->container);
  $renderer = $this->container
    ->get('renderer');
  $build = $controller
    ->view($this->node, 'default');
  $text = (string) $renderer
    ->renderPlain($build);
  $this
    ->assertTrue(stripos($text, 'View PDF') < stripos($text, 'body text'), 'View PDF link appears first');

  // Change the weight so the View PDF goes to the end.
  EntityViewDisplay::load('node.page.default')
    ->setComponent('entity_print_view_pdf', [
    'weight' => 10,
  ])
    ->save();
  $build = $controller
    ->view($this->node, 'default');
  $text = (string) $renderer
    ->renderPlain($build);
  $this
    ->assertTrue(stripos($text, 'View PDF') > stripos($text, 'body text'), 'View PDF link appears last');
}