function StatisticsReportsTestCase::testPopularContentBlock

Tests the "popular content" block.

File

modules/statistics/statistics.test, line 230

Class

StatisticsReportsTestCase
Tests that report pages render properly, and that access logging works.

Code

function testPopularContentBlock() {
    // Visit a node to have something show up in the block.
    $node = $this->drupalCreateNode(array(
        'type' => 'page',
        'uid' => $this->blocking_user->uid,
    ));
    $this->drupalGet('node/' . $node->nid);
    // Configure and save the block.
    $block = block_load('statistics', 'popular');
    $block->theme = variable_get('theme_default', 'bartik');
    $block->status = 1;
    $block->pages = '';
    $block->region = 'sidebar_first';
    $block->cache = -1;
    $block->visibility = 0;
    $edit = array(
        'statistics_block_top_day_num' => 3,
        'statistics_block_top_all_num' => 3,
        'statistics_block_top_last_num' => 3,
    );
    module_invoke('statistics', 'block_save', 'popular', $edit);
    drupal_write_record('block', $block);
    // Get some page and check if the block is displayed.
    $this->drupalGet('user');
    $this->assertText('Popular content', 'Found the popular content block.');
    $this->assertText("Today's", 'Found today\'s popular content.');
    $this->assertText('All time', 'Found the alll time popular content.');
    $this->assertText('Last viewed', 'Found the last viewed popular content.');
    $this->assertRaw(l($node->title, 'node/' . $node->nid), 'Found link to visited node.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.