You are here

public function EntityPrintAdminTest::testViewPdfLink in Entity Print 8

Test the view PDF extra field and the configurable text.

File

src/Tests/EntityPrintAdminTest.php, line 94

Class

EntityPrintAdminTest
Entity Print Admin tests.

Namespace

Drupal\entity_print\Tests

Code

public function testViewPdfLink() {

  // Run the module install actions as a workaround for the fact that the
  // page content type isn't created until setUp() here and therefore our PDF
  // view mode isn't added the first time. Note, this might causes issues if
  // we ever add to hook_install() actions that cannot run twice.
  module_load_install('entity_print');
  entity_print_install();

  // Ensure the link doesn't appear by default.
  $this
    ->drupalGet($this->node
    ->toUrl());
  $this
    ->assertNoText('View PDF');
  $this
    ->assertNoLinkByHref('entityprint/node/1');

  // Save the default display with custom text.
  $random_text = $this
    ->randomMachineName();
  $this
    ->drupalPostForm('admin/structure/types/manage/page/display', [
    'fields[entity_print_view][empty_cell]' => $random_text,
    'fields[entity_print_view][region]' => 'content',
  ], 'Save');

  // Visit our page node and ensure the link is available.
  $this
    ->drupalGet($this->node
    ->toUrl());
  $this
    ->assertLink($random_text);
  $this
    ->assertLinkByHref('/entityprint/node/1');

  // Ensure we're using the full view mode and not the PDF view mode.
  $this
    ->drupalGet('/entityprint/node/1/debug');
  $this
    ->assertRaw('node--view-mode-full');
  $this
    ->assertNoRaw('node--view-mode-pdf');

  // Configure the PDF view mode.
  $this
    ->drupalPostForm('admin/structure/types/manage/page/display', [
    'display_modes_custom[pdf]' => 1,
  ], 'Save');
  $this
    ->drupalPostForm('admin/structure/types/manage/page/display/pdf', [
    'fields[entity_print_view][empty_cell]' => $random_text,
    'fields[entity_print_view][region]' => 'content',
  ], 'Save');

  // Ensure the PDF view mode is now in use.
  $this
    ->drupalGet('/entityprint/node/1/debug');
  $this
    ->assertRaw('node--view-mode-pdf');
  $this
    ->assertNoRaw('node--view-mode-full');

  // Load the EntityViewDisplay and ensure the settings are in the correct
  // place.

  /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $display */
  $display = EntityViewDisplay::load('node.page.default');
  $this
    ->assertIdentical($random_text, $display
    ->getThirdPartySetting('entity_print', 'label'));
}