CleanupUrlTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Unitary tests for cleanup_url()
  4. */
  5. require_once 'application/Url.php';
  6. class CleanupUrlTest extends PHPUnit_Framework_TestCase
  7. {
  8. /**
  9. * @var string reference URL
  10. */
  11. protected $ref = 'http://domain.tld:3000';
  12. /**
  13. * Clean empty URL
  14. */
  15. public function testCleanupUrlEmpty()
  16. {
  17. $this->assertEquals('', cleanup_url(''));
  18. }
  19. /**
  20. * Clean an already cleaned URL
  21. */
  22. public function testCleanupUrlAlreadyClean()
  23. {
  24. $this->assertEquals($this->ref, cleanup_url($this->ref));
  25. $this->ref2 = $this->ref.'/path/to/dir/';
  26. $this->assertEquals($this->ref2, cleanup_url($this->ref2));
  27. }
  28. /**
  29. * Clean URL fragments
  30. */
  31. public function testCleanupUrlFragment()
  32. {
  33. $this->assertEquals($this->ref, cleanup_url($this->ref.'#tk.rss_all'));
  34. $this->assertEquals($this->ref, cleanup_url($this->ref.'#xtor=RSS-'));
  35. $this->assertEquals($this->ref, cleanup_url($this->ref.'#xtor=RSS-U3ht0tkc4b'));
  36. }
  37. /**
  38. * Clean URL query - single annoying parameter
  39. */
  40. public function testCleanupUrlQuerySingle()
  41. {
  42. $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_object_map=junk'));
  43. $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_ref_map=Cr4p!'));
  44. $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_type_map=g4R84g3'));
  45. $this->assertEquals($this->ref, cleanup_url($this->ref.'?fb_stuff=v41u3'));
  46. $this->assertEquals($this->ref, cleanup_url($this->ref.'?fb=71m3w4573'));
  47. $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_campaign=zomg'));
  48. $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_medium=numnum'));
  49. $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_source=c0d3'));
  50. $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_term=1n4l'));
  51. $this->assertEquals($this->ref, cleanup_url($this->ref.'?xtor=some-url'));
  52. $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_name=junk'));
  53. $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_start=junk'));
  54. $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_item_index=junk'));
  55. }
  56. /**
  57. * Clean URL query - multiple annoying parameters
  58. */
  59. public function testCleanupUrlQueryMultiple()
  60. {
  61. $this->assertEquals($this->ref, cleanup_url($this->ref.'?xtor=some-url&fb=som3th1ng'));
  62. $this->assertEquals($this->ref, cleanup_url(
  63. $this->ref.'?fb=stuff&utm_campaign=zomg&utm_medium=numnum&utm_source=c0d3'
  64. ));
  65. $this->assertEquals($this->ref, cleanup_url(
  66. $this->ref.'?campaign_start=zomg&campaign_name=numnum'
  67. ));
  68. }
  69. /**
  70. * Clean URL query - multiple annoying parameters and fragment
  71. */
  72. public function testCleanupUrlQueryFragment()
  73. {
  74. $this->assertEquals($this->ref, cleanup_url(
  75. $this->ref.'?xtor=some-url&fb=som3th1ng#tk.rss_all'
  76. ));
  77. // ditch annoying query params and fragment, keep useful params
  78. $this->assertEquals(
  79. $this->ref.'?my=stuff&is=kept',
  80. cleanup_url(
  81. $this->ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
  82. )
  83. );
  84. // ditch annoying query params, keep useful params and fragment
  85. $this->assertEquals(
  86. $this->ref.'?my=stuff&is=kept#again',
  87. cleanup_url(
  88. $this->ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'
  89. )
  90. );
  91. }
  92. }