View source
<?php
namespace Drupal\Tests\entity_print\Functional;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Tests\BrowserTestBase;
class EntityPrintAdminTest extends BrowserTestBase {
public static $modules = [
'node',
'entity_print_test',
'field',
'field_ui',
];
protected $defaultTheme = 'stark';
protected $node;
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
]);
$this->node = $this
->drupalCreateNode();
$account = $this
->createUser([
'bypass entity print access',
'administer entity print',
'access content',
'administer content types',
'administer node display',
'administer user display',
]);
$this
->drupalLogin($account);
}
public function testViewPdfLink() {
$assert = $this
->assertSession();
module_load_install('entity_print');
entity_print_install();
$this
->drupalGet($this->node
->toUrl());
$assert
->pageTextNotContains('View PDF');
$assert
->linkByHrefNotExists('print/pdf/node/1');
$full_view_mode = 'Full view mode';
$pdf_view_mode = 'PDF view mode';
$this
->drupalPostForm('admin/structure/types/manage/page/display', [
'fields[entity_print_view_pdf][empty_cell]' => $full_view_mode,
'fields[entity_print_view_pdf][region]' => 'content',
], 'Save');
$this
->drupalGet($this->node
->toUrl());
$assert
->linkExists($full_view_mode);
$assert
->linkByHrefExists('/print/pdf/node/1');
$this
->drupalGet('/print/pdf/node/1/debug');
$assert
->pageTextContains($full_view_mode);
$assert
->pageTextNotContains($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_pdf][empty_cell]' => $pdf_view_mode,
'fields[entity_print_view_pdf][region]' => 'content',
], 'Save');
$this
->drupalGet('/print/pdf/node/1/debug');
$assert
->pageTextNotContains($full_view_mode);
$assert
->pageTextContains($pdf_view_mode);
$display = EntityViewDisplay::load('node.page.default');
$this
->assertSame($full_view_mode, $display
->getThirdPartySetting('entity_print', 'pdf_label'));
$this
->drupalGet('/admin/config/people/accounts/display');
$assert
->pageTextContains('View PDF');
}
}