X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fsrc%2FKernel%2FMigrate%2Fd7%2FMigrateFieldTest.php;h=14c6c31767790bafab7893c1011b6d4230156876;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=ab2fe8e12589f6bb8f1aca6845b4b7564a6781a6;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php b/web/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php index ab2fe8e12..14c6c3176 100644 --- a/web/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php +++ b/web/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php @@ -57,11 +57,11 @@ class MigrateFieldTest extends MigrateDrupal7TestBase { /** @var \Drupal\field\FieldStorageConfigInterface $field */ $field = FieldStorageConfig::load($id); - $this->assertTrue($field instanceof FieldStorageConfigInterface); - $this->assertIdentical($expected_name, $field->getName()); - $this->assertIdentical($expected_type, $field->getType()); - $this->assertEqual($expected_translatable, $field->isTranslatable()); - $this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId()); + $this->assertInstanceOf(FieldStorageConfigInterface::class, $field); + $this->assertEquals($expected_name, $field->getName()); + $this->assertEquals($expected_type, $field->getType()); + $this->assertEquals($expected_translatable, $field->isTranslatable()); + $this->assertEquals($expected_entity_type, $field->getTargetEntityTypeId()); if ($expected_cardinality === 1) { $this->assertFalse($field->isMultiple()); @@ -69,7 +69,7 @@ class MigrateFieldTest extends MigrateDrupal7TestBase { else { $this->assertTrue($field->isMultiple()); } - $this->assertIdentical($expected_cardinality, $field->getCardinality()); + $this->assertEquals($expected_cardinality, $field->getCardinality()); } /** @@ -91,38 +91,98 @@ class MigrateFieldTest extends MigrateDrupal7TestBase { $this->assertEntity('node.field_tags', 'entity_reference', TRUE, -1); $this->assertEntity('node.field_term_reference', 'entity_reference', TRUE, 1); $this->assertEntity('node.taxonomy_forums', 'entity_reference', TRUE, 1); - $this->assertEntity('node.field_text', 'text', TRUE, 1); + $this->assertEntity('node.field_text', 'string', TRUE, 1); $this->assertEntity('node.field_text_list', 'list_string', TRUE, 3); + $this->assertEntity('node.field_float_list', 'list_float', TRUE, 1); $this->assertEntity('node.field_boolean', 'boolean', TRUE, 1); $this->assertEntity('node.field_email', 'email', TRUE, -1); $this->assertEntity('node.field_phone', 'telephone', TRUE, 1); $this->assertEntity('node.field_date', 'datetime', TRUE, 1); - $this->assertEntity('node.field_date_with_end_time', 'datetime', TRUE, 1); + $this->assertEntity('node.field_date_with_end_time', 'timestamp', TRUE, 1); $this->assertEntity('node.field_node_entityreference', 'entity_reference', TRUE, -1); $this->assertEntity('node.field_user_entityreference', 'entity_reference', TRUE, 1); $this->assertEntity('node.field_term_entityreference', 'entity_reference', TRUE, -1); + $this->assertEntity('node.field_date_without_time', 'datetime', TRUE, 1); + $this->assertEntity('node.field_datetime_without_time', 'datetime', TRUE, 1); + + // Tests that fields created by the Title module are not migrated. + $title_field = FieldStorageConfig::load('node.title_field'); + $this->assertNull($title_field); + $subject_field = FieldStorageConfig::load('comment.subject_field'); + $this->assertNull($subject_field); + $name_field = FieldStorageConfig::load('taxonomy_term.name_field'); + $this->assertNull($name_field); + $description_field = FieldStorageConfig::load('taxonomy_term.description_field'); + $this->assertNull($description_field); // Assert that the taxonomy term reference fields are referencing the // correct entity type. $field = FieldStorageConfig::load('node.field_term_reference'); - $this->assertIdentical('taxonomy_term', $field->getSetting('target_type')); + $this->assertEquals('taxonomy_term', $field->getSetting('target_type')); $field = FieldStorageConfig::load('node.taxonomy_forums'); - $this->assertIdentical('taxonomy_term', $field->getSetting('target_type')); + $this->assertEquals('taxonomy_term', $field->getSetting('target_type')); // Assert that the entityreference fields are referencing the correct // entity type. $field = FieldStorageConfig::load('node.field_node_entityreference'); - $this->assertIdentical('node', $field->getSetting('target_type')); + $this->assertEquals('node', $field->getSetting('target_type')); $field = FieldStorageConfig::load('node.field_user_entityreference'); - $this->assertIdentical('user', $field->getSetting('target_type')); + $this->assertEquals('user', $field->getSetting('target_type')); $field = FieldStorageConfig::load('node.field_term_entityreference'); - $this->assertIdentical('taxonomy_term', $field->getSetting('target_type')); + $this->assertEquals('taxonomy_term', $field->getSetting('target_type')); + + // Make sure that datetime fields get the right datetime_type setting + $field = FieldStorageConfig::load('node.field_date'); + $this->assertEquals('datetime', $field->getSetting('datetime_type')); + $field = FieldStorageConfig::load('node.field_date_without_time'); + $this->assertEquals('date', $field->getSetting('datetime_type')); + $field = FieldStorageConfig::load('node.field_datetime_without_time'); + $this->assertEquals('date', $field->getSetting('datetime_type')); + // Except for field_date_with_end_time which is a timestamp and so does not + // have a datetime_type setting. + $field = FieldStorageConfig::load('node.field_date_with_end_time'); + $this->assertNull($field->getSetting('datetime_type')); + } + + /** + * Tests the migration of text fields with different text processing. + */ + public function testTextFields() { + // All text and text_long field bases that have only plain text instances + // should be migrated to string and string_long fields. + // All text_with_summary field bases that have only plain text instances + // should not have been migrated since there's no such thing as a + // string_with_summary field. + $this->assertEntity('node.field_text_plain', 'string', TRUE, 1); + $this->assertEntity('node.field_text_long_plain', 'string_long', TRUE, 1); + $this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain')); + + // All text, text_long and text_with_summary field bases that have only + // filtered text instances should be migrated to text, text_long and + // text_with_summary fields. + $this->assertEntity('node.field_text_filtered', 'text', TRUE, 1); + $this->assertEntity('node.field_text_long_filtered', 'text_long', TRUE, 1); + $this->assertEntity('node.field_text_sum_filtered', 'text_with_summary', TRUE, 1); + + // All text, text_long and text_with_summary field bases that have both + // plain text and filtered text instances should not have been migrated. + $this->assertNull(FieldStorageConfig::load('node.field_text_plain_filtered')); + $this->assertNull(FieldStorageConfig::load('node.field_text_long_plain_filtered')); + $this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain_filtered')); - // Validate that the source count and processed count match up. - /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */ + // For each text field bases that were skipped, there should be a log + // message with the required steps to fix this. $migration = $this->getMigration('d7_field'); - $this->assertSame($migration->getSourcePlugin() - ->count(), $migration->getIdMap()->processedCount()); + $messages = $migration->getIdMap()->getMessageIterator()->fetchAll(); + $errors = array_map(function ($message) { + return $message->message; + }, $messages); + sort($errors); + $this->assertCount(4, $errors); + $this->assertEquals($errors[0], 'Can\'t migrate source field field_text_long_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text'); + $this->assertEquals($errors[1], 'Can\'t migrate source field field_text_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text'); + $this->assertEquals($errors[2], 'Can\'t migrate source field field_text_sum_plain of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text'); + $this->assertEquals($errors[3], 'Can\'t migrate source field field_text_sum_plain_filtered of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text'); } }