You are here

public function EntityGenerateTest::transformDataProvider in Migrate Plus 8.5

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php \Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process\EntityGenerateTest::transformDataProvider()
  2. 8.4 tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php \Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process\EntityGenerateTest::transformDataProvider()

Provides multiple migration definitions for "transform" test.

File

tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php, line 320

Class

EntityGenerateTest
Tests the migration plugin.

Namespace

Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process

Code

public function transformDataProvider() {
  return [
    'no arguments' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => 'Apples',
            ],
            [
              'id' => 2,
              'title' => 'content item 2',
              'term' => 'Bananas',
            ],
            [
              'id' => 3,
              'title' => 'content item 3',
              'term' => 'Grapes',
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          'title' => 'title',
          $this->fieldName => [
            'plugin' => 'entity_generate',
            'source' => 'term',
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'title' => 'content item 1',
          $this->fieldName => [
            'tid' => 2,
            'name' => 'Apples',
          ],
        ],
        'row 2' => [
          'id' => 2,
          'title' => 'content item 2',
          $this->fieldName => [
            'tid' => 3,
            'name' => 'Bananas',
          ],
        ],
        'row 3' => [
          'id' => 3,
          'title' => 'content item 3',
          $this->fieldName => [
            'tid' => 1,
            'name' => 'Grapes',
          ],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          'name' => 'Grapes',
          'vid' => $this->vocabulary,
          'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        ],
      ],
    ],
    'no arguments_lookup_only' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => 'Apples',
            ],
            [
              'id' => 2,
              'title' => 'content item 2',
              'term' => 'Bananas',
            ],
            [
              'id' => 3,
              'title' => 'content item 3',
              'term' => 'Grapes',
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          'title' => 'title',
          $this->fieldName => [
            'plugin' => 'entity_lookup',
            'source' => 'term',
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'title' => 'content item 1',
          $this->fieldName => [
            'tid' => NULL,
            'name' => NULL,
          ],
        ],
        'row 2' => [
          'id' => 2,
          'title' => 'content item 2',
          $this->fieldName => [
            'tid' => NULL,
            'name' => NULL,
          ],
        ],
        'row 3' => [
          'id' => 3,
          'title' => 'content item 3',
          $this->fieldName => [
            'tid' => 1,
            'name' => 'Grapes',
          ],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          'name' => 'Grapes',
          'vid' => $this->vocabulary,
          'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        ],
      ],
    ],
    'provide values' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => 'Apples',
            ],
            [
              'id' => 2,
              'title' => 'content item 2',
              'term' => 'Bananas',
            ],
            [
              'id' => 3,
              'title' => 'content item 3',
              'term' => 'Grapes',
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          'title' => 'title',
          'term_upper' => [
            'plugin' => 'callback',
            'source' => 'term',
            'callable' => 'strtoupper',
          ],
          $this->fieldName => [
            'plugin' => 'entity_generate',
            'source' => 'term',
            'values' => [
              'description' => '@term_upper',
            ],
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'title' => 'content item 1',
          $this->fieldName => [
            'tid' => 2,
            'name' => 'Apples',
            'description' => 'APPLES',
          ],
        ],
        'row 2' => [
          'id' => 2,
          'title' => 'content item 2',
          $this->fieldName => [
            'tid' => 3,
            'name' => 'Bananas',
            'description' => 'BANANAS',
          ],
        ],
        'row 3' => [
          'id' => 3,
          'title' => 'content item 3',
          $this->fieldName => [
            'tid' => 1,
            'name' => 'Grapes',
            'description' => NULL,
          ],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          'name' => 'Grapes',
          'vid' => $this->vocabulary,
          'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        ],
      ],
    ],
    'provide multiple values' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => 'Apples',
            ],
            [
              'id' => 2,
              'title' => 'content item 2',
              'term' => 'Bananas',
            ],
            [
              'id' => 3,
              'title' => 'content item 3',
              'term' => 'Grapes',
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
          'constants' => [
            'foo' => 'bar',
          ],
        ],
        'process' => [
          'id' => 'id',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          'title' => 'title',
          'term_upper' => [
            'plugin' => 'callback',
            'source' => 'term',
            'callable' => 'strtoupper',
          ],
          $this->fieldName => [
            'plugin' => 'entity_generate',
            'source' => 'term',
            'values' => [
              'name' => '@term_upper',
              'description' => 'constants/foo',
            ],
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'title' => 'content item 1',
          $this->fieldName => [
            'tid' => 2,
            'name' => 'APPLES',
            'description' => 'bar',
          ],
        ],
        'row 2' => [
          'id' => 2,
          'title' => 'content item 2',
          $this->fieldName => [
            'tid' => 3,
            'name' => 'BANANAS',
            'description' => 'bar',
          ],
        ],
        'row 3' => [
          'id' => 3,
          'title' => 'content item 3',
          $this->fieldName => [
            'tid' => 1,
            'name' => 'Grapes',
            'description' => NULL,
          ],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          'name' => 'Grapes',
          'vid' => $this->vocabulary,
          'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        ],
      ],
    ],
    'lookup single existing term returns correct term' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => 'Grapes',
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          'title' => 'title',
          $this->fieldName => [
            'plugin' => 'entity_lookup',
            'source' => 'term',
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'title' => 'content item 1',
          $this->fieldName => [
            'tid' => 1,
            'name' => 'Grapes',
          ],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          'name' => 'Grapes',
          'vid' => $this->vocabulary,
          'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        ],
      ],
    ],
    'lookup single missing term returns null value' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => 'Apple',
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          'title' => 'title',
          $this->fieldName => [
            'plugin' => 'entity_lookup',
            'source' => 'term',
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'title' => 'content item 1',
          $this->fieldName => [],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          'name' => 'Grapes',
          'vid' => $this->vocabulary,
          'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        ],
      ],
    ],
    'lookup multiple existing terms returns correct terms' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => [
                'Grapes',
                'Apples',
              ],
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'title' => 'title',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          $this->fieldName => [
            'plugin' => 'entity_lookup',
            'source' => 'term',
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'title' => 'content item 1',
          $this->fieldName => [
            [
              'tid' => 1,
              'name' => 'Grapes',
            ],
            [
              'tid' => 2,
              'name' => 'Apples',
            ],
          ],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          [
            'name' => 'Grapes',
            'vid' => $this->vocabulary,
            'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
          ],
          [
            'name' => 'Apples',
            'vid' => $this->vocabulary,
            'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
          ],
        ],
      ],
    ],
    'lookup multiple mixed terms returns correct terms' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => [
                'Grapes',
                'Pears',
              ],
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'title' => 'title',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          $this->fieldName => [
            'plugin' => 'entity_lookup',
            'source' => 'term',
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => '1',
          'title' => 'content item 1',
          $this->fieldName => [
            [
              'tid' => 1,
              'name' => 'Grapes',
            ],
          ],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          [
            'name' => 'Grapes',
            'vid' => $this->vocabulary,
            'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
          ],
          [
            'name' => 'Apples',
            'vid' => $this->vocabulary,
            'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
          ],
        ],
      ],
    ],
    'lookup with empty term value returns no terms' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'title' => 'content item 1',
              'term' => [],
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'title' => 'title',
          'type' => [
            'plugin' => 'default_value',
            'default_value' => $this->bundle,
          ],
          $this->fieldName => [
            'plugin' => 'entity_lookup',
            'source' => 'term',
          ],
        ],
        'destination' => [
          'plugin' => 'entity:node',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'title' => 'content item 1',
          $this->fieldName => [],
        ],
      ],
      'pre seed' => [
        'taxonomy_term' => [
          'name' => 'Grapes',
          'vid' => $this->vocabulary,
          'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        ],
      ],
    ],
    'lookup config entity' => [
      'definition' => [
        'source' => [
          'plugin' => 'embedded_data',
          'data_rows' => [
            [
              'id' => 1,
              'name' => 'user 1',
              'mail' => 'user1@user1.com',
              'roles' => [
                'role_1',
              ],
            ],
          ],
          'ids' => [
            'id' => [
              'type' => 'integer',
            ],
          ],
        ],
        'process' => [
          'id' => 'id',
          'name' => 'name',
          'roles' => [
            'plugin' => 'entity_lookup',
            'entity_type' => 'user_role',
            'value_key' => 'id',
            'source' => 'roles',
          ],
        ],
        'destination' => [
          'plugin' => 'entity:user',
        ],
      ],
      'expected' => [
        'row 1' => [
          'id' => 1,
          'name' => 'user 1',
          'roles' => [
            'id' => 'role_1',
            'label' => 'Role 1',
          ],
        ],
      ],
      'pre seed' => [
        'user_role' => [
          'id' => 'role_1',
          'label' => 'Role 1',
        ],
      ],
    ],
  ];
}