1 nodeapi_example.test public NodeApiExampleTestCase::testNodeExampleRevision()

Test revisions of ratings.

Logs user in, creates an example node, and tests rating functionality with a node using revisions.

File

modules/examples/nodeapi_example/nodeapi_example.test, line 124
Test case for Testing the node API example module.

Class

NodeApiExampleTestCase
Functional tests for the NodeAPI Example module.

Code

public function testNodeExampleRevision() {

  // Login the user.
  $this->backdropLogin($this->webUser);

  // Create custom content type.
  $content_type = $this->backdropCreateContentType();
  $type = $content_type->type;

  // Go to edit the settings of this content type.
  $this->backdropGet('admin/structure/types/manage/' . $type);
  $this->assertResponse(200);

  // Check if the new Rating options appear in the settings page.
  $this->assertText(t('NodeAPI Example Rating'), 'Rating options found in content type.');
  $this->assertFieldByName('nodeapi_example_node_type', 1, 'Rating is Disabled by default.');

  // Disable the rating for this content type: 0 for Disabled, 1 for Enabled.
  $content_settings = array(
    'nodeapi_example_node_type' => 0,
  );
  $this->backdropPost('admin/structure/types/manage/' . $type, $content_settings, t('Save content type'));
  $this->assertResponse(200);
  $this->assertRaw(' has been updated.', 'Settings modified successfully for content type.');

  // Create an example node.
  $langcode = LANGUAGE_NONE;
  $edit = array(
    "title" => $this->randomName(),
  );
  $this->backdropPost('node/add/' . $type, $edit, t('Save'));
  $this->assertResponse(200);

  // Check that the rating is not shown, as we have not yet enabled it.
  $this->assertNoRaw('Rating: <em>', 'Extended rating information is not shown.');

  // Save current current url (we are viewing the new node).
  $node_url = $this->getUrl();

  // Enable the rating for this content type: 0 for Disabled, 1 for Enabled.
  $content_settings = array(
    'nodeapi_example_node_type' => TRUE,
  );
  $this->backdropPost('admin/structure/types/manage/' . $type, $content_settings, t('Save content type'));
  $this->assertResponse(200);
  $this->assertRaw(' has been updated.', 'Settings modified successfully for content type.');

  // Check previously create node. It should be not rated.
  $this->backdropGet($node_url);
  $this->assertResponse(200);
  $this->assertRaw(t('Rating: %rating', array('%rating' => t('Unrated'))), 'Content is not rated.');

  // Rate the content, 4 is for "Good"
  $rate = array(
    'nodeapi_example_rating' => 4,
  );
  $this->backdropPost($node_url . '/edit', $rate, t('Save'));
  $this->assertResponse(200);

  // Check that content has been rated.
  $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), 'Content is successfully rated.');

  // Rate the content to poor using a new revision, 1 is for "Poor"
  $rate = array(
    'nodeapi_example_rating' => 1,
    'revision' => 1,
  );
  $this->backdropPost($node_url . '/edit', $rate, t('Save'));
  $this->assertResponse(200);

  // Check that content has been rated.
  $this->assertRaw(t('Rating: %rating', array('%rating' => t('Poor'))), 'Content is successfully rated.');

  // Now switch back to previous revision of the node.
  $this->backdropGet($node_url . '/revisions');
  // There is only a revision, so it must work just clicking the first link..
  $this->clickLink('Revert');
  $revert_form = $this->getUrl();
  $this->backdropPost($revert_form, array(), t('Revert'));

  // Go back to the node page.
  $this->backdropGet($node_url);
  $this->assertResponse(200);

  // Check that content has been rated.
  $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), 'Content rating matches reverted revision.');

}