function NodeApiExampleTestCase::testNodeExampleBasic in Examples for Developers 6
Same name and namespace in other branches
- 7 nodeapi_example/nodeapi_example.test \NodeApiExampleTestCase::testNodeExampleBasic()
Login user, create an example node, and use the rating system
File
- nodeapi_example/
nodeapi_example.test, line 54 - Test case for Testing the node API example module.
Class
- NodeApiExampleTestCase
- @file Test case for Testing the node API example module.
Code
function testNodeExampleBasic() {
// Login the user.
$this
->drupalLogin($this->web_user);
// Create custom content type
$content_type = $this
->drupalCreateContentType();
$type = $content_type->type;
// Disable the rating for this content type: 0 for Disabled, 1 for Enabled.
$content_settings = array(
'nodeapi_example' => 0,
);
$this
->drupalPost('admin/content/node-type/' . $type, $content_settings, t('Save content type'));
$this
->assertResponse(200);
$this
->assertRaw(' has been updated.', t('Settings modified successfully for content type.'));
// Create an example node.
$edit = array(
"title" => $this
->randomName(),
);
$this
->drupalPost('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>', t('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' => TRUE,
);
$this
->drupalPost('admin/content/node-type/' . $type, $content_settings, t('Save content type'));
$this
->assertResponse(200);
$this
->assertRaw(' has been updated.', t('Settings modified successfully for content type.'));
// Check previously create node. It should be not rated
$this
->drupalGet($node_url);
$this
->assertResponse(200);
$this
->assertRaw(t('Rating: %rating', array(
'%rating' => t('Unrated'),
)), t('Content is not rated.'));
// Rate the content, 4 is for "Good"
$rate = array(
'nodeapi_example_rating' => 4,
);
$this
->drupalPost($node_url . '/edit', $rate, t('Save'));
$this
->assertResponse(200);
// Check that content has been rated
$this
->assertRaw(t('Rating: %rating', array(
'%rating' => t('Good'),
)), t('Content is successfully rated.'));
}