1 node_hooks_example.test | public NodeHooksExampleTestCase::testNodeExampleRevision() |
Tests revisions of ratings.
Logs user in, creates an example node, and tests rating functionality with a node using revisions.
File
- modules/
examples/ node_hooks_example/ tests/ node_hooks_example.test, line 117 - Test case for testing the Node Hooks Example module.
Class
- NodeHooksExampleTestCase
- Functional tests for the Node Hooks Example module.
Code
public function testNodeExampleRevision() {
$this->backdropLogin($this->webUser);
$content_type = $this->backdropCreateContentType();
$type = $content_type->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('Node Hooks Example rating'), 'Rating options found in the content type.');
$this->assertFieldByName('node_hooks_example_node_type', 1, 'The rating is disabled by default.');
// Disable the rating for this content type.
$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 have been successfully modified for the content type.');
// Create an example node.
$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>', 'The extended rating information is not shown.');
// Save the current URL. We are viewing the new node.
$node_url = $this->getUrl();
// Enable the rating for this content type.
$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 has been successfully modified for the content type.');
// Check the previously create node. It should be not rated.
$this->backdropGet($node_url);
$this->assertResponse(200);
$this->assertRaw(t('Rating: %rating', array('%rating' => t('Unrated'))), 'The content is not rated.');
// Rate the content; 4 is for "Good."
$rate = array(
'node_hooks_example_rating' => 4,
);
$this->backdropPost($node_url . '/edit', $rate, t('Save'));
$this->assertResponse(200);
// Check the content has been rated.
$this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), 'The content has been 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 the content has been rated.
$this->assertRaw(t('Rating: %rating', array('%rating' => t('Poor'))), 'The content has been successfully rated.');
// Switch back to the previous revision.
$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 the content has been rated.
$this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), 'The content rating matches the reverted revision.');
}