MigrateUploadInstanceTest.php 2.2 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Contains \Drupal\file\Tests\Migrate\d6\MigrateUploadInstanceTest.
6
7
 */

8
namespace Drupal\file\Tests\Migrate\d6;
9

10
use Drupal\field\Entity\FieldConfig;
11
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
12
13

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

  /**
   * 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
      'type' => 'file',
      'translatable' => '0',
    ))->save();

54
    $this->executeMigration('d6_upload_field_instance');
55
56
57
58
59
60
  }

  /**
   * Tests the Drupal 6 upload settings to Drupal 8 field instance migration.
   */
  public function testUploadFieldInstance() {
61
    $field = FieldConfig::load('node.page.upload');
62
    $settings = $field->getSettings();
63
64
65
66
    $this->assertIdentical('node.page.upload', $field->id());
    $this->assertIdentical('jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp', $settings['file_extensions']);
    $this->assertIdentical('1MB', $settings['max_filesize']);
    $this->assertIdentical(TRUE, $settings['description_field']);
67

68
    $field = FieldConfig::load('node.story.upload');
69
    $this->assertIdentical('node.story.upload', $field->id());
70
71

    // Shouldn't exist.
72
    $field = FieldConfig::load('node.article.upload');
73
74
    $this->assertTrue(is_null($field));

75
    $this->assertIdentical(array('node', 'page', 'upload'), entity_load('migration', 'd6_upload_field_instance')->getIdMap()->lookupDestinationID(array('page')));
76
77
78
  }

}