You are here

function StatisticsProTestCase::testMainTests in Statistics Pro 6.2

Same name and namespace in other branches
  1. 6 tests/statspro.test \StatisticsProTestCase::testMainTests()

File

tests/statspro.test, line 346
Functionality tests for Statistics Pro.

Class

StatisticsProTestCase
Class responsible for testing the module.

Code

function testMainTests() {
  $this
    ->createInitialData();

  /**
   * Turning on the access logs.
   */
  $this
    ->drupalLogin($this->users['stats_admin']);
  $edit = array(
    'statistics_enable_access_log' => 1,
    'statistics_flush_accesslog_timer' => 9676800,
  );
  $this
    ->drupalPost('admin/reports/settings', $edit, t('Save configuration'));
  $this
    ->drupalLogout();

  // Anonymous user navigation.
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - now', array(
    '!this' => 1,
    '!total' => 1,
  )));
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - last week', array(
    '!this' => 2,
    '!total' => 2,
  )));
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - last year', array(
    '!this' => 2,
    '!total' => 3,
  )));

  // Asking for inexistent pages.
  $this
    ->drupalGet('node/111');
  $this
    ->drupalGet('node/1099');

  // Authenticated user nagivation.
  $this
    ->drupalLogin($this->users['regular_3']);
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - last week', array(
    '!this' => 2,
    '!total' => 2,
  )));
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - last month', array(
    '!this' => 1,
    '!total' => 1,
  )));
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - last week', array(
    '!this' => 1,
    '!total' => 2,
  )));
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - now', array(
    '!this' => 1,
    '!total' => 1,
  )));

  // Asking for inexistent pages.
  $this
    ->drupalGet('node/700');
  $this
    ->drupalGet('node/199');
  $this
    ->drupalLogin($this->users['regular_1']);
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - last week', array(
    '!this' => 1,
    '!total' => 2,
  )));
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - now', array(
    '!this' => 1,
    '!total' => 1,
  )));
  $this
    ->drupalGetNodeByTitle(t('Node !this/!total - last year', array(
    '!this' => 1,
    '!total' => 3,
  )));
  $this
    ->callCron();
  $group = t('General Statistics Pro tests');
  $periods = statspro_get_period_items();

  //    $this->drupalLogin($this->users['stats_admin']);
  //
  //    $edit = array(
  //      'plugin' => 'google',
  //      'type' => 'line2D',
  //      'width' => 400,
  //      'height' => 200,
  //      'color[background]' => '#ffffff',
  //      'color[text]' => '#000000',
  //      'color[0]' => '#ff0000',
  //      'color[1]' => '#00cc00',
  //      'color[2]' => '#0066b3',
  //      'color[3]' => '#ff8000',
  //      'color[4]' => '#ffcc00',
  //      'color[5]' => '#330099',
  //      'color[6]' => '#990099',
  //      'color[7]' => '#ccff00',
  //    );
  //    $this->drupalPost('admin/settings/charts', $edit, t('Save settings'));
  $this
    ->drupalLogin($this->users['stats']);

  /**
   * Common stats.
   *
   * Period: default (today).
   */
  $period = 'today';
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes1',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, FALSE, FALSE);

  /**
   * Common stats.
   *
   * Period: yesterday.
   */
  $period = 'yesterday';
  $texts = array(
    'User registrations0',
    'User online0',
    'New nodes1',
    'Changed nodes0',
    'Comments0',
    'No access and log files available for specified period.',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Common stats.
   *
   * Period: custom days (2).
   */
  $period = 2;
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes2',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Common stats.
   *
   * Period: custom days (5).
   */
  $period = 5;
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes3',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Common stats.
   *
   * Period: custom days (7).
   */
  $period = 7;
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes4',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Common stats.
   *
   * Period: custom days (15).
   */
  $period = 15;
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes5',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Common stats.
   *
   * Period: custom days (45).
   */
  $period = 45;
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes6',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Common stats.
   *
   * Period: custom days (183).
   */
  $period = 183;
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes7',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Common stats.
   *
   * Period: custom days (315).
   */
  $period = 315;
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes8',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Common stats.
   *
   * Period: custom days (1000).
   */
  $period = 1000;
  $texts = array(
    'User registrations8',
    'User online7',
    'New nodes8',
    'Changed nodes0',
    'Comments0',
    'Page impressions21',
    'Page impressions for authenticated users10',
    'Errors0',
    'Errors for authenticated users0',
    'Warnings4',
    'Warnings for authenticated users2',
    'Emergencies0',
    'Emergencies for authenticated users0',
    'Alerts0',
    'Alerts for authenticated users0',
    'Critical conditions0',
    'Critical conditions for authenticated users0',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, $period, $group);

  /**
   * Not testing other periods as their results are hard to reproduce because
   * "current month" for example can have from a few seconds (at the begining
   * of the month) up to 31 days at the end so the resultings stats vary.
   */

  /**
   * Comments stats.
   */
  $texts = array(
    'Overview for new created comments.',
    'Date',
    'Comments',
    'Trend',
    'Amount',
  );
  $result = db_query('SELECT day FROM {statspro}');
  while ($row = db_fetch_array($result)) {
    $texts[] = $row['day'];
  }
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, 'admin/reports/statspro/comment', FALSE);

  /**
   * Log stats.
   */
  $texts = array(
    'Overview for warnings.',
    'Overview for warnings, registered users only.',
    'Date',
    'Trend',
    'Amount',
  );
  $result = db_query('SELECT day
        FROM {statspro}
        WHERE error > 0
          OR uerror > 0
          OR warning > 0
          OR uwarning > 0');
  while ($row = db_fetch_array($result)) {
    $texts[] = $row['day'];
  }
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, 'admin/reports/statspro/log', FALSE);

  /**
   * Nodes stats.
   */
  $texts = array(
    'Overview for new created nodes.',
    'Overview for changed nodes.',
    'Date',
    'Trend',
    'Amount',
    'New nodes',
    'Changed nodes',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, 'admin/reports/statspro/node', FALSE);

  /**
   * PI stats.
   */
  $texts = array(
    'Page impressions for guests and registered users.',
    'Page impressions registered users.',
    'Date',
    'Trend',
    'Amount',
    'Page impressions',
    'Page impressions, users',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, 'admin/reports/statspro/pi', FALSE);

  /**
   * Users stats.
   */
  $texts = array(
    'Overview for new user registrations.',
    'Overview for online user activity.',
    'Date',
    'Trend',
    'Amount',
    'User registrations',
    'User online',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, 'admin/reports/statspro/user', FALSE);

  /**
   * Generating some traffic to be reported by path aggregator.
   */
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/1');
  $this
    ->drupalGet('node/4');
  $this
    ->drupalGet('node/5');
  $this
    ->drupalGet('node/6');
  $this
    ->drupalGet('node/7');
  $this
    ->drupalGet('node/8');
  $this
    ->drupalLogin($this->users['regular_2']);
  $this
    ->drupalGet('node/1');
  $this
    ->drupalGet('node/2');
  $this
    ->drupalGet('node/3');
  $this
    ->drupalGet('node/4');
  $this
    ->drupalGet('node/5');
  $this
    ->drupalLogin($this->users['regular_3']);
  $this
    ->drupalGet('node/4');
  $this
    ->drupalGet('node/5');
  $this
    ->drupalGet('node/6');
  $this
    ->drupalGet('node/7');
  $this
    ->drupalGet('node/8');

  /**
   * Path aggregated aggregator creation tests.
   */
  $this
    ->drupalLogin($this->users['stats_admin']);
  $aggregators = array();
  $texts = array(
    'No path aggregators defined.',
  );
  $raws = array();
  $group = 'Path aggregated';
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, 'admin/settings/statspro/path_aggregator/list', FALSE);
  $aggregator_name = 'Aggregator 1';
  $aggregators[] = $aggregator_name;
  $edit = array(
    'name' => $aggregator_name,
    'paths' => "node/1\nnode/3",
  );
  $this
    ->drupalPost('admin/settings/statspro/path_aggregator/add', $edit, t('Add'));
  $this
    ->assertText($aggregator_name, t('New path aggregator %name created.', array(
    '%name' => $aggregator_name,
  )), $group);
  $aggregator_name = 'Aggregator 2';
  $aggregators[] = $aggregator_name;
  $edit = array(
    'name' => $aggregator_name,
    'paths' => "node/2\nnode/4",
  );
  $this
    ->drupalPost('admin/settings/statspro/path_aggregator/add', $edit, t('Add'));
  $this
    ->assertText($aggregator_name, t('New path aggregator %name created.', array(
    '%name' => $aggregator_name,
  )), $group);
  $aggregator_name = 'Aggregator even';
  $aggregators[] = $aggregator_name;
  $edit = array(
    'name' => $aggregator_name,
    'paths' => "node/2\nnode/4\nnode/6\nnode/8",
  );
  $this
    ->drupalPost('admin/settings/statspro/path_aggregator/add', $edit, t('Add'));
  $this
    ->assertText($aggregator_name, t('New path aggregator %name created.', array(
    '%name' => $aggregator_name,
  )), $group);
  $aggregator_name = 'Aggregator odd';
  $aggregators[] = $aggregator_name;
  $edit = array(
    'name' => $aggregator_name,
    'paths' => "node/1\nnode/3\nnode/5\nnode/7",
  );
  $this
    ->drupalPost('admin/settings/statspro/path_aggregator/add', $edit, t('Add'));
  $this
    ->assertText($aggregator_name, t('New path aggregator %name created.', array(
    '%name' => $aggregator_name,
  )), $group);
  $texts = $aggregators;
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, 'admin/settings/statspro/path_aggregator/list', FALSE);

  /**
   * Path aggregated report tests.
   */
  $this
    ->drupalLogin($this->users['stats']);
  $texts = array(
    'Aggregator 1321',
    'Aggregator 2431',
    'Aggregator even421',
    'Aggregator odd531',
  );
  $raws = array();
  $this
    ->completeTestStatsHasTexts($texts, $raws, FALSE, $group, 'admin/reports/statspro/path_aggregated', FALSE);
  $this
    ->drupalLogin($this->users['stats_admin']);
  $edit = array();
  $this
    ->drupalPost('admin/settings/statspro/path_aggregator/delete/3', $edit, 'Delete');
  $texts = array(
    'Aggregator 1',
    'Aggregator 2',
    'Aggregator odd',
  );
  foreach ($texts as $text) {
    $this
      ->assertText($text, t('Text %text found on page.', array(
      '%text' => $text,
    )), $group);
  }
  $text = 'Aggregator even';
  $this
    ->assertNoText($text, t('Text %text not found on page.', array(
    '%text' => $text,
  )), $group);
}