You are here

public function EntityGenerateTest::transformDataProvider in Migrate Plus 8.3

Same name and namespace in other branches
  1. 8.5 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 166

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,
        ],
      ],
    ],
  ];
}