You are here

public function FieldTest::providerSource in Commerce Migrate 8.2

Same name in this branch
  1. 8.2 modules/ubercart/tests/src/Kernel/Plugin/migrate/source/uc7/FieldTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Plugin\migrate\source\uc7\FieldTest::providerSource()
  2. 8.2 modules/commerce/tests/src/Kernel/Plugin/migrate/source/commerce1/FieldTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Plugin\migrate\source\commerce1\FieldTest::providerSource()
Same name and namespace in other branches
  1. 3.1.x modules/commerce/tests/src/Kernel/Plugin/migrate/source/commerce1/FieldTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Plugin\migrate\source\commerce1\FieldTest::providerSource()
  2. 3.0.x modules/commerce/tests/src/Kernel/Plugin/migrate/source/commerce1/FieldTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Plugin\migrate\source\commerce1\FieldTest::providerSource()

The data provider.

Return value

array Array of data sets to test, each of which is a numerically indexed array with the following elements:

  • An array of source data, which can be optionally processed and set up by subclasses.
  • An array of expected result rows.
  • (optional) The number of result rows the plugin under test is expected to return. If this is not a numeric value, the plugin will not be counted.
  • (optional) Array of configuration options for the plugin under test.

Overrides MigrateSourceTestBase::providerSource

See also

\Drupal\Tests\migrate\Kernel\MigrateSourceTestBase::testSource

File

modules/commerce/tests/src/Kernel/Plugin/migrate/source/commerce1/FieldTest.php, line 35

Class

FieldTest
Tests the Commerce 1 field source plugin.

Namespace

Drupal\Tests\commerce_migrate_commerce\Kernel\Plugin\migrate\source\commerce1

Code

