You are here

protected function MongoDBLogTestCase::ztestFilter in MongoDB 7

Same name and namespace in other branches
  1. 8 mongodb_watchdog/mongodb_watchdog.test \MongoDBLogTestCase::ZtestFilter()

Test the dblog filter on admin/reports/dblog.

File

mongodb_watchdog/mongodb_watchdog.test, line 584
Contains \MongoDBLogTestCase.

Class

MongoDBLogTestCase

Code

protected function ztestFilter() {
  $this
    ->drupalLogin($this->bigUser);

  // Clear log to ensure that only generated entries are found.
  db_delete('watchdog')
    ->execute();

  // Generate watchdog entries.
  $type_names = array();
  $types = array();
  for ($i = 0; $i < 3; $i++) {
    $type_names[] = $type_name = $this
      ->randomName();
    $severity = WATCHDOG_EMERGENCY;
    for ($j = 0; $j < 3; $j++) {
      $types[] = $type = array(
        'count' => mt_rand(1, 5),
        'type' => $type_name,
        'severity' => $severity++,
      );
      $this
        ->generateLogEntries($type['count'], $type['type'], $type['severity']);
    }
  }

  // View the dblog.
  $this
    ->drupalGet('admin/reports/dblog');

  // Confirm all the entries are displayed.
  $count = $this
    ->getTypeCount($types);
  foreach ($types as $key => $type) {
    $this
      ->assertEqual($count[$key], $type['count'], 'Count matched');
  }

  // Filter by each type and confirm that entries with various severities are
  // displayed.
  foreach ($type_names as $type_name) {
    $edit = array(
      'type[]' => array(
        $type_name,
      ),
    );
    $this
      ->drupalPost(NULL, $edit, t('Filter'));

    // Count the number of entries of this type.
    $type_count = 0;
    foreach ($types as $type) {
      if ($type['type'] == $type_name) {
        $type_count += $type['count'];
      }
    }
    $count = $this
      ->getTypeCount($types);
    $this
      ->assertEqual(array_sum($count), $type_count, 'Count matched');
  }

  // Set filter to match each of the three type attributes and confirm the
  // number of entries displayed.
  foreach ($types as $key => $type) {
    $edit = array(
      'type[]' => array(
        $type['type'],
      ),
      'severity[]' => array(
        $type['severity'],
      ),
    );
    $this
      ->drupalPost(NULL, $edit, t('Filter'));
    $count = $this
      ->getTypeCount($types);
    $this
      ->assertEqual(array_sum($count), $type['count'], 'Count matched');
  }
}