1 node.test public NodeLayoutPreviewTestCase::testNodeLayoutPreview()

Tests that the correct layout is used for node add and node edit previews.

File

core/modules/node/tests/node.test, line 866
Tests for node.module.

Class

NodeLayoutPreviewTestCase
Tests that the correct layout is used for node previews.

Code

public function testNodeLayoutPreview() {

  // The node preview should use the 'custom_node' layout with path node/%.

  // Create a node to test through the admin interface.
  $this->backdropGet('node/add/' . $this->content_type->type);

  // Fill in its title and body, then select the 'Preview' option.
  $title = $this->randomName();
  $body = $this->randomName();
  $edit = array(
    'title' => $title,
    'body[und][0][value]' => $body,
  );
  $this->backdropPost(NULL, $edit, t('Preview'));

  // Look for the taylor template (only exists in our layout).
  $this->assertText('taylor', 'Layout template "taylor" found.');

  // Look for the heading of the field body block that exists only in our
  // layout.
  $this->assertText('Node body field', '"Node body field" found.');

  // Look for the heading of the custom block that exists only in our
  // layout.
  $this->assertText('Custom Node layout title', '"Custom Node layout title" found.');

  // Look for the body text, which appears only in that field if the context
  // was set properly.
  $this->assertText($body, "Body text \"{$body}\" found.");

  // Create a new node; fill in its title and body, then save.
  $this->backdropGet('node/add/' . $this->content_type->type);
  $title = $this->randomName();
  $body = $this->randomName();
  $edit = array(
    'title' => $title,
    'body[und][0][value]' => $body,
  );
  $this->backdropPost(NULL, $edit, t('Save'));

  // Edit the last node with a new random body content, then preview.
  $this->backdropGet('node/' . $this->lastNid() . '/edit');
  $body = $this->randomName();
  $edit = array(
    'body[und][0][value]' => $body,
  );
  $this->backdropPost(NULL, $edit, t('Preview'));

  // Look for the taylor template (only exists in our layout).
  $this->assertText('taylor', 'Layout template "taylor" found.');

  // Look for the heading of the field body block that exists only in our
  // layout.
  $this->assertText('Node body field', '"Node body field" found.');

  // Look for the heading of the custom block that exists only in our
  // layout.
  $this->assertText('Custom Node layout title', '"Custom Node layout title" found.');

  // Look for the body text, which appears only in that field if the context
  // was set properly.
  $this->assertText($body, "Body text \"{$body}\" found.");

  // Now enable the 'custom_node_preview' layout; give it path
  // node/preview/{$this->content_type->type}/%, and run the same tests.

  $layouts = layout_load_all();
  $preview_layout = $layouts['custom_node_preview'];
  $preview_layout->enable();
  $preview_layout->setPath('node/preview/' . $this->content_type->type . '/%');
  $preview_layout->save();

  // Create a node to test through the admin interface.
  $this->backdropGet('node/add/' . $this->content_type->type);

  // Fill in its title and body, then select the 'Preview' option.
  $title = $this->randomName();
  $body = $this->randomName();
  $edit = array(
    'title' => $title,
    'body[und][0][value]' => $body,
  );
  $this->backdropPost(NULL, $edit, t('Preview'));

  // Look for the sutro template (only exists in our layout).
  $this->assertText('sutro', 'Layout template "sutro" found.');

  // Look for the heading of the custom block that exists only in our
  // layout.
  $this->assertText('Custom Node Preview layout title', '"Custom Node Preview layout title" found.');

  // Look for the body text, which appears only in that field if the context
  // was set properly.
  $this->assertText($body, "Body text \"{$body}\" found.");

  // Create a new node; fill in its title and body, then save.
  $this->backdropGet('node/add/' . $this->content_type->type);
  $title = $this->randomName();
  $body = $this->randomName();
  $edit = array(
    'title' => $title,
    'body[und][0][value]' => $body,
  );
  $this->backdropPost(NULL, $edit, t('Save'));

  // Edit the last node with a new random body content, then preview.
  $this->backdropGet('node/' . $this->lastNid() . '/edit');
  $body = $this->randomName();
  $edit = array(
    'body[und][0][value]' => $body,
  );
  $this->backdropPost(NULL, $edit, t('Preview'));

  // Look for the sutro template (only exists in our layout).
  $this->assertText('sutro', 'Layout template "sutro" found.');

  // Look for the heading of the custom block that exists only in our
  // layout.
  $this->assertText('Custom Node Preview layout title', '"Custom Node Preview layout title" found.');

  // Look for the body text, which appears only in that field if the context
  // was set properly.
  $this->assertText($body, "Body text \"{$body}\" found.");


}