diff --git a/tests/src/Kernel/MigrateDrupal5TestBase.php b/tests/src/Kernel/MigrateDrupal5TestBase.php new file mode 100644 index 0000000000000000000000000000000000000000..2d46085cea07134616141b743d57185da024e5ca --- /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 0000000000000000000000000000000000000000..5f87629638fc8b4259346d9ae239707ac3cd2dde --- /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.'); + } +}