3 namespace Drupal\Tests\statistics\Kernel\Migrate\d7;
5 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
8 * Tests the migration of node counter data to Drupal 8.
12 class MigrateNodeCounterTest extends MigrateDrupal7TestBase {
17 public static $modules = [
18 'content_translation',
21 // Required for translation migrations.
22 'migrate_drupal_multilingual',
31 protected function setUp() {
34 $this->installEntitySchema('node');
35 $this->installConfig('node');
36 $this->installSchema('node', ['node_access']);
37 $this->installSchema('statistics', ['node_counter']);
39 $this->executeMigrations([
44 'd7_language_content_settings',
46 'd7_node_translation',
47 'statistics_node_counter',
52 * Tests migration of node counter.
54 public function testStatisticsSettings() {
55 $this->assertNodeCounter(1, 2, 0, 1421727536);
56 $this->assertNodeCounter(2, 1, 0, 1471428059);
57 $this->assertNodeCounter(4, 1, 1, 1478755275);
59 // Tests that translated node counts include all translation counts.
60 $this->executeMigration('statistics_node_translation_counter');
61 $this->assertNodeCounter(2, 2, 0, 1471428153);
62 $this->assertNodeCounter(4, 2, 2, 1478755314);
66 * Asserts various aspects of a node counter.
70 * @param int $total_count
71 * The expected total count.
72 * @param int $day_count
73 * The expected day count.
74 * @param int $timestamp
75 * The expected timestamp.
77 protected function assertNodeCounter($nid, $total_count, $day_count, $timestamp) {
78 /** @var \Drupal\statistics\StatisticsViewsResult $statistics */
79 $statistics = $this->container->get('statistics.storage.node')->fetchView($nid);
80 // @todo Remove casting after https://www.drupal.org/node/2926069 lands.
81 $this->assertSame($total_count, (int) $statistics->getTotalCount());
82 $this->assertSame($day_count, (int) $statistics->getDayCount());
83 $this->assertSame($timestamp, (int) $statistics->getTimestamp());