1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Tests for variable.module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Helper class for module test cases.
|
10 |
|
|
*/
|
11 |
|
|
class VariableStoreTestCase extends DrupalWebTestCase {
|
12 |
|
|
protected $admin_user;
|
13 |
|
|
|
14 |
|
|
public static function getInfo() {
|
15 |
|
|
return array(
|
16 |
|
|
'name' => 'Test Variable store and realms',
|
17 |
|
|
'description' => 'Exercise the Variable API, default values, save and delete variables, etc.',
|
18 |
|
|
'group' => 'Variable',
|
19 |
|
|
);
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
function setUp() {
|
23 |
|
|
parent::setUp('variable', 'variable_realm', 'variable_store', 'variable_example');
|
24 |
|
|
|
25 |
|
|
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration'));
|
26 |
|
|
$this->drupalLogin($this->admin_user);
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
|
|
* Test that all core modules can be enabled, disabled and uninstalled.
|
31 |
|
|
*/
|
32 |
|
|
function testVariableStoreAPI() {
|
33 |
|
|
// Store two values for the 'example' realm.
|
34 |
|
|
$realm = 'example';
|
35 |
|
|
$store = array(
|
36 |
|
|
'first' => 'My first test site',
|
37 |
|
|
'second' => 'My second test site',
|
38 |
|
|
);
|
39 |
|
|
$values = array(
|
40 |
|
|
'default' => 'Drupal',
|
41 |
|
|
) + $store;
|
42 |
|
|
foreach ($store as $key => $value) {
|
43 |
|
|
variable_store_set($realm, $key, 'site_name', $value);
|
44 |
|
|
}
|
45 |
|
|
// Check we've got stored the right value for each realm.
|
46 |
|
|
foreach ($store as $key => $value) {
|
47 |
|
|
$this->assertEqual(variable_store_get($realm, $key, 'site_name'), $value, 'Variable has been saved to the store.');
|
48 |
|
|
// Check the value is displayed with example page.
|
49 |
|
|
$this->drupalGet('variable/realm/' . $realm . '/' . $key);
|
50 |
|
|
$this->assertText($value, "The right site name is displayed for realm $realm:$key");
|
51 |
|
|
}
|
52 |
|
|
// Load realms from store and set them as different realm.
|
53 |
|
|
foreach ($store as $key => $value) {
|
54 |
|
|
$variables = variable_store($realm, $key);
|
55 |
|
|
variable_realm_add($realm, $key, $variables);
|
56 |
|
|
}
|
57 |
|
|
// Switch realms and get the right values.
|
58 |
|
|
foreach ($values as $key => $value) {
|
59 |
|
|
// Check value before setting realm
|
60 |
|
|
$this->assertEqual(variable_realm_get($realm, $key, 'site_name', 'Drupal'), $value, "We get the right value for realm $realm:$key");
|
61 |
|
|
variable_realm_switch($realm, $key);
|
62 |
|
|
$this->assertEqual(variable_get_value('site_name'), $value, "We get the right value with Variable API after switching to realm $realm:$key");
|
63 |
|
|
$this->assertEqual(variable_get('site_name', 'Drupal'), $value, "We get the right value with Drupal API after switching to realm $realm:$key");
|
64 |
|
|
}
|
65 |
|
|
// Delete variable and check it has been deleted, first from realms and then from store.
|
66 |
|
|
variable_delete('site_name');
|
67 |
|
|
// Check we've got stored the right value for each realm.
|
68 |
|
|
foreach ($store as $key => $value) {
|
69 |
|
|
$this->assertFalse(variable_store_get($realm, $key, 'site_name'), "Variable has been deleted from the realm for $realm:$key.");
|
70 |
|
|
$this->assertFalse(variable_store_get($realm, $key, 'site_name'), "Variable has been deleted from the store for $realm:$key.");
|
71 |
|
|
}
|
72 |
|
|
// Finally check variable has returned to default value. Use any of the realms.
|
73 |
|
|
variable_realm_switch($realm, 'first');
|
74 |
|
|
$this->assertEqual($value = variable_get_value('site_name'), 'Drupal', "We get the right value with Variable API after deleting the variable: $value");
|
75 |
|
|
$this->assertFalse($value = variable_get('site_name'), "We get the right value with Drupal API after deleting the variable: $value");
|
76 |
|
|
|
77 |
|
|
}
|
78 |
|
|
} |