public function providerSource() {
  $tests = [];
  $tests[0]['source_data']['commerce_product_type'] = [
    [
      'type' => 'product',
      'name' => 'Product',
      'description' => 'Basic product type',
      'help' => '',
      'revision' => '1',
    ],
  ];

  // The source data.
  $tests[0]['source_data']['field_config'] = [
    [
      'id' => '3',
      'field_name' => 'commerce_price',
      'type' => 'commerce_price',
      'module' => 'commerce_price',
      'active' => '1',
      'storage_type' => 'field_sql_storage',
      'storage_module' => 'field_sql_storage',
      'storage_active' => '1',
      'locked' => '1',
      'data' => 'a:7:{s:12:"entity_types";a:1:{i:0;s:16:"commerce_product";}s:7:"indexes";a:1:{s:14:"currency_price";a:2:{i:0;s:6:"amount";i:1;s:13:"currency_code";}}s:8:"settings";a:0:{}s:12:"translatable";i:0;s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";}s:12:"foreign keys";a:0:{}s:2:"id";s:1:"9";}',
      'cardinality' => '-1',
      'translatable' => '0',
      'deleted' => '0',
    ],
    [
      'id' => '10',
      'field_name' => 'field_file',
      'type' => 'file',
      'module' => 'file',
      'active' => '1',
      'storage_type' => 'field_sql_storage',
      'storage_module' => 'field_sql_storage',
      'storage_active' => '1',
      'locked' => '0',
      'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
      'cardinality' => '1',
      'translatable' => '0',
      'deleted' => '0',
    ],
  ];
  $tests[0]['source_data']['field_config_instance'] = [
    [
      'id' => '1',
      'field_id' => '10',
      'field_name' => 'field_file',
      'entity_type' => 'node',
      'bundle' => 'test_content_type',
      'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"5";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:15:"txt pdf ods odf";s:12:"max_filesize";s:5:"10 MB";s:17:"description_field";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:6:"weight";s:1:"5";s:8:"settings";a:0:{}s:6:"module";s:4:"file";}}s:8:"required";i:0;s:11:"description";s:0:"";}',
      'deleted' => '0',
    ],
    [
      'id' => '2',
      'field_id' => '2',
      'field_name' => 'commerce_price',
      'entity_type' => 'commerce_product',
      'bundle' => 'product',
      'data' => 'a:6:{s:5:"label";s:5:"Price";s:8:"required";b:1;s:8:"settings";a:1:{s:18:"user_register_form";b:0;}s:6:"widget";a:4:{s:4:"type";s:19:"commerce_price_full";s:6:"weight";i:0;s:8:"settings";a:1:{s:13:"currency_code";s:7:"default";}s:6:"module";s:14:"commerce_price";}s:7:"display";a:5:{s:4:"full";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:31:"commerce_price_formatted_amount";s:8:"settings";a:1:{s:11:"calculation";s:21:"calculated_sell_price";}s:6:"weight";i:0;s:6:"module";s:14:"commerce_price";}s:9:"line_item";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:31:"commerce_price_formatted_amount";s:8:"settings";a:1:{s:11:"calculation";s:21:"calculated_sell_price";}s:6:"weight";i:0;s:6:"module";s:14:"commerce_price";}s:26:"commerce_line_item_display";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:31:"commerce_price_formatted_amount";s:8:"settings";a:1:{s:11:"calculation";s:21:"calculated_sell_price";}s:6:"weight";i:0;s:6:"module";s:14:"commerce_price";}s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:31:"commerce_price_formatted_amount";s:8:"settings";a:1:{s:11:"calculation";s:21:"calculated_sell_price";}s:6:"weight";i:0;s:6:"module";s:14:"commerce_price";}s:11:"node_teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:31:"commerce_price_formatted_amount";s:8:"settings";a:1:{s:11:"calculation";s:21:"calculated_sell_price";}s:6:"weight";i:0;s:6:"module";s:14:"commerce_price";}}s:11:"description";s:0:"";}',
      'deleted' => '0',
    ],
    [
      'id' => '3',
      'field_id' => '10',
      'field_name' => 'field_file',
      'entity_type' => 'node',
      'bundle' => 'product',
      'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"5";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:15:"txt pdf ods odf";s:12:"max_filesize";s:5:"10 MB";s:17:"description_field";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:6:"weight";s:1:"5";s:8:"settings";a:0:{}s:6:"module";s:4:"file";}}s:8:"required";i:0;s:11:"description";s:0:"";}',
      'deleted' => '0',
    ],
  ];
  $tests[0]['source_data']['field_revision_commerce_order_total'] = [
    [
      'entity_type' => 'commerce_order',
      'bundle' => 'commerce_order',
      'deleted' => 0,
      'entity_id' => 2,
      'revision_id' => '16',
      'language' => 'und',
      'delta' => 0,
      'commerce_order_total_amount' => '77.23',
      'commerce_order_total_currency_code' => 'USD',
      'data' => 'a:1:{s:10:"components";a:1:{i:0;a:3:{s:4:"name";s:10:"base_price";s:5:"price";a:3:{s:6:"amount";i:3999;s:13:"currency_code";s:3:"USD";s:4:"data";a:0:{}}s:8:"included";b:1;}}}',
    ],
  ];

  // The expected results.
  $tests[0]['expected_data'] = [
    [
      'id' => '11',
      'field_name' => 'field_file',
      'type' => 'file',
      'module' => 'file',
      'active' => '1',
      'storage_type' => 'field_sql_storage',
      'storage_module' => 'field_sql_storage',
      'storage_active' => '1',
      'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
      'cardinality' => '1',
      'translatable' => '0',
      'deleted' => '0',
      'entity_type' => 'node',
      'commerce1_entity_type' => 'node',
    ],
    [
      'id' => '11',
      'field_name' => 'field_file',
      'type' => 'file',
      'module' => 'file',
      'active' => '1',
      'storage_type' => 'field_sql_storage',
      'storage_module' => 'field_sql_storage',
      'storage_active' => '1',
      'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
      'cardinality' => '1',
      'translatable' => '0',
      'deleted' => '0',
      'entity_type' => 'product_display',
      'commerce1_entity_type' => 'product_display',
    ],
  ];

  // Set expected count to 1 because custom Field::InitializeIterator()
  // is not executed when counting the rows.
  $tests[0]['expected_count'] = 1;
  return $tests;
}