View source
<?php
namespace Drupal\entity_print\Tests;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\simpletest\WebTestBase;
class EntityPrintAdminTest extends WebTestBase {
public static $modules = [
'node',
'entity_print_test',
'field',
'field_ui',
];
protected $node;
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType(array(
'type' => 'page',
'name' => 'Page',
));
$this->node = $this
->drupalCreateNode();
$account = $this
->drupalCreateUser([
'bypass entity print access',
'administer entity print',
'access content',
'administer content types',
'administer node display',
]);
$this
->drupalLogin($account);
}
public function testAdminSettings() {
$this
->drupalGet('/admin/config/content/entityprint');
$this
->assertNoText('Dompdf Settings');
$this
->assertText('Dompdf is not available because it is not configured. Please install using composer.');
$this
->drupalPostForm(NULL, [], 'Save configuration');
$this
->drupalPostAjaxForm(NULL, [
'pdf_engine' => 'testpdfengine',
], 'pdf_engine');
$this
->assertFieldByName('test_engine_setting', 'initial value');
$this
->drupalPostForm(NULL, [
'pdf_engine' => 'testpdfengine',
'test_engine_setting' => 'rejected',
], 'Save configuration');
$this
->assertText('Setting has an invalid value');
$this
->drupalPostForm(NULL, [
'default_css' => 0,
'force_download' => 0,
'pdf_engine' => 'testpdfengine',
'test_engine_setting' => 'testvalue',
], 'Save configuration');
$config_entity = \Drupal::entityTypeManager()
->getStorage('pdf_engine')
->load('testpdfengine');
$this
->assertEqual('testpdfengine', $config_entity
->id());
$this
->assertEqual([
'test_engine_setting' => 'testvalue',
'test_engine_suffix' => 'overridden',
], $config_entity
->getSettings());
$this
->assertEqual('entity_print_test', $config_entity
->getDependencies()['module'][0]);
$this
->drupalGet('/entityprint/node/1');
$this
->assertText('Using testpdfengine - overridden');
}
public function testViewPdfLink() {
module_load_install('entity_print');
entity_print_install();
$this
->drupalGet($this->node
->toUrl());
$this
->assertNoText('View PDF');
$this
->assertNoLinkByHref('entityprint/node/1');
$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');
$this
->drupalGet($this->node
->toUrl());
$this
->assertLink($random_text);
$this
->assertLinkByHref('/entityprint/node/1');
$this
->drupalGet('/entityprint/node/1/debug');
$this
->assertRaw('node--view-mode-full');
$this
->assertNoRaw('node--view-mode-pdf');
$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');
$this
->drupalGet('/entityprint/node/1/debug');
$this
->assertRaw('node--view-mode-pdf');
$this
->assertNoRaw('node--view-mode-full');
$display = EntityViewDisplay::load('node.page.default');
$this
->assertIdentical($random_text, $display
->getThirdPartySetting('entity_print', 'label'));
}
}