MigrateVocabularyFieldInstanceTest.php 2.17 KB
Newer Older
1
2
3
4
<?php

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

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

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

/**
15
16
 * Vocabulary field instance migration.
 *
17
 * @group migrate_drupal_6
18
 */
19
class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
20
21

  /**
22
   * {@inheritdoc}
23
   */
24
  public static $modules = ['taxonomy'];
25
26
27
28
29
30

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
31
    $this->migrateTaxonomy();
32
33
34
35
36
37
38
39
  }

  /**
   * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
   */
  public function testVocabularyFieldInstance() {
    // Test that the field exists.
    $field_id = 'node.article.tags';
40
    $field = FieldConfig::load($field_id);
41
    $this->assertIdentical($field_id, $field->id(), 'Field instance exists on article bundle.');
42
    $this->assertIdentical('Tags', $field->label());
43
    $this->assertTrue($field->isRequired(), 'Field is required');
44
45
46

    // Test the page bundle as well.
    $field_id = 'node.page.tags';
47
    $field = FieldConfig::load($field_id);
48
    $this->assertIdentical($field_id, $field->id(), 'Field instance exists on page bundle.');
49
    $this->assertIdentical('Tags', $field->label());
50
    $this->assertTrue($field->isRequired(), 'Field is required');
51

52
53
    $settings = $field->getSettings();
    $this->assertIdentical('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
54
    $this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
55
56
    $this->assertIdentical(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');

57
    $this->assertIdentical(array('node', 'article', 'tags'), Migration::load('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
58
59
60
61
62

    // Test the the field vocabulary_1_i_0_
    $field_id = 'node.story.vocabulary_1_i_0_';
    $field = FieldConfig::load($field_id);
    $this->assertFalse($field->isRequired(), 'Field is not required');
63
64
65
  }

}