1.20.x dblog.test | private DBLogTestCase::doNode($type) |
Generates and then verifies some node events.
Parameters
string $type: A node type (e.g., 'post', 'page' or 'poll').
File
- modules/
dblog/ tests/ dblog.test, line 313 - Tests for dblog.module.
Class
- DBLogTestCase
- Tests logging messages to the database.
Code
private function doNode($type) {
// Create user.
$perm = array('create ' . $type . ' content', 'edit own ' . $type . ' content', 'delete own ' . $type . ' content');
$user = $this->backdropCreateUser($perm);
// Login user.
$this->backdropLogin($user);
// Create a node using the form in order to generate an add content event
// (which is not triggered by backdropCreateNode).
$edit = $this->getContent($type);
$langcode = LANGUAGE_NONE;
$title = $edit["title"];
$this->backdropPost('node/add/' . $type, $edit, t('Save'));
$this->assertResponse(200);
// Retrieve the node object.
$node = $this->backdropGetNodeByTitle($title);
$this->assertTrue($node != NULL, format_string('Node @title was loaded', array('@title' => $title)));
// Edit the node.
$edit = $this->getContentUpdate($type);
$this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertResponse(200);
// Delete the node.
$this->backdropPost('node/' . $node->nid . '/delete', array(), t('Delete'));
$this->assertResponse(200);
// View the node (to generate page not found event).
$this->backdropGet('node/' . $node->nid);
$this->assertResponse(404);
// View the database log report (to generate access denied event).
$this->backdropGet('admin/reports/dblog');
$this->assertResponse(403);
// Login the admin user.
$this->backdropLogin($this->big_user);
// View the database log report.
$this->backdropGet('admin/reports/dblog');
$this->assertResponse(200);
// Verify that node events were recorded.
// Was node content added?
$this->assertLogMessage(t('@type: added %title.', array('@type' => $type, '%title' => $title)), 'DBLog event was recorded: [content added]');
// Was node content updated?
$this->assertLogMessage(t('@type: updated %title.', array('@type' => $type, '%title' => $title)), 'DBLog event was recorded: [content updated]');
// Was node content deleted?
$this->assertLogMessage(t('@type: deleted %title.', array('@type' => $type, '%title' => $title)), 'DBLog event was recorded: [content deleted]');
// View the database log access-denied report page.
$this->backdropGet('admin/reports/access-denied');
$this->assertResponse(200);
// Verify that the 'access denied' event was recorded.
$this->assertText(t('admin/reports/dblog'), 'DBLog event was recorded: [access denied]');
// View the database log page-not-found report page.
$this->backdropGet('admin/reports/page-not-found');
$this->assertResponse(200);
// Verify that the 'page not found' event was recorded.
$this->assertText(t('node/@nid', array('@nid' => $node->nid)), 'DBLog event was recorded: [page not found]');
}