Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -0,0 +1,26 @@
|
|||
id: statistics_node_counter
|
||||
label: Node counter
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Content
|
||||
source:
|
||||
plugin: node_counter
|
||||
process:
|
||||
nid:
|
||||
-
|
||||
plugin: migration_lookup
|
||||
migration: [d6_node, d7_node]
|
||||
source: nid
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
totalcount: totalcount
|
||||
daycount: daycount
|
||||
timestamp: timestamp
|
||||
destination:
|
||||
plugin: node_counter
|
||||
migration_dependencies:
|
||||
optional:
|
||||
- d6_node
|
||||
- d7_node
|
|
@ -3,12 +3,14 @@ label: Statistics configuration
|
|||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
- statistics_enable_access_log
|
||||
- statistics_flush_accesslog_timer
|
||||
- statistics_count_content_views
|
||||
source_module: statistics
|
||||
process:
|
||||
'count_content_views': statistics_count_content_views
|
||||
destination:
|
|
@ -131,7 +131,7 @@ class NodeStatisticsDatabaseStorage implements StatisticsStorageInterface {
|
|||
public function maxTotalCount() {
|
||||
$query = $this->connection->select('node_counter', 'nc');
|
||||
$query->addExpression('MAX(totalcount)');
|
||||
$max_total_count = (int)$query->execute()->fetchField();
|
||||
$max_total_count = (int) $query->execute()->fetchField();
|
||||
return $max_total_count;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ class StatisticsPopularBlock extends BlockBase implements ContainerFactoryPlugin
|
|||
return [
|
||||
'top_day_num' => 0,
|
||||
'top_all_num' => 0,
|
||||
'top_last_num' => 0
|
||||
'top_last_num' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -194,11 +194,7 @@ class StatisticsPopularBlock extends BlockBase implements ContainerFactoryPlugin
|
|||
$items = [];
|
||||
foreach ($nids as $nid) {
|
||||
$node = $this->entityRepository->getTranslationFromContext($nodes[$nid]);
|
||||
$item = [
|
||||
'#type' => 'link',
|
||||
'#title' => $node->getTitle(),
|
||||
'#url' => $node->urlInfo('canonical'),
|
||||
];
|
||||
$item = $node->toLink()->toRenderable();
|
||||
$this->renderer->addCacheableDependency($item, $node);
|
||||
$items[] = $item;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\statistics\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Destination for node counter.
|
||||
*
|
||||
* @MigrateDestination(
|
||||
* id = "node_counter",
|
||||
* destination_module = "statistics"
|
||||
* )
|
||||
*/
|
||||
class NodeCounter extends DestinationBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Constructs a node counter plugin.
|
||||
*
|
||||
* @param array $configuration
|
||||
* Plugin configuration.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin definition.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The current migration.
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, Connection $connection) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return ['nid' => ['type' => 'integer']];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields(MigrationInterface $migration = NULL) {
|
||||
return [
|
||||
'nid' => $this->t('The ID of the node to which these statistics apply.'),
|
||||
'totalcount' => $this->t('The total number of times the node has been viewed.'),
|
||||
'daycount' => $this->t('The total number of times the node has been viewed today.'),
|
||||
'timestamp' => $this->t('The most recent time the node has been viewed.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$nid = $row->getDestinationProperty('nid');
|
||||
$daycount = $row->getDestinationProperty('daycount');
|
||||
$totalcount = $row->getDestinationProperty('totalcount');
|
||||
$timestamp = $row->getDestinationProperty('timestamp');
|
||||
|
||||
$this->connection
|
||||
->merge('node_counter')
|
||||
->key('nid', $nid)
|
||||
->fields([
|
||||
'daycount' => $daycount,
|
||||
'totalcount' => $totalcount,
|
||||
'timestamp' => $timestamp,
|
||||
])
|
||||
->expression('daycount', 'daycount + :daycount', [':daycount' => $daycount])
|
||||
->expression('totalcount', 'totalcount + :totalcount', [':totalcount' => $totalcount])
|
||||
->expression('timestamp', 'CASE WHEN timestamp > :timestamp THEN timestamp ELSE :timestamp END', [':timestamp' => $timestamp])
|
||||
->execute();
|
||||
|
||||
return [$row->getDestinationProperty('nid')];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\statistics\Plugin\migrate\source;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Node counter source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "node_counter",
|
||||
* source_module = "statistics"
|
||||
* )
|
||||
*/
|
||||
class NodeCounter extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('node_counter', 'nc')->fields('nc');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'nid' => $this->t('The node ID.'),
|
||||
'totalcount' => $this->t('The total number of times the node has been viewed.'),
|
||||
'daycount' => $this->t('The total number of times the node has been viewed today.'),
|
||||
'timestamp' => $this->t('The most recent time the node has been viewed.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['nid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Configure statistics settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class StatisticsSettingsForm extends ConfigFormBase {
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ class StatisticsViewsResult {
|
|||
protected $timestamp;
|
||||
|
||||
public function __construct($total_count, $day_count, $timestamp) {
|
||||
$this->totalCount = $total_count;
|
||||
$this->dayCount = $day_count;
|
||||
$this->timestamp = $timestamp;
|
||||
$this->totalCount = (int) $total_count;
|
||||
$this->dayCount = (int) $day_count;
|
||||
$this->timestamp = (int) $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,6 @@ class StatisticsViewsResult {
|
|||
return $this->totalCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Total number of times the entity has been viewed "today".
|
||||
*
|
||||
|
@ -47,7 +46,6 @@ class StatisticsViewsResult {
|
|||
return $this->dayCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Timestamp of when the entity was last viewed.
|
||||
*
|
||||
|
|
15
web/core/modules/statistics/statistics.es6.js
Normal file
15
web/core/modules/statistics/statistics.es6.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* @file
|
||||
* Statistics functionality.
|
||||
*/
|
||||
|
||||
(function($, Drupal, drupalSettings) {
|
||||
$(document).ready(() => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: drupalSettings.statistics.url,
|
||||
data: drupalSettings.statistics.data,
|
||||
});
|
||||
});
|
||||
})(jQuery, Drupal, drupalSettings);
|
|
@ -6,4 +6,4 @@ version: VERSION
|
|||
core: 8.x
|
||||
configure: statistics.settings
|
||||
dependencies:
|
||||
- node
|
||||
- drupal:node
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
/**
|
||||
* @file
|
||||
* Statistics functionality.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
'use strict';
|
||||
|
||||
$(document).ready(function () {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
|
@ -15,4 +14,4 @@
|
|||
data: drupalSettings.statistics.data
|
||||
});
|
||||
});
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
})(jQuery, Drupal, drupalSettings);
|
|
@ -41,7 +41,7 @@ function statistics_help($route_name, RouteMatchInterface $route_match) {
|
|||
function statistics_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
|
||||
if (!$node->isNew() && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
|
||||
$build['#attached']['library'][] = 'statistics/drupal.statistics';
|
||||
$settings = ['data' => ['nid' => $node->id()], 'url' => Url::fromUri('base:' . drupal_get_path('module', 'statistics') . '/statistics.php')->toString()];
|
||||
$settings = ['data' => ['nid' => $node->id()], 'url' => \Drupal::request()->getBasePath() . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'];
|
||||
$build['#attached']['drupalSettings']['statistics'] = $settings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* Implements hook_views_data().
|
||||
*/
|
||||
function statistics_views_data() {
|
||||
$data['node_counter']['table']['group'] = t('Content statistics');
|
||||
$data['node_counter']['table']['group'] = t('Content statistics');
|
||||
|
||||
$data['node_counter']['table']['join'] = [
|
||||
'node_field_data' => [
|
||||
|
|
|
@ -5,5 +5,5 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- statistics
|
||||
- views
|
||||
- drupal:statistics
|
||||
- drupal:views
|
||||
|
|
|
@ -38,7 +38,7 @@ class StatisticsAdminTest extends BrowserTestBase {
|
|||
/**
|
||||
* The Guzzle HTTP client.
|
||||
*
|
||||
* @var \GuzzleHttp\Client;
|
||||
* @var \GuzzleHttp\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class StatisticsAttachedTest extends BrowserTestBase {
|
|||
$node = Node::create([
|
||||
'type' => 'page',
|
||||
'title' => 'Page node',
|
||||
'body' => 'body text'
|
||||
'body' => 'body text',
|
||||
]);
|
||||
$node->save();
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
|
|
@ -39,7 +39,7 @@ class StatisticsLoggingTest extends BrowserTestBase {
|
|||
/**
|
||||
* The Guzzle HTTP client.
|
||||
*
|
||||
* @var \GuzzleHttp\Client;
|
||||
* @var \GuzzleHttp\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
|
@ -125,7 +125,7 @@ class StatisticsLoggingTest extends BrowserTestBase {
|
|||
$post = ['nid' => $this->node->id()];
|
||||
$this->client->post($base_root . $stats_path, ['form_params' => $post]);
|
||||
$node_counter = statistics_get($this->node->id());
|
||||
$this->assertIdentical($node_counter['totalcount'], '1');
|
||||
$this->assertIdentical($node_counter['totalcount'], 1);
|
||||
|
||||
// Try fetching statistics for an invalid node ID and verify it returns
|
||||
// FALSE.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\statistics\Functional;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* Tests display of statistics report blocks.
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\Tests\statistics\Functional;
|
|||
* @group statistics
|
||||
*/
|
||||
class StatisticsTokenReplaceTest extends StatisticsTestBase {
|
||||
|
||||
/**
|
||||
* Creates a node, then tests the statistics tokens generated from it.
|
||||
*/
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\statistics\Tests\Views;
|
||||
namespace Drupal\Tests\statistics\Functional\Views;
|
||||
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
|
@ -42,8 +42,8 @@ class IntegrationTest extends ViewTestBase {
|
|||
*/
|
||||
public static $testViews = ['test_statistics_integration'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), ['statistics_test_views']);
|
||||
|
||||
|
@ -74,7 +74,7 @@ class IntegrationTest extends ViewTestBase {
|
|||
// @see \Drupal\statistics\Tests\StatisticsLoggingTest::testLogging().
|
||||
global $base_url;
|
||||
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
|
||||
$client = \Drupal::httpClient();
|
||||
$client = $this->getHttpClient();
|
||||
$client->post($stats_path, ['form_params' => ['nid' => $this->node->id()]]);
|
||||
$this->drupalGet('test_statistics_integration');
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\FunctionalJavascript;
|
||||
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Tests that statistics works.
|
||||
*
|
||||
* @group system
|
||||
*/
|
||||
class StatisticsLoggingTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'statistics', 'language'];
|
||||
|
||||
/**
|
||||
* Node for tests.
|
||||
*
|
||||
* @var \Drupal\node\Entity\Node
|
||||
*/
|
||||
protected $node;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->config('statistics.settings')
|
||||
->set('count_content_views', 1)
|
||||
->save();
|
||||
|
||||
Role::load(AccountInterface::ANONYMOUS_ROLE)
|
||||
->grantPermission('view post access counter')
|
||||
->save();
|
||||
|
||||
// Add another language to enable multilingual path processor.
|
||||
ConfigurableLanguage::create(['id' => 'xx'])->save();
|
||||
$this->config('language.negotiation')->set('url.prefixes.en', 'en')->save();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->node = $this->drupalCreateNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that statistics works with different addressing variants.
|
||||
*/
|
||||
public function testLoggingPage() {
|
||||
// At the first request, the page does not contain statistics counter.
|
||||
$this->assertNull($this->getStatisticsCounter('node/1'));
|
||||
$this->assertSame(1, $this->getStatisticsCounter('node/1'));
|
||||
$this->assertSame(2, $this->getStatisticsCounter('en/node/1'));
|
||||
$this->assertSame(3, $this->getStatisticsCounter('en/node/1'));
|
||||
$this->assertSame(4, $this->getStatisticsCounter('index.php/node/1'));
|
||||
$this->assertSame(5, $this->getStatisticsCounter('index.php/node/1'));
|
||||
$this->assertSame(6, $this->getStatisticsCounter('index.php/en/node/1'));
|
||||
$this->assertSame(7, $this->getStatisticsCounter('index.php/en/node/1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets counter of views by path.
|
||||
*
|
||||
* @param string $path
|
||||
* A path to node.
|
||||
*
|
||||
* @return int|null
|
||||
* A counter of views. Returns NULL if the page does not contain statistics.
|
||||
*/
|
||||
protected function getStatisticsCounter($path) {
|
||||
$this->drupalGet($path);
|
||||
// Wait while statistics module send ajax request.
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
// Resaving the node to call the hook_node_links_alter(), which is used to
|
||||
// update information on the page. See statistics_node_links_alter().
|
||||
$this->node->save();
|
||||
|
||||
$field_counter = $this->getSession()->getPage()->find('css', '.statistics-counter');
|
||||
return $field_counter ? (int) explode(' ', $field_counter->getText())[0] : NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration of node counter data to Drupal 8.
|
||||
*
|
||||
* @group statistics
|
||||
*/
|
||||
class MigrateNodeCounterTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'language',
|
||||
'menu_ui',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
'node',
|
||||
'statistics',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installConfig('node');
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('statistics', ['node_counter']);
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_filter_format',
|
||||
'd6_user_role',
|
||||
'd6_node_settings',
|
||||
'd6_user',
|
||||
'd6_node_type',
|
||||
'd6_language_content_settings',
|
||||
'd6_node',
|
||||
'd6_node_translation',
|
||||
'statistics_node_counter',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of node counter.
|
||||
*/
|
||||
public function testStatisticsSettings() {
|
||||
$this->assertNodeCounter(1, 2, 0, 1421727536);
|
||||
$this->assertNodeCounter(2, 1, 0, 1471428059);
|
||||
$this->assertNodeCounter(3, 1, 0, 1471428153);
|
||||
$this->assertNodeCounter(4, 1, 1, 1478755275);
|
||||
$this->assertNodeCounter(5, 1, 1, 1478755314);
|
||||
$this->assertNodeCounter(10, 5, 1, 1521137459);
|
||||
$this->assertNodeCounter(12, 3, 0, 1521137469);
|
||||
|
||||
// Tests that translated node counts include all translation counts.
|
||||
$this->executeMigration('statistics_node_translation_counter');
|
||||
$this->assertNodeCounter(10, 8, 2, 1521137463);
|
||||
$this->assertNodeCounter(12, 5, 1, 1521137470);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a node counter.
|
||||
*
|
||||
* @param int $nid
|
||||
* The node ID.
|
||||
* @param int $total_count
|
||||
* The expected total count.
|
||||
* @param int $day_count
|
||||
* The expected day count.
|
||||
* @param int $timestamp
|
||||
* The expected timestamp.
|
||||
*/
|
||||
protected function assertNodeCounter($nid, $total_count, $day_count, $timestamp) {
|
||||
/** @var \Drupal\statistics\StatisticsViewsResult $statistics */
|
||||
$statistics = $this->container->get('statistics.storage.node')->fetchView($nid);
|
||||
// @todo Remove casting after https://www.drupal.org/node/2926069 lands.
|
||||
$this->assertSame($total_count, (int) $statistics->getTotalCount());
|
||||
$this->assertSame($day_count, (int) $statistics->getDayCount());
|
||||
$this->assertSame($timestamp, (int) $statistics->getTimestamp());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration of node counter data to Drupal 8.
|
||||
*
|
||||
* @group statistics
|
||||
*/
|
||||
class MigrateNodeCounterTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'language',
|
||||
'menu_ui',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
'node',
|
||||
'statistics',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installConfig('node');
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('statistics', ['node_counter']);
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_user_role',
|
||||
'd7_user',
|
||||
'd7_node_type',
|
||||
'd7_language_content_settings',
|
||||
'd7_node',
|
||||
'd7_node_translation',
|
||||
'statistics_node_counter',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of node counter.
|
||||
*/
|
||||
public function testStatisticsSettings() {
|
||||
$this->assertNodeCounter(1, 2, 0, 1421727536);
|
||||
$this->assertNodeCounter(2, 1, 0, 1471428059);
|
||||
$this->assertNodeCounter(4, 1, 1, 1478755275);
|
||||
|
||||
// Tests that translated node counts include all translation counts.
|
||||
$this->executeMigration('statistics_node_translation_counter');
|
||||
$this->assertNodeCounter(2, 2, 0, 1471428153);
|
||||
$this->assertNodeCounter(4, 2, 2, 1478755314);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a node counter.
|
||||
*
|
||||
* @param int $nid
|
||||
* The node ID.
|
||||
* @param int $total_count
|
||||
* The expected total count.
|
||||
* @param int $day_count
|
||||
* The expected day count.
|
||||
* @param int $timestamp
|
||||
* The expected timestamp.
|
||||
*/
|
||||
protected function assertNodeCounter($nid, $total_count, $day_count, $timestamp) {
|
||||
/** @var \Drupal\statistics\StatisticsViewsResult $statistics */
|
||||
$statistics = $this->container->get('statistics.storage.node')->fetchView($nid);
|
||||
// @todo Remove casting after https://www.drupal.org/node/2926069 lands.
|
||||
$this->assertSame($total_count, (int) $statistics->getTotalCount());
|
||||
$this->assertSame($day_count, (int) $statistics->getDayCount());
|
||||
$this->assertSame($timestamp, (int) $statistics->getTimestamp());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Kernel\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the node_counter source plugin.
|
||||
*
|
||||
* @covers \Drupal\statistics\Plugin\migrate\source\NodeCounter
|
||||
*
|
||||
* @group statistics
|
||||
*/
|
||||
class NodeCounterTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal', 'statistics'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['node_counter'] = [
|
||||
[
|
||||
'nid' => 1,
|
||||
'totalcount' => 2,
|
||||
'daycount' => 0,
|
||||
'timestamp' => 1421727536,
|
||||
],
|
||||
[
|
||||
'nid' => 2,
|
||||
'totalcount' => 1,
|
||||
'daycount' => 0,
|
||||
'timestamp' => 1471428059,
|
||||
],
|
||||
[
|
||||
'nid' => 3,
|
||||
'totalcount' => 1,
|
||||
'daycount' => 0,
|
||||
'timestamp' => 1471428153,
|
||||
],
|
||||
[
|
||||
'nid' => 4,
|
||||
'totalcount' => 1,
|
||||
'daycount' => 1,
|
||||
'timestamp' => 1478755275,
|
||||
],
|
||||
[
|
||||
'nid' => 5,
|
||||
'totalcount' => 1,
|
||||
'daycount' => 1,
|
||||
'timestamp' => 1478755314,
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = $tests[0]['source_data']['node_counter'];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Unit;
|
||||
|
||||
use Drupal\statistics\StatisticsViewsResult;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\statistics\StatisticsViewsResult
|
||||
* @group statistics
|
||||
*/
|
||||
class StatisticsViewsResultTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests migration of node counter.
|
||||
*
|
||||
* @covers ::__construct
|
||||
*
|
||||
* @dataProvider providerTestStatisticsCount
|
||||
*/
|
||||
public function testStatisticsCount($total_count, $day_count, $timestamp) {
|
||||
$statistics = new StatisticsViewsResult($total_count, $day_count, $timestamp);
|
||||
$this->assertSame((int) $total_count, $statistics->getTotalCount());
|
||||
$this->assertSame((int) $day_count, $statistics->getDayCount());
|
||||
$this->assertSame((int) $timestamp, $statistics->getTimestamp());
|
||||
}
|
||||
|
||||
public function providerTestStatisticsCount() {
|
||||
return [
|
||||
[2, 0, 1421727536],
|
||||
[1, 0, 1471428059],
|
||||
[1, 1, 1478755275],
|
||||
['1', '1', '1478755275'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue