You are here

protected function PageManagerAdminTest::doTestAddPage in Page Manager 8

Tests adding a page.

1 call to PageManagerAdminTest::doTestAddPage()
PageManagerAdminTest::testAdmin in page_manager_ui/src/Tests/PageManagerAdminTest.php
Tests the Page Manager admin UI.

File

page_manager_ui/src/Tests/PageManagerAdminTest.php, line 77
Contains \Drupal\page_manager_ui\Tests\PageManagerAdminTest.

Class

PageManagerAdminTest
Tests the admin UI for page entities.

Namespace

Drupal\page_manager_ui\Tests

Code

protected function doTestAddPage() {
  $this
    ->drupalGet('admin/structure');
  $this
    ->clickLink('Pages');
  $this
    ->assertText('Add a new page.');

  // Add a new page without a label.
  $this
    ->clickLink('Add page');
  $edit = [
    'id' => 'foo',
    'path' => 'admin/foo',
    'variant_plugin_id' => 'http_status_code',
    'use_admin_theme' => TRUE,
    'description' => 'This is our first test page.',
    // Go through all available steps (we skip them all in doTestSecondPage())
    'wizard_options[access]' => TRUE,
    'wizard_options[selection]' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Next');
  $this
    ->assertText('Administrative title field is required.');

  // Add a new page with a label.
  $edit += [
    'label' => 'Foo',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Next');

  // Test the 'Page access' step.
  $this
    ->assertTitle('Page access | Drupal');
  $access_path = 'admin/structure/page_manager/add/foo/access';
  $this
    ->assertUrl($access_path . '?js=nojs');
  $this
    ->doTestAccessConditions($access_path, FALSE);
  $this
    ->drupalPostForm(NULL, [], 'Next');

  // Test the 'Selection criteria' step.
  $this
    ->assertTitle('Selection criteria | Drupal');
  $selection_path = 'admin/structure/page_manager/add/foo/selection';
  $this
    ->assertUrl($selection_path . '?js=nojs');
  $this
    ->doTestSelectionCriteria($selection_path, FALSE);
  $this
    ->drupalPostForm(NULL, [], 'Next');

  // Configure the variant.
  $edit = [
    'page_variant_label' => 'Status Code',
    'variant_settings[status_code]' => 200,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Finish');
  $this
    ->assertRaw(new FormattableMarkup('Saved the %label Page.', [
    '%label' => 'Foo',
  ]));

  // We've gone from the add wizard to the edit wizard.
  $this
    ->drupalGet('admin/structure/page_manager/manage/foo/general');
  $this
    ->drupalGet('admin/foo');
  $this
    ->assertResponse(200);
  $this
    ->assertTitle('Foo | Drupal');

  // Change the status code to 403.
  $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');

  // Set the weight of the 'Status Code' variant to 10.
  $this
    ->drupalGet('admin/structure/page_manager/manage/foo/reorder_variants');
  $edit = [
    'variants[foo-http_status_code-0][weight]' => 10,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Update');
  $this
    ->drupalPostForm(NULL, [], 'Update and save');
}