You are here

purl_test.module in Persistent URL 7

Same filename and directory in other branches
  1. 6 tests/purl_test.module

File

tests/purl_test.module
View source
<?php

/**
 * Implements hook_menu().
 */
function purl_test_menu() {
  return array(
    'admin/config/development/testing/purl' => array(
      'page callback' => 'purl_test_page',
      'page arguments' => array(),
      'access callback' => 'user_access',
      'access arguments' => array(
        'administer site configuration',
      ),
      'type' => MENU_CALLBACK,
    ),
  );
}

/**
 * Test page callback.
 */
function purl_test_page() {
  $tests = array();
  $tests[] = t('Rewrite: !link', array(
    '!link' => purl_test_remove_base_path(url('node')),
  ));
  $tests[] = t('Disable providers: !link', array(
    '!link' => purl_test_remove_base_path(url('node', array(
      'purl' => array(
        'disabled' => TRUE,
      ),
    ))),
  ));
  $tests[] = t('Remove provider: !link', array(
    '!link' => purl_test_remove_base_path(url('node', array(
      'purl' => array(
        'remove' => array(
          'purl_test',
        ),
      ),
    ))),
  ));
  $tests[] = t('Add provider: !link', array(
    '!link' => purl_test_remove_base_path(url('node', array(
      'purl' => array(
        'add' => array(
          array(
            'provider' => 'purl_alt',
            'id' => 'sweden',
          ),
        ),
      ),
    ))),
  ));
  return implode('<br/>', $tests);
}

/**
 * Helper function to remove $base_path from testing links.
 */
function purl_test_remove_base_path($link) {
  global $base_path;
  if ($base_path != '/') {
    return substr($link, strlen($base_path) - 1);
  }
  return $link;
}

/**
 * Implements hook_purl_provider().
 */
function purl_test_purl_provider() {
  $items = array();
  $items['purl_test'] = array(
    'name' => t('PURL test'),
    'description' => t('Provider for use with PURL tests.'),
    'callback' => 'purl_test_activate',
    'callback arguments' => array(),
    'example' => 'foo',
  );
  $items['purl_alt'] = array(
    'name' => t('PURL test (alternate provider)'),
    'description' => t('Alternate provider for use with PURL tests.'),
    'callback' => 'purl_test_activate',
    'callback arguments' => array(),
    'example' => 'sweden',
  );
  return $items;
}

/**
 * PURL callback for test providers.
 */
function purl_test_activate($value) {
  $modifiers = purl_test_purl_modifiers();
  drupal_set_message(t('PURL test ID: @id', array(
    '@id' => $value,
  )));
}

/**
 * Implements hook_purl_modifiers().
 */
function purl_test_purl_modifiers() {
  return array(
    'purl_test' => array(
      array(
        'value' => 'foo',
        'id' => 'foo',
      ),
      array(
        'value' => 'bar',
        'id' => 'bar',
      ),
      array(
        'value' => 'baz',
        'id' => 'baz',
      ),
    ),
    'purl_alt' => array(
      array(
        'value' => 'sweden',
        'id' => 'sweden',
      ),
      array(
        'value' => 'norway',
        'id' => 'norway',
      ),
      array(
        'value' => 'finland',
        'id' => 'finland',
      ),
    ),
  );
}

Functions

Namesort descending Description
purl_test_activate PURL callback for test providers.
purl_test_menu Implements hook_menu().
purl_test_page Test page callback.
purl_test_purl_modifiers Implements hook_purl_modifiers().
purl_test_purl_provider Implements hook_purl_provider().
purl_test_remove_base_path Helper function to remove $base_path from testing links.