url.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. include_once 'config.php';
  3. __p::require_plugins('url');
  4. class pQueryUrlTest extends PHPUnit_Framework_TestCase {
  5. function setUp() {
  6. $this->url = _url('foo/bar');
  7. }
  8. function tearDown() {
  9. __url::$handlers = array();
  10. }
  11. function test_constructor() {
  12. $this->assertInstanceOf('pQueryUrl', $this->url, 'constructor does not return pQueryUrl object');
  13. }
  14. function test_parse_url() {
  15. $this->assertEquals('foo/bar', _url('/foo/bar')->url);
  16. $this->assertEquals('foo/bar', _url('foo/bar/')->url);
  17. }
  18. function test_add_handler_callable() {
  19. $handler = create_function('$a', 'return true;');
  20. __url::add_handler('foo/.*', $handler);
  21. $this->assertArrayHasKey('%foo/.*%', __url::$handlers);
  22. $this->assertEquals($handler, __url::$handlers['%foo/.*%']);
  23. }
  24. /**
  25. * @expectedException pQueryException
  26. */
  27. function test_add_handler_not_callable() {
  28. __url::add_handler('foo/.*', 'bar');
  29. }
  30. /**
  31. * @depends test_add_handler_callable
  32. */
  33. function test_add_handlers() {
  34. $handler1 = create_function('$a', 'return true;');
  35. $handler2 = create_function('$a', 'return false;');
  36. __url::add_handlers(array(
  37. 'foo/.*' => $handler1,
  38. 'bar/.*' => $handler2
  39. ));
  40. $this->assertArrayHasKey('%foo/.*%', __url::$handlers);
  41. $this->assertArrayHasKey('%bar/.*%', __url::$handlers);
  42. $this->assertEquals($handler1, __url::$handlers['%foo/.*%']);
  43. $this->assertEquals($handler2, __url::$handlers['%bar/.*%']);
  44. }
  45. /**
  46. * @depends test_add_handler_callable
  47. */
  48. function test_handler() {
  49. $handler = create_function('$a', 'return $a;');
  50. __url::add_handler('foo/(.*)', $handler);
  51. $result = $this->url->handler();
  52. $this->assertEquals('bar', $result);
  53. }
  54. /**
  55. * @depends test_handler
  56. * @expectedException pQueryException
  57. */
  58. function test_handler_error() {
  59. $this->url->handler();
  60. }
  61. }
  62. ?>