ApplicationAvailabilityTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace Tests;
  3. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  4. /**
  5. * Simple availability tests to ensure the application isn't majorly screwed up.
  6. */
  7. class ApplicationAvailabilityTest extends WebTestCase {
  8. /**
  9. * @dataProvider publicUrlProvider
  10. *
  11. * @param string $url
  12. */
  13. public function testCanAccessPublicPages($url) {
  14. $client = self::createClient();
  15. $client->request('GET', $url);
  16. $this->assertTrue($client->getResponse()->isSuccessful());
  17. }
  18. /**
  19. * @dataProvider authUrlProvider
  20. *
  21. * @param string $url
  22. */
  23. public function testCanAccessPagesThatNeedAuthentication($url) {
  24. $client = self::createClient([], [
  25. 'PHP_AUTH_USER' => 'emma',
  26. 'PHP_AUTH_PW' => 'goodshit',
  27. ]);
  28. $client->request('GET', $url);
  29. $this->assertTrue($client->getResponse()->isSuccessful());
  30. }
  31. /**
  32. * @dataProvider authUrlProvider
  33. *
  34. * @param string $url
  35. */
  36. public function testCannotAccessPagesThatNeedAuthenticationWhenNotAuthenticated($url) {
  37. $client = self::createClient();
  38. $client->request('GET', $url);
  39. $this->assertTrue($client->getResponse()->isRedirect());
  40. $this->assertStringEndsWith('/login', $client->getResponse()->headers->get('Location'));
  41. }
  42. /**
  43. * @dataProvider redirectUrlProvider
  44. *
  45. * @param string $expectedLocation
  46. * @param string $url
  47. */
  48. public function testRedirectedUrlsGoToExpectedLocation($expectedLocation, $url) {
  49. $client = self::createClient();
  50. $client->followRedirects();
  51. $client->request('GET', $url);
  52. $this->assertTrue($client->getResponse()->isSuccessful());
  53. $this->assertEquals(
  54. "http://localhost{$expectedLocation}",
  55. $client->getCrawler()->getUri()
  56. );
  57. }
  58. /**
  59. * Public URLs that should exist when fixtures are loaded into a fresh
  60. * database.
  61. */
  62. public function publicUrlProvider() {
  63. yield ['/'];
  64. yield ['/hot'];
  65. yield ['/new'];
  66. yield ['/top'];
  67. yield ['/controversial'];
  68. yield ['/most_commented'];
  69. yield ['/all/hot'];
  70. yield ['/all/new'];
  71. yield ['/all/top'];
  72. yield ['/all/controversial'];
  73. yield ['/all/most_commented'];
  74. yield ['/featured/hot'];
  75. yield ['/featured/new'];
  76. yield ['/featured/top'];
  77. yield ['/featured/controversial'];
  78. yield ['/featured/most_commented'];
  79. yield ['/featured/hot.atom'];
  80. yield ['/featured/new.atom'];
  81. yield ['/featured/top.atom'];
  82. yield ['/featured/controversial.atom'];
  83. yield ['/featured/most_commented.atom'];
  84. yield ['/f/news/hot'];
  85. yield ['/f/news/new'];
  86. yield ['/f/news/top'];
  87. yield ['/f/news/controversial'];
  88. yield ['/f/news/most_commented'];
  89. yield ['/f/news/hot.atom'];
  90. yield ['/f/news/new.atom'];
  91. yield ['/f/news/top.atom'];
  92. yield ['/f/news/controversial.atom'];
  93. yield ['/f/news/most_commented.atom'];
  94. yield ['/f/news/1/comment/1'];
  95. yield ['/f/news/bans'];
  96. yield ['/f/news/moderation_log'];
  97. yield ['/forums'];
  98. yield ['/forums/by_name'];
  99. yield ['/forums/by_title'];
  100. yield ['/forums/by_subscribers'];
  101. yield ['/forums/by_submissions'];
  102. yield ['/forums/by_name/1'];
  103. yield ['/forums/by_title/1'];
  104. yield ['/forums/by_subscribers/1'];
  105. yield ['/forums/by_submissions/1'];
  106. yield ['/login'];
  107. yield ['/registration'];
  108. yield ['/user/emma'];
  109. yield ['/reset_password'];
  110. }
  111. public function redirectUrlProvider() {
  112. yield ['/f/cats', '/f/cats/'];
  113. yield ['/f/news', '/f/NeWs/hot'];
  114. yield ['/f/news/new', '/f/NeWs/new'];
  115. yield ['/f/news/top', '/f/NeWs/top'];
  116. yield ['/f/news/controversial', '/f/NeWs/controversial'];
  117. yield ['/f/news/most_commented', '/f/NeWs/most_commented'];
  118. yield ['/f/news/1/comment/1', '/f/NeWs/1/comment/1'];
  119. yield ['/f/news/hot.atom', '/f/news/hot/1.atom'];
  120. yield ['/f/news/new.atom', '/f/news/new/1.atom'];
  121. }
  122. /**
  123. * URLs that need authentication to access.
  124. */
  125. public function authUrlProvider() {
  126. yield ['/subscribed/hot'];
  127. yield ['/subscribed/new'];
  128. yield ['/subscribed/top'];
  129. yield ['/subscribed/controversial'];
  130. yield ['/subscribed/most_commented'];
  131. yield ['/moderated/hot'];
  132. yield ['/moderated/new'];
  133. yield ['/moderated/top'];
  134. yield ['/moderated/controversial'];
  135. yield ['/moderated/most_commented'];
  136. yield ['/create_forum'];
  137. yield ['/f/news/edit'];
  138. yield ['/f/news/appearance'];
  139. yield ['/f/news/add_moderator'];
  140. yield ['/f/news/delete'];
  141. yield ['/inbox'];
  142. yield ['/submit'];
  143. yield ['/submit/news'];
  144. yield ['/block_list'];
  145. }
  146. }