| 1 |
<?php
|
| 2 |
// $Id: taxonomy_filter.test,v 1.1 2009/05/29 21:12:45 solotandem Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Tests for Taxonomy Filter module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Class with common helper methods.
|
| 11 |
*/
|
| 12 |
class TaxonomyFilterTestCase extends DrupalWebTestCase {
|
| 13 |
// TODO Do we need this class?
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Tests for the admin settings interface.
|
| 18 |
*/
|
| 19 |
class TaxonomyFilterSettingsTest extends TaxonomyFilterTestCase {
|
| 20 |
|
| 21 |
public static function getInfo() {
|
| 22 |
return array(
|
| 23 |
'name' => t('Settings interface'),
|
| 24 |
'description' => t('Test the administration interface for the taxonomy filter menus.'),
|
| 25 |
'group' => t('Taxonomy filter'),
|
| 26 |
);
|
| 27 |
}
|
| 28 |
|
| 29 |
function setUp() {
|
| 30 |
parent::setUp('taxonomy', 'taxonomy_filter');
|
| 31 |
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration', 'administer blocks' /*, 'administer taxonomy'*/));
|
| 32 |
$this->drupalLogin($this->admin_user);
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Call test methods (prefixed with 'check' to avoid setUp overhead).
|
| 37 |
*/
|
| 38 |
function testAdminInterface() {
|
| 39 |
// Include the admin file so we can call its functions.
|
| 40 |
module_load_include('inc', 'taxonomy_filter', 'taxonomy_filter.admin');
|
| 41 |
// Reset this file so all other calls can append.
|
| 42 |
// file_put_contents('output.html', "");
|
| 43 |
|
| 44 |
// These three settings do not depend on having taxonomy and content.
|
| 45 |
$this->checkMenuInterface();
|
| 46 |
$this->checkGeneralInterface();
|
| 47 |
$this->checkAdvancedInterface();
|
| 48 |
|
| 49 |
// Check mappings page before and after adding vocabularies.
|
| 50 |
$this->checkMappingsInterface();
|
| 51 |
// Add test data.
|
| 52 |
$this->addTestData();
|
| 53 |
$this->checkMappingsInterface();
|
| 54 |
$this->enableBlocks();
|
| 55 |
$this->checkContentListings();
|
| 56 |
|
| 57 |
// TODO
|
| 58 |
// Add tests for the other submodules.
|
| 59 |
// Add tests for the content listings.
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* Add test data.
|
| 64 |
*/
|
| 65 |
function addTestData() {
|
| 66 |
// Add taxonomy (vocabularies and terms) and content.
|
| 67 |
module_load_include('php', 'taxonomy_filter', 'tests/test_data');
|
| 68 |
taxonomy_filter_add_test_data();
|
| 69 |
|
| 70 |
// Add a menu. (Add more than one???)
|
| 71 |
$name = $this->randomName();
|
| 72 |
$template = 'base';
|
| 73 |
$all_templates = _taxonomy_filter_menu_templates(FALSE);
|
| 74 |
$module = $all_templates[$template]['module'];
|
| 75 |
_taxonomy_filter_menu_create($name, $template, $module);
|
| 76 |
}
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Add, edit and delete a menu via the user interface.
|
| 80 |
*/
|
| 81 |
function checkMenuInterface() {
|
| 82 |
// Visit the main settings page.
|
| 83 |
$this->drupalGet('admin/settings/taxonomy_filter');
|
| 84 |
|
| 85 |
$names = array();
|
| 86 |
|
| 87 |
$i = 0;
|
| 88 |
while ($i < 3) {
|
| 89 |
$i++;
|
| 90 |
// Add a menu.
|
| 91 |
$edit = array();
|
| 92 |
$edit['new_name'] = $this->randomName();
|
| 93 |
$edit['new_template'] = 'base';
|
| 94 |
$this->drupalPost(NULL, $edit, t('Add menu'));
|
| 95 |
$this->assertRaw(t('Added menu %name.', array('%name' => $edit['new_name'])), t('Menu created successfully'));
|
| 96 |
$this->assertText($edit['new_name'], t('Menu found in the filter menu overview listing.'));
|
| 97 |
|
| 98 |
// Find the menu id.
|
| 99 |
$menus = variable_get('taxonomy_filter_menus', array());
|
| 100 |
$mid = array_pop(array_keys($menus));
|
| 101 |
$menu = array_pop($menus);
|
| 102 |
$name = $menu['name'];
|
| 103 |
$this->assertTrue($menu, t('Menu found in database.'));
|
| 104 |
$this->assertEqual($name, $edit['new_name'], t('Menu name found in variable.'));
|
| 105 |
$this->assertEqual($mid, $i, t("Menu index $mid matches menu count."));
|
| 106 |
|
| 107 |
// Update the menu.
|
| 108 |
$this->drupalGet('admin/settings/taxonomy_filter/' . $mid . '/edit');
|
| 109 |
$edit = array();
|
| 110 |
$edit['name'] = $this->randomName();
|
| 111 |
$this->drupalPost(NULL, $edit, t('Save settings'));
|
| 112 |
$this->assertRaw(t('Updated menu %name.', array('%name' => $edit['name'])));
|
| 113 |
$this->assertText($edit['name'], t('Menu found in the filter menu overview listing.'));
|
| 114 |
|
| 115 |
// Save names for delete checks.
|
| 116 |
$names[] = $edit['name'];
|
| 117 |
|
| 118 |
// TODO Change more menu settings and confirm the display. Do this in a separate function?
|
| 119 |
}
|
| 120 |
|
| 121 |
$i = 3;
|
| 122 |
while ($i > 0) {
|
| 123 |
$mid = $i;
|
| 124 |
$i--;
|
| 125 |
// Delete the menu.
|
| 126 |
$this->drupalGet('admin/settings/taxonomy_filter/' . $mid . '/delete');
|
| 127 |
$this->assertRaw(t('Are you sure you want to delete the taxonomy filter menu %name?', array('%name' => $names[$i])), t('[confirm deletion] Asks for confirmation.'));
|
| 128 |
$this->assertText(t('This action cannot be undone.'), t('[confirm deletion] Inform that the menu will be deleted.'));
|
| 129 |
|
| 130 |
// Confirm deletion.
|
| 131 |
$this->drupalPost(NULL, array(), t('Delete'));
|
| 132 |
$this->assertRaw(t('Deleted menu %name.', array('%name' => $names[$i])), t('Menu deleted'));
|
| 133 |
$menus = variable_get('taxonomy_filter_menus', array());
|
| 134 |
$this->assertFalse(isset($menus[$mid]), t('Menu is not found in the database'));
|
| 135 |
}
|
| 136 |
}
|
| 137 |
|
| 138 |
/**
|
| 139 |
* Edit the general menu settings via the user interface.
|
| 140 |
*/
|
| 141 |
function checkGeneralInterface() {
|
| 142 |
// Visit the general menu settings page.
|
| 143 |
$this->drupalGet('admin/settings/taxonomy_filter/general');
|
| 144 |
|
| 145 |
// Update the general settings.
|
| 146 |
$edit = array();
|
| 147 |
$edit['current_block_title'] = $this->randomName();
|
| 148 |
$edit['refine_block_title'] = $this->randomName();
|
| 149 |
$edit['display_current_atop_content'] = 1;
|
| 150 |
$this->drupalPost(NULL, $edit, t('Save settings'));
|
| 151 |
$this->assertRaw(t('Updated the general settings.'), t('General settings updated successfully'));
|
| 152 |
|
| 153 |
// Verify the general settings.
|
| 154 |
$settings = variable_get('taxonomy_filter_general', array());
|
| 155 |
$this->assertEqual($settings['current_block_title'], $edit['current_block_title'], t('Current block title found in variable.'));
|
| 156 |
$this->assertEqual($settings['refine_block_title'], $edit['refine_block_title'], t('Refine block title found in variable.'));
|
| 157 |
$this->assertEqual($settings['display_current_atop_content'], $edit['display_current_atop_content'], t('Display current atop content found in variable.'));
|
| 158 |
|
| 159 |
// Reset the general settings.
|
| 160 |
$edit = array();
|
| 161 |
$edit['current_block_title'] = TAXONOMY_FILTER_CURRENT_BLOCK_TITLE;
|
| 162 |
$edit['refine_block_title'] = TAXONOMY_FILTER_REFINE_BLOCK_TITLE;
|
| 163 |
$edit['display_current_atop_content'] = FALSE;
|
| 164 |
$this->drupalPost(NULL, $edit, t('Save settings'));
|
| 165 |
$this->assertRaw(t('Updated the general settings.'), t('General settings updated successfully'));
|
| 166 |
|
| 167 |
// Verify the general settings.
|
| 168 |
$settings = variable_get('taxonomy_filter_general', array());
|
| 169 |
$this->assertEqual($settings['current_block_title'], $edit['current_block_title'], t('Current block title found in variable.'));
|
| 170 |
$this->assertEqual($settings['refine_block_title'], $edit['refine_block_title'], t('Refine block title found in variable.'));
|
| 171 |
$this->assertEqual($settings['display_current_atop_content'], 0, t('Display current atop content found in variable.'));
|
| 172 |
}
|
| 173 |
|
| 174 |
/**
|
| 175 |
* Edit the advanced menu settings via the user interface.
|
| 176 |
*/
|
| 177 |
function checkAdvancedInterface() {
|
| 178 |
// Visit the advanced menu settings page.
|
| 179 |
$this->drupalGet('admin/settings/taxonomy_filter/advanced');
|
| 180 |
|
| 181 |
// Update the advanced settings.
|
| 182 |
$edit = array();
|
| 183 |
$edit['taxonomy_filter_input'] = $this->randomName();
|
| 184 |
$edit['taxonomy_filter_output'] = $this->randomName();
|
| 185 |
$this->drupalPost(NULL, $edit, t('Save settings'));
|
| 186 |
$this->assertRaw(t('Updated the advanced settings.'), t('Advanced settings updated successfully'));
|
| 187 |
|
| 188 |
// Verify the advanced settings.
|
| 189 |
$settings = variable_get('taxonomy_filter_input', '');
|
| 190 |
$this->assertEqual($settings, $edit['taxonomy_filter_input'], t('Input URLs found in variable.'));
|
| 191 |
$settings = variable_get('taxonomy_filter_output', '');
|
| 192 |
$this->assertEqual($settings, $edit['taxonomy_filter_output'], t('Output URL found in variable.'));
|
| 193 |
|
| 194 |
// Verify the parsed input filters.
|
| 195 |
// TODO How to get value to compare to??? The function taxonomy_filter_parse_input_filters does not return it.
|
| 196 |
$settings = variable_get('taxonomy_filter_input_parsed', array());
|
| 197 |
// $this->assertEqual($settings['taxonomy_filter_input'], $edit['taxonomy_filter_input'], t('Current block title found in variable.'));
|
| 198 |
|
| 199 |
// Reset the advanced settings.
|
| 200 |
$edit = array();
|
| 201 |
$this->drupalPost(NULL, $edit, t('Reset to defaults'));
|
| 202 |
$this->assertRaw(t('Updated the advanced settings.'), t('Advanced settings updated successfully'));
|
| 203 |
|
| 204 |
// Verify the advanced settings.
|
| 205 |
$settings = variable_get('taxonomy_filter_input', '');
|
| 206 |
$this->assertEqual($settings, '', t('Input URL variable was cleared.'));
|
| 207 |
$settings = variable_get('taxonomy_filter_output', '');
|
| 208 |
$this->assertEqual($settings, '', t('Output URL variable was cleared.'));
|
| 209 |
}
|
| 210 |
|
| 211 |
/**
|
| 212 |
* Edit the mappings menu settings via the user interface.
|
| 213 |
*/
|
| 214 |
function checkMappingsInterface() {
|
| 215 |
// Visit the mappings menu settings page.
|
| 216 |
$this->drupalGet('admin/settings/taxonomy_filter/mappings');
|
| 217 |
|
| 218 |
// Verify message display with empty environment.
|
| 219 |
$vocabs = _taxonomy_filter_get_vocabs();
|
| 220 |
if (!$vocabs) {
|
| 221 |
$this->assertRaw(t('No vocabularies have been defined to be mapped.'), 'Warning message displays when no vocabularies');
|
| 222 |
}
|
| 223 |
$menus = _taxonomy_filter_menu_list();
|
| 224 |
if (!$menus) {
|
| 225 |
$this->assertRaw(t('No menus have been defined to be mapped.'), 'Warning message displays when no menus');
|
| 226 |
}
|
| 227 |
if (!$vocabs || !$menus) {
|
| 228 |
return;
|
| 229 |
}
|
| 230 |
|
| 231 |
// Verify vocabulary names.
|
| 232 |
foreach ($vocabs as $vocab) {
|
| 233 |
$this->assertRaw($vocab, t('Vocabulary name %name displays on mappings page', array('%name' => $vocab)));
|
| 234 |
}
|
| 235 |
|
| 236 |
// Verify menu names in select field.
|
| 237 |
foreach ($menus as $menu) {
|
| 238 |
$this->assertRaw($menu, t('Menu name %name displays on mappings page', array('%name' => $menu)));
|
| 239 |
}
|
| 240 |
|
| 241 |
// file_put_contents('output.html', $this->getUrl() . $this->drupalGetContent(), FILE_APPEND);
|
| 242 |
|
| 243 |
// This looks for filter menu with id = 1!!!
|
| 244 |
// if ($this->assertTrue($select = $this->xpath('//select[@name="refine_menu1"]'))) {
|
| 245 |
$select = $this->xpath('//select[@name="refine_menu1"]');
|
| 246 |
// file_put_contents('output.html', "select = \n", FILE_APPEND);
|
| 247 |
// file_put_contents('output.html', print_r($select, 1), FILE_APPEND);
|
| 248 |
if ($this->assertTrue($select, t('Select field for refine menu found on page'))) {
|
| 249 |
$this->assertTrue(count($select) == 1, t('Only one select field for refine menu found on page'));
|
| 250 |
// This only returns the values not the text of the options.
|
| 251 |
$x_options = $this->getAllOptions($select[0]);
|
| 252 |
// file_put_contents('output.html', "select options = \n", FILE_APPEND);
|
| 253 |
// file_put_contents('output.html', print_r($x_options, 1), FILE_APPEND);
|
| 254 |
$options = array();
|
| 255 |
foreach ($x_options as $option) {
|
| 256 |
// $this->assertTrue(is_array($option), t('Option is an array'));
|
| 257 |
// file_put_contents('output.html', "option = \n", FILE_APPEND);
|
| 258 |
// file_put_contents('output.html', print_r($option, 1), FILE_APPEND);
|
| 259 |
$options[] = $option['value'];
|
| 260 |
}
|
| 261 |
// file_put_contents('output.html', "extracted options = \n", FILE_APPEND);
|
| 262 |
// file_put_contents('output.html', print_r($options, 1), FILE_APPEND);
|
| 263 |
// $filler = array_diff($options, $menus);
|
| 264 |
// $this->assertTrue(count($filler) == 1, t('All menus found in select field options'));
|
| 265 |
}
|
| 266 |
|
| 267 |
// Update the criteria menu choices.
|
| 268 |
$edit = array();
|
| 269 |
$edit['refine_menu1'] = 1;
|
| 270 |
$edit['current_menu1'] = 1;
|
| 271 |
$edit['refine_menu2'] = 1;
|
| 272 |
$edit['current_menu2'] = 1;
|
| 273 |
$edit['refine_menu3'] = 1;
|
| 274 |
$edit['current_menu3'] = 1;
|
| 275 |
$this->drupalPost(NULL, $edit, t('Save settings'));
|
| 276 |
$this->assertRaw(t('Updated the criteria menus.'), t('Criteria menus updated successfully'));
|
| 277 |
|
| 278 |
// Verify the criteria menu choices.
|
| 279 |
$settings = variable_get('taxonomy_filter_mappings', array());
|
| 280 |
$this->assertEqual($settings[1]['refine_menu'], $edit['refine_menu1'], t('Refine menu found in variable.'));
|
| 281 |
$this->assertEqual($settings[1]['current_menu'], $edit['current_menu1'], t('Current menu found in variable.'));
|
| 282 |
|
| 283 |
// TODO Could clear the criteria menus and see that the refine criteria menu is not displayed.
|
| 284 |
|
| 285 |
// Update the mappings.
|
| 286 |
$vid = 1;
|
| 287 |
$this->drupalGet('admin/settings/taxonomy_filter/mappings/' . $vid . '/edit');
|
| 288 |
$edit = array();
|
| 289 |
$edit['vocabs[]'] = array('2', '3');
|
| 290 |
$this->drupalPost(NULL, $edit, t('Save settings'));
|
| 291 |
$this->assertRaw(t('Updated the vocabulary mappings.'), t('Vocabulary mappings updated successfully'));
|
| 292 |
|
| 293 |
// Verify the mappings.
|
| 294 |
$settings = variable_get('taxonomy_filter_mappings', array());
|
| 295 |
$this->assertEqual($settings[$vid]['mappings'], $edit['vocabs[]'], t('Vocabulary mappings found in variable.'));
|
| 296 |
|
| 297 |
// Clear the mappings.
|
| 298 |
$this->drupalGet('admin/settings/taxonomy_filter/mappings/' . $vid . '/edit');
|
| 299 |
$edit['vocabs[]'] = array('0');
|
| 300 |
$this->drupalPost(NULL, $edit, t('Save settings'));
|
| 301 |
$this->assertRaw(t('Updated the vocabulary mappings.'), t('Vocabulary mappings updated successfully'));
|
| 302 |
|
| 303 |
// Verify the mappings.
|
| 304 |
// Note: can not compare $edit['vocabs[]'] = array('0') since code changes value to array().
|
| 305 |
$settings = variable_get('taxonomy_filter_mappings', array());
|
| 306 |
$this->assertEqual($settings[$vid]['mappings'], array(), t('Vocabulary mappings found in variable.'));
|
| 307 |
|
| 308 |
// Reset the mappings.
|
| 309 |
foreach ($vocabs as $vid => $name) {
|
| 310 |
$this->drupalGet('admin/settings/taxonomy_filter/mappings/' . $vid . '/edit');
|
| 311 |
$edit['vocabs[]'] = array('1', '2', '3');
|
| 312 |
$this->drupalPost(NULL, $edit, t('Save settings'));
|
| 313 |
$this->assertRaw(t('Updated the vocabulary mappings.'), t('Vocabulary mappings updated successfully'));
|
| 314 |
|
| 315 |
// Verify the mappings.
|
| 316 |
$settings = variable_get('taxonomy_filter_mappings', array());
|
| 317 |
$this->assertEqual($settings[$vid]['mappings'], $edit['vocabs[]'], t('Vocabulary mappings found in variable.'));
|
| 318 |
}
|
| 319 |
|
| 320 |
// file_put_contents('output.html', $this->getUrl() . $this->drupalGetContent(), FILE_APPEND);
|
| 321 |
}
|
| 322 |
|
| 323 |
/**
|
| 324 |
* Adapted from block.test.
|
| 325 |
*/
|
| 326 |
function enableBlocks() {
|
| 327 |
// Specify the region.
|
| 328 |
$region = array('name' => 'left', 'id' => 'sidebar-left');
|
| 329 |
|
| 330 |
// Enable blocks in the region.
|
| 331 |
$block['module'] = 'taxonomy_filter';
|
| 332 |
$deltas = array(0, 1);
|
| 333 |
foreach ($deltas as $delta) {
|
| 334 |
$block['delta'] = $delta;
|
| 335 |
|
| 336 |
// Add the block to the region.
|
| 337 |
$edit = array();
|
| 338 |
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = $region['name'];
|
| 339 |
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
|
| 340 |
|
| 341 |
// Confirm that the block was moved to the proper region.
|
| 342 |
$this->assertText(t('The block settings have been updated.'), t('Block successfully moved to %region_name region.', array( '%region_name'=> $region['name'])));
|
| 343 |
}
|
| 344 |
}
|
| 345 |
|
| 346 |
/**
|
| 347 |
* Verify the content listing displays match the filter settings.
|
| 348 |
*/
|
| 349 |
function checkContentListings() {
|
| 350 |
// Visit a non-taxonomy listings page.
|
| 351 |
$this->drupalGet('taxonomy/terms/11');
|
| 352 |
|
| 353 |
// Verify the advanced settings.
|
| 354 |
$this->assertNoRaw(t(TAXONOMY_FILTER_CURRENT_BLOCK_TITLE), t('Current block title not found on page'));
|
| 355 |
$this->assertNoRaw(t(TAXONOMY_FILTER_REFINE_BLOCK_TITLE), t('Refine block title not found on page'));
|
| 356 |
|
| 357 |
// Visit a taxonomy listings page.
|
| 358 |
$this->drupalGet('taxonomy/term/11');
|
| 359 |
|
| 360 |
// Verify the general settings.
|
| 361 |
$this->assertRaw(t(TAXONOMY_FILTER_CURRENT_BLOCK_TITLE), t('Current block title found on page'));
|
| 362 |
$this->assertRaw(t(TAXONOMY_FILTER_REFINE_BLOCK_TITLE), t('Refine block title found on page'));
|
| 363 |
|
| 364 |
// Verify the advanced settings.
|
| 365 |
// TODO View a taxonomy listing page and verify the links against 'taxonomy_filter_output'.
|
| 366 |
|
| 367 |
// Verify the mapping settings.
|
| 368 |
$div = $this->xpath('//*[@id="block-taxonomy_filter-0"]');
|
| 369 |
if ($this->assertTrue($div, 'Refine block found')) {
|
| 370 |
$div = $div[0];
|
| 371 |
// Verify the vocabulary names.
|
| 372 |
$vids = array(1, 2, 3);
|
| 373 |
foreach ($vids as $vid) {
|
| 374 |
$this->assertTrue(strpos($div->asXML(), 'Vocab #' . $vid) !== FALSE, 'Found vocabulary name ' . $vid);
|
| 375 |
}
|
| 376 |
// Verify the term names.
|
| 377 |
$tids = array(1, 6, 11, 16, 21, 26, 31);
|
| 378 |
foreach ($tids as $tid) {
|
| 379 |
$this->assertTrue(strpos($div->asXML(), 'term #' . $tid) !== FALSE, 'Found term name ' . $tid);
|
| 380 |
}
|
| 381 |
}
|
| 382 |
|
| 383 |
// Verify the mapping settings.
|
| 384 |
// TODO View taxonomy listing pages and verify the menu display corresponds to the menu selected for the vocab.
|
| 385 |
// Verify the vocab links appear on pages with other term listings.
|
| 386 |
}
|
| 387 |
|
| 388 |
// file_put_contents('output.html', "mappings = \n", FILE_APPEND);
|
| 389 |
// file_put_contents('output.html', print_r($settings, 1), FILE_APPEND);
|
| 390 |
// file_put_contents('output.html', "filter input = $settings\n", FILE_APPEND);
|
| 391 |
// file_put_contents('output.html', $this->getUrl() . $this->drupalGetContent());
|
| 392 |
|
| 393 |
}
|