Projet

Général

Profil

Paste
Télécharger (4,34 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / date / date_all_day / tests / DateAllDayUpdatesTest.test @ 599a39cd

1
<?php
2

    
3
/**
4
 * @file
5
 * Test updates for the Date All Day module.
6
 */
7

    
8
/**
9
 * Test updates for the Date All Day module.
10
 */
11
class DateAllDayUpdatesTest extends DrupalWebTestCase {
12

    
13
  /**
14
   * Define this test class.
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => t('Update updates'),
19
      'description' => t('Confirm update Date All Day updates works as intended.'),
20
      'group' => t('Date'),
21
    );
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function setUp(array $modules = array()) {
28
    $modules[] = 'date_all_day_test_feature';
29
    parent::setUp($modules);
30

    
31
    // Error logging.
32
    variable_set('error_level', 2);
33

    
34
    // Log in as user 1, so that permissions are irrelevant.
35
    $this->loginUser1();
36

    
37
    // Clear the caches so that the field specs are properly loaded.
38
    cache_clear_all();
39
  }
40

    
41
  /**
42
   * Log in as user 1.
43
   *
44
   * The benefit of doing this is that it ignores permissions entirely, so the
45
   * raw functionality can be tested.
46
   */
47
  protected function loginUser1() {
48
    // Load user 1.
49
    $account = user_load(1, TRUE);
50

    
51
    // Reset the password.
52
    $password = user_password();
53
    $edit = array(
54
      'pass' => $password,
55
    );
56
    user_save($account, $edit);
57
    $account->pass_raw = $password;
58

    
59
    // Login.
60
    $this->drupalLogin($account);
61
  }
62

    
63
  /**
64
   * {@inheritdoc}
65
   */
66
  protected function verbose($message, $title = NULL) {
67
    // Handle arrays, objects, etc.
68
    if (!is_string($message)) {
69
      $message = "<pre>\n" . print_r($message, TRUE) . "\n</pre>\n";
70
    }
71

    
72
    // Optional title to go before the output.
73
    if (!empty($title)) {
74
      $title = '<h2>' . check_plain($title) . "</h2>\n";
75
    }
76

    
77
    parent::verbose($title . $message);
78
  }
79

    
80
  /**
81
   * Test update 7200.
82
   */
83
  public function testUpdate7200() {
84
    // Load the install file, so that the update script is available.
85
    module_load_include('install', 'date_all_day');
86
    $this->assertEqual(function_exists('date_all_day_update_7200'), TRUE, 'Update 7200 exists.');
87

    
88
    // Create a sample node.
89
    $this->drupalGet('node/add/date-all-day-test');
90
    $this->assertResponse(200);
91
    $this->assertText('Create Date Test');
92

    
93
    $edit = array(
94
      'title' => 'Test All Day option',
95
      // This field is required.
96
      // 'field_datetime_range[und][0][value2][date]' => '2020-09-07 08:00:00',
97
      // The All-Day field.
98
      'field_date_all_day[und][0][all_day]' => TRUE,
99
      'field_date_all_day[und][0][value][year]' => 2020,
100
      'field_date_all_day[und][0][value][month]' => 8,
101
      'field_date_all_day[und][0][value][day]' => 30,
102
    );
103
    $this->drupalPost(NULL, $edit, 'Save');
104
    $this->assertResponse(200);
105
    // Make sure the form submitted.
106
    $this->assertNoText('Create Date Test');
107

    
108
    // Load the node.
109
    // @todo get the node ID from the URL.
110
    $node = node_load(1, NULL, TRUE);
111
    $this->verbose($node);
112

    
113
    // Update the field so it's stored the old way.
114
    $node->field_date_all_day[LANGUAGE_NONE][0]['value'] = '2020-08-30 00:00:00';
115
    node_save($node);
116

    
117
    // Reload the node and confirm that it has the old value stored.
118
    $node = node_load($node->nid, NULL, TRUE);
119
    $this->verbose($node);
120
    $this->assertEqual($node->field_date_all_day[LANGUAGE_NONE][0]['value'], '2020-08-30 00:00:00');
121

    
122
    // Load the code, confirm the data is invalid.
123
    $this->drupalGet('node/' . $node->nid);
124
    $this->assertResponse(200);
125
    $this->assertText($edit['title']);
126
    $this->assertText('Date All Day');
127
    $this->assertNoText('Sunday, August 30, 2020 (All day)');
128

    
129
    // Load the node's edit form to confirm the values are incorrect.
130
    $this->drupalGet('node/' . $node->nid . '/edit');
131
    $this->assertResponse(200);
132

    
133
    // Execute the update function.
134
    $results = date_all_day_update_7200();
135
    $this->assertTrue($results);
136
    $this->verbose($results);
137

    
138
    // Reload the node and confirm that it has the old value stored.
139
    $node = node_load($node->nid, NULL, TRUE);
140
    $this->verbose($node);
141
    // The expected timestamp is relative to the increment value, which is set
142
    // to 15 minutes for this field.
143
    $this->assertEqual($node->field_date_all_day[LANGUAGE_NONE][0]['value'], '2020-08-30 23:45:59');
144

    
145
    // Load the node again, confirm the data is now valid.
146
    $this->drupalGet('node/' . $node->nid);
147
    $this->assertText('Date All Day:');
148
    $this->assertText('Sunday, August 30, 2020 (All day)');
149
  }
150

    
151
}