MigrateCckFieldValuesTest.php 6.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\migrate_drupal\Tests\d6\MigrateCckFieldValuesTest.
 */

namespace Drupal\migrate_drupal\Tests\d6;

use Drupal\migrate\MigrateExecutable;
11
use Drupal\node\Entity\Node;
12 13

/**
14 15 16
 * CCK field content migration.
 *
 * @group migrate_drupal
17 18 19 20 21 22 23 24
 */
class MigrateCckFieldValuesTest extends MigrateNodeTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
25
  public static $modules = array('node', 'text', 'link', 'file');
26 27 28 29 30 31

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
32
    entity_create('field_storage_config', array(
33
      'entity_type' => 'node',
34
      'field_name' => 'field_test',
35 36
      'type' => 'text',
    ))->save();
37
    entity_create('field_config', array(
38 39 40 41
      'entity_type' => 'node',
      'field_name' => 'field_test',
      'bundle' => 'story',
    ))->save();
42
    entity_create('field_storage_config', array(
43
      'entity_type' => 'node',
44
      'field_name' => 'field_test_two',
45 46 47
      'type' => 'integer',
      'cardinality' => -1,
    ))->save();
48
    entity_create('field_config', array(
49 50 51 52
      'entity_type' => 'node',
      'field_name' => 'field_test_two',
      'bundle' => 'story',
    ))->save();
53
    entity_create('field_storage_config', array(
54
      'entity_type' => 'node',
55
      'field_name' => 'field_test_three',
56 57
      'type' => 'decimal',
    ))->save();
58
    entity_create('field_config', array(
59 60 61 62
      'entity_type' => 'node',
      'field_name' => 'field_test_three',
      'bundle' => 'story',
    ))->save();
63 64
    entity_create('field_storage_config', array(
      'entity_type' => 'node',
65
      'field_name' => 'field_test_integer_selectlist',
66 67
      'type' => 'integer',
    ))->save();
68
    entity_create('field_config', array(
69 70 71 72
      'entity_type' => 'node',
      'field_name' => 'field_test_integer_selectlist',
      'bundle' => 'story',
    ))->save();
73 74 75 76 77 78 79 80 81 82
    entity_create('field_storage_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_exclude_unset',
      'type' => 'text',
    ))->save();
    entity_create('field_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_exclude_unset',
      'bundle' => 'story',
    ))->save();
83

84 85
    entity_create('field_storage_config', array(
      'entity_type' => 'node',
86
      'field_name' => 'field_multivalue',
87 88 89 90 91 92 93 94 95
      'type' => 'integer',
      'cardinality' => -1,
    ))->save();
    entity_create('field_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_multivalue',
      'bundle' => 'test_planet',
    ))->save();

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    entity_create('field_storage_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_identical1',
      'type' => 'integer',
    ))->save();
    entity_create('field_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_identical1',
      'bundle' => 'story',
    ))->save();

    entity_create('field_storage_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_identical2',
      'type' => 'integer',
    ))->save();
    entity_create('field_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_identical2',
      'bundle' => 'story',
    ))->save();

118 119 120 121 122 123 124 125 126 127 128
    entity_create('field_storage_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_link',
      'type' => 'link',
    ))->save();
    entity_create('field_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_link',
      'bundle' => 'story',
    ))->save();

129 130 131 132 133 134 135 136 137 138 139
    entity_create('field_storage_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_filefield',
      'type' => 'file',
    ))->save();
    entity_create('field_config', array(
      'entity_type' => 'node',
      'field_name' => 'field_test_filefield',
      'bundle' => 'story',
    ))->save();

140 141 142 143 144 145 146 147 148 149 150
    // Add some id mappings for the dependant migrations.
    $id_mappings = array(
      'd6_field_formatter_settings' => array(
        array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test')),
      ),
      'd6_field_instance_widget_settings' => array(
        array(array('page', 'field_test'), array('node', 'page', 'default', 'test')),
      ),
      'd6_node' => array(
        array(array(1), array(1)),
        array(array(2), array(2)),
151
        array(array(3), array(3)),
152 153
      ),
    );
154
    $this->prepareMigrations($id_mappings);
155 156 157 158 159 160 161 162 163 164 165 166 167

    $migrations = entity_load_multiple('migration', array('d6_cck_field_values:*'));
    foreach ($migrations as $migration) {
      $executable = new MigrateExecutable($migration, $this);
      $executable->import();
    }

  }

  /**
   * Test CCK migration from Drupal 6 to 8.
   */
  public function testCckFields() {
168
    $node = Node::load(1);
169 170

    $this->assertEqual($node->field_test->value, 'This is a shared text field');
171
    $this->assertEqual($node->field_test->format, 'filtered_html');
172 173 174
    $this->assertEqual($node->field_test_two->value, 10);
    $this->assertEqual($node->field_test_two[1]->value, 20);

175
    $this->assertEqual($node->field_test_three->value, '42.42', 'Single field second value is correct.');
176
    $this->assertEqual($node->field_test_integer_selectlist[0]->value, '3412');
177 178
    $this->assertEqual($node->field_test_identical1->value, '1', 'Integer value is correct');
    $this->assertEqual($node->field_test_identical2->value, '1', 'Integer value is correct');
179
    $this->assertEqual($node->field_test_exclude_unset->value, 'This is a field with exclude unset.', 'Field with exclude unset is correct.');
180

181
    // Test that link fields are migrated.
182
    $this->assertIdentical($node->field_test_link->uri, 'http://drupal.org/project/drupal');
183 184 185
    $this->assertIdentical($node->field_test_link->title, 'Drupal project page');
    $this->assertIdentical($node->field_test_link->options['attributes'], ['target' => '_blank']);

186 187
    // Test the file field meta.
    $this->assertIdentical($node->field_test_filefield->description, 'desc');
188
    $this->assertIdentical($node->field_test_filefield->target_id, '5');
189

190 191 192
    $planet_node = Node::load(3);
    $this->assertEqual($planet_node->field_multivalue->value, 33);
    $this->assertEqual($planet_node->field_multivalue[1]->value, 44);
193 194 195
  }

}