You are here

private function DbLogTest::doNode in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/dblog/src/Tests/DbLogTest.php \Drupal\dblog\Tests\DbLogTest::doNode()

Generates and then verifies some node events.

Parameters

string $type: A node type (e.g., 'article', 'page' or 'forum').

1 call to DbLogTest::doNode()
DbLogTest::verifyEvents in core/modules/dblog/src/Tests/DbLogTest.php
Generates and then verifies various types of events.

File

core/modules/dblog/src/Tests/DbLogTest.php, line 378
Contains \Drupal\dblog\Tests\DbLogTest.

Class

DbLogTest
Generate events and verify dblog entries; verify user access to log reports based on permissions.

Namespace

Drupal\dblog\Tests

Code

private function doNode($type) {

  // Create user.
  $perm = array(
    'create ' . $type . ' content',
    'edit own ' . $type . ' content',
    'delete own ' . $type . ' content',
  );
  $user = $this
    ->drupalCreateUser($perm);

  // Login user.
  $this
    ->drupalLogin($user);

  // Create a node using the form in order to generate an add content event
  // (which is not triggered by drupalCreateNode).
  $edit = $this
    ->getContent($type);
  $title = $edit['title[0][value]'];
  $this
    ->drupalPostForm('node/add/' . $type, $edit, t('Save'));
  $this
    ->assertResponse(200);

  // Retrieve the node object.
  $node = $this
    ->drupalGetNodeByTitle($title);
  $this
    ->assertTrue($node != NULL, format_string('Node @title was loaded', array(
    '@title' => $title,
  )));

  // Edit the node.
  $edit = $this
    ->getContentUpdate($type);
  $this
    ->drupalPostForm('node/' . $node
    ->id() . '/edit', $edit, t('Save'));
  $this
    ->assertResponse(200);

  // Delete the node.
  $this
    ->drupalPostForm('node/' . $node
    ->id() . '/delete', array(), t('Delete'));
  $this
    ->assertResponse(200);

  // View the node (to generate page not found event).
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertResponse(404);

  // View the database log report (to generate access denied event).
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertResponse(403);

  // Login the admin user.
  $this
    ->drupalLogin($this->adminUser);

  // View the database log report.
  $this
    ->drupalGet('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
    ->drupalGet('admin/reports/access-denied');
  $this
    ->assertResponse(200);

  // Verify that the 'access denied' event was recorded.
  $this
    ->assertText('admin/reports/dblog', 'DBLog event was recorded: [access denied]');

  // View the database log page-not-found report page.
  $this
    ->drupalGet('admin/reports/page-not-found');
  $this
    ->assertResponse(200);

  // Verify that the 'page not found' event was recorded.
  $this
    ->assertText('node/' . $node
    ->id(), 'DBLog event was recorded: [page not found]');
}