summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapp/Controllers/configureController.php83
-rw-r--r--app/Exceptions/DAOException.php5
-rw-r--r--app/Models/CategoryDAO.php2
-rw-r--r--app/Models/ConfigurationSetter.php7
-rw-r--r--app/Models/EntryDAO.php2
-rw-r--r--app/Models/FeedDAO.php2
-rw-r--r--app/Models/Searchable.php6
-rw-r--r--app/Models/UserQuery.php226
-rw-r--r--app/views/configure/queries.phtml47
-rw-r--r--tests/app/Models/UserQueryTest.php229
10 files changed, 505 insertions, 104 deletions
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index 38ccd2b2d..fc92aa0c2 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -241,13 +241,16 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
* checking if categories and feeds are still in use.
*/
public function queriesAction() {
+ $category_dao = new FreshRSS_CategoryDAO();
+ $feed_dao = FreshRSS_Factory::createFeedDao();
if (Minz_Request::isPost()) {
- $queries = Minz_Request::param('queries', array());
+ $params = Minz_Request::param('queries', array());
- foreach ($queries as $key => $query) {
+ foreach ($params as $key => $query) {
if (!$query['name']) {
$query['name'] = _t('conf.query.number', $key + 1);
}
+ $queries[] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao);
}
FreshRSS_Context::$user_conf->queries = $queries;
FreshRSS_Context::$user_conf->save();
@@ -255,62 +258,9 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
Minz_Request::good(_t('feedback.conf.updated'),
array('c' => 'configure', 'a' => 'queries'));
} else {
- $this->view->query_get = array();
- $cat_dao = new FreshRSS_CategoryDAO();
- $feed_dao = FreshRSS_Factory::createFeedDao();
+ $this->view->queries = array();
foreach (FreshRSS_Context::$user_conf->queries as $key => $query) {
- if (!isset($query['get'])) {
- continue;
- }
-
- switch ($query['get'][0]) {
- case 'c':
- $category = $cat_dao->searchById(substr($query['get'], 2));
-
- $deprecated = true;
- $cat_name = '';
- if ($category) {
- $cat_name = $category->name();
- $deprecated = false;
- }
-
- $this->view->query_get[$key] = array(
- 'type' => 'category',
- 'name' => $cat_name,
- 'deprecated' => $deprecated,
- );
- break;
- case 'f':
- $feed = $feed_dao->searchById(substr($query['get'], 2));
-
- $deprecated = true;
- $feed_name = '';
- if ($feed) {
- $feed_name = $feed->name();
- $deprecated = false;
- }
-
- $this->view->query_get[$key] = array(
- 'type' => 'feed',
- 'name' => $feed_name,
- 'deprecated' => $deprecated,
- );
- break;
- case 's':
- $this->view->query_get[$key] = array(
- 'type' => 'favorite',
- 'name' => 'favorite',
- 'deprecated' => false,
- );
- break;
- case 'a':
- $this->view->query_get[$key] = array(
- 'type' => 'all',
- 'name' => 'all',
- 'deprecated' => false,
- );
- break;
- }
+ $this->view->queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao);
}
}
@@ -325,16 +275,17 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
* lean data.
*/
public function addQueryAction() {
- $whitelist = array('get', 'order', 'name', 'search', 'state');
- $queries = FreshRSS_Context::$user_conf->queries;
- $query = Minz_Request::params();
- $query['name'] = _t('conf.query.number', count($queries) + 1);
- foreach ($query as $key => $value) {
- if (!in_array($key, $whitelist)) {
- unset($query[$key]);
- }
+ $category_dao = new FreshRSS_CategoryDAO();
+ $feed_dao = FreshRSS_Factory::createFeedDao();
+ $queries = array();
+ foreach (FreshRSS_Context::$user_conf->queries as $key => $query) {
+ $queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao);
}
- $queries[] = $query;
+ $params = Minz_Request::params();
+ $params['url'] = Minz_Url::display(array('params' => $params));
+ $params['name'] = _t('conf.query.number', count($queries) + 1);
+ $queries[] = new FreshRSS_UserQuery($params, $feed_dao, $category_dao);
+
FreshRSS_Context::$user_conf->queries = $queries;
FreshRSS_Context::$user_conf->save();
diff --git a/app/Exceptions/DAOException.php b/app/Exceptions/DAOException.php
new file mode 100644
index 000000000..6bd8f4ff0
--- /dev/null
+++ b/app/Exceptions/DAOException.php
@@ -0,0 +1,5 @@
+<?php
+
+class FreshRSS_DAOException extends \Exception {
+
+}
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index 27a558522..4eee226ba 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -1,6 +1,6 @@
<?php
-class FreshRSS_CategoryDAO extends Minz_ModelPdo {
+class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable{
public function addCategory($valuesTmp) {
$sql = 'INSERT INTO `' . $this->prefix . 'category`(name) VALUES(?)';
$stm = $this->bd->prepare($sql);
diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php
index eeb1f2f4c..d7689752f 100644
--- a/app/Models/ConfigurationSetter.php
+++ b/app/Models/ConfigurationSetter.php
@@ -117,12 +117,7 @@ class FreshRSS_ConfigurationSetter {
private function _queries(&$data, $values) {
$data['queries'] = array();
foreach ($values as $value) {
- $value = array_filter($value);
- $params = $value;
- unset($params['name']);
- unset($params['url']);
- $value['url'] = Minz_Url::display(array('params' => $params));
- $data['queries'][] = $value;
+ $data['queries'][] = $value->toArray();
}
}
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index cf75a02c9..b8a1a43b0 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -1,6 +1,6 @@
<?php
-class FreshRSS_EntryDAO extends Minz_ModelPdo {
+class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable{
public function isCompressed() {
return parent::$sharedDbType !== 'sqlite';
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 74597c730..e8b07acbd 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -1,6 +1,6 @@
<?php
-class FreshRSS_FeedDAO extends Minz_ModelPdo {
+class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable{
public function addFeed($valuesTmp) {
$sql = 'INSERT INTO `' . $this->prefix . 'feed` (url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history, ttl) VALUES(?, ?, ?, ?, ?, ?, 10, ?, 0, -2, -2)';
$stm = $this->bd->prepare($sql);
diff --git a/app/Models/Searchable.php b/app/Models/Searchable.php
new file mode 100644
index 000000000..d5bcea49d
--- /dev/null
+++ b/app/Models/Searchable.php
@@ -0,0 +1,6 @@
+<?php
+
+interface FreshRSS_Searchable {
+
+ public function searchById($id);
+}
diff --git a/app/Models/UserQuery.php b/app/Models/UserQuery.php
new file mode 100644
index 000000000..754b6996b
--- /dev/null
+++ b/app/Models/UserQuery.php
@@ -0,0 +1,226 @@
+<?php
+
+/**
+ * Contains the description of a user query
+ *
+ * It allows to extract the meaningful bits of the query to be manipulated in an
+ * easy way.
+ */
+class FreshRSS_UserQuery {
+
+ private $deprecated = false;
+ private $get;
+ private $get_name;
+ private $get_type;
+ private $name;
+ private $order;
+ private $search;
+ private $state;
+ private $url;
+ private $feed_dao;
+ private $category_dao;
+
+ /**
+ * @param array $query
+ * @param FreshRSS_Searchable $feed_dao
+ * @param FreshRSS_Searchable $category_dao
+ */
+ public function __construct($query, FreshRSS_Searchable $feed_dao = null, FreshRSS_Searchable $category_dao = null) {
+ $this->category_dao = $category_dao;
+ $this->feed_dao = $feed_dao;
+ if (isset($query['get'])) {
+ $this->parseGet($query['get']);
+ }
+ if (isset($query['name'])) {
+ $this->name = $query['name'];
+ }
+ if (isset($query['order'])) {
+ $this->order = $query['order'];
+ }
+ if (!isset($query['search'])) {
+ $query['search'] = '';
+ }
+ // linked to deeply with the search object, need to use dependency injection
+ $this->search = new FreshRSS_Search($query['search']);
+ if (isset($query['state'])) {
+ $this->state = $query['state'];
+ }
+ if (isset($query['url'])) {
+ $this->url = $query['url'];
+ }
+ }
+
+ /**
+ * Convert the current object to an array.
+ *
+ * @return array
+ */
+ public function toArray() {
+ return array_filter(array(
+ 'get' => $this->get,
+ 'name' => $this->name,
+ 'order' => $this->order,
+ 'search' => $this->search->__toString(),
+ 'state' => $this->state,
+ 'url' => $this->url,
+ ));
+ }
+
+ /**
+ * Parse the get parameter in the query string to extract its name and
+ * type
+ *
+ * @param string $get
+ */
+ private function parseGet($get) {
+ $this->get = $get;
+ if (preg_match('/(?P<type>[acfs])(_(?P<id>\d+))?/', $get, $matches)) {
+ switch ($matches['type']) {
+ case 'a':
+ $this->parseAll();
+ break;
+ case 'c':
+ $this->parseCategory($matches['id']);
+ break;
+ case 'f':
+ $this->parseFeed($matches['id']);
+ break;
+ case 's':
+ $this->parseFavorite();
+ break;
+ }
+ }
+ }
+
+ /**
+ * Parse the query string when it is an "all" query
+ */
+ private function parseAll() {
+ $this->get_name = 'all';
+ $this->get_type = 'all';
+ }
+
+ /**
+ * Parse the query string when it is a "category" query
+ *
+ * @param integer $id
+ * @throws FreshRSS_DAOException
+ */
+ private function parseCategory($id) {
+ if (is_null($this->category_dao)) {
+ throw new FreshRSS_DAOException('Category DAO is not loaded i UserQuery');
+ }
+ $category = $this->category_dao->searchById($id);
+ if ($category) {
+ $this->get_name = $category->name();
+ } else {
+ $this->deprecated = true;
+ }
+ $this->get_type = 'category';
+ }
+
+ /**
+ * Parse the query string when it is a "feed" query
+ *
+ * @param integer $id
+ * @throws FreshRSS_DAOException
+ */
+ private function parseFeed($id) {
+ if (is_null($this->feed_dao)) {
+ throw new FreshRSS_DAOException('Feed DAO is not loaded i UserQuery');
+ }
+ $feed = $this->feed_dao->searchById($id);
+ if ($feed) {
+ $this->get_name = $feed->name();
+ } else {
+ $this->deprecated = true;
+ }
+ $this->get_type = 'feed';
+ }
+
+ /**
+ * Parse the query string when it is a "favorite" query
+ */
+ private function parseFavorite() {
+ $this->get_name = 'favorite';
+ $this->get_type = 'favorite';
+ }
+
+ /**
+ * Check if the current user query is deprecated.
+ * It is deprecated if the category or the feed used in the query are
+ * not existing.
+ *
+ * @return boolean
+ */
+ public function isDeprecated() {
+ return $this->deprecated;
+ }
+
+ /**
+ * Check if the user query has parameters.
+ * If the type is 'all', it is considered equal to no parameters
+ *
+ * @return boolean
+ */
+ public function hasParameters() {
+ if ($this->get_type === 'all') {
+ return false;
+ }
+ if ($this->hasSearch()) {
+ return true;
+ }
+ if ($this->state) {
+ return true;
+ }
+ if ($this->order) {
+ return true;
+ }
+ if ($this->get) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Check if there is a search in the search object
+ *
+ * @return boolean
+ */
+ public function hasSearch() {
+ return $this->search->getRawInput() != "";
+ }
+
+ public function getGet() {
+ return $this->get;
+ }
+
+ public function getGetName() {
+ return $this->get_name;
+ }
+
+ public function getGetType() {
+ return $this->get_type;
+ }
+
+ public function getName() {
+ return $this->name;
+ }
+
+ public function getOrder() {
+ return $this->order;
+ }
+
+ public function getSearch() {
+ return $this->search;
+ }
+
+ public function getState() {
+ return $this->state;
+ }
+
+ public function getUrl() {
+ return $this->url;
+ }
+
+}
diff --git a/app/views/configure/queries.phtml b/app/views/configure/queries.phtml
index 5f449deb3..69efcf365 100644
--- a/app/views/configure/queries.phtml
+++ b/app/views/configure/queries.phtml
@@ -6,27 +6,28 @@
<form method="post" action="<?php echo _url('configure', 'queries'); ?>">
<legend><?php echo _t('conf.query'); ?></legend>
- <?php foreach (FreshRSS_Context::$user_conf->queries as $key => $query) { ?>
+ <?php foreach ($this->queries as $key => $query) { ?>
<div class="form-group" id="query-group-<?php echo $key; ?>">
<label class="group-name" for="queries_<?php echo $key; ?>_name">
<?php echo _t('conf.query.number', $key + 1); ?>
</label>
<div class="group-controls">
- <input type="hidden" id="queries_<?php echo $key; ?>_search" name="queries[<?php echo $key; ?>][search]" value="<?php echo isset($query['search']) ? $query['search'] : ""; ?>"/>
- <input type="hidden" id="queries_<?php echo $key; ?>_state" name="queries[<?php echo $key; ?>][state]" value="<?php echo isset($query['state']) ? $query['state'] : ""; ?>"/>
- <input type="hidden" id="queries_<?php echo $key; ?>_order" name="queries[<?php echo $key; ?>][order]" value="<?php echo isset($query['order']) ? $query['order'] : ""; ?>"/>
- <input type="hidden" id="queries_<?php echo $key; ?>_get" name="queries[<?php echo $key; ?>][get]" value="<?php echo isset($query['get']) ? $query['get'] : ""; ?>"/>
+ <input type="hidden" id="queries_<?php echo $key; ?>_search" name="queries[<?php echo $key; ?>][url]" value="<?php echo $query->getUrl(); ?>"/>
+ <input type="hidden" id="queries_<?php echo $key; ?>_search" name="queries[<?php echo $key; ?>][search]" value="<?php echo $query->getSearch(); ?>"/>
+ <input type="hidden" id="queries_<?php echo $key; ?>_state" name="queries[<?php echo $key; ?>][state]" value="<?php echo $query->getState(); ?>"/>
+ <input type="hidden" id="queries_<?php echo $key; ?>_order" name="queries[<?php echo $key; ?>][order]" value="<?php echo $query->getOrder(); ?>"/>
+ <input type="hidden" id="queries_<?php echo $key; ?>_get" name="queries[<?php echo $key; ?>][get]" value="<?php echo $query->getGet(); ?>"/>
<div class="stick">
<input class="extend"
type="text"
id="queries_<?php echo $key; ?>_name"
name="queries[<?php echo $key; ?>][name]"
- value="<?php echo $query['name']; ?>"
+ value="<?php echo $query->getName(); ?>"
/>
- <a class="btn" href="<?php echo $query['url']; ?>">
+ <a class="btn" href="<?php echo $query->getUrl(); ?>">
<?php echo _i('link'); ?>
</a>
@@ -35,23 +36,11 @@
</a>
</div>
- <?php
- $exist = (isset($query['search']) ? 1 : 0)
- + (isset($query['state']) ? 1 : 0)
- + (isset($query['order']) ? 1 : 0)
- + (isset($query['get']) ? 1 : 0);
- // If the only filter is "all" articles, we consider there is no filter
- $exist = ($exist === 1 && isset($query['get']) && $query['get'] === 'a') ? 0 : $exist;
-
- $deprecated = (isset($this->query_get[$key]) &&
- $this->query_get[$key]['deprecated']);
- ?>
-
- <?php if ($exist === 0) { ?>
+ <?php if (!$query->hasParameters()) { ?>
<div class="alert alert-warn">
<div class="alert-head"><?php echo _t('conf.query.no_filter'); ?></div>
</div>
- <?php } elseif ($deprecated) { ?>
+ <?php } elseif ($query->isDeprecated()) { ?>
<div class="alert alert-error">
<div class="alert-head"><?php echo _t('conf.query.deprecated'); ?></div>
</div>
@@ -60,20 +49,20 @@
<div class="alert-head"><?php echo _t('conf.query.filter'); ?></div>
<ul>
- <?php if (isset($query['search'])) { ?>
- <li class="item"><?php echo _t('conf.query.search', $query['search']); ?></li>
+ <?php if ($query->hasSearch()) { ?>
+ <li class="item"><?php echo _t('conf.query.search', $query->getSearch()->getRawInput()); ?></li>
<?php } ?>
- <?php if (isset($query['state'])) { ?>
- <li class="item"><?php echo _t('conf.query.state_' . $query['state']); ?></li>
+ <?php if ($query->getState()) { ?>
+ <li class="item"><?php echo _t('conf.query.state_' . $query->getState()); ?></li>
<?php } ?>
- <?php if (isset($query['order'])) { ?>
- <li class="item"><?php echo _t('conf.query.order_' . strtolower($query['order'])); ?></li>
+ <?php if ($query->getOrder()) { ?>
+ <li class="item"><?php echo _t('conf.query.order_' . strtolower($query->getOrder())); ?></li>
<?php } ?>
- <?php if (isset($query['get'])) { ?>
- <li class="item"><?php echo _t('conf.query.get_' . $this->query_get[$key]['type'], $this->query_get[$key]['name']); ?></li>
+ <?php if ($query->getGet()) { ?>
+ <li class="item"><?php echo _t('conf.query.get_' . $query->getGetType(), $query->getGetName()); ?></li>
<?php } ?>
</ul>
</div>
diff --git a/tests/app/Models/UserQueryTest.php b/tests/app/Models/UserQueryTest.php
new file mode 100644
index 000000000..2234be6e1
--- /dev/null
+++ b/tests/app/Models/UserQueryTest.php
@@ -0,0 +1,229 @@
+<?php
+
+/**
+ * Description of UserQueryTest
+ */
+class UserQueryTest extends \PHPUnit_Framework_TestCase {
+
+ public function test__construct_whenAllQuery_storesAllParameters() {
+ $query = array('get' => 'a');
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertEquals('all', $user_query->getGetName());
+ $this->assertEquals('all', $user_query->getGetType());
+ }
+
+ public function test__construct_whenFavoriteQuery_storesFavoriteParameters() {
+ $query = array('get' => 's');
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertEquals('favorite', $user_query->getGetName());
+ $this->assertEquals('favorite', $user_query->getGetType());
+ }
+
+ /**
+ * @expectedException Exceptions/FreshRSS_DAOException
+ * @expectedExceptionMessage Category DAO is not loaded in UserQuery
+ */
+ public function test__construct_whenCategoryQueryAndNoDao_throwsException() {
+ $this->markTestIncomplete('There is a problem with the exception autoloading. We need to make a better autoloading process');
+ $query = array('get' => 'c_1');
+ new FreshRSS_UserQuery($query);
+ }
+
+ public function test__construct_whenCategoryQuery_storesCategoryParameters() {
+ $category_name = 'some category name';
+ $cat = $this->getMock('FreshRSS_Category');
+ $cat->expects($this->atLeastOnce())
+ ->method('name')
+ ->withAnyParameters()
+ ->willReturn($category_name);
+ $cat_dao = $this->getMock('FreshRSS_Searchable');
+ $cat_dao->expects($this->atLeastOnce())
+ ->method('searchById')
+ ->withAnyParameters()
+ ->willReturn($cat);
+ $query = array('get' => 'c_1');
+ $user_query = new FreshRSS_UserQuery($query, null, $cat_dao);
+ $this->assertEquals($category_name, $user_query->getGetName());
+ $this->assertEquals('category', $user_query->getGetType());
+ }
+
+ /**
+ * @expectedException Exceptions/FreshRSS_DAOException
+ * @expectedExceptionMessage Feed DAO is not loaded in UserQuery
+ */
+ public function test__construct_whenFeedQueryAndNoDao_throwsException() {
+ $this->markTestIncomplete('There is a problem with the exception autoloading. We need to make a better autoloading process');
+ $query = array('get' => 'c_1');
+ new FreshRSS_UserQuery($query);
+ }
+
+ public function test__construct_whenFeedQuery_storesFeedParameters() {
+ $feed_name = 'some feed name';
+ $feed = $this->getMock('FreshRSS_Feed', array(), array('', false));
+ $feed->expects($this->atLeastOnce())
+ ->method('name')
+ ->withAnyParameters()
+ ->willReturn($feed_name);
+ $feed_dao = $this->getMock('FreshRSS_Searchable');
+ $feed_dao->expects($this->atLeastOnce())
+ ->method('searchById')
+ ->withAnyParameters()
+ ->willReturn($feed);
+ $query = array('get' => 'f_1');
+ $user_query = new FreshRSS_UserQuery($query, $feed_dao, null);
+ $this->assertEquals($feed_name, $user_query->getGetName());
+ $this->assertEquals('feed', $user_query->getGetType());
+ }
+
+ public function test__construct_whenUnknownQuery_doesStoreParameters() {
+ $query = array('get' => 'q');
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertNull($user_query->getGetName());
+ $this->assertNull($user_query->getGetType());
+ }
+
+ public function test__construct_whenName_storesName() {
+ $name = 'some name';
+ $query = array('name' => $name);
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertEquals($name, $user_query->getName());
+ }
+
+ public function test__construct_whenOrder_storesOrder() {
+ $order = 'some order';
+ $query = array('order' => $order);
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertEquals($order, $user_query->getOrder());
+ }
+
+ public function test__construct_whenState_storesState() {
+ $state = 'some state';
+ $query = array('state' => $state);
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertEquals($state, $user_query->getState());
+ }
+
+ public function test__construct_whenUrl_storesUrl() {
+ $url = 'some url';
+ $query = array('url' => $url);
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertEquals($url, $user_query->getUrl());
+ }
+
+ public function testToArray_whenNoData_returnsEmptyArray() {
+ $user_query = new FreshRSS_UserQuery(array());
+ $this->assertInternalType('array', $user_query->toArray());
+ $this->assertCount(0, $user_query->toArray());
+ }
+
+ public function testToArray_whenData_returnsArray() {
+ $query = array(
+ 'get' => 's',
+ 'name' => 'some name',
+ 'order' => 'some order',
+ 'search' => 'some search',
+ 'state' => 'some state',
+ 'url' => 'some url',
+ );
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertInternalType('array', $user_query->toArray());
+ $this->assertCount(6, $user_query->toArray());
+ $this->assertEquals($query, $user_query->toArray());
+ }
+
+ public function testHasSearch_whenSearch_returnsTrue() {
+ $query = array(
+ 'search' => 'some search',
+ );
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertTrue($user_query->hasSearch());
+ }
+
+ public function testHasSearch_whenNoSearch_returnsFalse() {
+ $user_query = new FreshRSS_UserQuery(array());
+ $this->assertFalse($user_query->hasSearch());
+ }
+
+ public function testHasParameters_whenAllQuery_returnsFalse() {
+ $query = array('get' => 'a');
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertFalse($user_query->hasParameters());
+ }
+
+ public function testHasParameters_whenNoParameter_returnsFalse() {
+ $query = array();
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertFalse($user_query->hasParameters());
+ }
+
+ public function testHasParameters_whenParameter_returnTrue() {
+ $query = array('get' => 's');
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertTrue($user_query->hasParameters());
+ }
+
+ public function testIsDeprecated_whenCategoryExists_returnFalse() {
+ $cat = $this->getMock('FreshRSS_Category');
+ $cat_dao = $this->getMock('FreshRSS_Searchable');
+ $cat_dao->expects($this->atLeastOnce())
+ ->method('searchById')
+ ->withAnyParameters()
+ ->willReturn($cat);
+ $query = array('get' => 'c_1');
+ $user_query = new FreshRSS_UserQuery($query, null, $cat_dao);
+ $this->assertFalse($user_query->isDeprecated());
+ }
+
+ public function testIsDeprecated_whenCategoryDoesNotExist_returnTrue() {
+ $cat_dao = $this->getMock('FreshRSS_Searchable');
+ $cat_dao->expects($this->atLeastOnce())
+ ->method('searchById')
+ ->withAnyParameters()
+ ->willReturn(null);
+ $query = array('get' => 'c_1');
+ $user_query = new FreshRSS_UserQuery($query, null, $cat_dao);
+ $this->assertTrue($user_query->isDeprecated());
+ }
+
+ public function testIsDeprecated_whenFeedExists_returnFalse() {
+ $feed = $this->getMock('FreshRSS_Feed', array(), array('', false));
+ $feed_dao = $this->getMock('FreshRSS_Searchable');
+ $feed_dao->expects($this->atLeastOnce())
+ ->method('searchById')
+ ->withAnyParameters()
+ ->willReturn($feed);
+ $query = array('get' => 'f_1');
+ $user_query = new FreshRSS_UserQuery($query, $feed_dao, null);
+ $this->assertFalse($user_query->isDeprecated());
+ }
+
+ public function testIsDeprecated_whenFeedDoesNotExist_returnTrue() {
+ $feed_dao = $this->getMock('FreshRSS_Searchable');
+ $feed_dao->expects($this->atLeastOnce())
+ ->method('searchById')
+ ->withAnyParameters()
+ ->willReturn(null);
+ $query = array('get' => 'f_1');
+ $user_query = new FreshRSS_UserQuery($query, $feed_dao, null);
+ $this->assertTrue($user_query->isDeprecated());
+ }
+
+ public function testIsDeprecated_whenAllQuery_returnFalse() {
+ $query = array('get' => 'a');
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertFalse($user_query->isDeprecated());
+ }
+
+ public function testIsDeprecated_whenFavoriteQuery_returnFalse() {
+ $query = array('get' => 's');
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertFalse($user_query->isDeprecated());
+ }
+
+ public function testIsDeprecated_whenUnknownQuery_returnFalse() {
+ $query = array('get' => 'q');
+ $user_query = new FreshRSS_UserQuery($query);
+ $this->assertFalse($user_query->isDeprecated());
+ }
+
+}