Mercurial > hg > rr-repo
comparison sites/all/modules/features/tests/features.test @ 4:ce11bbd8f642
added modules
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Thu, 19 Sep 2013 10:38:44 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:b28be78d8160 | 4:ce11bbd8f642 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * User permission component tests for Features | |
5 */ | |
6 class FeaturesUserTestCase extends DrupalWebTestCase { | |
7 protected $profile = 'testing'; | |
8 | |
9 /** | |
10 * Test info. | |
11 */ | |
12 public static function getInfo() { | |
13 return array( | |
14 'name' => t('Component tests'), | |
15 'description' => t('Run tests for components of Features.') , | |
16 'group' => t('Features'), | |
17 ); | |
18 } | |
19 | |
20 /** | |
21 * Set up test. | |
22 */ | |
23 public function setUp() { | |
24 parent::setUp(array( | |
25 'field', | |
26 'filter', | |
27 'image', | |
28 'taxonomy', | |
29 'views', | |
30 'features', | |
31 'features_test' | |
32 )); | |
33 | |
34 // Run a features rebuild to ensure our feature is fully installed. | |
35 features_rebuild(); | |
36 | |
37 $admin_user = $this->drupalCreateUser(array('administer features')); | |
38 $this->drupalLogin($admin_user); | |
39 } | |
40 | |
41 /** | |
42 * Run test. | |
43 */ | |
44 public function test() { | |
45 module_load_include('inc', 'features', 'features.export'); | |
46 | |
47 $components = array_filter(array( | |
48 'field_instance' => 'field', | |
49 'filter' => 'filter', | |
50 'image' => 'image', | |
51 'node' => 'node', | |
52 'user_permission' => 'user', | |
53 'views_view' => 'views', | |
54 ), 'module_exists'); | |
55 | |
56 foreach (array_keys($components) as $component) { | |
57 $callback = "_test_{$component}"; | |
58 | |
59 // Ensure that the component/default is properly available. | |
60 $object = $this->$callback('load'); | |
61 $this->assertTrue(!empty($object), t('@component present.', array('@component' => $component))); | |
62 | |
63 // Ensure that the component is defaulted. | |
64 $states = features_get_component_states(array('features_test'), FALSE, TRUE); | |
65 $this->assertTrue($states['features_test'][$component] === FEATURES_DEFAULT, t('@component state: Default.', array('@component' => $component))); | |
66 | |
67 // Override component and test that Features detects the override. | |
68 $this->$callback('override', $this); | |
69 $states = features_get_component_states(array('features_test'), FALSE, TRUE); | |
70 $this->assertTrue($states['features_test'][$component] === FEATURES_OVERRIDDEN, t('@component state: Overridden.', array('@component' => $component))); | |
71 } | |
72 | |
73 // Revert component and ensure that component has reverted. | |
74 // Do this in separate loops so we only have to run | |
75 // drupal_flush_all_caches() once. | |
76 foreach (array_keys($components) as $component) { | |
77 features_revert(array('features_test' => array($component))); | |
78 } | |
79 drupal_flush_all_caches(); | |
80 foreach (array_keys($components) as $component) { | |
81 // Reload so things like Views can clear it's cache | |
82 $this->$callback('load'); | |
83 $states = features_get_component_states(array('features_test'), FALSE, TRUE); | |
84 $this->assertTrue($states['features_test'][$component] === FEATURES_DEFAULT, t('@component reverted.', array('@component' => $component))); | |
85 } | |
86 } | |
87 | |
88 protected function _test_field_instance($op = 'load') { | |
89 switch ($op) { | |
90 case 'load': | |
91 return field_info_instance('node', 'field_features_test', 'features_test'); | |
92 case 'override': | |
93 $field_instance = field_info_instance('node', 'field_features_test', 'features_test'); | |
94 $field_instance['label'] = 'Foo bar'; | |
95 field_update_instance($field_instance); | |
96 break; | |
97 } | |
98 } | |
99 | |
100 protected function _test_filter($op = 'load') { | |
101 // So... relying on our own API functions to test is pretty lame. | |
102 // But these modules don't have APIs either. So might as well use | |
103 // the ones we've written for them... | |
104 features_include(); | |
105 switch ($op) { | |
106 case 'load': | |
107 return features_filter_format_load('features_test'); | |
108 case 'override': | |
109 $format = features_filter_format_load('features_test'); | |
110 unset($format->filters['filter_url']); | |
111 filter_format_save($format); | |
112 break; | |
113 } | |
114 } | |
115 | |
116 protected function _test_image($op = 'load') { | |
117 switch ($op) { | |
118 case 'load': | |
119 return image_style_load('features_test'); | |
120 case 'override': | |
121 $style = image_style_load('features_test'); | |
122 $style = image_style_save($style); | |
123 foreach ($style['effects'] as $effect) { | |
124 $effect['data']['width'] = '120'; | |
125 image_effect_save($effect); | |
126 } | |
127 break; | |
128 } | |
129 } | |
130 | |
131 protected function _test_node($op = 'load') { | |
132 switch ($op) { | |
133 case 'load': | |
134 return node_type_get_type('features_test'); | |
135 case 'override': | |
136 $type = node_type_get_type('features_test'); | |
137 $type->description = 'Foo bar baz.'; | |
138 $type->modified = TRUE; | |
139 node_type_save($type); | |
140 break; | |
141 } | |
142 } | |
143 | |
144 protected function _test_views_view($op = 'load') { | |
145 switch ($op) { | |
146 case 'load': | |
147 return views_get_view('features_test', TRUE); | |
148 case 'override': | |
149 $view = views_get_view('features_test', TRUE); | |
150 $view->set_display('default'); | |
151 $view->display_handler->override_option('title', 'Foo bar'); | |
152 $view->save(); | |
153 // Clear the load cache from above | |
154 views_get_view('features_test', TRUE); | |
155 break; | |
156 } | |
157 } | |
158 | |
159 protected function _test_user_permission($op = 'load') { | |
160 switch ($op) { | |
161 case 'load': | |
162 $permissions = user_role_permissions(array(DRUPAL_AUTHENTICATED_RID => 'authenticated user')); | |
163 return !empty($permissions[DRUPAL_AUTHENTICATED_RID]['create features_test content']); | |
164 case 'override': | |
165 user_role_change_permissions(DRUPAL_AUTHENTICATED_RID, array('create features_test content' => 0)); | |
166 break; | |
167 } | |
168 } | |
169 } | |
170 | |
171 /** | |
172 * Tests enabling of feature modules. | |
173 */ | |
174 class FeaturesEnableTestCase extends DrupalWebTestCase { | |
175 protected $profile = 'testing'; | |
176 | |
177 /** | |
178 * Test info. | |
179 */ | |
180 public static function getInfo() { | |
181 return array( | |
182 'name' => t('Features enable tests'), | |
183 'description' => t('Run tests for enabling of features.') , | |
184 'group' => t('Features'), | |
185 ); | |
186 } | |
187 | |
188 | |
189 /** | |
190 * Run test for features_get_components on enable. | |
191 */ | |
192 public function testFeaturesGetComponents() { | |
193 | |
194 // Testing that features_get_components returns correct after enable. | |
195 $modules = array( | |
196 'features', | |
197 'taxonomy', | |
198 'features_test', | |
199 ); | |
200 | |
201 // Make sure features_get_components is cached if features already enabled. | |
202 if (!module_exists('features')) { | |
203 drupal_load('module', 'features'); | |
204 } | |
205 features_get_components(); | |
206 | |
207 module_enable($modules); | |
208 | |
209 // Make sure correct information for enabled modules is now cached. | |
210 $components = features_get_components(); | |
211 $taxonomy_component_info = taxonomy_features_api(); | |
212 $this->assertTrue(!empty($components['taxonomy']) && $components['taxonomy'] == $taxonomy_component_info['taxonomy'], 'features_get_components returns correct taxonomy information on enable'); | |
213 | |
214 features_rebuild(); | |
215 $this->assertNotNull(taxonomy_vocabulary_machine_name_load('taxonomy_features_test'), 'Taxonomy vocabulary correctly enabled on enable.'); | |
216 } | |
217 } | |
218 | |
219 | |
220 /** | |
221 * Tests intergration of ctools for features. | |
222 */ | |
223 class FeaturesCtoolsIntegrationTest extends DrupalWebTestCase { | |
224 protected $profile = 'testing'; | |
225 | |
226 /** | |
227 * Test info. | |
228 */ | |
229 public static function getInfo() { | |
230 return array( | |
231 'name' => t('Features Chaos Tools integration'), | |
232 'description' => t('Run tests for ctool integration of features.') , | |
233 'group' => t('Features'), | |
234 ); | |
235 } | |
236 | |
237 /** | |
238 * Set up test. | |
239 */ | |
240 public function setUp() { | |
241 parent::setUp(array( | |
242 'features', | |
243 'ctools', | |
244 )); | |
245 } | |
246 | |
247 /** | |
248 * Run test. | |
249 */ | |
250 public function testModuleEnable() { | |
251 $try = array( | |
252 'strongarm', | |
253 'views', | |
254 ); | |
255 | |
256 // Trigger the first includes and the static to be set. | |
257 features_include(); | |
258 $function_ends = array( | |
259 'features_export', | |
260 'features_export_options', | |
261 'features_export_render', | |
262 'features_revert', | |
263 ); | |
264 foreach ($try as $module) { | |
265 $function = $module . '_features_api'; | |
266 $this->assertFalse(function_exists($function), 'Chaos tools functions for ' . $module . ' do not exist while it is disabled.'); | |
267 // Module enable will trigger declaring the new functions. | |
268 module_enable(array($module)); | |
269 } | |
270 | |
271 // CTools hooks only created when there is an actual feature exportable | |
272 // enabled. | |
273 module_enable(array('features_test')); | |
274 | |
275 foreach ($try as $module) { | |
276 if (module_exists($module)) { | |
277 $function_exists = function_exists($function); | |
278 if ($function_exists) { | |
279 foreach ($function() as $component_type => $component_info) { | |
280 foreach ($function_ends as $function_end) { | |
281 $function_exists = $function_exists && function_exists($component_type . '_' . $function_end); | |
282 } | |
283 } | |
284 } | |
285 $this->assertTrue($function_exists, 'Chaos tools functions for ' . $module . ' exist when it is enabled.'); | |
286 } | |
287 } | |
288 } | |
289 } |