MigrateCustomBlockContentTranslationTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Drupal\Tests\block_content\Kernel\Migrate\d7;
  3. use Drupal\block_content\Entity\BlockContent;
  4. use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
  5. /**
  6. * Tests migration of i18n custom block strings.
  7. *
  8. * @group migrate_drupal_7
  9. */
  10. class MigrateCustomBlockContentTranslationTest extends MigrateDrupal7TestBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public static $modules = [
  15. 'block_content',
  16. 'content_translation',
  17. 'filter',
  18. 'language',
  19. 'text',
  20. // Required for translation migrations.
  21. 'migrate_drupal_multilingual',
  22. ];
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function setUp() {
  27. parent::setUp();
  28. $this->installConfig(['block_content']);
  29. $this->installEntitySchema('block_content');
  30. $this->executeMigrations([
  31. 'language',
  32. 'd7_filter_format',
  33. 'block_content_type',
  34. 'block_content_body_field',
  35. 'd7_custom_block',
  36. 'd7_custom_block_translation',
  37. ]);
  38. }
  39. /**
  40. * Tests the Drupal 7 i18n custom block strings to Drupal 8 migration.
  41. */
  42. public function testCustomBlockContentTranslation() {
  43. /** @var \Drupal\block_content\Entity\BlockContent $block */
  44. $block = BlockContent::load(1)->getTranslation('fr');
  45. $this->assertSame('fr - Mildly amusing limerick of the day', $block->label());
  46. $this->assertGreaterThanOrEqual($block->getChangedTime(), \Drupal::time()->getRequestTime());
  47. $this->assertLessThanOrEqual(time(), $block->getChangedTime());
  48. $this->assertSame('fr', $block->language()->getId());
  49. $translation = "fr - A fellow jumped off a high wall\r\nAnd had a most terrible fall\r\nHe went back to bed\r\nWith a bump on his head\r\nThat's why you don't jump off a wall";
  50. $this->assertSame($translation, $block->body->value);
  51. $this->assertSame('filtered_html', $block->body->format);
  52. $block = $block->getTranslation('is');
  53. $this->assertSame('is - Mildly amusing limerick of the day', $block->label());
  54. $this->assertGreaterThanOrEqual($block->getChangedTime(), \Drupal::time()->getRequestTime());
  55. $this->assertLessThanOrEqual(time(), $block->getChangedTime());
  56. $this->assertSame('is', $block->language()->getId());
  57. $text = "A fellow jumped off a high wall\r\nAnd had a most terrible fall\r\nHe went back to bed\r\nWith a bump on his head\r\nThat's why you don't jump off a wall";
  58. $this->assertSame($text, $block->body->value);
  59. $this->assertSame('filtered_html', $block->body->format);
  60. }
  61. }