UserQueryTest.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /**
  3. * Description of UserQueryTest
  4. */
  5. class UserQueryTest extends PHPUnit\Framework\TestCase {
  6. public function test__construct_whenAllQuery_storesAllParameters() {
  7. $query = array('get' => 'a');
  8. $user_query = new FreshRSS_UserQuery($query);
  9. $this->assertEquals('all', $user_query->getGetName());
  10. $this->assertEquals('all', $user_query->getGetType());
  11. }
  12. public function test__construct_whenFavoriteQuery_storesFavoriteParameters() {
  13. $query = array('get' => 's');
  14. $user_query = new FreshRSS_UserQuery($query);
  15. $this->assertEquals('favorite', $user_query->getGetName());
  16. $this->assertEquals('favorite', $user_query->getGetType());
  17. }
  18. /**
  19. * @expectedException Exceptions/FreshRSS_DAO_Exception
  20. * @expectedExceptionMessage Category DAO is not loaded in UserQuery
  21. */
  22. public function test__construct_whenCategoryQueryAndNoDao_throwsException() {
  23. $this->markTestIncomplete('There is a problem with the exception autoloading. We need to make a better autoloading process');
  24. $query = array('get' => 'c_1');
  25. new FreshRSS_UserQuery($query);
  26. }
  27. public function test__construct_whenCategoryQuery_storesCategoryParameters() {
  28. $category_name = 'some category name';
  29. $cat = $this->getMock('FreshRSS_Category');
  30. $cat->expects($this->atLeastOnce())
  31. ->method('name')
  32. ->withAnyParameters()
  33. ->willReturn($category_name);
  34. $cat_dao = $this->getMock('FreshRSS_Searchable');
  35. $cat_dao->expects($this->atLeastOnce())
  36. ->method('searchById')
  37. ->withAnyParameters()
  38. ->willReturn($cat);
  39. $query = array('get' => 'c_1');
  40. $user_query = new FreshRSS_UserQuery($query, null, $cat_dao);
  41. $this->assertEquals($category_name, $user_query->getGetName());
  42. $this->assertEquals('category', $user_query->getGetType());
  43. }
  44. /**
  45. * @expectedException Exceptions/FreshRSS_DAO_Exception
  46. * @expectedExceptionMessage Feed DAO is not loaded in UserQuery
  47. */
  48. public function test__construct_whenFeedQueryAndNoDao_throwsException() {
  49. $this->markTestIncomplete('There is a problem with the exception autoloading. We need to make a better autoloading process');
  50. $query = array('get' => 'c_1');
  51. new FreshRSS_UserQuery($query);
  52. }
  53. public function test__construct_whenFeedQuery_storesFeedParameters() {
  54. $feed_name = 'some feed name';
  55. $feed = $this->getMock('FreshRSS_Feed', array(), array('', false));
  56. $feed->expects($this->atLeastOnce())
  57. ->method('name')
  58. ->withAnyParameters()
  59. ->willReturn($feed_name);
  60. $feed_dao = $this->getMock('FreshRSS_Searchable');
  61. $feed_dao->expects($this->atLeastOnce())
  62. ->method('searchById')
  63. ->withAnyParameters()
  64. ->willReturn($feed);
  65. $query = array('get' => 'f_1');
  66. $user_query = new FreshRSS_UserQuery($query, $feed_dao, null);
  67. $this->assertEquals($feed_name, $user_query->getGetName());
  68. $this->assertEquals('feed', $user_query->getGetType());
  69. }
  70. public function test__construct_whenUnknownQuery_doesStoreParameters() {
  71. $query = array('get' => 'q');
  72. $user_query = new FreshRSS_UserQuery($query);
  73. $this->assertNull($user_query->getGetName());
  74. $this->assertNull($user_query->getGetType());
  75. }
  76. public function test__construct_whenName_storesName() {
  77. $name = 'some name';
  78. $query = array('name' => $name);
  79. $user_query = new FreshRSS_UserQuery($query);
  80. $this->assertEquals($name, $user_query->getName());
  81. }
  82. public function test__construct_whenOrder_storesOrder() {
  83. $order = 'some order';
  84. $query = array('order' => $order);
  85. $user_query = new FreshRSS_UserQuery($query);
  86. $this->assertEquals($order, $user_query->getOrder());
  87. }
  88. public function test__construct_whenState_storesState() {
  89. $state = 'some state';
  90. $query = array('state' => $state);
  91. $user_query = new FreshRSS_UserQuery($query);
  92. $this->assertEquals($state, $user_query->getState());
  93. }
  94. public function test__construct_whenUrl_storesUrl() {
  95. $url = 'some url';
  96. $query = array('url' => $url);
  97. $user_query = new FreshRSS_UserQuery($query);
  98. $this->assertEquals($url, $user_query->getUrl());
  99. }
  100. public function testToArray_whenNoData_returnsEmptyArray() {
  101. $user_query = new FreshRSS_UserQuery(array());
  102. $this->assertInternalType('array', $user_query->toArray());
  103. $this->assertCount(0, $user_query->toArray());
  104. }
  105. public function testToArray_whenData_returnsArray() {
  106. $query = array(
  107. 'get' => 's',
  108. 'name' => 'some name',
  109. 'order' => 'some order',
  110. 'search' => 'some search',
  111. 'state' => 'some state',
  112. 'url' => 'some url',
  113. );
  114. $user_query = new FreshRSS_UserQuery($query);
  115. $this->assertInternalType('array', $user_query->toArray());
  116. $this->assertCount(6, $user_query->toArray());
  117. $this->assertEquals($query, $user_query->toArray());
  118. }
  119. public function testHasSearch_whenSearch_returnsTrue() {
  120. $query = array(
  121. 'search' => 'some search',
  122. );
  123. $user_query = new FreshRSS_UserQuery($query);
  124. $this->assertTrue($user_query->hasSearch());
  125. }
  126. public function testHasSearch_whenNoSearch_returnsFalse() {
  127. $user_query = new FreshRSS_UserQuery(array());
  128. $this->assertFalse($user_query->hasSearch());
  129. }
  130. public function testHasParameters_whenAllQuery_returnsFalse() {
  131. $query = array('get' => 'a');
  132. $user_query = new FreshRSS_UserQuery($query);
  133. $this->assertFalse($user_query->hasParameters());
  134. }
  135. public function testHasParameters_whenNoParameter_returnsFalse() {
  136. $query = array();
  137. $user_query = new FreshRSS_UserQuery($query);
  138. $this->assertFalse($user_query->hasParameters());
  139. }
  140. public function testHasParameters_whenParameter_returnTrue() {
  141. $query = array('get' => 's');
  142. $user_query = new FreshRSS_UserQuery($query);
  143. $this->assertTrue($user_query->hasParameters());
  144. }
  145. public function testIsDeprecated_whenCategoryExists_returnFalse() {
  146. $cat = $this->getMock('FreshRSS_Category');
  147. $cat_dao = $this->getMock('FreshRSS_Searchable');
  148. $cat_dao->expects($this->atLeastOnce())
  149. ->method('searchById')
  150. ->withAnyParameters()
  151. ->willReturn($cat);
  152. $query = array('get' => 'c_1');
  153. $user_query = new FreshRSS_UserQuery($query, null, $cat_dao);
  154. $this->assertFalse($user_query->isDeprecated());
  155. }
  156. public function testIsDeprecated_whenCategoryDoesNotExist_returnTrue() {
  157. $cat_dao = $this->getMock('FreshRSS_Searchable');
  158. $cat_dao->expects($this->atLeastOnce())
  159. ->method('searchById')
  160. ->withAnyParameters()
  161. ->willReturn(null);
  162. $query = array('get' => 'c_1');
  163. $user_query = new FreshRSS_UserQuery($query, null, $cat_dao);
  164. $this->assertTrue($user_query->isDeprecated());
  165. }
  166. public function testIsDeprecated_whenFeedExists_returnFalse() {
  167. $feed = $this->getMock('FreshRSS_Feed', array(), array('', false));
  168. $feed_dao = $this->getMock('FreshRSS_Searchable');
  169. $feed_dao->expects($this->atLeastOnce())
  170. ->method('searchById')
  171. ->withAnyParameters()
  172. ->willReturn($feed);
  173. $query = array('get' => 'f_1');
  174. $user_query = new FreshRSS_UserQuery($query, $feed_dao, null);
  175. $this->assertFalse($user_query->isDeprecated());
  176. }
  177. public function testIsDeprecated_whenFeedDoesNotExist_returnTrue() {
  178. $feed_dao = $this->getMock('FreshRSS_Searchable');
  179. $feed_dao->expects($this->atLeastOnce())
  180. ->method('searchById')
  181. ->withAnyParameters()
  182. ->willReturn(null);
  183. $query = array('get' => 'f_1');
  184. $user_query = new FreshRSS_UserQuery($query, $feed_dao, null);
  185. $this->assertTrue($user_query->isDeprecated());
  186. }
  187. public function testIsDeprecated_whenAllQuery_returnFalse() {
  188. $query = array('get' => 'a');
  189. $user_query = new FreshRSS_UserQuery($query);
  190. $this->assertFalse($user_query->isDeprecated());
  191. }
  192. public function testIsDeprecated_whenFavoriteQuery_returnFalse() {
  193. $query = array('get' => 's');
  194. $user_query = new FreshRSS_UserQuery($query);
  195. $this->assertFalse($user_query->isDeprecated());
  196. }
  197. public function testIsDeprecated_whenUnknownQuery_returnFalse() {
  198. $query = array('get' => 'q');
  199. $user_query = new FreshRSS_UserQuery($query);
  200. $this->assertFalse($user_query->isDeprecated());
  201. }
  202. }