View source
<?php
namespace Drupal\Tests\page_manager_ui\FunctionalJavascript;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\page_manager\Entity\Page;
class PageManagerAdminTest extends WebDriverTestBase {
protected $defaultTheme = 'classy';
public static $modules = [
'block',
'page_manager_ui',
'page_manager_test',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('local_actions_block');
$this
->drupalPlaceBlock('system_branding_block');
$this
->drupalPlaceBlock('page_title_block');
\Drupal::service('theme_installer')
->install([
'bartik',
]);
$this
->config('system.theme')
->set('admin', 'classy')
->save();
$this
->drupalLogin($this
->drupalCreateUser([
'administer pages',
'access administration pages',
'view the administration theme',
]));
Page::load('node_view')
->delete();
}
public function testAdmin() {
$this
->doTestAddPage();
$this
->doTestSelectionCriteriaWithAjax();
}
protected function doTestAddPage() {
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/structure');
$this
->clickLink('Pages');
$assert_session
->pageTextContains('Add a new page.');
$this
->clickLink('Add page');
$this
->getSession()
->getPage()
->fillField('label', 'Foo');
$this
->assertNotEmpty($assert_session
->waitForText('Machine name: foo'));
$edit = [
'path' => 'admin/foo',
'variant_plugin_id' => 'http_status_code',
'use_admin_theme' => TRUE,
'description' => 'This is our first test page.',
'wizard_options[access]' => TRUE,
'wizard_options[selection]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Next');
$this
->assertTitle('Page access | Drupal');
$access_path = 'admin/structure/page_manager/add/foo/access';
$this
->assertUrl($access_path . '?js=nojs');
$this
->drupalPostForm(NULL, [], 'Next');
$this
->assertTitle('Selection criteria | Drupal');
$selection_path = 'admin/structure/page_manager/add/foo/selection';
$this
->assertUrl($selection_path . '?js=nojs');
$this
->drupalPostForm(NULL, [], 'Next');
$edit = [
'page_variant_label' => 'Status Code',
'variant_settings[status_code]' => 200,
];
$this
->drupalPostForm(NULL, $edit, 'Finish');
$this
->assertRaw(new FormattableMarkup('The page %label has been added.', [
'%label' => 'Foo',
]));
$this
->drupalGet('admin/structure/page_manager/manage/foo/general');
$this
->drupalGet('admin/foo');
$this
->assertTitle('Foo | Drupal');
$this
->drupalGet('admin/structure/page_manager/manage/foo/page_variant__foo-http_status_code-0__general');
$edit = [
'variant_settings[status_code]' => 403,
];
$this
->drupalPostForm(NULL, $edit, 'Update and save');
}
protected function assertTitle($expected_title) {
$actual_title = $this
->assertSession()
->elementExists('css', 'title')
->getHtml();
$this
->assertSame($expected_title, $actual_title);
}
protected function doTestSelectionCriteriaWithAjax() {
$page = $this
->getSession()
->getPage();
$this
->drupalGet('admin/structure/page_manager/manage/foo/page_variant__foo-http_status_code-0__selection');
$page
->selectFieldOption('conditions', 'user_role');
$page
->pressButton('Add Condition');
$this
->assertNotEmpty($this
->assertSession()
->waitForText('Configure Required Context'));
}
}