summaryrefslogtreecommitdiffstats
path: root/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php
blob: e1720d1b5141cb399febb53d68e66e5b018c2ee9 (plain)
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
<?php

/**
 * @file
 * Contains Drupal\system\Tests\Upgrade\DateUpgradePathTest.
 */

namespace Drupal\system\Tests\Upgrade;

/**
 * Test upgrade of date formats.
 */
class DateUpgradePathTest extends UpgradePathTestBase {
  public static function getInfo() {
    return array(
      'name' => 'Date upgrade test',
      'description' => 'Upgrade tests for date formats.',
      'group' => 'Upgrade path',
    );
  }

  public function setUp() {
    $this->databaseDumpFiles = array(
      drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
      drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.date.database.php',
    );
    parent::setUp();
  }

  /**
   * Tests that date formats have been upgraded.
   */
  public function testDateUpgrade() {
    $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');

    // Verify standard date formats.
    $expected_formats['short'] = array(
      'name' => 'Short',
      'pattern' => array(
        'php' => 'm/d/Y - H:i',
      ),
      'locked' => '1',
    );
    $expected_formats['medium'] = array(
      'name' => 'Medium',
      'pattern' => array(
        'php' => 'D, m/d/Y - H:i',
      ),
      'locked' => '1',
    );
    $expected_formats['long'] = array(
      'name' => 'Long',
      'pattern' => array(
        'php' => 'l, j F, Y - H:i',
      ),
      'locked' => '1',
    );

    // Verify custom date format.
    $expected_formats['test_custom'] = array(
      'name' => 'Test Custom',
      'pattern' => array(
        'php' => 'd m Y',
        ),
      'locked' => '0',
    );

    foreach ($expected_formats as $type => $format) {
      $format_info = config('system.date')->get('formats.' . $type);

      $this->assertEqual($format_info['name'], $format['name'], format_string('Config value for @type name is the same', array('@type' => $type)));
      $this->assertEqual($format_info['locked'], $format['locked'], format_string('Config value for @type locked is the same', array('@type' => $type)));
      $this->assertEqual($format_info['pattern']['php'], $format['pattern']['php'], format_string('Config value for @type PHP date pattern is the same', array('@type' => $type)));

      // Make sure that the variable was deleted.
      $this->assertNull(update_variable_get('date_format_' . $type), format_string('Date format variable for @type was deleted.', array('@type' => $type)));
    }

    $expected_de_formats = array(
      array(
        'type' => 'long',
        'format' => 'l, j. F, Y - H:i',
      ),
      array(
        'type' => 'medium',
        'format' => 'D, d/m/Y - H:i',
      ),
      array(
        'type' => 'short',
        'format' => 'd/m/Y - H:i',
      ),
    );

    $config = config('locale.config.de.system.date');
    foreach ($expected_de_formats as $locale_format) {
      $format = $config->get('formats.' . $locale_format['type'] . '.pattern.php');
      $this->assertEqual($locale_format['format'], $format);
    }
  }
}