You are here

function EditableViewsBasicWebTestCase::testNodeTitleView in Editable Views 7

Test basic node view 'test_editable_views_node_title'.

File

tests/editableviews.test, line 42
Tests for editableviews.module.

Class

EditableViewsBasicWebTestCase
Test simple editable views with no editable fields on relationships.

Code

function testNodeTitleView() {
  $first_node_title = $this
    ->randomName();
  $first_node = $this
    ->drupalCreateNode(array(
    'title' => $first_node_title,
    'type' => 'editable_views_test_node',
  ));
  $second_node_title = $this
    ->randomName();
  $second_node = $this
    ->drupalCreateNode(array(
    'title' => $second_node_title,
    'type' => 'editable_views_test_node',
  ));

  // Look at the node title editable view.
  $this
    ->drupalGet('test-editable-views-node-title');

  // Check both nodes are shown in the view form.
  $first_node_title_element_name = "node[{$first_node->nid}][title]";
  $this
    ->assertFieldByName($first_node_title_element_name, $first_node_title, t("View shows an edit form for the first node's title."));
  $second_node_title_element_name = "node[{$second_node->nid}][title]";
  $this
    ->assertFieldByName($second_node_title_element_name, $second_node_title, t("View shows an edit form for the second node's title."));

  // Save the form with changes to both nodes.
  $edit = array(
    $first_node_title_element_name => $this
      ->randomName(),
    $second_node_title_element_name => $this
      ->randomName(),
  );
  $this
    ->drupalPost('test-editable-views-node-title', $edit, t('Save'));

  // Load the nodes again and check their titles have changed.
  entity_get_controller('node')
    ->resetCache();
  $first_node = node_load($first_node->nid);
  $second_node = node_load($second_node->nid);
  $this
    ->assertEqual($first_node->title, $edit[$first_node_title_element_name], t("The first node's title has been changed by saving the editable view."));
  $this
    ->assertEqual($second_node->title, $edit[$second_node_title_element_name], t("The second node's title has been changed by saving the editable view."));

  // Save the form again, with changes to just one node.
  $edit = array(
    $first_node_title_element_name => $this
      ->randomName(),
  );
  $second_node_title_old = $second_node->title;
  $this
    ->drupalPost('test-editable-views-node-title', $edit, t('Save'));

  // Load the nodes again and check their titles.
  entity_get_controller('node')
    ->resetCache();
  $first_node = node_load($first_node->nid);
  $second_node = node_load($second_node->nid);
  $this
    ->assertEqual($first_node->title, $edit[$first_node_title_element_name], t("The first node's title has been changed by saving the editable view."));
  $this
    ->assertEqual($second_node->title, $second_node_title_old, t("The second node's title was not changed when the editable view was saved with no value for it."));
}