1401e60fd492af65dac290f7a50886e9da57ff4c
[yaffs-website] / web / core / modules / statistics / tests / src / Kernel / Migrate / d7 / MigrateNodeCounterTest.php
1 <?php
2
3 namespace Drupal\Tests\statistics\Kernel\Migrate\d7;
4
5 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
6
7 /**
8  * Tests the migration of node counter data to Drupal 8.
9  *
10  * @group statistics
11  */
12 class MigrateNodeCounterTest extends MigrateDrupal7TestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = [
18     'content_translation',
19     'language',
20     'menu_ui',
21     // Required for translation migrations.
22     'migrate_drupal_multilingual',
23     'node',
24     'statistics',
25     'text',
26   ];
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp() {
32     parent::setUp();
33
34     $this->installEntitySchema('node');
35     $this->installConfig('node');
36     $this->installSchema('node', ['node_access']);
37     $this->installSchema('statistics', ['node_counter']);
38
39     $this->executeMigrations([
40       'language',
41       'd7_user_role',
42       'd7_user',
43       'd7_node_type',
44       'd7_language_content_settings',
45       'd7_node',
46       'd7_node_translation',
47       'statistics_node_counter',
48     ]);
49   }
50
51   /**
52    * Tests migration of node counter.
53    */
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);
58
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);
63   }
64
65   /**
66    * Asserts various aspects of a node counter.
67    *
68    * @param int $nid
69    *   The node ID.
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.
76    */
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());
84   }
85
86 }