Révision ecb492a9
Ajouté par Assos Assos il y a presque 6 ans
drupal7/sites/all/modules/block_class/block_class.test | ||
---|---|---|
11 | 11 |
class BlockClassTestCase extends DrupalWebTestCase { |
12 | 12 |
|
13 | 13 |
/** |
14 |
* User object to perform site browsing |
|
14 |
* User object to perform site browsing. |
|
15 |
* |
|
15 | 16 |
* @var object |
16 | 17 |
*/ |
17 | 18 |
protected $privilegedUser; |
18 | 19 |
|
19 | 20 |
/** |
20 | 21 |
* Machine name of the module providing the block coupled with delta. |
22 |
* |
|
21 | 23 |
* @var string |
22 | 24 |
*/ |
23 | 25 |
protected $module = 'system'; |
24 | 26 |
|
25 | 27 |
/** |
26 | 28 |
* Block delta as provided by its module. |
29 |
* |
|
27 | 30 |
* @var string |
28 | 31 |
*/ |
29 | 32 |
protected $delta = 'main'; |
30 | 33 |
|
31 | 34 |
/** |
32 | 35 |
* Permissions required by the user to perform the tests. |
36 |
* |
|
33 | 37 |
* @var array |
34 | 38 |
*/ |
35 | 39 |
protected $permissions = array( |
... | ... | |
86 | 90 |
$this->drupalPost("admin/structure/block/manage/$module/$delta/configure", array('css_class' => $css_classes), t('Save block')); |
87 | 91 |
// Check Block configuration was saved successfully. |
88 | 92 |
$this->assertText(t('The block configuration has been saved.')); |
89 |
// Browse to the homepage. |
|
90 |
$this->drupalGet(''); |
|
91 | 93 |
// Log out if the test is for anonymous user. |
92 | 94 |
if ($anon) { |
93 | 95 |
$this->drupalLogout(); |
94 |
// Browse back to the homepage. |
|
95 |
$this->drupalGet(''); |
|
96 | 96 |
} |
97 |
// Browse to the homepage. |
|
98 |
$this->drupalGet(''); |
|
97 | 99 |
// Check if the Block CSS classes could be found. |
98 | 100 |
$this->assertPattern('/class=\"(.*?)' . $css_classes . '(.*?)\"/', format_string('The CSS classes were found: @css_classes', array('@css_classes' => $css_classes))); |
99 |
// Login again after testing with the anonumous user.
|
|
101 |
// Login again after testing with the anonymous user.
|
|
100 | 102 |
if ($anon) { |
101 | 103 |
$this->drupalLogin($this->privilegedUser); |
102 | 104 |
} |
103 | 105 |
} |
106 |
|
|
104 | 107 |
} |
105 | 108 |
|
106 | 109 |
/** |
... | ... | |
123 | 126 |
* Update and display a Block multiple times to ensure CSS class is found. |
124 | 127 |
* |
125 | 128 |
* A Block is updated and displayed several times and with logged in or |
126 |
* anonymous user, with Block cache turned enabled or disabled.
|
|
129 |
* anonymous user, with Block cache enabled or disabled. |
|
127 | 130 |
*/ |
128 | 131 |
public function testUpdateDisplayClass() { |
129 | 132 |
// Edit the block, change the class and check if the CSS classes are found. |
... | ... | |
140 | 143 |
// Edit the block, change the class and check with the anonymous user. |
141 | 144 |
$this->assertUpdateBlockClass(TRUE); |
142 | 145 |
} |
146 |
|
|
143 | 147 |
} |
144 | 148 |
|
145 | 149 |
/** |
... | ... | |
180 | 184 |
// If the field is not found, it can't be submitted through drupalPost. |
181 | 185 |
$this->assertNoFieldById('css_class', 'The Css classes field was not found on the page.'); |
182 | 186 |
} |
187 |
|
|
183 | 188 |
} |
184 | 189 |
|
185 | 190 |
/** |
... | ... | |
252 | 257 |
// Save the context. |
253 | 258 |
context_save($context); |
254 | 259 |
} |
260 |
|
|
255 | 261 |
} |
256 | 262 |
|
257 | 263 |
/** |
... | ... | |
280 | 286 |
$this->module = 'user'; |
281 | 287 |
$this->delta = 'online'; |
282 | 288 |
// Include all Features related modules and Test Helper feature. |
283 |
parent::setUp('block_class_fe_block_test');
|
|
289 |
parent::setUp('block_class_fe_block_test');
|
|
284 | 290 |
} |
285 | 291 |
|
286 | 292 |
/** |
... | ... | |
307 | 313 |
// Run a standard Update/Display Test check with Anon. |
308 | 314 |
$this->assertUpdateBlockClass(TRUE); |
309 | 315 |
|
310 |
// Ensure Feature's state is overriden for 'fe_block_settings' component. |
|
316 |
// Ensure Feature's state is overridden for 'fe_block_settings' component.
|
|
311 | 317 |
module_load_include('inc', 'features', 'features.export'); |
312 | 318 |
$test_feature_state = features_get_storage($test_feature); |
313 | 319 |
$this->assertFalse(empty($test_feature_state), 'The state of the <em>Block Class FE Block Integration Test Helper</em> feature is <strong>Overridden</strong>.'); |
... | ... | |
326 | 332 |
$this->drupalGet("admin/structure/block/manage/{$this->module}/{$this->delta}/configure"); |
327 | 333 |
$this->assertFieldByName('css_class', $test_classes, format_string('After reverting the feature, the CSS classes from exported feature were found for the field <em>css_class</em> in the Block\'s configuration page: @css_classes', array('@css_classes' => $test_classes))); |
328 | 334 |
} |
335 |
|
|
336 |
} |
|
337 |
|
|
338 |
/** |
|
339 |
* Test Block Class integration with Menu Block. |
|
340 |
*/ |
|
341 |
class BlockClassMenuBlockTestCase extends BlockClassTestCase { |
|
342 |
|
|
343 |
/** |
|
344 |
* Implements DrupalWebTestCase::getInfo(). |
|
345 |
*/ |
|
346 |
public static function getInfo() { |
|
347 |
return array( |
|
348 |
'name' => 'Integration with Menu Block', |
|
349 |
'description' => 'Test the integration of Block Class with the Menu Block module and the update/display of a Menu Block CSS class.', |
|
350 |
// We could use Menu Block's API to import a block from code. But part of |
|
351 |
// this test is about the creation process of a Menu Block. |
|
352 |
'dependencies' => array('menu_block'), |
|
353 |
'group' => 'Block Class', |
|
354 |
); |
|
355 |
} |
|
356 |
|
|
357 |
/** |
|
358 |
* Enable modules and create user with specific permissions. |
|
359 |
*/ |
|
360 |
public function setUp() { |
|
361 |
// Override default parameters to test with the first Menu Block created. |
|
362 |
$this->module = 'menu_block'; |
|
363 |
$this->delta = 1; |
|
364 |
// Add permission required by Menu Block to browse the add menu block page. |
|
365 |
$this->permissions[] = 'administer menu'; |
|
366 |
// Include the Menu Block module and its dependencies to be loaded. |
|
367 |
parent::setUp('menu_block'); |
|
368 |
} |
|
369 |
|
|
370 |
/** |
|
371 |
* Create, update and display a Menu Block to ensure CSS class is found. |
|
372 |
* |
|
373 |
* A Menu Block is added through the user interface. It is then updated and |
|
374 |
* displayed several times with logged in or anonymous user. |
|
375 |
*/ |
|
376 |
public function testMenuBlockDisplayClass() { |
|
377 |
// Test with three random class names. |
|
378 |
$css_classes = implode(' ', array( |
|
379 |
$this->randomName(8), |
|
380 |
$this->randomName(8), |
|
381 |
$this->randomName(8), |
|
382 |
)); |
|
383 |
// Start with the creation of a new Menu Block. |
|
384 |
$this->drupalPost("admin/structure/block/add-menu-block", array( |
|
385 |
'css_class' => $css_classes, |
|
386 |
'menu_name' => 'navigation', |
|
387 |
'regions[bartik]' => 'content', |
|
388 |
), t('Save block')); |
|
389 |
// Check if the Block was successfully created. |
|
390 |
$this->assertText(t('The block has been created.')); |
|
391 |
// Browse to the homepage. |
|
392 |
$this->drupalGet(''); |
|
393 |
// Check if the Block CSS classes could be found. |
|
394 |
$this->assertPattern('/class=\"(.*?)' . $css_classes . '(.*?)\"/', format_string('The CSS classes were found: @css_classes', array('@css_classes' => $css_classes))); |
|
395 |
// Run the standard tests on the existing Menu Block created above. |
|
396 |
// Edit the block, change the class and check with the anonymous user. |
|
397 |
$this->assertUpdateBlockClass(TRUE); |
|
398 |
} |
|
399 |
|
|
400 |
} |
|
401 |
|
|
402 |
/** |
|
403 |
* Test Block Class integration with Views block. |
|
404 |
*/ |
|
405 |
class BlockClassViewsTestCase extends BlockClassUpdateDisplayTestCase { |
|
406 |
|
|
407 |
/** |
|
408 |
* Implements DrupalWebTestCase::getInfo(). |
|
409 |
*/ |
|
410 |
public static function getInfo() { |
|
411 |
return array( |
|
412 |
'name' => 'Integration with Views block', |
|
413 |
'description' => 'Test the integration of Block Class with Views blocks and the update/display of a CSS class.', |
|
414 |
'dependencies' => array('views'), |
|
415 |
'group' => 'Block Class', |
|
416 |
); |
|
417 |
} |
|
418 |
|
|
419 |
/** |
|
420 |
* Enable modules and create the data necessary to run the tests. |
|
421 |
*/ |
|
422 |
public function setUp() { |
|
423 |
// Override default parameters to test with the Views: Archive block. |
|
424 |
$this->module = 'views'; |
|
425 |
$this->delta = 'archive-block'; |
|
426 |
// Include the Views module and its dependencies to be loaded. |
|
427 |
parent::setUp('views'); |
|
428 |
|
|
429 |
// Programmatically enable the default Archive View, based on #820110-1. |
|
430 |
$status = variable_get('views_defaults', array()); |
|
431 |
$status['archive'] = FALSE; |
|
432 |
variable_set('views_defaults', $status); |
|
433 |
|
|
434 |
// Note that the Views Archive block is not visible on the Block admin page |
|
435 |
// unless the registry is rebuilt with: registry_rebuild(). |
|
436 |
// Directly publish the Views Archive Block to the content region. |
|
437 |
$this->drupalPost("admin/structure/block/manage/{$this->module}/{$this->delta}/configure", array('regions[bartik]' => 'content'), t('Save block')); |
|
438 |
|
|
439 |
// Create a sample node to have some data to display in Views: Archive. |
|
440 |
$this->drupalCreateNode(array( |
|
441 |
'type' => 'page', |
|
442 |
'status' => 1, |
|
443 |
'uid' => $this->privilegedUser->uid, |
|
444 |
)); |
|
445 |
} |
|
446 |
|
|
329 | 447 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules