Projet

Général

Profil

Révision c304a780

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ctools/tests/ctools.test
1 1
<?php
2

  
2 3
/**
3 4
 * @file Test classes for code in the CTools module file.
4 5
 */
......
9 10
class CtoolsModuleTestCase extends DrupalWebTestCase {
10 11

  
11 12
  /**
12
   * {@inheritDoc}
13
   * {@inheritdoc}
13 14
   */
14 15
  public static function getInfo() {
15 16
    return array(
......
21 22
  }
22 23

  
23 24
  /**
24
   * {@inheritDoc}
25
   * {@inheritdoc}
25 26
   */
26
  function setUp(array $modules = array()) {
27
  public function setUp(array $modules = array()) {
27 28
    $modules[] = 'ctools';
28 29
    parent::setUp($modules);
29 30
  }
......
32 33
   * Test that the break phrase function behaves as expected.
33 34
   */
34 35
  public function testBreakPhrase() {
35
    $tests = [
36
      NULL => ['value' => []],
37
      '' => ['value' => []],
38
      '1' => ['operator' => 'and', 'value' => [1]],
39
      '99' => ['operator' => 'and', 'value' => [99]],
40
      '+1' => ['invalid_input' => TRUE, 'value' => [-1]],
41
      ' 1' => ['invalid_input' => TRUE, 'value' => [-1]],
42
      '1 ' => ['invalid_input' => TRUE, 'value' => [-1]],
43
      '-1' => ['invalid_input' => TRUE, 'value' => [-1]],
44
      '-99' => ['invalid_input' => TRUE, 'value' => [-1]],
45
      '1,2' => ['operator' => 'and', 'value' => [1, 2]],
46
      '1 2' => ['operator' => 'or', 'value' => [1, 2]],
47
      '1+2' => ['operator' => 'or', 'value' => [1, 2]],
48
      '1,2,3' => ['operator' => 'and', 'value' => [1, 2, 3]],
49
      '1 2 3' => ['operator' => 'or', 'value' => [1, 2, 3]],
50
      '1+2+3' => ['operator' => 'or', 'value' => [1, 2, 3]],
51
      '1 , 2 , 3' => ['invalid_input' => TRUE, 'value' => [-1]],
52
      '1 + 2 + 3' => ['invalid_input' => TRUE, 'value' => [-1]],
53
      '1,2,3,4,5,6,7,8,9' => [
36
    $tests = array(
37
      NULL => array('value' => array()),
38
      '' => array('value' => array()),
39
      '1' => array('operator' => 'and', 'value' => array(1)),
40
      '99' => array('operator' => 'and', 'value' => array(99)),
41
      '+1' => array('invalid_input' => TRUE, 'value' => array(-1)),
42
      ' 1' => array('invalid_input' => TRUE, 'value' => array(-1)),
43
      '1 ' => array('invalid_input' => TRUE, 'value' => array(-1)),
44
      '-1' => array('invalid_input' => TRUE, 'value' => array(-1)),
45
      '-99' => array('invalid_input' => TRUE, 'value' => array(-1)),
46
      '1,2' => array('operator' => 'and', 'value' => array(1, 2)),
47
      '1 2' => array('operator' => 'or', 'value' => array(1, 2)),
48
      '1+2' => array('operator' => 'or', 'value' => array(1, 2)),
49
      '1,2,3' => array('operator' => 'and', 'value' => array(1, 2, 3)),
50
      '1 2 3' => array('operator' => 'or', 'value' => array(1, 2, 3)),
51
      '1+2+3' => array('operator' => 'or', 'value' => array(1, 2, 3)),
52
      '1 , 2 , 3' => array('invalid_input' => TRUE, 'value' => array(-1)),
53
      '1 + 2 + 3' => array('invalid_input' => TRUE, 'value' => array(-1)),
54
      '1,2,3,4,5,6,7,8,9' => array(
54 55
        'operator' => 'and',
55
        'value' => [1, 2, 3, 4, 5, 6, 7, 8, 9]
56
      ],
57
      '1 2,3,4 5 6 7 8 9' => ['invalid_input' => TRUE, 'value' => [-1]],
58
    ];
56
        'value' => array(1, 2, 3, 4, 5, 6, 7, 8, 9),
57
      ),
58
      '1 2,3,4 5 6 7 8 9' => array('invalid_input' => TRUE, 'value' => array(-1)),
59
    );
59 60

  
60 61
    foreach ($tests as $string => $expected) {
61 62
      $result = ctools_break_phrase($string);
......
142 143
    $ok = ctools_api_version('10.0');
143 144
    $this->assertFalse($ok, 'Check API version 10.0 is not ok');
144 145

  
145
    // We are (currently) between version 1.1 and version 4.0
146
    // We are (currently) between version 1.1 and version 4.0.
146 147
    $ok = ctools_api_version('1.1', '4.0');
147 148
    $this->assertTrue($ok, 'Check API is between 1 and 4');
148 149
  }
149 150

  
150 151
  /**
151
   * Test that the ctools_classs_add works
152
   * Test that the ctools_classs_add works.
152 153
   */
153 154
  public function testClassesAdd() {
154 155
    ctools_class_reset();
......
160 161
    $this->assertEqual(count($classes), 1, 'Classes array has one element');
161 162
    $this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
162 163
    $this->assertTrue(isset($classes['html']['add']), 'Classes array has element: html/add');
163
    $this->assertEqual($classes['html']['add'], ['testclass'], 'Classes array has expected value');
164
    $this->assertEqual($classes['html']['add'], array('testclass'), 'Classes array has expected value');
164 165

  
165 166
    ctools_class_add('class2 class3');
166 167

  
167 168
    $classes = ctools_get_classes();
168 169
    $this->assertEqual(is_array($classes), 1, 'Classes should be an array');
169 170
    $this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
170
    // TODO: An undesirable result: ['testclass', 'class2', 'class3'] is better.
171
    $this->assertEqual($classes['html']['add'], [
171
    // TODO: An undesirable result: array('testclass', 'class2', 'class3') is better.
172
    $this->assertEqual($classes['html']['add'], array(
172 173
      'testclass',
173
      'class2 class3'
174
    ], 'Classes array has expected value');
174
      'class2 class3',
175
    ), 'Classes array has expected value');
175 176
  }
176 177

  
177 178
  /**
178
   * Test that the ctools_classs_remove works
179
   * Test that the ctools_classs_remove works.
179 180
   */
180 181
  public function testClassesRemove() {
181 182
    ctools_class_reset();
......
187 188
    $this->assertEqual(count($classes), 1, 'Classes array has one element');
188 189
    $this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
189 190
    $this->assertTrue(isset($classes['html']['remove']), 'Classes array has element: html/remove');
190
    $this->assertEqual($classes['html']['remove'], ['testclass'], 'Classes array has expected value');
191
    $this->assertEqual($classes['html']['remove'], array('testclass'), 'Classes array has expected value');
191 192

  
192 193
    ctools_class_remove('class2 class3');
193 194

  
194 195
    $classes = ctools_get_classes();
195 196
    $this->assertEqual(count($classes), 1, 'Classes array has one element');
196 197
    $this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
197
    // This is an undesirable result, is ['testclass', 'class2', 'class3'] better.
198
    $this->assertEqual($classes['html']['remove'], [
198
    // This is an undesirable result, is array('testclass', 'class2', 'class3') better.
199
    $this->assertEqual($classes['html']['remove'], array(
199 200
      'testclass',
200
      'class2 class3'
201
    ], 'Classes array has expected value');
201
      'class2 class3',
202
    ), 'Classes array has expected value');
202 203
  }
203 204

  
204 205
  /**
......
212 213

  
213 214
    $classes = ctools_get_classes();
214 215
    $this->assertTrue(isset($classes['html']['add']), 'Classes array has an add set');
215
    $this->assertEqual($classes['html']['add'], ['testclass'], 'testclass is in the add set');
216
    $this->assertEqual($classes['html']['add'], array('testclass'), 'testclass is in the add set');
216 217
    $this->assertTrue(isset($classes['html']['remove']), 'Classes array has a remove set');
217 218
    // TODO: Is it really good to let this happen?
218
    $this->assertEqual($classes['html']['remove'], ['testclass'], 'testclass is in the remove set');
219
    $this->assertEqual($classes['html']['remove'], array('testclass'), 'testclass is in the remove set');
219 220
  }
220 221

  
221 222
  /**
......
229 230

  
230 231
    $classes = ctools_get_classes();
231 232
    $this->assertTrue(isset($classes['html']['add']), 'Classes array has an add set');
232
    $this->assertEqual($classes['html']['add'], ['class2 class3'], 'Added class2 class3 is in add set');
233
    $this->assertEqual($classes['html']['add'], array('class2 class3'), 'Added class2 class3 is in add set');
233 234
    $this->assertTrue(isset($classes['html']['remove']), 'Classes array has a remove set');
234 235
    // TODO: Is it really good to let this happen?
235
    $this->assertEqual($classes['html']['remove'], ['class3'], 'class3 in remove set');
236
    $this->assertEqual($classes['html']['remove'], array('class3'), 'class3 in remove set');
236 237
  }
237 238

  
238 239
}

Formats disponibles : Unified diff