diff --git a/tests/modules/entity_print_test/entity_print_test.info.yml b/tests/modules/entity_print_test/entity_print_test.info.yml index 781c79d..dbb6834 100644 --- a/tests/modules/entity_print_test/entity_print_test.info.yml +++ b/tests/modules/entity_print_test/entity_print_test.info.yml @@ -1,6 +1,5 @@ name: Entity Print Test type: module -core: 8.x package: Testing hidden: true dependencies: diff --git a/tests/src/Functional/EntityPrintAdminTest.php b/tests/src/Functional/EntityPrintAdminTest.php index 3a1f96e..cb020b7 100644 --- a/tests/src/Functional/EntityPrintAdminTest.php +++ b/tests/src/Functional/EntityPrintAdminTest.php @@ -55,61 +55,6 @@ class EntityPrintAdminTest extends BrowserTestBase { $this->drupalLogin($account); } - /** - * Test the configuration form and expected settings. - */ - public function testAdminSettings() { - $assert = $this->assertSession(); - - $this->drupalGet('/admin/config/content/entityprint'); - // The default implementation is Dompdf but that is not available in tests - // make sure its settings form is not rendered. - $assert->pageTextNotContains('Dompdf Settings'); - - // Make sure we also get a warning telling us to install it. - $assert->pageTextContains('Dompdf is not available because it is not configured. Please install with:'); - - // Ensure saving the form without any PDF engine selected doesn't blow up. - $this->drupalPostForm(NULL, [], 'Save configuration'); - - // Assert the intial config values. - $this->drupalPostForm(NULL, ['pdf' => 'testprintengine'], 'Save configuration'); - $this->drupalPostForm(NULL, ['word_docx' => 'test_word_print_engine', 'pdf' => 'testprintengine'], 'Save configuration'); - $assert->fieldValueEquals('testprintengine[test_engine_setting]', 'initial value'); - $assert->fieldValueEquals('test_word_print_engine[test_word_setting]', 'my-default'); - - // Ensure the plugin gets the chance to validate the form. - $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'); - - /** @var \Drupal\entity_print\Entity\PrintEngineStorageInterface $config_entity */ - $config_entity = \Drupal::entityTypeManager()->getStorage('print_engine')->load('testprintengine'); - // Assert the expected settings were stored. - $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()); - - // Assert that the testprintengine is actually used. - $this->drupalGet('/print/pdf/node/1'); - $assert->pageTextContains('Using testprintengine - overridden'); - } - /** * Test the view PDF extra field and the configurable text. */ diff --git a/tests/src/FunctionalJavascript/EntityPrintAdminTest.php b/tests/src/FunctionalJavascript/EntityPrintAdminTest.php new file mode 100644 index 0000000..0202783 --- /dev/null +++ b/tests/src/FunctionalJavascript/EntityPrintAdminTest.php @@ -0,0 +1,115 @@ +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); + } + + /** + * Test the configuration form and expected settings. + */ + public function testAdminSettings() { + $assert = $this->assertSession(); + + $this->drupalGet('/admin/config/content/entityprint'); + // The default implementation is Dompdf but that is not available in tests + // make sure its settings form is not rendered. + $assert->pageTextNotContains('Dompdf Settings'); + + // Make sure we also get a warning telling us to install it. + $assert->pageTextContains('Dompdf is not available because it is not configured. Please install with:'); + + // Ensure saving the form without any PDF engine selected doesn't blow up. + $this->drupalPostForm(NULL, [], 'Save configuration'); + + // Assert the intial config values. + $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'); + + // Ensure the plugin gets the chance to validate the form. + $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'); + + /** @var \Drupal\entity_print\Entity\PrintEngineStorageInterface $config_entity */ + $config_entity = \Drupal::entityTypeManager()->getStorage('print_engine')->load('testprintengine'); + // Assert the expected settings were stored. + $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()); + + // Assert that the testprintengine is actually used. + $this->drupalGet('/print/pdf/node/1'); + $assert->pageTextContains('Using testprintengine - overridden'); + } + +}