Projet

Général

Profil

Paste
Télécharger (11,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / makemeeting / makemeeting.test @ b75b6b8b

1
<?php
2

    
3
/**
4
 * @file
5
 * Makemeeting tests
6
 */
7

    
8
/**
9
 * Test for the creation of a makemeeting poll.
10
 */
11
class MakemeetingPollAdminTestCase extends DrupalWebTestCase {
12
  protected $privileged_user;
13
  protected $lambda_user;
14
  protected $lambda_user2;
15
  protected $anon_user;
16

    
17
  /**
18
   * Implements getInfo().
19
   */
20
  public static function getInfo() {
21
    return array(
22
      'name' => t('Poll authoring tasks'),
23
      'description' => t('Tests for creating, updating and deleting polls.'),
24
      'group' => t('Makemeeting'),
25
    );
26
  }
27

    
28
  public function setUp() {
29
    parent::setUp('field', 'field_ui', 'makemeeting');
30
    $this->privileged_user = $this->drupalCreateUser(array(
31
      'administer content types',
32
      'administer nodes',
33
      'bypass node access',
34
      'answer makemeeting form',
35
      'delete any makemeeting answer',
36
    ));
37
    $this->lambda_user = $this->drupalCreateUser(array(
38
      'answer makemeeting form',
39
    ));
40
    $this->lambda_user2 = $this->drupalCreateUser(array(
41
      'answer makemeeting form',
42
    ));
43
    $this->anon_user = $this->drupalCreateUser();
44
    $this->drupalLogin($this->privileged_user);
45

    
46
    // Setting default timezone
47
    date_default_timezone_set('UTC');
48
  }
49

    
50
  /**
51
   * Test the creation of a content type and attach a field
52
   */
53
  public function testFieldUI() {
54
    // Create the content type and attach the field
55
    $this->_testCreateField();
56

    
57
    // Delete the field
58
    $this->drupalGet('admin/structure/types/manage/event/fields');
59
    $this->clickLink('delete', 1); // Body field present?
60
    $this->drupalPost(NULL, NULL, t('Delete'));
61
    $this->assertText('The field Choose date has been deleted from the Event content type.', 'Removed makemeeting field.');
62
  }
63

    
64
  /**
65
   * Test the creation of event content with multiple makmeeting values
66
   */
67
  public function testCreateEvent() {
68
    $this->_testCreateField();
69

    
70
    // Basic creation
71
    $edit = array();
72
    $edit['title'] = $this->randomName();
73
    $edit += array(
74
      'field_choose_date[und][0][choices][new:0][chdate][month]' => '5',
75
      'field_choose_date[und][0][choices][new:0][chdate][day]' => '20',
76
      'field_choose_date[und][0][choices][new:0][chdate][year]' => '2012',
77
    );
78
    $this->drupalPost('node/add/event', $edit, t('Save'));
79
    $this->assertText('Event ' . $edit['title'] . ' has been created.', 'Content created');
80

    
81
    // Test adding choice
82
    $this->drupalPostAJAX('node/add/event', $edit, array('op' => t('More choices')));
83
    $newedit = array(
84
      'field_choose_date[und][0][choices][1337472000][chdate][month]' => '5',
85
      'field_choose_date[und][0][choices][1337472000][chdate][day]' => '20',
86
      'field_choose_date[und][0][choices][1337472000][chdate][year]' => '2012',
87
      'field_choose_date[und][0][choices][new:0][chdate][month]' => '5',
88
      'field_choose_date[und][0][choices][new:0][chdate][day]' => '21',
89
      'field_choose_date[und][0][choices][new:0][chdate][year]' => '2012',
90
    ) + $edit;
91
    $this->drupalPost(NULL, $newedit, t('Save'));
92
    $this->assertRaw('<td colspan="1" class="date date-first">Sun. 20</td><td colspan="1" class="date date-last">Mon. 21</td>', 'Two dates found');
93

    
94
    // Test adding suggestion
95
    $this->drupalPostAJAX('node/add/event', $edit, array('op' => t('More suggestions')));
96
    $newedit = $edit + array(
97
      'field_choose_date[und][0][choices][1337472000][chdate][month]' => '5',
98
      'field_choose_date[und][0][choices][1337472000][chdate][day]' => '20',
99
      'field_choose_date[und][0][choices][1337472000][chdate][year]' => '2012',
100
      'field_choose_date[und][0][choices][1337472000][chsuggestions][sugg:0]' => 'foo',
101
      'field_choose_date[und][0][choices][1337472000][chsuggestions][sugg:1]' => 'foobarbaz',
102
    );
103
    unset($newedit['field_choose_date[und][0][choices][new:0][chdate][day]']);
104
    unset($newedit['field_choose_date[und][0][choices][new:0][chdate][month]']);
105
    unset($newedit['field_choose_date[und][0][choices][new:0][chdate][year]']);
106
    $this->drupalPost(NULL, $newedit, t('Save'));
107
    $this->assertText('foobarbaz', 'Added suggestion');
108

    
109
    // Testing copying first suggestion
110
    $this->drupalPostAJAX('node/add/event', $edit, array('op' => t('More choices')));
111
    $newedit = array(
112
      'field_choose_date[und][0][choices][1337472000][chdate][month]' => '5',
113
      'field_choose_date[und][0][choices][1337472000][chdate][day]' => '20',
114
      'field_choose_date[und][0][choices][1337472000][chdate][year]' => '2012',
115
      'field_choose_date[und][0][choices][1337472000][chsuggestions][sugg:0]' => 'foobar',
116
      'field_choose_date[und][0][choices][new:0][chdate][month]' => '5',
117
      'field_choose_date[und][0][choices][new:0][chdate][day]' => '21',
118
      'field_choose_date[und][0][choices][new:0][chdate][year]' => '2012',
119
    ) + $edit;
120
    $this->drupalPost(NULL, $newedit, t('Copy and paste first row'));
121
    $this->drupalPost(NULL, array(), t('Save'));
122
    $this->assertRaw('<td class="suggestion suggestion-first">foobar</td><td class="suggestion suggestion-first">foobar</td>', 'Copied and pasted first row');
123
  }
124

    
125
  /**
126
   * Test the creation of event content with multiple makmeeting values
127
   */
128
  public function testEmptyField() {
129
    $this->_testCreateField();
130

    
131
    // Removing choice
132
    $edit = array();
133
    $edit['title'] = $this->randomName();
134
    $this->drupalGet('node/add/event');
135
    $this->drupalPostAJAX(NULL, $edit, array('new:0' => t('Remove')));
136
    $this->verbose($this->content);
137
    $this->assertNoRaw('<td class="makemeeting-choice-date">');
138

    
139
    // Must not have answering form
140
    $this->drupalPost(NULL, $edit, t('Save'));
141
    $this->assertNoRaw('<table class="makemeeting-table');
142

    
143
    // Must not have additional choice
144
    $this->drupalGet('node/1/edit');
145
    $this->assertNoRaw('<td class="makemeeting-choice-date">');
146

    
147
    // Removing choice after saving
148
    $edit = array();
149
    $edit['title'] = $this->randomName();
150
    $this->drupalPost('node/add/event', $edit, t('Save'));
151
    $this->assertRaw('<table class="makemeeting-table');
152
    $this->drupalGet('node/2/edit');
153
    $this->assertRaw('<td class="makemeeting-choice-date">');
154

    
155
    $additional_stamp = strtotime('+1 day', REQUEST_TIME);
156
    $default_date = array(
157
      'month' => date('n', $additional_stamp),
158
      'day' => date('j', $additional_stamp),
159
      'year' => date('Y', $additional_stamp)
160
    );
161
    $key = _makemeeting_date_timestamp($default_date);
162
    $this->verbose($key);
163
    $this->drupalPostAJAX(NULL, $edit, array($key => t('Remove')));
164
    $this->assertNoRaw('<td class="makemeeting-choice-date">');
165
    $this->drupalPost(NULL, array(), t('Save'));
166
    $this->assertNoRaw('<table class="makemeeting-table');
167
  }
168

    
169
  /**
170
   * Test answering the makemeeting poll
171
   */
172
  public function testAnswerEvent() {
173
    // Fill in a default event node form with some suggestions
174
    $this->_testCreateField();
175
    $this->_testFillMakemeetingForm();
176

    
177
    // Create the event as is
178
    $this->drupalPost(NULL, array(), t('Save'));
179
    $this->assertRaw('<input title="Tuesday 22 May 2012 bar" type="checkbox" id="edit-answers-1337644800sugg1" name="answers[1337644800:sugg:1]" value="1" class="form-checkbox"', 'Checkboxes exist');
180

    
181
    // Test answering a poll
182
    $this->assertRaw('<tr class="answer-form-row', 'Answer form exists');
183
    $this->drupalPost(NULL, array(), t('Submit'));
184
    $this->assertNoRaw('<tr class="answer-form-row', 'No answer form once submitted');
185

    
186
    // Test a single option form
187
    $this->_testFillMakemeetingForm();
188
    $this->drupalPost(NULL, array('field_choose_date[und][0][one_option]' => '1'), t('Save'));
189
    $this->assertRaw('<input title="Tuesday 22 May 2012 bar" type="radio" id="edit-answers--7" name="answers" value="1337644800:sugg:1" class="form-radio"', 'Radios exist');
190

    
191
    // Test a closed form
192
    $this->_testFillMakemeetingForm();
193
    $this->drupalPost(NULL, array('field_choose_date[und][0][closed]' => '1'), t('Save'));
194
    $this->assertNoRaw('<input disabled="disabled" type="text" id="edit-name" name="name"');
195
  }
196

    
197
  /**
198
   * Helper function to create an event content type and attach a makemeeting field
199
   */
200
  public function _testCreateField() {
201
    // Login as admin
202
    $this->drupalLogin($this->privileged_user);
203

    
204
    // Create the content type
205
    $edit = array();
206
    $edit['name'] = 'Event';
207
    $edit['type'] = 'event';
208
    $this->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
209
    $this->assertText('The content type Event has been added.', 'Content type added.');
210

    
211
    // Creates the field.
212
    $edit = array();
213
    $edit['fields[_add_new_field][label]'] = 'Choose date';
214
    $edit['fields[_add_new_field][field_name]'] = 'choose_date';
215
    $edit['fields[_add_new_field][weight]'] = '0';
216
    $edit['fields[_add_new_field][type]'] = 'makemeeting';
217
    $edit['fields[_add_new_field][widget_type]'] = 'makemeeting_choices';
218
    $this->drupalPost('admin/structure/types/manage/event/fields', $edit, t('Save'));
219

    
220
    $edit = array();
221
    $this->drupalPost(NULL, $edit, t('Save field settings'));
222
  }
223

    
224
  public function _testFillMakemeetingForm() {
225
    $edit = array();
226
    $edit['title'] = $this->randomName();
227
    $edit += array(
228
      'field_choose_date[und][0][choices][new:0][chdate][month]' => '5',
229
      'field_choose_date[und][0][choices][new:0][chdate][day]' => '20',
230
      'field_choose_date[und][0][choices][new:0][chdate][year]' => '2012',
231
    );
232
    $this->drupalPostAJAX('node/add/event', $edit, array('op' => t('More choices')));
233
    $edit = array(
234
      'field_choose_date[und][0][choices][1337472000][chdate][month]' => '5',
235
      'field_choose_date[und][0][choices][1337472000][chdate][day]' => '20',
236
      'field_choose_date[und][0][choices][1337472000][chdate][year]' => '2012',
237
      'field_choose_date[und][0][choices][1337472000][chsuggestions][sugg:0]' => 'foo',
238
      'field_choose_date[und][0][choices][new:0][chdate][month]' => '5',
239
      'field_choose_date[und][0][choices][new:0][chdate][day]' => '21',
240
      'field_choose_date[und][0][choices][new:0][chdate][year]' => '2012',
241
    ) + $edit;
242
    $this->drupalPost(NULL, $edit, t('More choices'));
243
    $edit = array(
244
      'field_choose_date[und][0][choices][1337558400][chdate][month]' => '5',
245
      'field_choose_date[und][0][choices][1337558400][chdate][day]' => '21',
246
      'field_choose_date[und][0][choices][1337558400][chdate][year]' => '2012',
247
      'field_choose_date[und][0][choices][new:0][chdate][month]' => '5',
248
      'field_choose_date[und][0][choices][new:0][chdate][day]' => '22',
249
      'field_choose_date[und][0][choices][new:0][chdate][year]' => '2012',
250
    ) + $edit;
251
    $this->drupalPost(NULL, $edit, t('More suggestions'));
252
    $edit += array(
253
      'field_choose_date[und][0][choices][1337644800][chdate][month]' => '5',
254
      'field_choose_date[und][0][choices][1337644800][chdate][day]' => '22',
255
      'field_choose_date[und][0][choices][1337644800][chdate][year]' => '2012',
256
      'field_choose_date[und][0][choices][1337472000][chsuggestions][sugg:1]' => 'bar',
257
    );
258
    unset($edit['field_choose_date[und][0][choices][new:0][chdate][day]']);
259
    unset($edit['field_choose_date[und][0][choices][new:0][chdate][month]']);
260
    unset($edit['field_choose_date[und][0][choices][new:0][chdate][year]']);
261
    $this->drupalPost(NULL, $edit, t('Copy and paste first row'));
262
  }
263
}