You are here

public function PrintableLinkTest::testPrintLinkExists in Printer and PDF versions for Drupal 8+ 8

Same name and namespace in other branches
  1. 2.x src/Tests/PrintableLinkTest.php \Drupal\printable\Tests\PrintableLinkTest::testPrintLinkExists()

Tests that the links are rendered correctly in the page.

File

src/Tests/PrintableLinkTest.php, line 38

Class

PrintableLinkTest
Tests the printable module functionality.

Namespace

Drupal\printable\Tests

Code

public function testPrintLinkExists() {
  $this
    ->drupalGet('admin/config/user-interface/printable/links');
  $this
    ->assertResponse(200);

  // Enable the print link in content area.
  $this
    ->drupalPostForm(NULL, [
    'print_print_link_pos' => 'node',
  ], t('Submit'));
  $this
    ->drupalGet('admin/config/user-interface/printable/pdf');
  $this
    ->assertResponse(200);
  $node_type_storage = \Drupal::entityManager()
    ->getStorage('node_type');

  // Test /node/add page with only one content type.
  $node_type_storage
    ->load('article')
    ->delete();
  $this
    ->drupalGet('node/add');

  // Create a node.
  $edit = [];
  $edit['title[0][value]'] = $this
    ->randomMachineName(8);
  $edit['body[0][value]'] = $this
    ->randomMachineName(16);
  $this
    ->drupalPostForm('node/add/page', $edit, t('Save'));

  // Check that the Basic page has been created.
  $this
    ->assertRaw(t('!post %title has been created.', [
    '!post' => 'Basic page',
    '%title' => $edit['title[0][value]'],
  ]), 'Basic page created.');

  // Check that the node exists in the database.
  $node = $this
    ->drupalGetNodeByTitle($edit['title[0][value]']);
  $this
    ->assertTrue($node, 'Node found in database.');

  // Verify that pages do not show submitted information by default.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertResponse(200);
  $this
    ->assertRaw('Print', 'Print link discovered successfully in the printable page');
}