You are here

function StatisticsProTestCase::testMainTests in Statistics Pro 6

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

File

tests/statspro.test, line 339
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',
  );
  $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);

  /**
   * Not testing other periods as their results are hardto 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);
}