You are here

public static function ProductTest::migrateDumpAlter in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\ProductTest::migrateDumpAlter()
  2. 3.0.x modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\ProductTest::migrateDumpAlter()

Allows tests to alter dumps after they have loaded.

Parameters

\Drupal\KernelTests\KernelTestBase $test: The test that is being run.

Overrides MigrateDumpAlterInterface::migrateDumpAlter

File

modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductTest.php, line 76

Class

ProductTest
Tests product migration.

Namespace

Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1

Code

public static function migrateDumpAlter(KernelTestBase $test) {
  $db = Database::getConnection('default', 'migrate');

  // Remove all product types that can be referenced by the hat content type.
  $results = $db
    ->select('field_config_instance', 'fci')
    ->condition('field_name', 'field_product')
    ->condition('entity_type', 'node')
    ->condition('bundle', 'hats')
    ->fields('fci', [
    'data',
  ])
    ->execute()
    ->fetchCol();
  if ($results) {
    $data = unserialize(reset($results));
  }
  $data['settings']['referenceable_types'] = [
    'bags_cases' => 0,
    'drinks' => 0,
    'hats' => 0,
    'shoes' => 0,
    'storage_devices' => 0,
    'tops' => 0,
  ];
  $data = serialize($data);
  $db
    ->update('field_config_instance')
    ->condition('field_name', 'field_product')
    ->condition('entity_type', 'node')
    ->condition('bundle', 'hats')
    ->fields([
    'data' => $data,
  ])
    ->execute();

  // Change the  product types that can be referenced by the shoe content
  // type to 'hats' and 'shoes'.
  $results = $db
    ->select('field_config_instance', 'fci')
    ->condition('field_name', 'field_product')
    ->condition('entity_type', 'node')
    ->condition('bundle', 'shoes')
    ->fields('fci', [
    'data',
  ])
    ->execute()
    ->fetchCol();
  if ($results) {
    $data = unserialize(reset($results));
  }
  $data['settings']['referenceable_types'] = [
    'bags_cases' => 0,
    'drinks' => 0,
    'hats' => 'shoes',
    'shoes' => 'shoes',
    'storage_devices' => 0,
    'tops' => 0,
  ];
  $data = serialize($data);
  $db
    ->update('field_config_instance')
    ->condition('field_name', 'field_product')
    ->condition('entity_type', 'node')
    ->condition('bundle', 'shoes')
    ->fields([
    'data' => $data,
  ])
    ->execute();
}