Projet

Général

Profil

Révision db9ffd17

Ajouté par Assos Assos il y a presque 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/tests/date.test
5 5
 * Test date UI.
6 6
 */
7 7

  
8
class DateUITestCase extends DrupalWebTestCase {
9
  protected $privileged_user;
8
class DateUITestCase extends DateFieldBasic {
10 9

  
11 10
  /**
12 11
   * @todo.
......
23 22
   * @todo.
24 23
   */
25 24
  public function setUp() {
26
    // Load the date_api module.
27
    parent::setUp('field', 'field_ui', 'date_api', 'date', 'date_popup', 'date_tools');
28

  
29
    // Create and log in our privileged user.
30
    $this->privileged_user = $this->drupalCreateUser(
31
      array('administer content types', 'administer nodes', 'bypass node access', 'administer date tools')
32
    );
33
    $this->drupalLogin($this->privileged_user);
25
    parent::setUp();
34 26

  
35 27
    variable_set('date_format_long', 'D, m/d/Y - H:i');
36 28
  }
......
39 31
   * @todo.
40 32
   */
41 33
  public function testFieldUI() {
42
    $edit = array();
43
    $edit['name'] = 'Story';
44
    $edit['type'] = 'story';
45
    $this->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
46
    $this->assertText('The content type Story has been added.', 'Content type added.');
34
    $label = 'Test';
35
    $current_year = date('Y');
47 36

  
48
    // Creates select list field stored as a date with default settings.
49
    $this->createDateField($type = 'date', $widget = 'date_select');
50
    $edit = array();
51
    $this->drupalPost(NULL, $edit, t('Save field settings'));
52
    $this->dateForm($options = 'select');
53
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_select widget.');
54
    $this->deleteDateField();
55
    // Creates text field stored as a date with default settings.
56
    $this->createDateField($type = 'date', $widget = 'date_text');
57
    $edit = array();
58
    $this->drupalPost(NULL, $edit, t('Save field settings'));
59
    $this->dateForm($options = 'text');
60
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_text widget.');
61
    $this->deleteDateField();
62
    // Creates popup field stored as a date with default settings.
63
    $this->createDateField($type = 'date', $widget = 'date_popup');
64
    $edit = array();
65
    $this->drupalPost(NULL, $edit, t('Save field settings'));
66
    $this->dateForm($options = 'popup');
67
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_popup widget.');
68
    $this->deleteDateField();
69
    // Creates select list field stored as a datestamp with default settings.
70
    $this->createDateField($type = 'datestamp', $widget = 'date_select');
71
    $edit = array();
72
    $this->drupalPost(NULL, $edit, t('Save field settings'));
73
    $this->dateForm($options = 'select');
74
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_select widget.');
75
    $this->deleteDateField();
76
    // Creates text field stored as a datestamp with default settings.
77
    $this->createDateField($type = 'datestamp', $widget = 'date_text');
78
    $edit = array();
79
    $this->drupalPost(NULL, $edit, t('Save field settings'));
80
    $this->dateForm($options = 'text');
81
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_text widget.');
82
    $this->deleteDateField();
83
    // Creates popup field stored as a datestamp with default settings.
84
    $this->createDateField($type = 'datestamp', $widget = 'date_popup');
85
    $edit = array();
86
    $this->drupalPost(NULL, $edit, t('Save field settings'));
87
    $this->dateForm($options = 'popup');
88
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_popup widget.');
89
    $this->deleteDateField();
90
    // Creates select list field stored as a datetime with default settings.
91
    $this->createDateField($type = 'datetime', $widget = 'date_select');
92
    $edit = array();
93
    $this->drupalPost(NULL, $edit, t('Save field settings'));
94
    $this->dateForm($options = 'select');
95
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_select widget.');
96
    $this->deleteDateField();
97
    // Creates text field stored as a datetime with default settings.
98
    $this->createDateField($type = 'datetime', $widget = 'date_text');
99
    $edit = array();
100
    $this->drupalPost(NULL, $edit, t('Save field settings'));
101
    $this->dateForm($options = 'text');
102
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_text widget.');
103
    $this->deleteDateField();
104
    // Creates popup field stored as a datetime with default settings.
105
    $this->createDateField($type = 'datetime', $widget = 'date_popup');
106
    $edit = array();
107
    $this->drupalPost(NULL, $edit, t('Save field settings'));
108
    $this->dateForm($options = 'popup');
109
    $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_popup widget.');
110
    $this->deleteDateField();
37
    $field_types = array('date', 'datestamp', 'datetime');
38
    $widget_types = array('date_select', 'date_text', 'date_popup');
39

  
40
    // Test widgets with default settings using every widget and field type.
41
    foreach ($field_types as $field_type) {
42
      foreach ($widget_types as $widget_type) {
43
        $this->createDateField(
44
            array(
45
              'label' => $label,
46
              'field_type' => $field_type,
47
              'widget_type' => $widget_type,
48
            )
49
        );
50
        $this->dateForm($widget_type);
51
        $this->assertText(format_string('10/07/!year - 10:30', array('!year' => $current_year)), 'Found the correct date for a date field using the ' . $widget_type . ' widget.');
52
        $this->deleteDateField($label);
53
      }
54
    }
111 55

  
112 56
    // Test timezone handling validation on the field settings form.
113
    $this->createDateField($type = 'date', $widget = 'date_select');
57
    $this->createDateField(array('label' => $label, 'field_type' => 'date', 'widget_type' => 'date_select', 'granularity' => array('year', 'month', 'day')));
114 58
    $edit = array('field[settings][granularity][hour]' => FALSE);
115
    $this->drupalPost(NULL, $edit, t('Save field settings'));
59
    $this->drupalPost('admin/structure/types/manage/story/fields/field_' . strtolower($label), $edit, t('Save settings'));
116 60
    $this->assertText("Dates without hours granularity must not use any timezone handling.", "Dates without hours granularity required to use timezone handling of 'none.'");
117
    $this->deleteDateField();
61
    $this->deleteDateField($label);
118 62
  }
119 63

  
120 64
  /**
......
125 69
    $edit = array();
126 70
    $edit['title'] = $this->randomName(8);
127 71
    $edit['body[und][0][value]'] = $this->randomName(16);
128
    if ($options == 'select') {
129
      $edit['field_test[und][0][value][year]'] = '2010';
72
    $current_year = date('Y');
73

  
74
    if ($options == 'date_select') {
75
      $edit['field_test[und][0][value][year]'] = $current_year;
130 76
      $edit['field_test[und][0][value][month]'] = '10';
131 77
      $edit['field_test[und][0][value][day]'] = '7';
132 78
      $edit['field_test[und][0][value][hour]'] = '10';
133 79
      $edit['field_test[und][0][value][minute]'] = '30';
134 80
    }
135
    elseif ($options == 'text') {
136
      $edit['field_test[und][0][value][date]'] = '10/07/2010 - 10:30';
81
    elseif ($options == 'date_text') {
82
      $edit['field_test[und][0][value][date]'] = format_string('10/07/!year - 10:30', array('!year' => $current_year));
137 83
    }
138
    elseif ($options == 'popup') {
139
      $edit['field_test[und][0][value][date]'] = '10/07/2010';
84
    elseif ($options == 'date_popup') {
85
      $edit['field_test[und][0][value][date]'] = format_string('10/07/!year', array('!year' => $current_year));
140 86
      $edit['field_test[und][0][value][time]'] = '10:30';
141 87
    }
142 88
    $this->drupalPost('node/add/story', $edit, t('Save'));
143 89
    $this->assertText($edit['body[und][0][value]'], 'Test node has been created');
144 90
  }
145

  
146
  /**
147
   * @todo.
148
   */
149
  function createDateField($type, $widget) {
150
    $edit = array();
151
    $edit['fields[_add_new_field][label]'] = 'Test';
152
    $edit['fields[_add_new_field][field_name]'] = 'test';
153
    $edit['fields[_add_new_field][weight]'] = '-4';
154
    $edit['fields[_add_new_field][type]'] = $type;
155
    $edit['fields[_add_new_field][widget_type]'] = $widget;
156
    $this->drupalPost('admin/structure/types/manage/story/fields', $edit, t('Save'));
157
  }
158

  
159
  /**
160
   * @todo.
161
   */
162
  function deleteDateField() {
163
    $this->drupalGet('admin/structure/types/manage/story/fields');
164
    $this->clickLink('delete');
165
    $this->drupalPost(NULL, NULL, t('Delete'));
166
    $this->assertText('The field Test has been deleted from the Story content type.', 'Removed date field.');
167
  }
168 91
}

Formats disponibles : Unified diff