View source
<?php
namespace Drupal\Tests\entity_print\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class EntityPrintAdminTest extends WebDriverTestBase {
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 testAdminSettings() {
$assert = $this
->assertSession();
$this
->drupalGet('/admin/config/content/entityprint');
$assert
->pageTextNotContains('Dompdf Settings');
$assert
->pageTextContains('Dompdf is not available because it is not configured. Please install with:');
$this
->drupalPostForm(NULL, [], 'Save configuration');
$this
->getSession()
->getPage()
->fillField('pdf', 'testprintengine');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->getPage()
->fillField('word_docx', 'test_word_print_engine');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$assert
->fieldValueEquals('testprintengine[test_engine_setting]', 'initial value');
$assert
->fieldValueEquals('test_word_print_engine[test_word_setting]', 'my-default');
$this
->drupalPostForm(NULL, [
'pdf' => 'testprintengine',
'word_docx' => 'test_word_print_engine',
'testprintengine[test_engine_setting]' => 'rejected',
], 'Save configuration');
$assert
->pageTextContains('Setting has an invalid value');
$this
->drupalPostForm(NULL, [
'default_css' => 0,
'force_download' => 0,
'pdf' => 'testprintengine',
'word_docx' => 'test_word_print_engine',
'test_word_print_engine[test_word_setting]' => 'test word setting',
'testprintengine[test_engine_setting]' => 'testvalue',
], 'Save configuration');
$config_entity = \Drupal::entityTypeManager()
->getStorage('print_engine')
->load('testprintengine');
$this
->assertEquals('testprintengine', $config_entity
->id());
$this
->assertEquals([
'test_engine_setting' => 'testvalue',
'test_engine_suffix' => 'overridden',
], $config_entity
->getSettings());
$this
->assertEquals('entity_print_test', $config_entity
->getDependencies()['module'][0]);
$config_entity = \Drupal::entityTypeManager()
->getStorage('print_engine')
->load('test_word_print_engine');
$this
->assertEquals([
'test_word_setting' => 'test word setting',
], $config_entity
->getSettings());
$this
->drupalGet('/print/pdf/node/1');
$assert
->pageTextContains('Using testprintengine - overridden');
}
}