function OverlayCloseTest::testNodeCreation

Tests that the overlay is correctly closed after creating a node.

File

drupal/core/modules/overlay/lib/Drupal/overlay/Tests/OverlayCloseTest.php, line 35
Contains \Drupal\overlay\Tests\OverlayCloseTest.

Class

OverlayCloseTest
Tests that the overlay can be properly closed.

Namespace

Drupal\overlay\Tests

Code

function testNodeCreation() {

  // Make sure the node creation page is considered an administrative path
  // (which will appear in the overlay).
  variable_set('node_admin_theme', TRUE);

  // Create a content type and a user who has permission to create it inside
  // the overlay.
  $this
    ->drupalCreateContentType(array(
    'type' => 'test',
    'name' => 'Test content type',
  ));
  $admin_user = $this
    ->drupalCreateUser(array(
    'access content',
    'access overlay',
    'create test content',
  ));
  $this
    ->drupalLogin($admin_user);

  // Create a new node, with ?render=overlay in the query parameter to
  // simulate creating it inside the overlay.
  $this
    ->drupalPost('node/add/test', array(
    'title' => 'Test node title',
  ), t('Save'), array(
    'query' => array(
      'render' => 'overlay',
    ),
  ));

  // Make sure a bare minimum HTML page is displayed that contains the
  // JavaScript necessary to close the overlay.
  $this
    ->assertRaw('<body class="overlay"></body>', 'An empty body tag is present on the page request after a node is created inside the overlay.');
  $this
    ->assertRaw('"closeOverlay":true', 'The JavaScript setting for closing the overlay is present on the page request after a node is created inside the overlay.');

  // Visit another page and make sure that we now see the message saying the
  // node was created (i.e., that it does not appear inside the overlay where
  // no one would have time to read it before the overlay closes).
  $this
    ->drupalGet('');
  $this
    ->assertRaw(t('!post %title has been created.', array(
    '!post' => 'Test content type',
    '%title' => 'Test node title',
  )), 'Message about the node being created is displayed on the next page request after the overlay is closed.');
}