3 namespace Drupal\Tests\field\Kernel\Migrate\d7;
5 use Drupal\field\Entity\FieldStorageConfig;
6 use Drupal\migrate\MigrateExecutable;
9 * Migrates and rolls back Drupal 7 fields.
13 class RollbackFieldTest extends MigrateFieldTest {
16 * Tests migrating D7 fields to field_storage_config entities, then rolling back.
18 public function testFields() {
19 // Test that the fields have migrated (prior to rollback).
22 $this->executeRollback('d7_field');
24 // Check that fields have been rolled back.
25 $rolled_back_field_ids = [
26 'comment.field_integer',
27 'node.taxonomy_forums',
30 'node.field_term_reference',
31 'node.field_text_list',
37 'node.field_long_text',
38 'node.field_date_with_end_time',
39 'node.field_integer_list',
47 foreach ($rolled_back_field_ids as $field_id) {
48 $this->assertNull(FieldStorageConfig::load($field_id));
51 // Check that fields that should persist have not been rolled back.
52 $non_rolled_back_field_ids = [
54 'comment.comment_body',
56 foreach ($non_rolled_back_field_ids as $field_id) {
57 $this->assertNotNull(FieldStorageConfig::load($field_id));
62 * Executes a single rollback.
64 * @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
65 * The migration to rollback, or its ID.
67 protected function executeRollback($migration) {
68 if (is_string($migration)) {
69 $this->migration = $this->getMigration($migration);
72 $this->migration = $migration;
74 (new MigrateExecutable($this->migration, $this))->rollback();