You are here

public function EntityReferenceRevisionsDestinationTest::destinationFieldMappingDataProvider in Entity Reference Revisions 8

Provides multiple migration definitions for "getEntity" test.

File

tests/src/Kernel/Plugin/migrate/destination/EntityReferenceRevisionsDestinationTest.php, line 442

Class

EntityReferenceRevisionsDestinationTest
Tests the migration destination plugin.

Namespace

Drupal\Tests\entity_reference_revisions\Kernel\Plugin\migrate\destination

Code

public function destinationFieldMappingDataProvider() {
  return [
    'scenario 1' => [
      [
        'single err' => [
          'definition' => [
            'id' => 'single_err',
            'class' => Migration::class,
            'source' => [
              'plugin' => 'embedded_data',
              'data_rows' => [
                [
                  'id' => 1,
                  'photo' => 'Photo1 here',
                ],
                [
                  'id' => 2,
                  'photo' => 'Photo2 here',
                ],
              ],
              'ids' => [
                'id' => [
                  'type' => 'integer',
                ],
              ],
            ],
            'process' => [
              'name' => 'photo',
            ],
            'destination' => [
              'plugin' => 'entity_reference_revisions:entity_test_composite',
            ],
          ],
          'expected' => [
            [
              'id' => 1,
              'name' => 'Photo1 here',
            ],
            [
              'id' => 2,
              'name' => 'Photo2 here',
            ],
          ],
        ],
        'multiple err author1' => [
          'definition' => [
            'id' => 'multiple_err_author1',
            'class' => Migration::class,
            'source' => [
              'plugin' => 'embedded_data',
              'data_rows' => [
                [
                  'id' => 1,
                  'author' => 'Author 1',
                ],
                [
                  'id' => 2,
                  'author' => 'Author 2',
                ],
              ],
              'ids' => [
                'author' => [
                  'type' => 'text',
                ],
              ],
            ],
            'process' => [
              'name' => 'author',
            ],
            'destination' => [
              'plugin' => 'entity_reference_revisions:entity_test_composite',
            ],
          ],
          'expected' => [
            [
              'id' => 3,
              'name' => 'Author 1',
            ],
            [
              'id' => 4,
              'name' => 'Author 2',
            ],
          ],
        ],
        'multiple err author 2' => [
          'definition' => [
            'id' => 'multiple_err_author2',
            'class' => Migration::class,
            'source' => [
              'plugin' => 'embedded_data',
              'data_rows' => [
                [
                  'id' => 1,
                  'author' => 'Author 3',
                ],
                [
                  'id' => 2,
                  'author' => 'Author 4',
                ],
              ],
              'ids' => [
                'author' => [
                  'type' => 'text',
                ],
              ],
            ],
            'process' => [
              'name' => 'author',
            ],
            'destination' => [
              'plugin' => 'entity_reference_revisions:entity_test_composite',
            ],
          ],
          'expected' => [
            [
              'id' => 5,
              'name' => 'Author 3',
            ],
            [
              'id' => 6,
              'name' => 'Author 4',
            ],
          ],
        ],
        'destination entity' => [
          'definition' => [
            'id' => 'node_migration',
            'class' => Migration::class,
            'source' => [
              'plugin' => 'embedded_data',
              'data_rows' => [
                [
                  'id' => 1,
                  'title' => 'Article 1',
                  'photo' => 'Photo1 here',
                  'author' => [
                    'Author 1',
                    'Author 3',
                  ],
                ],
                [
                  'id' => 2,
                  'title' => 'Article 2',
                  'photo' => 'Photo2 here',
                  'author' => [
                    'Author 2',
                    'Author 4',
                  ],
                ],
              ],
              'ids' => [
                'id' => [
                  'type' => 'integer',
                ],
              ],
            ],
            'process' => [
              'title' => 'title',
              'type' => [
                'plugin' => 'default_value',
                'default_value' => 'article',
              ],
              'field_err_single/target_id' => [
                [
                  'plugin' => 'migration_lookup',
                  'migration' => [
                    'single_err',
                  ],
                  'no_stub' => TRUE,
                  'source' => 'id',
                ],
                [
                  'plugin' => 'extract',
                  'index' => [
                    '0',
                  ],
                ],
              ],
              'field_err_single/target_revision_id' => [
                [
                  'plugin' => 'migration_lookup',
                  'migration' => [
                    'single_err',
                  ],
                  'no_stub' => TRUE,
                  'source' => 'id',
                ],
                [
                  'plugin' => 'extract',
                  'index' => [
                    1,
                  ],
                ],
              ],
              'field_err_multiple' => [
                [
                  'plugin' => 'migration_lookup',
                  'migration' => [
                    'multiple_err_author1',
                    'multiple_err_author2',
                  ],
                  'no_stub' => TRUE,
                  'source' => 'author',
                ],
                [
                  'plugin' => 'sub_process',
                  'process' => [
                    'target_id' => '0',
                    'target_revision_id' => '1',
                  ],
                ],
              ],
            ],
            'destination' => [
              'plugin' => 'entity:node',
            ],
          ],
          'expected' => [
            [
              'id' => 1,
              'title' => 'Article 1',
              'field_err_single' => [
                'Photo1 here',
              ],
              'field_err_multiple' => [
                'Author 1',
                'Author 3',
              ],
            ],
            [
              'id' => 2,
              'title' => 'Article 2',
              'field_err_single' => [
                'Photo2 here',
              ],
              'field_err_multiple' => [
                'Author 2',
                'Author 4',
              ],
            ],
          ],
        ],
      ],
    ],
  ];
}