MigrateUploadInstanceTest.php 2.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

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

namespace Drupal\migrate_drupal\Tests\d6;

10
use Drupal\field\Entity\FieldConfig;
11
12
13
14
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;

/**
15
16
17
 * Upload field instance migration.
 *
 * @group migrate_drupal
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 */
class MigrateUploadInstanceTest extends MigrateDrupalTestBase {

  /**
   * The modules to be enabled during the test.
   *
   * @var array
   */
  static $modules = array('file', 'node');

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    // Add some node mappings to get past checkRequirements().
    $id_mappings = array(
      'd6_upload_field' => array(
        array(array(1), array('node', 'upload')),
      ),
38
39
40
41
      'd6_node_type' => array(
        array(array('page'), array('page')),
        array(array('story'), array('story')),
      ),
42
    );
43
    $this->prepareMigrations($id_mappings);
44
45
46
47

    foreach (array('page', 'story') as $type) {
      entity_create('node_type', array('type' => $type))->save();
    }
48
    entity_create('field_storage_config', array(
49
      'entity_type' => 'node',
50
      'field_name' => 'upload',
51
52
53
54
55
56
      'type' => 'file',
      'translatable' => '0',
    ))->save();

    $migration = entity_load('migration', 'd6_upload_field_instance');
    $dumps = array(
57
58
      $this->getDumpDirectory() . '/NodeType.php',
      $this->getDumpDirectory() . '/Variable.php',
59
60
61
62
63
64
65
66
67
68
    );
    $this->prepare($migration, $dumps);
    $executable = new MigrateExecutable($migration, $this);
    $executable->import();
  }

  /**
   * Tests the Drupal 6 upload settings to Drupal 8 field instance migration.
   */
  public function testUploadFieldInstance() {
69
    $field = FieldConfig::load('node.page.upload');
70
71
72
73
74
75
    $settings = $field->getSettings();
    $this->assertEqual($field->id(), 'node.page.upload');
    $this->assertEqual($settings['file_extensions'], 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp');
    $this->assertEqual($settings['max_filesize'], '1MB');
    $this->assertEqual($settings['description_field'], TRUE);

76
    $field = FieldConfig::load('node.story.upload');
77
78
79
    $this->assertEqual($field->id(), 'node.story.upload');

    // Shouldn't exist.
80
    $field = FieldConfig::load('node.article.upload');
81
82
83
84
85
86
    $this->assertTrue(is_null($field));

    $this->assertEqual(array('node', 'page', 'upload'), entity_load('migration', 'd6_upload_field_instance')->getIdMap()->lookupDestinationID(array('page')));
  }

}