'Pathauto unit tests', 'description' => 'Unit tests for Pathauto functions.', 'group' => 'Pathauto', ); } function setUp() { parent::setUp('path', 'pathauto'); module_load_include('inc', 'pathauto'); } /** * Test _pathauto_get_schema_alias_maxlength(). */ function testGetSchemaAliasMaxLength() { $this->assertIdentical(_pathauto_get_schema_alias_maxlength(), 255); } } /** * Helper test class with some added functions for testing. */ class PathautoTestHelper extends DrupalWebTestCase { protected $admin_user; function setUp() { // Call parent::setUp() allowing test cases to pass further modules. $modules = func_get_args(); $modules = array_merge(array('path', 'pathauto'), $modules); call_user_func_array(array('parent', 'setUp'), $modules); // Set pathauto settings we assume to be as-is in this test. variable_set('pathauto_node_page_pattern', 'content/[node:title]'); $this->admin_user = $this->drupalCreateUser(array( 'administer pathauto', 'create page content', 'edit own page content', 'administer url aliases', 'create url aliases', )); $this->drupalLogin($this->admin_user); } function assertNodeAlias(stdClass $node, $expected_alias) { $alias = drupal_get_path_alias('node/' . $node->nid); $this->assertEqual($alias, $expected_alias); } } /** * Test basic pathauto functionality. */ class PathautoFunctionalTestCase extends PathautoTestHelper { public static function getInfo() { return array( 'name' => 'Pathauto basic tests', 'description' => 'Test basic pathauto functionality.', 'group' => 'Pathauto', ); } /** * Basic functional testing of Pathauto. */ function testNodeEditing() { // Create node for testing. $random_title = $this->randomName(10); $title = ' Simpletest title ' . $random_title . ' ['; $automatic_alias = 'content/simpletest-title-' . strtolower($random_title); $node = $this->drupalCreateNode(array('title' => $title, 'type' => 'page')); // Look for alias generated in the form. $this->drupalGet('node/' . $node->nid . '/edit'); $this->assertFieldChecked('edit-path-pathauto-perform-alias'); $this->assertFieldByName('path[alias]', $automatic_alias, 'Proper automated alias generated.'); // Check whether the alias actually works. $this->drupalGet($automatic_alias); $this->assertText($title, 'Node accessible through automatic alias.'); // Manually set the node's alias. $manual_alias = 'content/' . $node->nid; $edit = array( 'path[pathauto_perform_alias]' => FALSE, 'path[alias]' => $manual_alias, ); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); $this->assertText(t('@type @title has been updated', array('@type' => 'Basic page', '@title' => $title))); // Check that the automatic alias checkbox is now unchecked by default. $this->drupalGet('node/' . $node->nid . '/edit'); $this->assertNoFieldChecked('edit-path-pathauto-perform-alias'); $this->assertFieldByName('path[alias]', $manual_alias); // Submit the node form with the default values. $this->drupalPost(NULL, array(), t('Save')); $this->assertText(t('@type @title has been updated', array('@type' => 'Basic page', '@title' => $title))); // Test that the old (automatic) alias has been deleted and only accessible // through the new (manual) alias. $this->drupalGet($automatic_alias); $this->assertResponse(404, 'Node not accessible through automatic alias.'); $this->drupalGet($manual_alias); $this->assertText($title, 'Node accessible through manual alias.'); } } /* * Unit tests for the book tokens provided by Pathauto. */ class PathautoBookTokenTestCase extends PathautoTestHelper { public static function getInfo() { return array( 'name' => 'Pathauto book tokens', 'description' => 'Unit tests for the book tokens provided by Pathauto.', 'group' => 'Pathauto', ); } function setUp() { parent::setUp('book'); variable_set('book_allowed_types', array('book', 'page')); } function testBookPathAlias() { variable_set('pathauto_node_book_pattern', '[node:bookpathalias]/[node:title]'); // Add a root book page. $parent_node = $this->drupalCreateNode(array('type' => 'book', 'title' => 'Root', 'book' => array('bid' => 'new'))); $this->assertNodeAlias($parent_node, 'root'); // Add a first child page. $child_node1 = $this->drupalCreateNode(array('type' => 'book', 'title' => 'Sub page1', 'book' => array('bid' => $parent_node->book['bid'], 'plid' => $parent_node->book['mlid']))); $this->assertNodeAlias($child_node1, 'root/sub-page1'); // Add a second child page. $child_node2 = $this->drupalCreateNode(array('type' => 'book', 'title' => 'Sub page2', 'book' => array('bid' => $parent_node->book['bid'], 'plid' => $parent_node->book['mlid']))); $this->assertNodeAlias($child_node2, 'root/sub-page2'); // Add a child page on an existing child page. $sub_child_node1 = $this->drupalCreateNode(array('type' => 'book', 'title' => 'Sub-sub Page1', 'book' => array('bid' => $parent_node->book['bid'], 'plid' => $child_node1->book['mlid']))); $this->assertNodeAlias($sub_child_node1, 'root/sub-page1/sub-sub-page1'); } }