MigrateUploadInstanceTest.php 2.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

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

namespace Drupal\migrate_drupal\Tests\d6;

use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;

/**
14
15
16
 * Upload field instance migration.
 *
 * @group migrate_drupal
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 */
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')),
      ),
37
38
39
40
      'd6_node_type' => array(
        array(array('page'), array('page')),
        array(array('story'), array('story')),
      ),
41
    );
42
    $this->prepareMigrations($id_mappings);
43
44
45
46

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

    $migration = entity_load('migration', 'd6_upload_field_instance');
    $dumps = array(
56
      $this->getDumpDirectory() . '/Drupal6UploadInstance.php',
57
58
59
60
61
62
63
64
65
66
    );
    $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() {
67
    $field = entity_load('field_config', 'node.page.upload');
68
69
70
71
72
73
    $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);

74
    $field = entity_load('field_config', 'node.story.upload');
75
76
77
    $this->assertEqual($field->id(), 'node.story.upload');

    // Shouldn't exist.
78
    $field = entity_load('field_config', 'node.article.upload');
79
80
81
82
83
84
    $this->assertTrue(is_null($field));

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

}