1 node_hooks_example.test | public NodeHooksExampleTestCase::testNodeExampleBasic() |
Logs the user in, creates an example node, and uses the rating system.
File
- modules/
examples/ node_hooks_example/ tests/ node_hooks_example.test, line 55 - Test case for testing the Node Hooks Example module.
Class
- NodeHooksExampleTestCase
- Functional tests for the Node Hooks Example module.
Code
public function testNodeExampleBasic() {
$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>', '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 hav 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(
'nodeapi_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.');
}