MigrateCustomBlockContentTranslationTest.php 2.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php

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

use Drupal\block_content\Entity\BlockContent;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;

/**
 * Tests migration of i18n custom block strings.
 *
 * @group migrate_drupal_6
 */
class MigrateCustomBlockContentTranslationTest extends MigrateDrupal6TestBase {

  /**
   * {@inheritdoc}
   */
18
  public static $modules = [
19 20 21
    'block_content',
    'content_translation',
    'language',
22 23
    // Required for translation migrations.
    'migrate_drupal_multilingual',
24 25 26 27 28 29 30 31
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->installEntitySchema('block_content');
32
    $this->installConfig(['block_content']);
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
    $this->executeMigrations([
      'language',
      'd6_filter_format',
      'block_content_type',
      'block_content_body_field',
      'd6_custom_block',
      'd6_custom_block_translation',
    ]);
  }

  /**
   * Tests the Drupal 6 i18n custom block strings to Drupal 8 migration.
   */
  public function testCustomBlockContentTranslation() {
    /** @var \Drupal\block_content\Entity\BlockContent $block */
    $block = BlockContent::load(1)->getTranslation('fr');
    $this->assertSame('fr - Static Block', $block->label());
    $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
    $this->assertLessThanOrEqual(time(), $block->getChangedTime());
    $this->assertSame('fr', $block->language()->getId());
    $this->assertSame('<h3>fr - My first custom block body</h3>', $block->body->value);
    $this->assertSame('full_html', $block->body->format);

    $block = $block->getTranslation('zu');
    $this->assertSame('My block 1', $block->label());
    $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
    $this->assertLessThanOrEqual(time(), $block->getChangedTime());
    $this->assertSame('zu', $block->language()->getId());
    $this->assertSame('<h3>zu - My first custom block body</h3>', $block->body->value);
    $this->assertSame('full_html', $block->body->format);

    $block = BlockContent::load(2)->getTranslation('fr');
    $this->assertSame('Encore un bloc statique', $block->label());
    $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
    $this->assertLessThanOrEqual(time(), $block->getChangedTime());
    $this->assertSame('fr', $block->language()->getId());
    $this->assertSame('Nom de vocabulaire beaucoup plus long que trente-deux caractères', $block->body->value);
    $this->assertSame('full_html', $block->body->format);
  }

}