You are here

function SubPathautoUnitTestCase::testSubPathAliases in Sub-pathauto (Sub-path URL Aliases) 7

File

./subpathauto.test, line 25
Test integration for the subpathauto.module.

Class

SubPathautoUnitTestCase
@file Test integration for the subpathauto.module.

Code

function testSubPathAliases() {
  $this
    ->assertAlias('node/1', 'content/first-node');
  $this
    ->assertAlias('node/1/a', 'content/first-node/a');
  $this
    ->assertNoAlias('node/1/a/b');
  $this
    ->assertAlias('node/1/test', 'content/first-node-test');
  $this
    ->assertAlias('node/1/test/a', 'content/first-node-test/a');
  $this
    ->assertNoAlias('node/1/test/a/b');

  // Change the depth to two-levels deep.
  variable_set('subpathauto_depth', 2);
  drupal_static_reset();
  $this
    ->assertAlias('node/1', 'content/first-node');
  $this
    ->assertAlias('node/1/a', 'content/first-node/a');
  $this
    ->assertAlias('node/1/a/b', 'content/first-node/a/b');
  $this
    ->assertNoAlias('node/1/a/b/c');
  $this
    ->assertAlias('node/1/test', 'content/first-node-test');
  $this
    ->assertAlias('node/1/test/a/b', 'content/first-node-test/a/b');
  $this
    ->assertNoAlias('node/1/test/a/b/c');

  // Test that admin paths should be excluded.
  drupal_static_reset();
  $this
    ->assertNoAlias('node/1/edit');
  $this
    ->assertNoAlias('admin/modules');

  // Test with $options['alias'] and $options['external'].
  $this
    ->assertNoAlias('node/1/a', array(
    'alias' => TRUE,
  ));
  $this
    ->assertAlias('node/1/a', 'content/first-node/a', array(
    'alias' => FALSE,
  ));
  $this
    ->assertNoAlias('node/1/a', array(
    'external' => TRUE,
  ));
  $this
    ->assertAlias('node/1/a', 'content/first-node/a', array(
    'external' => FALSE,
  ));

  // Enable sub-path aliases for admin paths.
  variable_set('subpathauto_ignore_admin', 0);
  drupal_static_reset();
  $this
    ->assertAlias('node/1/edit', 'content/first-node/edit');
  $this
    ->assertAlias('admin/modules', 'malicious-path/modules');
}