Projet

Général

Profil

Révision b720ea3e

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/tests/date_timezone.test
50 50
    }
51 51
  }
52 52

  
53
  /**
54
   * Validates timezone handling with a multi-value date field.
55
   */
56
  public function testMultiUserTimezone() {
57
    // Create date fields with combinations of various types and granularity
58
    // using the "Date's Timezone" strategy.
59
    $field_type = 'datetime';
60
    $tz_handling = 'date';
61
    $max_granularity = 'minute';
62

  
63
    // Create date field
64
    $field_name = "field_test";
65
    $label = 'Test';
66
    $options = array(
67
      'label' => $label,
68
      'widget_type' => 'date_text',
69
      'field_name' => $field_name,
70
      'field_type' => $field_type,
71
      'input_format' => 'custom',
72
      'input_format_custom' => 'm/d/Y - H:i:s T',
73
      'cardinality' => 3,
74
      'tz_handling' => $tz_handling,
75
    );
76
    $this->createMultiDateField($options);
77

  
78
    // Submit a date field form with multiple values
79
    $this->dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling);
80

  
81

  
82
    $this->deleteDateField($label);
83
  }
84

  
85
  /**
86
   * Tests the submission of a date field's widget form when using unlimited
87
   * cardinality
88
   */
89
  public function dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling) {
90
    variable_set('date_format_long', 'D, m/d/Y - H:i:s T');
91

  
92
    $edit = array();
93
    $should_be = array();
94
    $edit['title'] = $this->randomName(8);
95
    $timezones = array('America/Chicago', 'America/Los_Angeles', 'America/New_York');
96

  
97
    switch ($max_granularity) {
98
      case 'hour':
99
        $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
100
        $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
101
        $should_be[0] = 'Thu, 10/07/2010 - 10 CDT';
102

  
103
        $edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
104
        $edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
105
        $should_be[1] = 'Thu, 10/07/2010 - 10 PDT';
106

  
107
        $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
108
        $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
109
        $should_be[2] = 'Thu, 10/07/2010 - 10 EDT';
110

  
111
        break;
112
      case 'minute':
113
        $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
114
        $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
115
        $should_be[0] = 'Thu, 10/07/2010 - 10:30 CDT';
116

  
117
        $edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
118
        $edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
119
        $should_be[1] = 'Thu, 10/07/2010 - 10:30 PDT';
120

  
121
        $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
122
        $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
123
        $should_be[2] = 'Thu, 10/07/2010 - 10:30 EDT';
124

  
125
        break;
126
      case 'second':
127
        $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
128
        $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
129
        $should_be[0] = 'Thu, 10/07/2010 - 10:30:30 CDT';
130

  
131
        $edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
132
        $edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
133
        $should_be[1] = 'Thu, 10/07/2010 - 10:30:30 PDT';
134

  
135
        $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
136
        $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
137
        $should_be[2] = 'Thu, 10/07/2010 - 10:30:30 EDT';
138
        break;
139
    }
140

  
141
    $this->drupalPost('node/add/story', $edit, t('Save'));
142
    $this->assertText($edit['title'], "Node has been created");
143

  
144
    foreach ($should_be as $assertion) {
145
      $this->assertText($assertion, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
146
    }
147

  
148
    // Goto the edit page and save the node again.
149
    $node = $this->drupalGetNodeByTitle($edit['title']);
150
    $this->drupalGet('node/' . $node->nid . '/edit');
151

  
152
    // Re-assert the proper date timezones.
153
    foreach ($timezones as $key => $timezone) {
154
      $this->assertOptionSelected('edit-field-test-und-' . $key . '-timezone-timezone', $timezone, "Found the correct timezone $timezone for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
155
    }
156
  }
157

  
53 158
  /**
54 159
   * @todo.
55 160
   */

Formats disponibles : Unified diff