StatisticsReportsTest.php in Zircon Profile 8
File
core/modules/statistics/src/Tests/StatisticsReportsTest.php
View source
<?php
namespace Drupal\statistics\Tests;
class StatisticsReportsTest extends StatisticsTestBase {
function testPopularContentBlock() {
$this->container
->get('plugin.manager.block')
->clearCachedDefinitions();
$node = $this
->drupalCreateNode(array(
'type' => 'page',
'uid' => $this->blockingUser
->id(),
));
$this
->drupalGet('node/' . $node
->id());
$nid = $node
->id();
$post = http_build_query(array(
'nid' => $nid,
));
$headers = array(
'Content-Type' => 'application/x-www-form-urlencoded',
);
global $base_url;
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
$client = \Drupal::service('http_client_factory')
->fromOptions([
'config/curl' => [
CURLOPT_TIMEOUT => 10,
],
]);
$client
->post($stats_path, array(
'headers' => $headers,
'body' => $post,
));
$this
->drupalPlaceBlock('statistics_popular_block', array(
'label' => 'Popular content',
'top_day_num' => 3,
'top_all_num' => 3,
'top_last_num' => 3,
));
$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 all time popular content.');
$this
->assertText('Last viewed', 'Found the last viewed popular content.');
$this
->assertRaw(\Drupal::l($node
->label(), $node
->urlInfo('canonical', [
'language' => NULL,
])), 'Found link to visited node.');
}
}