Updated to Drupal 8.5. Core Media not yet in use.
[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     'menu_ui',
19     'node',
20     'statistics',
21     'text',
22   ];
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function setUp() {
28     parent::setUp();
29
30     $this->installEntitySchema('node');
31     $this->installConfig('node');
32     $this->installSchema('statistics', ['node_counter']);
33
34     $this->executeMigrations([
35       'd7_user_role',
36       'd7_user',
37       'd7_node_type',
38       'd7_node',
39       'statistics_node_counter'
40     ]);
41   }
42
43   /**
44    * Tests migration of node counter.
45    */
46   public function testStatisticsSettings() {
47     $this->assertNodeCounter(1, 2, 0, 1421727536);
48     $this->assertNodeCounter(2, 1, 0, 1471428059);
49     $this->assertNodeCounter(4, 1, 1, 1478755275);
50   }
51
52   /**
53    * Asserts various aspects of a node counter.
54    *
55    * @param int $nid
56    *   The node ID.
57    * @param int $total_count
58    *   The expected total count.
59    * @param int $day_count
60    *   The expected day count.
61    * @param int $timestamp
62    *   The expected timestamp.
63    */
64   protected function assertNodeCounter($nid, $total_count, $day_count, $timestamp) {
65     /** @var \Drupal\statistics\StatisticsViewsResult $statistics */
66     $statistics = $this->container->get('statistics.storage.node')->fetchView($nid);
67     // @todo Remove casting after https://www.drupal.org/node/2926069 lands.
68     $this->assertSame($total_count, (int) $statistics->getTotalCount());
69     $this->assertSame($day_count, (int) $statistics->getDayCount());
70     $this->assertSame($timestamp, (int) $statistics->getTimestamp());
71   }
72
73 }