PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tests/libraries/models/UrlTest.php

https://github.com/yodasan/frontend
PHP | 127 lines | 118 code | 8 blank | 1 comment | 0 complexity | fbe31c527699bdbd12a4f217f9927042 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. <?php
  2. class UrlTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function setUp()
  5. {
  6. // to test the write methods
  7. ob_start();
  8. $this->url = new Url;
  9. $this->id = uniqid();
  10. }
  11. public function testActionCreate()
  12. {
  13. $url = $this->url->actionCreate($this->id, 'photo', false);
  14. $this->assertEquals("/action/{$this->id}/photo/create", $url, 'Urls do not match');
  15. $this->url->actionCreate($this->id, 'photo');
  16. $url = ob_get_contents();
  17. ob_clean();
  18. $this->assertEquals("/action/{$this->id}/photo/create", $url, 'Urls do not match');
  19. $this->url->actionCreate($this->id, 'photo', true);
  20. $url = ob_get_contents();
  21. ob_clean();
  22. $this->assertEquals("/action/{$this->id}/photo/create", $url, 'Urls do not match');
  23. }
  24. public function testActionDelete()
  25. {
  26. $url = $this->url->actionDelete($this->id, false);
  27. $this->assertEquals("/action/{$this->id}/delete", $url, 'Urls do not match');
  28. $this->url->actionDelete($this->id);
  29. $url = ob_get_contents();
  30. ob_clean();
  31. $this->assertEquals("/action/{$this->id}/delete", $url, 'Urls do not match');
  32. $this->url->actionDelete($this->id, true);
  33. $url = ob_get_contents();
  34. ob_clean();
  35. $this->assertEquals("/action/{$this->id}/delete", $url, 'Urls do not match');
  36. }
  37. public function testPhotoDelete()
  38. {
  39. $url = $this->url->photoDelete($this->id, false);
  40. $this->assertEquals("/photo/{$this->id}/delete", $url, 'Urls do not match');
  41. $this->url->photoDelete($this->id);
  42. $url = ob_get_contents();
  43. ob_clean();
  44. $this->assertEquals("/photo/{$this->id}/delete", $url, 'Urls do not match');
  45. $this->url->photoDelete($this->id, true);
  46. $url = ob_get_contents();
  47. ob_clean();
  48. $this->assertEquals("/photo/{$this->id}/delete", $url, 'Urls do not match');
  49. }
  50. public function testPhotoEdit()
  51. {
  52. $url = $this->url->photoEdit($this->id, false);
  53. $this->assertEquals("/photo/{$this->id}/edit", $url, 'Urls do not match');
  54. $this->url->photoEdit($this->id);
  55. $url = ob_get_contents();
  56. ob_clean();
  57. $this->assertEquals("/photo/{$this->id}/edit", $url, 'Urls do not match');
  58. $this->url->photoEdit($this->id, true);
  59. $url = ob_get_contents();
  60. ob_clean();
  61. $this->assertEquals("/photo/{$this->id}/edit", $url, 'Urls do not match');
  62. }
  63. public function testPhotoUpdate()
  64. {
  65. $url = $this->url->photoUpdate($this->id, false);
  66. $this->assertEquals("/photo/{$this->id}/update", $url, 'Urls do not match');
  67. $this->url->photoUpdate($this->id);
  68. $url = ob_get_contents();
  69. ob_clean();
  70. $this->assertEquals("/photo/{$this->id}/update", $url, 'Urls do not match');
  71. $this->url->photoUpdate($this->id, true);
  72. $url = ob_get_contents();
  73. ob_clean();
  74. $this->assertEquals("/photo/{$this->id}/update", $url, 'Urls do not match');
  75. }
  76. public function testPhotoUrl()
  77. {
  78. $key = '30x30';
  79. $val = uniqid();
  80. $photo = array("path{$key}" => $val);
  81. $url = $this->url->photoUrl($photo, $key, false);
  82. $this->assertEquals($val, $url, 'Urls do not match');
  83. $this->url->photoUrl($photo, $key);
  84. $url = ob_get_contents();
  85. ob_clean();
  86. $this->assertEquals($val, $url, 'Urls do not match');
  87. $this->url->photoUrl($photo, $key, true);
  88. $url = ob_get_contents();
  89. ob_clean();
  90. $this->assertEquals($val, $url, 'Urls do not match');
  91. }
  92. public function testPhotoView()
  93. {
  94. $url = $this->url->photoView($this->id, null, false);
  95. $this->assertEquals("/p/{$this->id}", $url, 'Urls do not match');
  96. $this->url->photoView($this->id);
  97. $url = ob_get_contents();
  98. ob_clean();
  99. $this->assertEquals("/p/{$this->id}", $url, 'Urls do not match');
  100. $this->url->photoView($this->id, null, true);
  101. $url = ob_get_contents();
  102. ob_clean();
  103. $this->assertEquals("/p/{$this->id}", $url, 'Urls do not match');
  104. }
  105. public function testPhotoViewShort()
  106. {
  107. $_SERVER['REDIRECT_URL'] = "/p/{$this->id}";
  108. $url = $this->url->photoView($this->id, null, false);
  109. $this->assertEquals("/p/{$this->id}", $url, 'Urls do not match');
  110. $this->url->photoView($this->id);
  111. $url = ob_get_contents();
  112. ob_clean();
  113. $this->assertEquals("/p/{$this->id}", $url, 'Urls do not match');
  114. $this->url->photoView($this->id, null, true);
  115. $url = ob_get_contents();
  116. ob_clean();
  117. $this->assertEquals("/p/{$this->id}", $url, 'Urls do not match');
  118. }
  119. }