Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\migrate\Unit;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Database\Connection;
|
Chris@0
|
6 use Drupal\migrate\Plugin\MigrationInterface;
|
Chris@0
|
7 use Drupal\migrate\MigrateException;
|
Chris@0
|
8 use Drupal\migrate\Plugin\migrate\id_map\Sql;
|
Chris@0
|
9 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Defines a SQL ID map for use in tests.
|
Chris@0
|
13 */
|
Chris@0
|
14 class TestSqlIdMap extends Sql implements \Iterator {
|
Chris@0
|
15
|
Chris@0
|
16 /**
|
Chris@0
|
17 * Constructs a TestSqlIdMap object.
|
Chris@0
|
18 *
|
Chris@0
|
19 * @param \Drupal\Core\Database\Connection $database
|
Chris@0
|
20 * The database.
|
Chris@0
|
21 * @param array $configuration
|
Chris@0
|
22 * The configuration.
|
Chris@0
|
23 * @param string $plugin_id
|
Chris@0
|
24 * The plugin ID for the migration process to do.
|
Chris@0
|
25 * @param mixed $plugin_definition
|
Chris@0
|
26 * The configuration for the plugin.
|
Chris@0
|
27 * @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
Chris@0
|
28 * The migration to do.
|
Chris@0
|
29 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
Chris@0
|
30 * The event dispatcher service.
|
Chris@0
|
31 */
|
Chris@0
|
32 public function __construct(Connection $database, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EventDispatcherInterface $event_dispatcher) {
|
Chris@0
|
33 $this->database = $database;
|
Chris@0
|
34 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $event_dispatcher);
|
Chris@0
|
35 }
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * {@inheritdoc}
|
Chris@0
|
39 */
|
Chris@0
|
40 public function getDatabase() {
|
Chris@0
|
41 return parent::getDatabase();
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * Gets the field schema.
|
Chris@0
|
46 *
|
Chris@0
|
47 * @param array $id_definition
|
Chris@0
|
48 * An array defining the field, with a key 'type'.
|
Chris@0
|
49 *
|
Chris@0
|
50 * @return array
|
Chris@0
|
51 * A field schema depending on value of key 'type'. An empty array is
|
Chris@0
|
52 * returned if 'type' is not defined.
|
Chris@0
|
53 *
|
Chris@0
|
54 * @throws \Drupal\migrate\MigrateException
|
Chris@0
|
55 */
|
Chris@0
|
56 protected function getFieldSchema(array $id_definition) {
|
Chris@0
|
57 if (!isset($id_definition['type'])) {
|
Chris@0
|
58 return [];
|
Chris@0
|
59 }
|
Chris@0
|
60 switch ($id_definition['type']) {
|
Chris@0
|
61 case 'integer':
|
Chris@0
|
62 return [
|
Chris@0
|
63 'type' => 'int',
|
Chris@0
|
64 'not null' => TRUE,
|
Chris@0
|
65 ];
|
Chris@0
|
66
|
Chris@0
|
67 case 'string':
|
Chris@0
|
68 return [
|
Chris@0
|
69 'type' => 'varchar',
|
Chris@0
|
70 'length' => 255,
|
Chris@0
|
71 'not null' => FALSE,
|
Chris@0
|
72 ];
|
Chris@0
|
73
|
Chris@0
|
74 default:
|
Chris@0
|
75 throw new MigrateException($id_definition['type'] . ' not supported');
|
Chris@0
|
76 }
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 }
|