MigrateFieldInstanceLabelDescriptionTest.php 6.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
<?php

namespace Drupal\Tests\field\Kernel\Migrate\d6;

use Drupal\KernelTests\KernelTestBase;
use Drupal\Core\Database\Database;
use Drupal\Tests\migrate\Kernel\MigrateDumpAlterInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;

/**
 * Tests migration field label and description i18n translations.
 *
 * @group migrate_drupal_6
 * @group legacy
 */
class MigrateFieldInstanceLabelDescriptionTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'config_translation',
    'locale',
    'language',
    'menu_ui',
    'node',
    'field',
  ];

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->migrateFields();

    $this->installEntitySchema('node');
    $this->installConfig(['node']);
    $this->installSchema('node', ['node_access']);
    $this->installSchema('system', ['sequences']);
    $this->executeMigration('language');
    $this->executeMigration('d6_field_instance_label_description_translation');
  }

  /**
   * {@inheritdoc}
   */
  public static function migrateDumpAlter(KernelTestBase $test) {
    $db = Database::getConnection('default', 'migrate');
    // Alter the database to test the migration is successful when a translated
    // field is deleted but the translation data for that field remains in both
    // the i18n_strings and locales_target tables.
    $db->delete('content_node_field_instance')
      ->condition('field_name', 'field_test')
      ->condition('type_name', 'story')
      ->execute();
  }

  /**
   * Tests migration of file variables to file.settings.yml.
   */
  public function testFieldInstanceLabelDescriptionTranslationMigration() {
    $language_manager = $this->container->get('language_manager');

    // Tests fields on 'story' node type.
    // Check that the deleted field with translations was skipped.
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test');
    $this->assertNull($config_translation->get('label'));
    $this->assertNull($config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_two');
    $this->assertSame("fr - Integer Field", $config_translation->get('label'));
    $this->assertSame("fr - An example integer field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_four');
    $this->assertSame("fr - Float Field", $config_translation->get('label'));
    $this->assertSame("fr - An example float field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_email');
    $this->assertSame("fr - Email Field", $config_translation->get('label'));
    $this->assertSame("fr - An example email field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_imagefield');
    $this->assertSame("fr - Image Field", $config_translation->get('label'));
    $this->assertSame("fr - An example image field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('zu', 'field.field.node.story.field_test_imagefield');
    $this->assertSame("zu - Image Field", $config_translation->get('label'));
    $this->assertSame("zu - An example image field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_filefield');
    $this->assertSame("fr - File Field", $config_translation->get('label'));
    $this->assertSame("fr - An example file field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_link');
    $this->assertSame("fr - Link Field", $config_translation->get('label'));
    $this->assertSame("fr - An example link field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_date');
    $this->assertSame("fr - Date Field", $config_translation->get('label'));
    $this->assertSame("fr - An example date field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_datetime');
    $this->assertSame("fr - Datetime Field", $config_translation->get('label'));
    $this->assertSame("fr - An example datetime field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_datestamp');
    $this->assertSame("fr - Date Stamp Field", $config_translation->get('label'));
    $this->assertSame("fr - An example date stamp field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_date');
    $this->assertSame("fr - Date Field", $config_translation->get('label'));
    $this->assertSame("fr - An example date field.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.story.field_test_phone');
    $this->assertSame("fr - Phone Field", $config_translation->get('label'));
    $this->assertSame("fr - An example phone field.", $config_translation->get('description'));

    // Tests fields on 'test_page' node type.
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_page.field_test');
    $this->assertSame("Champ de texte", $config_translation->get('label'));
    $this->assertSame("fr - An example text field.", $config_translation->get('description'));

    // Tests fields on 'test_planet' node type.
    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_planet.field_multivalue');
    $this->assertSame("fr - Decimal Field", $config_translation->get('label'));
    $this->assertSame("Un exemple plusieurs valeurs champ décimal.", $config_translation->get('description'));

    $config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.node.test_planet.field_test_text_single_checkbox');
    $this->assertNull($config_translation->get('label'));
    $this->assertSame('fr - An example text field using a single on/off checkbox.', $config_translation->get('description'));
  }

}