| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: pathauto.test,v 1.1.2.11 2010/09/27 15:52:58 greggles Exp $ 3 4 /** 5 * @file 6 * Functionality tests for Pathauto. 7 * 8 * @ingroup pathauto 9 */ 10 11 /** 12 * Helper test class with some added functions for testing. 13 */ 14 class PathautoTestHelper extends DrupalWebTestCase { 15 function setUp() { 16 $args = func_get_args(); 17 18 // Call parent::setUp() allowing test cases to pass further modules. 19 $modules = array('path', 'token', 'pathauto'); 20 if (isset($args[0]) && is_array($args[0])) { 21 $modules = array_merge($modules, $args[0]); 22 } 23 24 $parent_callback = 'parent::setUp'; 25 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 26 $parent_callback = array($this, 'parent::setUp'); 27 } 28 call_user_func_array($parent_callback, $modules); 29 } 30 31 function assertToken($type, $object, $token, $expected) { 32 $tokens = pathauto_get_placeholders($type, $object); 33 $this->assertEqual($tokens['values'][$token], $expected, t("Token value for [@token] was '!actual', expected value '!expected'.", array('@token' => $token, '!actual' => $tokens['values'][$token], '!expected' => $expected))); 34 } 35 36 function saveAlias($source, $alias, $language = '') { 37 path_set_alias($source, $alias, NULL, $language); 38 return db_fetch_array(db_query_range("SELECT * FROM {url_alias} WHERE src = '%s' AND dst = '%s' AND language = '%s' ORDER BY pid DESC", $source, $alias, $language, 0, 1)); 39 } 40 41 function saveEntityAlias($entity_type, $entity, $alias, $language = '') { 42 $uri = $this->entity_uri($entity_type, $entity); 43 return $this->saveAlias($uri['path'], $alias, $language); 44 } 45 46 function assertEntityAlias($entity_type, $entity, $expected_alias, $language = '') { 47 $uri = $this->entity_uri($entity_type, $entity); 48 $this->assertAlias($uri['path'], $expected_alias, $language); 49 } 50 51 function assertEntityAliasExists($entity_type, $entity) { 52 $uri = $this->entity_uri($entity_type, $entity); 53 return $this->assertAliasExists(array('source' => $uri['path'])); 54 } 55 56 function assertNoEntityAlias($entity_type, $entity, $language = '') { 57 $uri = $this->entity_uri($entity_type, $entity); 58 $this->assertEntityAlias($entity_type, $entity, $uri['path'], $language); 59 } 60 61 function assertNoEntityAliasExists($entity_type, $entity) { 62 $uri = $this->entity_uri($entity_type, $entity); 63 $this->assertNoAliasExists(array('source' => $uri['path'])); 64 } 65 66 function assertAlias($source, $expected_alias, $language = '') { 67 drupal_clear_path_cache(); 68 $alias = drupal_get_path_alias($source, $language); 69 $this->assertIdentical($alias, $expected_alias, t("Alias for %source with language '@language' was %actual, expected %expected.", array('%source' => $source, '%actual' => $alias, '%expected' => $expected_alias, '@language' => $language))); 70 } 71 72 function assertAliasExists($conditions) { 73 $path = $this->path_load($conditions); 74 $this->assertTrue($path, t('Alias with conditions @conditions found.', array('@conditions' => var_export($conditions, TRUE)))); 75 return $path; 76 } 77 78 function assertNoAliasExists($conditions) { 79 $alias = $this->path_load($conditions); 80 $this->assertFalse($alias, t('Alias with conditions @conditions not found.', array('@conditions' => var_export($conditions, TRUE)))); 81 } 82 83 /** 84 * Backport of Drupal 7's entity_uri() function. 85 */ 86 protected function entity_uri($entity_type, $entity) { 87 $uri = array(); 88 89 switch ($entity_type) { 90 case 'node': 91 $uri['path'] = 'node/' . $entity->nid; 92 break; 93 case 'taxonomy_term': 94 $uri['path'] = taxonomy_term_path($entity); 95 break; 96 case 'user': 97 $uri['path'] = 'user/' . $entity->uid; 98 break; 99 default: 100 return $this->fail(t('Unknown entity @type.', array('@type' => $entity_type))); 101 } 102 103 return $uri; 104 } 105 106 /** 107 * Backport of Drupal 7's path_load() function. 108 */ 109 protected function path_load($conditions) { 110 if (is_numeric($conditions)) { 111 $conditions = array('pid' => $conditions); 112 } 113 elseif (is_string($conditions)) { 114 $conditions = array('src' => $conditions); 115 } 116 117 // Adjust for some D7 {url_alias} column name changes so we can keep 118 // the test files in sync. 119 if (isset($conditions['source'])) { 120 $conditions['src'] = $conditions['source']; 121 unset($conditions['source']); 122 } 123 if (isset($conditions['alias'])) { 124 $conditions['dst'] = $conditions['alias']; 125 unset($conditions['alias']); 126 } 127 128 $args = array(); 129 $schema = drupal_get_schema_unprocessed('system', 'url_alias'); 130 foreach ($conditions as $field => $value) { 131 $field_type = $schema['fields'][$field]['type']; 132 if (is_array($value)) { 133 $conditions[$field] = "$field = " . db_placeholders($value, $field_type); 134 $args = array_merge($args, $value); 135 } 136 else { 137 $placeholder = db_type_placeholder($field_type); 138 $conditions[$field] = "$field = $placeholder"; 139 $args[] = $value; 140 } 141 142 } 143 144 $sql = "SELECT * FROM {url_alias} WHERE " . implode(' AND ', $conditions); 145 return db_fetch_array(db_query_range($sql, $args, 0, 1)); 146 } 147 148 function deleteAllAliases() { 149 db_query("DELETE FROM {url_alias}"); 150 drupal_clear_path_cache(); 151 } 152 153 function addVocabulary(array $vocabulary = array()) { 154 $vocabulary += array( 155 'name' => drupal_strtolower($this->randomName(5)), 156 'nodes' => array('story' => 'story'), 157 ); 158 taxonomy_save_vocabulary($vocabulary); 159 return (object) $vocabulary; 160 } 161 162 function addTerm(stdClass $vocabulary, array $term = array()) { 163 $term += array( 164 'name' => drupal_strtolower($this->randomName(5)), 165 'vid' => $vocabulary->vid, 166 ); 167 taxonomy_save_term($term); 168 return (object) $term; 169 } 170 } 171 172 /** 173 * Unit tests for Pathauto functions. 174 */ 175 class PathautoUnitTestCase extends PathautoTestHelper { 176 public static function getInfo() { 177 return array( 178 'name' => 'Pathauto unit tests', 179 'description' => 'Unit tests for Pathauto functions.', 180 'group' => 'Pathauto', 181 'dependencies' => array('token'), 182 ); 183 } 184 185 function setUp() { 186 parent::setUp(); 187 module_load_include('inc', 'pathauto'); 188 } 189 190 /** 191 * Test _pathauto_get_schema_alias_maxlength(). 192 */ 193 function testGetSchemaAliasMaxLength() { 194 $this->assertIdentical(_pathauto_get_schema_alias_maxlength(), 128); 195 } 196 197 /** 198 * Test pathauto_cleanstring(). 199 */ 200 function testCleanString() { 201 $tests = array(); 202 variable_set('pathauto_ignore_words', ', in, is,that, the , this, with, '); 203 variable_set('pathauto_max_component_length', 35); 204 205 // Test the 'ignored words' removal. 206 $tests['this'] = 'this'; 207 $tests['this with that'] = 'this-with-that'; 208 $tests['this thing with that thing'] = 'thing-thing'; 209 210 // Test length truncation and duplicate separator removal. 211 $tests[' - Pathauto is the greatest - module ever in Drupal history - '] = 'pathauto-greatest-module-ever-drupa'; 212 213 foreach ($tests as $input => $expected) { 214 $output = pathauto_cleanstring($input); 215 $this->assertEqual($output, $expected, t("pathauto_cleanstring('@input') expected '@expected', actual '@output'", array('@input' => $input, '@expected' => $expected, '@output' => $output))); 216 } 217 } 218 219 /** 220 * Test the feed alias functionality of pathauto_create_alias(). 221 */ 222 function testFeedAliases() { 223 variable_set('pathauto_node_pattern', '[title-raw]'); 224 variable_set('pathauto_node_applytofeeds', ''); 225 226 // Create a node with an empty title, which should not create an alias. 227 $node = $this->drupalCreateNode(array('title' => '')); 228 $this->assertNoAliasExists(array('source' => "node/{$node->nid}")); 229 $this->assertNoAliasExists(array('source' => "node/{$node->nid}/feed")); 230 231 // Add a title to the node. This should still not generate a feed alias. 232 $node->title = 'Node title'; 233 pathauto_nodeapi($node, 'update'); 234 $this->assertAliasExists(array('source' => "node/{$node->nid}", 'alias' => 'node-title')); 235 $this->assertNoAliasExists(array('source' => "node/{$node->nid}/feed")); 236 237 // Enable feeds for nodes. A feed alias should now be generated. 238 variable_set('pathauto_node_applytofeeds', ' feed '); 239 pathauto_nodeapi($node, 'update'); 240 $this->assertAliasExists(array('source' => "node/{$node->nid}/feed", 'alias' => 'node-title/feed')); 241 } 242 243 /** 244 * Test _pathauto_get_raw_tokens(). 245 */ 246 function testGetRawTokens() { 247 $raw_tokens = _pathauto_get_raw_tokens(); 248 $this->assertFalse(in_array('node-path', $raw_tokens), 'Non-raw tokens not included.'); 249 $this->assertTrue(in_array('node-path-raw', $raw_tokens), 'Token [catpath] has a matching raw token.'); 250 $this->assertFalse(in_array('node-url-raw', $raw_tokens), 'Token [catalias] does not have a matching raw token.'); 251 } 252 253 /** 254 * Test the different update actions in pathauto_create_alias(). 255 */ 256 function testUpdateActions() { 257 // Test PATHAUTO_UPDATE_ACTION_NO_NEW with unaliased node and 'insert'. 258 variable_set('pathauto_update_action', 0); 259 $node = $this->drupalCreateNode(array('title' => 'First title')); 260 $this->assertEntityAlias('node', $node, 'content/first-title'); 261 262 // Default action is PATHAUTO_UPDATE_ACTION_DELETE. 263 variable_set('pathauto_update_action', 2); 264 $node->title = 'Second title'; 265 pathauto_nodeapi($node, 'update'); 266 $this->assertEntityAlias('node', $node, 'content/second-title'); 267 $this->assertNoAliasExists(array('alias' => 'content/first-title')); 268 269 // Test PATHAUTO_UPDATE_ACTION_LEAVE. 270 variable_set('pathauto_update_action', 1); 271 $node->title = 'Third title'; 272 pathauto_nodeapi($node, 'update'); 273 $this->assertEntityAlias('node', $node, 'content/third-title'); 274 $this->assertAliasExists(array('source' => "node/{$node->nid}", 'alias' => 'content/second-title')); 275 276 variable_set('pathauto_update_action', 2); 277 $node->title = 'Fourth title'; 278 pathauto_nodeapi($node, 'update'); 279 $this->assertEntityAlias('node', $node, 'content/fourth-title'); 280 $this->assertNoAliasExists(array('alias' => 'content/third-title')); 281 // The older second alias is not deleted yet. 282 $older_path = $this->assertAliasExists(array('source' => "node/{$node->nid}", 'alias' => 'content/second-title')); 283 path_set_alias(NULL, NULL, $older_path['pid']); 284 285 variable_set('pathauto_update_action', 0); 286 $node->title = 'Fifth title'; 287 pathauto_nodeapi($node, 'update'); 288 $this->assertEntityAlias('node', $node, 'content/fourth-title'); 289 $this->assertNoAliasExists(array('alias' => 'content/fith-title')); 290 291 // Test PATHAUTO_UPDATE_ACTION_NO_NEW with unaliased node and 'update'. 292 $this->deleteAllAliases(); 293 pathauto_nodeapi($node, 'update'); 294 $this->assertEntityAlias('node', $node, 'content/fifth-title'); 295 296 // Test PATHAUTO_UPDATE_ACTION_NO_NEW with unaliased node and 'bulkupdate'. 297 $this->deleteAllAliases(); 298 $node->title = 'Sixth title'; 299 pathauto_node_update_alias($node, 'bulkupdate'); 300 $this->assertEntityAlias('node', $node, 'content/sixth-title'); 301 } 302 303 /** 304 * Test that pathauto_create_alias() will not create an alias for a pattern 305 * that does not get any tokens replaced. 306 */ 307 function testNoTokensNoAlias() { 308 $node = $this->drupalCreateNode(array('title' => '')); 309 $this->assertNoEntityAlias('node', $node); 310 311 $node->title = 'hello'; 312 pathauto_nodeapi($node, 'update'); 313 $this->assertEntityAlias('node', $node, 'content/hello'); 314 } 315 316 /** 317 * Test the handling of path vs non-path tokens in pathauto_clean_token_values(). 318 * 319 * @see PathautoBookTokenTestCase::testBookPathAlias() 320 */ 321 //function testPathTokens() { 322 //} 323 } 324 325 /** 326 * Helper test class with some added functions for testing. 327 */ 328 class PathautoFunctionalTestHelper extends PathautoTestHelper { 329 protected $admin_user; 330 331 function setUp() { 332 $args = func_get_args(); 333 334 // Call parent::setUp() allowing test cases to pass further modules. 335 $modules = array(); 336 if (isset($args[0]) && is_array($args[0])) { 337 $modules = array_merge($modules, $args[0]); 338 } 339 parent::setUp($modules); 340 341 // Set pathauto settings we assume to be as-is in this test. 342 variable_set('pathauto_node_page_pattern', 'content/[title-raw]'); 343 344 // Allow other modules to add additional permissions for the admin user. 345 $permissions = array( 346 'administer pathauto', 347 'administer url aliases', 348 'create url aliases', 349 'administer nodes', 350 'administer users', 351 ); 352 if (isset($args[1]) && is_array($args[1])) { 353 $permissions = array_merge($permissions, $args[1]); 354 } 355 $this->admin_user = $this->drupalCreateUser($permissions); 356 357 $this->drupalLogin($this->admin_user); 358 } 359 } 360 361 /** 362 * Test basic pathauto functionality. 363 */ 364 class PathautoFunctionalTestCase extends PathautoFunctionalTestHelper { 365 public static function getInfo() { 366 return array( 367 'name' => 'Pathauto basic tests', 368 'description' => 'Test basic pathauto functionality.', 369 'group' => 'Pathauto', 370 ); 371 } 372 373 /** 374 * Basic functional testing of Pathauto. 375 */ 376 function testNodeEditing() { 377 // Create node for testing. 378 $random_title = $this->randomName(10); 379 $title = ' Simpletest title ' . $random_title . ' ['; 380 $automatic_alias = 'content/simpletest-title-' . strtolower($random_title); 381 $node = $this->drupalCreateNode(array('title' => $title, 'type' => 'page')); 382 383 // Look for alias generated in the form. 384 $this->drupalGet('node/' . $node->nid . '/edit'); 385 $this->assertFieldChecked('edit-pathauto-perform-alias'); 386 $this->assertFieldByName('path', $automatic_alias, 'Proper automated alias generated.'); 387 388 // Check whether the alias actually works. 389 $this->drupalGet($automatic_alias); 390 $this->assertText($title, 'Node accessible through automatic alias.'); 391 392 // Manually set the node's alias. 393 $manual_alias = 'content/' . $node->nid; 394 $edit = array( 395 'pathauto_perform_alias' => FALSE, 396 'path' => $manual_alias, 397 ); 398 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); 399 $this->assertText(t('@type @title has been updated', array('@type' => 'Page', '@title' => $title))); 400 401 // Check that the automatic alias checkbox is now unchecked by default. 402 $this->drupalGet('node/' . $node->nid . '/edit'); 403 $this->assertNoFieldChecked('edit-pathauto-perform-alias'); 404 $this->assertFieldByName('path', $manual_alias); 405 406 // Submit the node form with the default values. 407 $this->drupalPost(NULL, array(), t('Save')); 408 $this->assertText(t('@type @title has been updated', array('@type' => 'Page', '@title' => $title))); 409 410 // Test that the old (automatic) alias has been deleted and only accessible 411 // through the new (manual) alias. 412 $this->drupalGet($automatic_alias); 413 $this->assertResponse(404, 'Node not accessible through automatic alias.'); 414 $this->drupalGet($manual_alias); 415 $this->assertText($title, 'Node accessible through manual alias.'); 416 } 417 418 /** 419 * Test node operations. 420 */ 421 function testNodeOperations() { 422 $node1 = $this->drupalCreateNode(array('title' => 'node1')); 423 $node2 = $this->drupalCreateNode(array('title' => 'node2')); 424 425 // Delete all current URL aliases. 426 $this->deleteAllAliases(); 427 428 $edit = array( 429 'operation' => 'pathauto_update_alias', 430 "nodes[{$node1->nid}]" => TRUE, 431 ); 432 $this->drupalPost('admin/content/node', $edit, t('Update')); 433 $this->assertText('Updated URL alias for 1 node.'); 434 435 $this->assertEntityAlias('node', $node1, 'content/' . $node1->title); 436 $this->assertEntityAlias('node', $node2, 'node/' . $node2->nid); 437 } 438 439 /** 440 * Test user operations. 441 */ 442 function testUserOperations() { 443 $account = $this->drupalCreateUser(); 444 445 // Delete all current URL aliases. 446 $this->deleteAllAliases(); 447 448 $edit = array( 449 'operation' => 'pathauto_update_alias', 450 "accounts[{$account->uid}]" => TRUE, 451 ); 452 $this->drupalPost('admin/user/user', $edit, t('Update')); 453 $this->assertText('Updated URL alias for 1 user account.'); 454 455 $this->assertEntityAlias('user', $account, 'users/' . drupal_strtolower($account->name)); 456 $this->assertEntityAlias('user', $this->admin_user, 'user/' . $this->admin_user->uid); 457 } 458 459 function testSettingsValidation() { 460 $edit = array(); 461 $edit['pathauto_max_length'] = 'abc'; 462 $edit['pathauto_max_component_length'] = 'abc'; 463 $this->drupalPost('admin/build/path/pathauto', $edit, 'Save configuration'); 464 $this->assertText('The field Maximum alias length is not a valid number.'); 465 $this->assertText('The field Maximum component length is not a valid number.'); 466 $this->assertNoText('The configuration options have been saved.'); 467 468 $edit['pathauto_max_length'] = '0'; 469 $edit['pathauto_max_component_length'] = '0'; 470 $this->drupalPost('admin/build/path/pathauto', $edit, 'Save configuration'); 471 $this->assertText('The field Maximum alias length cannot be less than 1.'); 472 $this->assertText('The field Maximum component length cannot be less than 1.'); 473 $this->assertNoText('The configuration options have been saved.'); 474 475 $edit['pathauto_max_length'] = '999'; 476 $edit['pathauto_max_component_length'] = '999'; 477 $this->drupalPost('admin/build/path/pathauto', $edit, 'Save configuration'); 478 $this->assertText('The field Maximum alias length cannot be greater than 128.'); 479 $this->assertText('The field Maximum component length cannot be greater than 128.'); 480 $this->assertNoText('The configuration options have been saved.'); 481 482 $edit['pathauto_max_length'] = '50'; 483 $edit['pathauto_max_component_length'] = '50'; 484 $this->drupalPost('admin/build/path/pathauto', $edit, 'Save configuration'); 485 $this->assertText('The configuration options have been saved.'); 486 } 487 488 function testPatternsValidation() { 489 $edit = array(); 490 $edit['pathauto_node_pattern'] = '[title-raw]/[user-created-small]/[cat]/[term]'; 491 $edit['pathauto_node_page_pattern'] = 'page'; 492 $this->drupalPost('admin/build/path/pathauto', $edit, 'Save configuration'); 493 $this->assertText('The Default path pattern (applies to all node types with blank patterns below) is using the following invalid tokens: [user-created-small], [cat].'); 494 $this->assertText('The Pattern for all Page paths should contain at least one token to ensure unique URL aliases are created.'); 495 $this->assertNoText('The configuration options have been saved.'); 496 497 $edit['pathauto_node_pattern'] = '[title-raw]'; 498 $edit['pathauto_node_page_pattern'] = 'page/[title-raw]'; 499 $edit['pathauto_node_story_pattern'] = ''; 500 $this->drupalPost('admin/build/path/pathauto', $edit, 'Save configuration'); 501 $this->assertText('The configuration options have been saved.'); 502 } 503 } 504 505 class PathautoLocaleTestCase extends PathautoFunctionalTestHelper { 506 public static function getInfo() { 507 return array( 508 'name' => 'Pathauto localization tests', 509 'description' => 'Test pathauto functionality with localization and translation.', 510 'group' => 'Pathauto', 511 ); 512 } 513 514 function setUp() { 515 parent::setUp(array('locale', 'translation'), array('administer languages')); 516 517 // Add predefined French language and reset the locale cache. 518 require_once './includes/locale.inc'; 519 locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr'); 520 language_list('language', TRUE); 521 drupal_init_language(); 522 } 523 524 /** 525 * Test that when an English node is updated, its old English alias is 526 * updated and its newer French alias is left intact. 527 */ 528 function testLanguageAliases() { 529 $node = array( 530 'title' => 'English node', 531 'language' => 'en', 532 'path' => 'english-node', 533 'pathauto_perform_alias' => FALSE, 534 ); 535 $node = $this->drupalCreateNode($node); 536 $english_alias = $this->path_load(array('alias' => 'english-node')); 537 $this->assertTrue($english_alias, 'Alias created with proper language.'); 538 539 // Also save a French alias that should not be left alone, even though 540 // it is the newer alias. 541 $this->saveEntityAlias('node', $node, 'french-node', 'fr'); 542 543 // Add an alias with the soon-to-be generated alias, causing the upcoming 544 // alias update to generate a unique alias with the '-0' suffix. 545 $this->saveAlias('node/invalid', 'content/english-node', ''); 546 547 // Update the node, triggering a change in the English alias. 548 $node->pathauto_perform_alias = TRUE; 549 pathauto_nodeapi($node, 'update'); 550 551 // Check that the new English alias replaced the old one. 552 $this->assertEntityAlias('node', $node, 'content/english-node-0', 'en'); 553 $this->assertEntityAlias('node', $node, 'french-node', 'fr'); 554 $this->assertAliasExists(array('pid' => $english_alias['pid'], 'alias' => 'content/english-node-0')); 555 } 556 } 557 558 /* 559 * Unit tests for the book tokens provided by Pathauto. 560 */ 561 class PathautoBookTokenTestCase extends PathautoTestHelper { 562 public static function getInfo() { 563 return array( 564 'name' => 'Pathauto book tokens', 565 'description' => 'Unit tests for the book tokens provided by Pathauto.', 566 'group' => 'Pathauto', 567 ); 568 } 569 570 function setUp() { 571 parent::setUp(array('book')); 572 variable_set('book_allowed_types', array('book', 'page')); 573 variable_set('pathauto_node_book_pattern', '[bookpathalias]/[title-raw]'); 574 } 575 576 function testBookPathAlias() { 577 // Add a non-book node. 578 $non_book_node = $this->drupalCreateNode(array('type' => 'book')); 579 $this->assertToken('node', $non_book_node, 'bookpathalias', ''); 580 581 // Add a root book page. 582 $parent_node = $this->drupalCreateNode(array('type' => 'book', 'title' => 'Root', 'book' => array('bid' => 'new'))); 583 $this->assertToken('node', $parent_node, 'bookpathalias', ''); 584 585 // Add a first child page. 586 $child_node1 = $this->drupalCreateNode(array('type' => 'book', 'title' => 'Sub page1', 'book' => array('bid' => $parent_node->book['bid'], 'plid' => $parent_node->book['mlid']))); 587 $this->assertToken('node', $child_node1, 'bookpathalias', 'root'); 588 589 // Add a second child page. 590 $child_node2 = $this->drupalCreateNode(array('type' => 'book', 'title' => 'Sub page2', 'book' => array('bid' => $parent_node->book['bid'], 'plid' => $parent_node->book['mlid']))); 591 $this->assertToken('node', $child_node2, 'bookpathalias', 'root'); 592 593 // Add a child page on an existing child page. 594 $sub_child_node1 = $this->drupalCreateNode(array('type' => 'book', 'title' => 'Sub-sub Page1', 'book' => array('bid' => $parent_node->book['bid'], 'plid' => $child_node1->book['mlid']))); 595 $this->assertToken('node', $sub_child_node1, 'bookpathalias', 'root/sub-page1'); 596 597 // Test that path tokens should not be altered. 598 $this->saveEntityAlias('node', $child_node1, 'My Crazy/Alias/'); 599 pathauto_nodeapi($sub_child_node1, 'update'); 600 $this->assertEntityAlias('node', $sub_child_node1, 'My Crazy/Alias/sub-sub-page1'); 601 } 602 } 603 604 /* 605 * Unit tests for the taxonomy tokens provided by Pathauto. 606 */ 607 class PathautoTaxonomyTokenTestCase extends PathautoFunctionalTestHelper { 608 protected $vocab; 609 610 public static function getInfo() { 611 return array( 612 'name' => 'Pathauto taxonomy tokens', 613 'description' => 'Unit tests for the taxonomy tokens provided by Pathauto.', 614 'group' => 'Pathauto', 615 ); 616 } 617 618 function setUp() { 619 parent::setUp(array('taxonomy')); 620 variable_set('pathauto_taxonomy_pattern', 'category/[vocab-raw]/[cat-raw]'); 621 // Reset the static taxonomy.module caches. 622 taxonomy_vocabulary_load(0, TRUE); 623 taxonomy_get_term(0, TRUE); 624 $this->vocab = $this->addVocabulary(); 625 } 626 627 /** 628 * Test the [catpath] and [catalias] tokens. 629 */ 630 function testCatTokens() { 631 $term1 = $this->addTerm($this->vocab); 632 $this->assertToken('taxonomy', $term1, 'catpath', $term1->name); 633 $this->assertToken('taxonomy', $term1, 'catalias', "category/{$this->vocab->name}/{$term1->name}"); 634 635 // Change the term name to check that the alias is also changed. 636 // Regression test for http://drupal.org/node/822174. 637 $term1->oldname = $term1->name; 638 $term1->name = drupal_strtolower($this->randomName()); 639 $form_values = (array) $term1; 640 taxonomy_save_term($form_values); 641 $this->assertToken('taxonomy', $term1, 'catpath', $term1->name); 642 643 $term2 = $this->addTerm($this->vocab, array('parent' => $term1->tid)); 644 $this->assertToken('taxonomy', $term2, 'catpath', "{$term1->name}/{$term2->name}"); 645 $this->assertToken('taxonomy', $term2, 'catalias', "category/{$this->vocab->name}/{$term2->name}"); 646 647 $term3 = $this->addTerm($this->vocab, array('parent' => $term2->tid, 'name' => ' foo/bar fer|zle ')); 648 $this->assertToken('taxonomy', $term3, 'catpath', "{$term1->name}/{$term2->name}/foobar-ferzle"); 649 $this->assertToken('taxonomy', $term3, 'catalias', "category/{$this->vocab->name}/foobar-ferzle"); 650 } 651 652 /** 653 * Test the [termpath] token. 654 */ 655 function testTermTokens() { 656 $term1 = $this->addTerm($this->vocab, array('weight' => 5)); 657 $term2 = $this->addTerm($this->vocab, array('weight' => -5)); 658 $term3 = $this->addTerm($this->vocab, array('weight' => 0)); 659 660 $node = $this->drupalCreateNode(array( 661 'type' => 'story', 662 'taxonomy' => array($term1->tid, $term2->tid, $term3->tid), 663 )); 664 $this->assertToken('node', $node, 'termpath', $term2->name); 665 $this->assertToken('node', $node, 'termalias', "category/{$this->vocab->name}/{$term2->name}"); 666 667 $non_term_node = $this->drupalCreateNode(array('type' => 'story')); 668 $this->assertToken('node', $non_term_node, 'termpath', ''); 669 $this->assertToken('node', $non_term_node, 'termalias', ''); 670 } 671 }
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 |