You are here

protected function ProductTest::setUp in Commerce Migrate 8.2

Same name in this branch
  1. 8.2 modules/csv_example/tests/src/Kernel/Migrate/ProductTest.php \Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate\ProductTest::setUp()
  2. 8.2 modules/magento/tests/src/Kernel/Migrate/magento2/ProductTest.php \Drupal\Tests\commerce_migrate_magento\Kernel\Migrate\magento2\ProductTest::setUp()
  3. 8.2 modules/ubercart/tests/src/Kernel/Migrate/uc7/ProductTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc7\ProductTest::setUp()
  4. 8.2 modules/ubercart/tests/src/Kernel/Migrate/uc6/ProductTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc6\ProductTest::setUp()
  5. 8.2 modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\ProductTest::setUp()
Same name and namespace in other branches
  1. 3.1.x modules/csv_example/tests/src/Kernel/Migrate/ProductTest.php \Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate\ProductTest::setUp()
  2. 3.0.x modules/csv_example/tests/src/Kernel/Migrate/ProductTest.php \Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate\ProductTest::setUp()

Overrides CsvTestBase::setUp

File

modules/csv_example/tests/src/Kernel/Migrate/ProductTest.php, line 61

Class

ProductTest
Tests Product migration.

Namespace

Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('commerce_store');
  $this
    ->createDefaultStore();
  $this
    ->installEntitySchema('paragraph');
  $this
    ->installEntitySchema('taxonomy_term');
  $this
    ->installEntitySchema('commerce_product_variation');
  $this
    ->installEntitySchema('commerce_product');
  $this
    ->installEntitySchema('commerce_product_attribute');
  $this
    ->installEntitySchema('commerce_product_attribute_value');
  $this
    ->installConfig('commerce_product');
  $this
    ->createAttribute([
    'Accessory Size',
    'Color',
    'Shoe Size',
    'Size',
  ]);
  $vocabularies = [
    'Category',
    'Season',
  ];
  $this
    ->createVocabularies($vocabularies);
  foreach ($vocabularies as $vocabulary) {
    $id = strtolower($vocabulary);
    $id = preg_replace('/[^a-z0-9_]+/', '_', $id);
    preg_replace('/_+/', '_', $id);
    $field_name = 'field_' . $id;
    $field_storage_definition = [
      'field_name' => $field_name,
      'entity_type' => 'commerce_product',
      'type' => 'entity_reference',
      'cardinality' => 3,
      'settings' => [
        'target_type' => 'taxonomy_term',
      ],
    ];
    $storage = FieldStorageConfig::create($field_storage_definition);
    $storage
      ->save();
    $field_instance = [
      'field_name' => $field_name,
      'entity_type' => 'commerce_product',
      'bundle' => 'default',
      'label' => $vocabulary,
      'settings' => [
        'handler' => 'default:taxonomy_term',
        'handler_settings' => [
          'target_bundles' => [
            'category' => 'category',
          ],
        ],
      ],
    ];
    $field = FieldConfig::create($field_instance);
    $field
      ->save();
  }
  $field_name = 'field_suggested_products';
  $field_storage_definition = [
    'field_name' => $field_name,
    'entity_type' => 'commerce_product',
    'type' => 'entity_reference',
    'cardinality' => 3,
    'settings' => [
      'target_type' => 'taxonomy_term',
    ],
  ];
  $storage = FieldStorageConfig::create($field_storage_definition);
  $storage
    ->save();
  $field_instance = [
    'field_name' => $field_name,
    'entity_type' => 'commerce_product',
    'bundle' => 'default',
    'label' => 'suggested',
    'field_type' => 'entity_reference',
    'settings' => [
      'handler' => 'default:commerce_product',
      'handler_settings' => [
        'target_bundles' => [
          'default' => 'default',
        ],
      ],
    ],
  ];
  $field = FieldConfig::create($field_instance);
  $field
    ->save();
}