| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: features.test,v 1.1.2.4 2010/07/23 23:35:55 yhahn Exp $ 3 4 /** 5 * User permission component tests for Features 6 */ 7 class FeaturesUserTestCase extends DrupalWebTestCase { 8 /** 9 * Test info. 10 */ 11 public function getInfo() { 12 return array( 13 'name' => t('Component tests'), 14 'description' => t('Run tests for components of Features.') , 15 'group' => t('Features'), 16 ); 17 } 18 19 /** 20 * Set up test. 21 */ 22 public function setUp() { 23 parent::setUp( 24 // Note that the test will only run for the components that are 25 // properly enabled here. 26 'fieldgroup', 27 'text', 28 'content', 29 'context', 30 'ctools', 31 'views', 32 'imageapi', 33 'imagecache', 34 35 'features', 36 'features_test' 37 ); 38 39 // Run a features rebuild to ensure our feature is fully installed. 40 features_rebuild(); 41 42 $admin_user = $this->drupalCreateUser(array('administer features')); 43 $this->drupalLogin($admin_user); 44 } 45 46 /** 47 * Run test. 48 */ 49 public function test() { 50 module_load_include('inc', 'features', 'features.export'); 51 52 $components = array_filter(array( 53 'content' => 'content', 54 // 'context' => 'context', // @TODO write tests for context. 55 'fieldgroup' => 'fieldgroup', 56 'filter' => 'filter', 57 'imagecache' => 'imagecache', 58 'node' => 'node', 59 'user_permission' => 'user', 60 'views' => 'views', 61 ), 'module_exists'); 62 63 foreach (array_keys($components) as $component) { 64 $callback = "_test_{$component}"; 65 66 // Ensure that the component/default is properly available. 67 $object = $this->$callback('load', $id); 68 $this->assertTrue(!empty($object), t('@component present.', array('@component' => $component))); 69 70 // Ensure that the component is defaulted. 71 $states = features_get_component_states(array('features_test'), FALSE, TRUE); 72 $this->assertTrue($states['features_test'][$component] === FEATURES_DEFAULT, t('@component state: Default.', array('@component' => $component))); 73 74 // Override component and test that Features detects the override. 75 $this->$callback('override', $this); 76 $states = features_get_component_states(array('features_test'), FALSE, TRUE); 77 $this->assertTrue($states['features_test'][$component] === FEATURES_OVERRIDDEN, t('@component state: Overridden.', array('@component' => $component))); 78 } 79 80 // Revert component and ensure that component has reverted. 81 // Do this in separate loops so we only have to run 82 // drupal_flush_all_caches() once. 83 foreach ($components as $component) { 84 features_revert(array('features_test' => array($component))); 85 } 86 drupal_flush_all_caches(); 87 foreach ($components as $component) { 88 $states = features_get_component_states(array('features_test'), FALSE, TRUE); 89 $this->assertTrue($states['features_test'][$component] === FEATURES_DEFAULT, t('@component reverted.', array('@component' => $component))); 90 } 91 } 92 93 protected function _test_content($op = 'load') { 94 switch ($op) { 95 case 'load': 96 return content_fields('field_features_test', 'features_test'); 97 case 'override': 98 module_load_include('inc', 'content', 'includes/content.crud'); 99 $field = content_fields('field_features_test', 'features_test'); 100 $field['widget']['label'] = 'Foo bar'; 101 content_field_instance_update($field, TRUE); 102 break; 103 } 104 } 105 106 protected function _test_fieldgroup($op = 'load') { 107 $groups = fieldgroup_groups('features_test', FALSE, TRUE); 108 $group = $groups['group_features_test']; 109 switch ($op) { 110 case 'load': 111 return $group; 112 case 'override': 113 $group['settings']['display']['teaser'] = 'fieldset_collapsible'; 114 $group['fields'] = array('0' => 'field_features_test_child_a'); 115 116 // Update each field from this group. 117 foreach ($group['fields'] as $field_name) { 118 if ($field = content_fields($field_name, 'features_test')) { 119 $field['group'] = $group['group_features_test']; 120 fieldgroup_update_fields($field); 121 } 122 } 123 124 // Save the group itself. 125 fieldgroup_save_group('features_test', $group); 126 break; 127 } 128 } 129 130 protected function _test_filter($op = 'load') { 131 // So... relying on our own API functions to test is pretty lame. 132 // But these modules don't have APIs either. So might as well use 133 // the ones we've written for them... 134 features_include(); 135 $formats = _filter_get_formats(); 136 foreach ($formats as $k => $v) { 137 if ($v['name'] === 'features_test') { 138 $format = $v; 139 $format_id = $k; 140 } 141 } 142 143 switch ($op) { 144 case 'load': 145 return isset($format) ? $format : FALSE; 146 case 'override': 147 if (isset($format_id)) { 148 db_query("DELETE FROM {filters} WHERE module = 'filter' AND format = %d AND delta = %d", $format_id, 0); 149 } 150 break; 151 } 152 } 153 154 protected function _test_imagecache($op = 'load', &$test) { 155 switch ($op) { 156 case 'load': 157 return imagecache_preset_by_name('features_test'); 158 case 'override': 159 $preset = imagecache_preset_by_name('features_test'); 160 $preset = imagecache_preset_save($preset); 161 foreach ($preset['actions'] as $action) { 162 $action['data']['width'] = '50%'; 163 $action['presetid'] = $preset['presetid']; 164 imagecache_action_save($action); 165 } 166 break; 167 } 168 } 169 170 protected function _test_node($op = 'load') { 171 switch ($op) { 172 case 'load': 173 return node_get_types('type', 'features_test'); 174 case 'override': 175 $type = node_get_types('type', 'features_test'); 176 $type->description = 'Foo bar baz.'; 177 $type->modified = TRUE; 178 node_type_save($type); 179 break; 180 } 181 } 182 183 protected function _test_views($op = 'load') { 184 switch ($op) { 185 case 'load': 186 return views_get_view('features_test', TRUE); 187 case 'override': 188 $view = views_get_view('features_test', TRUE); 189 $view->set_display('default'); 190 $view->display_handler->override_option('title', 'Foo bar'); 191 $view->save(); 192 break; 193 } 194 } 195 196 protected function _test_user_permission($op = 'load') { 197 switch ($op) { 198 case 'load': 199 // So... relying on our own API functions to test is pretty lame. 200 // But these modules don't have APIs either. So might as well use 201 // the ones we've written for them... 202 features_include(); 203 $permissions = _user_features_get_permissions(); 204 return isset($permissions['create features_test content']) ? $permissions['create features_test content'] : FALSE; 205 case 'override': 206 $roles = _features_get_roles(); 207 if (in_array('create features_test content', $roles['authenticated user']['perm'])) { 208 $position = array_search('create features_test content', $roles['authenticated user']['perm']); 209 unset($roles['authenticated user']['perm'][$position]); 210 } 211 _user_features_save_roles($roles); 212 break; 213 } 214 } 215 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |