MigrateDateFormatTest.php 1.79 KB
Newer Older
1 2
<?php

3 4
/**
 * @file
5
 * Contains \Drupal\system\Tests\Migrate\d6\MigrateDateFormatTest.
6 7
 */

8
namespace Drupal\system\Tests\Migrate\d6;
9 10 11

use Drupal\migrate\MigrateExecutable;
use Drupal\Core\Database\Database;
12
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
13 14

/**
15
 * Upgrade date formats to core.date_format.*.yml.
16
 *
17
 * @group migrate_drupal_6
18
 */
19
class MigrateDateFormatTest extends MigrateDrupal6TestBase {
20 21 22 23

  /**
   * {@inheritdoc}
   */
24
  protected function setUp() {
25
    parent::setUp();
26
    $this->executeMigration('d6_date_formats');
27 28 29 30 31 32 33
  }

  /**
   * Tests the Drupal 6 date formats to Drupal 8 migration.
   */
  public function testDateFormats() {
    $short_date_format = entity_load('date_format', 'short');
34
    $this->assertIdentical('\S\H\O\R\T m/d/Y - H:i', $short_date_format->getPattern());
35 36

    $medium_date_format = entity_load('date_format', 'medium');
37
    $this->assertIdentical('\M\E\D\I\U\M D, m/d/Y - H:i', $medium_date_format->getPattern());
38 39

    $long_date_format = entity_load('date_format', 'long');
40
    $this->assertIdentical('\L\O\N\G l, F j, Y - H:i', $long_date_format->getPattern());
41 42 43 44 45 46 47 48 49 50 51 52 53

    // Test that we can re-import using the EntityDateFormat destination.
    Database::getConnection('default', 'migrate')
      ->update('variable')
      ->fields(array('value' => serialize('\S\H\O\R\T d/m/Y - H:i')))
      ->condition('name', 'date_format_short')
      ->execute();
    db_truncate(entity_load('migration', 'd6_date_formats')->getIdMap()->mapTableName())->execute();
    $migration = entity_load_unchanged('migration', 'd6_date_formats');
    $executable = new MigrateExecutable($migration, $this);
    $executable->import();

    $short_date_format = entity_load('date_format', 'short');
54
    $this->assertIdentical('\S\H\O\R\T d/m/Y - H:i', $short_date_format->getPattern());
55 56 57 58

  }

}