KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.62
System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64
User : www ( 80)
PHP Version : 8.3.8
Disable Function : NONE
Directory :  /domains/afglcweb/ny/sites/all/modules/pathauto/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/afglcweb/ny/sites/all/modules/pathauto/tests/pathauto.test
<?php
// $Id: pathauto.test,v 1.2.2.6 2010/02/20 03:05:17 davereid Exp $

/**
 * @file
 * Functionality tests for Pathauto.
 *
 * @ingroup pathauto
 */

/**
 * Implements hook_simpletest_alter().
 */
function pathauto_simpletest_alter(&$groups) {
  // Enforce dependency on token for all pathauto tests.
  if (!drupal_get_filename('module', 'token')) {
    unset($groups['Pathauto']);
  }
}
/**
 * Unit tests for Pathauto functions.
 */
class PathautoUnitTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Pathauto unit tests',
      'description' => 'Unit tests for Pathauto functions.',
      'group' => 'Pathauto',
    );
  }

  function setUp() {
    parent::setUp('path', 'token', 'pathauto');
    module_load_include('inc', 'pathauto');
  }

  /**
   * Test _pathauto_get_schema_alias_maxlength().
   */
  function testGetSchemaAliasMaxLength() {
    $this->assertIdentical(_pathauto_get_schema_alias_maxlength(), 128);
  }
}

/**
 * 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', 'token', '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/[title-raw]');

    $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-pathauto-perform-alias');
    $this->assertFieldByName('path', $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(
      'pathauto_perform_alias' => FALSE,
      'path' => $manual_alias,
    );
    $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
    $this->assertText(t('@type @title has been updated', array('@type' => 'Page', '@title' => $title)));

    // Check that the automatic alias checkbox is now unchecked by default.
    $this->drupalGet('node/' . $node->nid . '/edit');
    $this->assertNoFieldChecked('edit-pathauto-perform-alias');
    $this->assertFieldByName('path', $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' => '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', '[bookpathalias]/[title-raw]');

    // 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');
  }
}

Anon7 - 2021