/
system.test
132 lines (105 loc) · 5.77 KB
/
system.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* @file
* SimpleTests for the System component of Patterns.
*/
class PatternsSystemTestCase extends PatternsTestCase {
var $system_tests_dir;
static function getInfo() {
return array(
'name' => 'System component',
'description' => 'Enables and disables modules, sets and deletes variables, enables a theme.',
'group' => 'Patterns',
);
}
public function setUp() {
$this->system_tests_dir = $this->getPatternsTestDir() . 'system/';
// Enable any modules required for the tests.
$modules = array('patterns_components',
'patterns_yamlparser',
);
parent::setUp($modules);
}
/**
* Check the database if a module is enabled/disabled.
* @name Module name
* @enabled TRUE iff the module should be enabled.
*/
private function assertModule($name, $enabled = TRUE) {
$module = db_select('system', 's')
->fields('s', array('name'))
->condition('name', $name)
->condition('type', 'module')
->condition('status', $enabled ? '1' : '0')
->countQuery()->execute()->fetchField();
$this->assertEqual($module, 1, $message = 'The ' . $name . ' module should ' . ($enabled ? '' : 'not ') . 'be enabled.');
}
public function testModules() {
// Check for modules before running the pattern.
$this->assertModule('aggregator', FALSE);
$this->assertModule('forum', FALSE);
$this->assertModule('overlay', TRUE);
$this->assertModule('number', TRUE);
// Run the pattern.
parent::runFile('modules.yaml', 'Enable/disable modules', $this->system_tests_dir);
// Expected messages.
$this->assertUniqueText(t('Module(s) forum, number enabled. No modules have been disabled.'), t('The forum module should get enabled.'));
$this->assertUniqueText(t('No modules have been enabled. Module(s) overlay disabled.'), t('The overlay module should get disabled.'));
$this->assertUniqueText(t('Warning: Could not disable admin_menu because it is missing.'), t('Disabling a missing module gives a warning.'));
$this->assertUniqueText(t('Warning: Did not disable aggregator because it is already disabled.'), t('Disabling a disabled module gives a warning.'));
$this->assertUniqueText(t('Warning: Did not enable number because it is already enabled.'), t('Enabling an enabled module gives a warning.'));
// Check for modules after running the pattern.
// TODO: it might be good to check if every other module is left untouched.
$this->assertModule('aggregator', FALSE);
$this->assertModule('forum', TRUE);
$this->assertModule('overlay', FALSE);
$this->assertModule('number', TRUE);
}
public function testVariables() {
// Check for variables before running the pattern.
/* debug(db_select('variable', 'v')
->fields('v', array('name'))
->execute()
->fetchAll());
*/
$this->assertNotIdentical(variable_get('user_pictures', NULL), NULL, t('user_pictures variable should be set.'));
$this->assertIdentical(variable_get('votingapi_anonymous_window', NULL), NULL, t('votingapi_anonymous_window variable should not be set.'));
$this->assertIdentical(variable_get('fivestar_widget', NULL), NULL, t('fivestar_widget variable should not be set.'));
// Run the pattern.
parent::runFile('variables.yaml', 'Create and delete variables', $this->system_tests_dir);
$this->assertUniqueText(t('Variable(s) votingapi_anonymous_window, fivestar_widget updated.'), t('The votingapi_anonymous_window, fivestar_widget variables should get updated.'));
$this->assertUniqueText(t('Variable(s) user_pictures updated.'), t('The user_pitures variabcle should get updated.'));
// Check for variables after running the pattern.
$this->assertIdentical(variable_get('user_pictures', NULL), NULL, t('user_pictures variable should not be set.'));
$this->assertIdentical(variable_get('votingapi_anonymous_window', NULL), 3600, t('votingapi_anonymous_window variable should be set properly.'));
$this->assertIdentical(variable_get('fivestar_widget', NULL), 'sites/all/modules/fivestar/widgets/craft/craft.css', t('fivestar_widget variable should be set properly.'));
/* debug(db_select('variable', 'v')
->fields('v', array('name'))
->execute()
->fetchAll());
*/
}
public function testForms() {
// Check for variables before running the pattern.
$this->assertIdentical(variable_get('cache', NULL), NULL, t('cache variable should not be set.'));
$this->assertIdentical(variable_get('anonymous', NULL), NULL, t("anonymous variable should not be set."));
// Run the pattern.
parent::runFile('fill_forms.yaml', 'Fill in values for forms', $this->system_tests_dir);
// Expected messages.
$this->assertText(t('The configuration options have been saved.'), t('The forms have been submitted.'));
// Check for variables after running the pattern.
$this->assertIdentical(variable_get('cache', NULL), 1, t('cache variable should be 1.'));
$this->assertIdentical(variable_get('anonymous', NULL), 'Anonymous2', t("Anonymous variable should be 'Anonymous2'."));
}
public function testTheme() {
// TODO: test when 'default' is not set
// Check for the current theme.
$this->assertIdentical(variable_get('theme_default', NULL), 'bartik', t('The default theme is bartik.'));
$this->assertIdentical(variable_get('admin_theme', NULL), 'seven', t('The default admin theme is seven.'));
// Run the pattern.
parent::runFile('theme.yaml', 'Set theme', $this->system_tests_dir);
// Check for the current theme after running the pattern.
$this->assertIdentical(variable_get('theme_default', NULL), 'garland', t('The default theme is garland.'));
$this->assertIdentical(variable_get('admin_theme', NULL), 'bartik', t('The default admin theme is bartik.'));
}
}