From 3bacf6ec6611cea2126c5c7663992c1d407d0f45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kurucz=20Istv=C3=A1n?= <kurucz.istvan@gmail.com>
Date: Wed, 3 Nov 2021 01:13:06 +0100
Subject: [PATCH] node-type migration test

---
 tests/src/Kernel/MigrateDrupal5TestBase.php | 52 ++++++++++++++++++++
 tests/src/Kernel/MigrateNodeTypeTest.php    | 54 +++++++++++++++++++++
 2 files changed, 106 insertions(+)
 create mode 100644 tests/src/Kernel/MigrateDrupal5TestBase.php
 create mode 100644 tests/src/Kernel/MigrateNodeTypeTest.php

diff --git a/tests/src/Kernel/MigrateDrupal5TestBase.php b/tests/src/Kernel/MigrateDrupal5TestBase.php
new file mode 100644
index 0000000..2d46085
--- /dev/null
+++ b/tests/src/Kernel/MigrateDrupal5TestBase.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Drupal\Tests\migrate_drupal_d5\Kernel;
+
+use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
+use Drupal\Tests\migrate_drupal\Traits\NodeMigrateTypeTestTrait;
+
+/**
+ * Base class for Drupal 5 migration tests.
+ */
+abstract class MigrateDrupal5TestBase extends MigrateDrupalTestBase {
+
+  use NodeMigrateTypeTestTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = [
+    'datetime',
+    'filter',
+    'image',
+    'link',
+    'migrate_drupal_d5',
+    'node',
+    'options',
+    'telephone',
+    'text',
+  ];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->loadFixture($this->getFixtureFilePath());
+  }
+
+  /**
+   * Gets the path to the fixture file.
+   */
+  protected function getFixtureFilePath() {
+    return __DIR__ . '/../../fixtures/drupal5.php';
+  }
+
+  /**
+   * Migrates node types.
+   */
+  protected function migrateContentTypes() {
+    $this->installConfig(['node']);
+    $this->executeMigration('d5_node_type');
+  }
+}
diff --git a/tests/src/Kernel/MigrateNodeTypeTest.php b/tests/src/Kernel/MigrateNodeTypeTest.php
new file mode 100644
index 0000000..5f87629
--- /dev/null
+++ b/tests/src/Kernel/MigrateNodeTypeTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Drupal\Tests\migrate_drupal_d5\Kernel;
+
+use Drupal\field\Entity\FieldConfig;
+use Drupal\node\Entity\NodeType;
+
+/**
+ * Upgrade node types to node.type.*.yml.
+ *
+ * @group migrate_drupal_5
+ */
+class MigrateNodeTypeTest extends MigrateDrupal5TestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp(): void {
+    parent::setUp();
+    $this->migrateContentTypes();
+  }
+
+  /**
+   * Tests Drupal 5 "page" node type to Drupal 8 migration.
+   */
+  public function testPageNodeType() {
+    $id_map = $this->getMigration('d5_node_type')->getIdMap();
+    $node_type= NodeType::load('page');
+    $this->assertSame('page', $node_type->id(), 'Node type page loaded');
+    $this->assertFalse($node_type->displaySubmitted());
+    $this->assertFalse($node_type->shouldCreateNewRevision());
+    $this->assertSame(DRUPAL_OPTIONAL, $node_type->getPreviewMode());
+    $this->assertSame($id_map->lookupDestinationIds(['page']), [['page']]);
+    // Test we have a body field.
+    $field_body = FieldConfig::loadByName('node', 'page', 'body');
+    $this->assertSame('Body', $field_body->getLabel(), 'Body field was found.');
+  }
+
+  /**
+   * Tests Drupal 5 "book" node type to Drupal 8 migration.
+   */
+  public function testBookNodeType() {
+    $id_map = $this->getMigration('d5_node_type')->getIdMap();
+    $node_type= NodeType::load('book');
+    $this->assertSame('book', $node_type->id(), 'Node type book loaded');
+    $this->assertTrue($node_type->displaySubmitted());
+    $this->assertTrue($node_type->shouldCreateNewRevision());
+    $this->assertSame(DRUPAL_OPTIONAL, $node_type->getPreviewMode());
+    $this->assertSame($id_map->lookupDestinationIds(['book']), [['book']]);
+    // Test we have a body field.
+    $field_body = FieldConfig::loadByName('node', 'book', 'body');
+    $this->assertSame('Book body label', $field_body->getLabel(), 'Body field was found.');
+  }
+}
-- 
GitLab