purl_test.module

Tracking 7.x-1.x branch
  1. drupal
    1. 6 contributions/purl/tests/purl_test.module
    2. 7 contributions/purl/tests/purl_test.module

Functions & methods

NameDescription
purl_test_activatePURL callback for test providers.
purl_test_menuImplements hook_menu().
purl_test_pageTest page callback.
purl_test_purl_modifiersImplements hook_purl_modifiers().
purl_test_purl_providerImplements hook_purl_provider().
purl_test_remove_base_pathHelper function to remove $base_path from testing links.

File

View source
  1. <?php
  2. /**
  3. * Implements hook_menu().
  4. */
  5. function purl_test_menu() {
  6. return array(
  7. 'admin/config/development/testing/purl' => array(
  8. 'page callback' => 'purl_test_page',
  9. 'page arguments' => array(),
  10. 'access callback' => 'user_access',
  11. 'access arguments' => array('administer site configuration'),
  12. 'type' => MENU_CALLBACK,
  13. ),
  14. );
  15. }
  16. /**
  17. * Test page callback.
  18. */
  19. function purl_test_page() {
  20. $tests = array();
  21. $tests[] = t('Rewrite: !link', array('!link' => purl_test_remove_base_path(url('node'))));
  22. $tests[] = t('Disable providers: !link', array('!link' => purl_test_remove_base_path(url('node', array('purl' => array('disabled' => TRUE))))));
  23. $tests[] = t('Remove provider: !link', array('!link' => purl_test_remove_base_path(url('node', array('purl' => array('remove' => array('purl_test')))))));
  24. $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'))))))));
  25. return implode('<br/>', $tests);
  26. }
  27. /**
  28. * Helper function to remove $base_path from testing links.
  29. */
  30. function purl_test_remove_base_path($link) {
  31. global $base_path;
  32. if ($base_path != '/') {
  33. return substr($link, strlen($base_path) - 1);
  34. }
  35. return $link;
  36. }
  37. /**
  38. * Implements hook_purl_provider().
  39. */
  40. function purl_test_purl_provider() {
  41. $items = array();
  42. $items['purl_test'] = array(
  43. 'name' => t('PURL test'),
  44. 'description' => t('Provider for use with PURL tests.'),
  45. 'callback' => 'purl_test_activate',
  46. 'callback arguments' => array(),
  47. 'example' => 'foo',
  48. );
  49. $items['purl_alt'] = array(
  50. 'name' => t('PURL test (alternate provider)'),
  51. 'description' => t('Alternate provider for use with PURL tests.'),
  52. 'callback' => 'purl_test_activate',
  53. 'callback arguments' => array(),
  54. 'example' => 'sweden',
  55. );
  56. return $items;
  57. }
  58. /**
  59. * PURL callback for test providers.
  60. */
  61. function purl_test_activate($value) {
  62. $modifiers = purl_test_purl_modifiers();
  63. drupal_set_message(t('PURL test ID: @id', array('@id' => $value)));
  64. }
  65. /**
  66. * Implements hook_purl_modifiers().
  67. */
  68. function purl_test_purl_modifiers() {
  69. return array(
  70. 'purl_test' => array(
  71. array('value' => 'foo', 'id' => 'foo'),
  72. array('value' => 'bar', 'id' => 'bar'),
  73. array('value' => 'baz', 'id' => 'baz'),
  74. ),
  75. 'purl_alt' => array(
  76. array('value' => 'sweden', 'id' => 'sweden'),
  77. array('value' => 'norway', 'id' => 'norway'),
  78. array('value' => 'finland', 'id' => 'finland'),
  79. ),
  80. );
  81. }