class StatisticsReportsTest
Same name and namespace in other branches
- 10 core/modules/statistics/tests/src/Functional/StatisticsReportsTest.php \Drupal\Tests\statistics\Functional\StatisticsReportsTest
- 8.9.x core/modules/statistics/tests/src/Functional/StatisticsReportsTest.php \Drupal\Tests\statistics\Functional\StatisticsReportsTest
Tests display of statistics report blocks.
@group statistics
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\statistics\Functional\StatisticsTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\statistics\Functional\StatisticsReportsTest uses \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait extends \Drupal\Tests\statistics\Functional\StatisticsTestBase
- class \Drupal\Tests\statistics\Functional\StatisticsTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of StatisticsReportsTest
File
-
core/
modules/ statistics/ tests/ src/ Functional/ StatisticsReportsTest.php, line 14
Namespace
Drupal\Tests\statistics\FunctionalView source
class StatisticsReportsTest extends StatisticsTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests the "popular content" block.
*/
public function testPopularContentBlock() {
// Clear the block cache to load the Statistics module's block definitions.
$this->container
->get('plugin.manager.block')
->clearCachedDefinitions();
// Visit a node to have something show up in the block.
$node = $this->drupalCreateNode([
'type' => 'page',
'uid' => $this->blockingUser
->id(),
]);
$this->drupalGet('node/' . $node->id());
// Manually calling statistics.php, simulating ajax behavior.
$nid = $node->id();
$post = http_build_query([
'nid' => $nid,
]);
$headers = [
'Content-Type' => 'application/x-www-form-urlencoded',
];
global $base_url;
$stats_path = $base_url . '/' . $this->getModulePath('statistics') . '/statistics.php';
$client = \Drupal::httpClient();
$client->post($stats_path, [
'headers' => $headers,
'body' => $post,
]);
// Configure and save the block.
$block = $this->drupalPlaceBlock('statistics_popular_block', [
'label' => 'Popular content',
'top_day_num' => 3,
'top_all_num' => 3,
'top_last_num' => 3,
]);
// Get some page and check if the block is displayed.
$this->drupalGet('user');
$this->assertSession()
->pageTextContains('Popular content');
$this->assertSession()
->pageTextContains("Today's");
$this->assertSession()
->pageTextContains('All time');
$this->assertSession()
->pageTextContains('Last viewed');
$tags = Cache::mergeTags($node->getCacheTags(), $block->getCacheTags());
$tags = Cache::mergeTags($tags, $this->blockingUser
->getCacheTags());
$tags = Cache::mergeTags($tags, [
'block_view',
'config:block_list',
'node_list',
'rendered',
'user_view',
]);
$this->assertCacheTags($tags);
$contexts = Cache::mergeContexts($node->getCacheContexts(), $block->getCacheContexts());
$contexts = Cache::mergeContexts($contexts, [
'url.query_args:_wrapper_format',
'url.site',
]);
$this->assertCacheContexts($contexts);
// Check if the node link is displayed.
$this->assertSession()
->responseContains(Link::fromTextAndUrl($node->label(), $node->toUrl('canonical'))
->toString());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.