You are here

public function PURLBasicTest::test in Persistent URL 6

Run test.

File

tests/purl.test, line 98

Class

PURLBasicTest
Basic tests for PURL.

Code

public function test() {

  // API aspects to test
  // - PURL activation
  // - URL rewriting
  // - PURL disabling
  // - PURL provider removal
  // - PURL provider addition
  variable_set('purl_types', array(
    'path' => 'path',
    'pair' => 'pair',
    'extension' => 'extension',
    'querystring' => 'querystring',
  ));
  foreach (array(
    "",
    "es/",
  ) as $langcode) {

    // Test with both providers set to path.
    variable_set('purl_method_purl_test', 'path');
    variable_set('purl_method_purl_alt', 'path');
    $testname = t('Path + Path');
    $output = $this
      ->drupalGet("{$langcode}admin/build/testing/purl");
    $this
      ->assertNoText('PURL test ID', t('@test: Modifier not present.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Rewrite: /{$langcode}node", t('@test: Link not rewritten.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Disable providers: /{$langcode}node", t('@test: Provider disabled.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Remove provider: /{$langcode}node", t('@test: Provider removed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Add provider: /{$langcode}sweden/node", t('@test: Provider added.', array(
      '@test' => $testname,
    )));
    $output = $this
      ->drupalGet("{$langcode}foo/admin/build/testing/purl");
    $this
      ->assertText('PURL test ID: foo', t('@test: Modifier parsed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Rewrite: /{$langcode}foo/node", t('@test: Link rewritten.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Disable providers: /{$langcode}node", t('@test: Provider disabled.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Remove provider: /{$langcode}node", t('@test: Provider removed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Add provider: /{$langcode}sweden/foo/node", t('@test: Provider added.', array(
      '@test' => $testname,
    )));

    // Test path + pair.
    variable_set('purl_method_purl_alt', 'pair');
    variable_set('purl_method_purl_alt_key', 'altkey');
    $testname = t('Path + Pair');
    $output = $this
      ->drupalGet("{$langcode}admin/build/testing/purl");
    $this
      ->assertNoText('PURL test ID', t('@test: Modifier not present.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Rewrite: /{$langcode}node", t('@test: Link not rewritten.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Disable providers: /{$langcode}node", t('@test: Provider disabled.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Remove provider: /{$langcode}node", t('@test: Provider removed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Add provider: /{$langcode}altkey/sweden/node", t('@test: Provider added.', array(
      '@test' => $testname,
    )));
    $output = $this
      ->drupalGet("{$langcode}foo/admin/build/testing/purl");
    $this
      ->assertText('PURL test ID: foo', t('@test: Modifier parsed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Rewrite: /{$langcode}foo/node", t('@test: Link rewritten.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Disable providers: /{$langcode}node", t('@test: Provider disabled.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Remove provider: /{$langcode}node", t('@test: Provider removed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Add provider: /{$langcode}altkey/sweden/foo/node", t('@test: Provider added.', array(
      '@test' => $testname,
    )));

    // Test path + querystring.
    variable_set('purl_method_purl_alt', 'querystring');
    variable_set('purl_method_purl_alt_key', 'altkey');
    $testname = t('Path + Querystring');
    $output = $this
      ->drupalGet("{$langcode}admin/build/testing/purl");
    $this
      ->assertNoText('PURL test ID', t('@test: Modifier not present.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Rewrite: /{$langcode}node", t('@test: Link not rewritten.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Disable providers: /{$langcode}node", t('@test: Provider disabled.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Remove provider: /{$langcode}node", t('@test: Provider removed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Add provider: /{$langcode}node?altkey=sweden", t('@test: Provider added.', array(
      '@test' => $testname,
    )));
    $output = $this
      ->drupalGet("{$langcode}foo/admin/build/testing/purl");
    $this
      ->assertText('PURL test ID: foo', t('@test: Modifier parsed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Rewrite: /{$langcode}foo/node", t('@test: Link rewritten.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Disable providers: /{$langcode}node", t('@test: Provider disabled.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Remove provider: /{$langcode}node", t('@test: Provider removed.', array(
      '@test' => $testname,
    )));
    $this
      ->assertText("Add provider: /{$langcode}foo/node?altkey=sweden", t('@test: Provider added.', array(
      '@test' => $testname,
    )));
  }
}