ModalPageTest.php in Modal 4.1.x
File
tests/src/Functional/ModalPageTest.php
View source
<?php
namespace Drupal\Tests\modal_page\Functional;
use Drupal\Tests\BrowserTestBase;
class ModalPageTest extends BrowserTestBase {
protected static $modules = [
'modal_page',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->createRole([], 'administrator');
$admin_user = $this
->drupalCreateUser([
'administer modal page',
'access administration pages',
]);
$admin_user
->addRole('administrator');
$admin_user
->save();
$this
->drupalLogin($admin_user);
\Drupal::configFactory()
->getEditable('system.site')
->set('page.front', '/admin')
->save();
}
public function testIfModalByPageIsLoaded() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/structure');
$assert_session
->responseContains('Thank you for installing Modal Page');
$this
->drupalGet('admin');
$assert_session
->responseNotContains('Thank you for installing Modal Page');
$modal = \Drupal::service('entity_type.manager')
->getStorage('modal')
->load('thank_you_for_installing_modal_page');
$modal
->setPages('<front>');
$modal
->save();
$this
->drupalGet('<front>');
$assert_session
->responseContains('Thank you for installing Modal Page');
$modal = \Drupal::service('entity_type.manager')
->getStorage('modal')
->load('thank_you_for_installing_modal_page');
$modal
->setPages("<front>\r\n/admin/*");
$modal
->save();
$this
->drupalGet('<front>');
$assert_session
->responseContains('Thank you for installing Modal Page');
$this
->drupalGet('admin/structure');
$assert_session
->responseContains('Thank you for installing Modal Page');
}
public function testIfModalByParameterIsLoaded() {
$assert_session = $this
->assertSession();
$modal = \Drupal::service('entity_type.manager')
->getStorage('modal')
->load('thank_you_for_installing_modal_page');
$modal
->setType('parameter');
$modal
->setParameters('welcome');
$modal
->save();
$this
->drupalGet('admin/structure');
$assert_session
->responseNotContains('Thank you for installing Modal Page');
$this
->drupalGet('admin/structure', [
'query' => [
'modal' => 'welcome',
],
]);
$assert_session
->responseContains('Thank you for installing Modal Page');
$modal = \Drupal::service('entity_type.manager')
->getStorage('modal')
->load('thank_you_for_installing_modal_page');
$modal
->setParameters("welcome\r\nwelcome_2");
$modal
->save();
$this
->drupalGet('admin/structure', [
'query' => [
'modal' => 'welcome',
],
]);
$assert_session
->responseContains('Thank you for installing Modal Page');
$this
->drupalGet('admin', [
'query' => [
'modal' => 'welcome_2',
],
]);
$assert_session
->responseContains('Thank you for installing Modal Page');
}
}