aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-11-04 20:26:30 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-11-04 20:26:30 +0100
commit74639cb1535feddb808a4262e058a67d4a3aef6b (patch)
tree78c5567578751752a3623574cbd768e602a46754 /tests
parent4c99fd689f0778cbf6a987471ebf72b3787739c2 (diff)
parent4525e547faa8781e37f86125110f28248eb67fd3 (diff)
Merge branch 'dev'
Diffstat (limited to 'tests')
-rw-r--r--tests/app/Models/ContextTest.php5
-rw-r--r--tests/app/Models/SearchTest.php293
-rw-r--r--tests/app/Models/UserQueryTest.php229
3 files changed, 527 insertions, 0 deletions
diff --git a/tests/app/Models/ContextTest.php b/tests/app/Models/ContextTest.php
new file mode 100644
index 000000000..4dc8b7757
--- /dev/null
+++ b/tests/app/Models/ContextTest.php
@@ -0,0 +1,5 @@
+<?php
+
+class ContextTest extends \PHPUnit_Framework_TestCase {
+
+}
diff --git a/tests/app/Models/SearchTest.php b/tests/app/Models/SearchTest.php
new file mode 100644
index 000000000..73ff56cc6
--- /dev/null
+++ b/tests/app/Models/SearchTest.php
@@ -0,0 +1,293 @@
+<?php
+
+require_once(LIB_PATH . '/lib_date.php');
+
+class SearchTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @dataProvider provideEmptyInput
+ * @param string|null $input
+ */
+ public function test__construct_whenInputIsEmpty_getsOnlyNullValues($input) {
+ $search = new FreshRSS_Search($input);
+ $this->assertEquals('', $search->getRawInput());
+ $this->assertNull($search->getIntitle());
+ $this->assertNull($search->getMinDate());
+ $this->assertNull($search->getMaxDate());
+ $this->assertNull($search->getMinPubdate());
+ $this->assertNull($search->getMaxPubdate());
+ $this->assertNull($search->getAuthor());
+ $this->assertNull($search->getTags());
+ $this->assertNull($search->getSearch());
+ }
+
+ /**
+ * Return an array of values for the search object.
+ * Here is the description of the values
+ * @return array
+ */
+ public function provideEmptyInput() {
+ return array(
+ array(''),
+ array(null),
+ );
+ }
+
+ /**
+ * @dataProvider provideIntitleSearch
+ * @param string $input
+ * @param string $intitle_value
+ * @param string|null $search_value
+ */
+ public function test__construct_whenInputContainsIntitle_setsIntitlePropery($input, $intitle_value, $search_value) {
+ $search = new FreshRSS_Search($input);
+ $this->assertEquals($intitle_value, $search->getIntitle());
+ $this->assertEquals($search_value, $search->getSearch());
+ }
+
+ /**
+ * @return array
+ */
+ public function provideIntitleSearch() {
+ return array(
+ array('intitle:word1', 'word1', null),
+ array('intitle:word1 word2', 'word1', array('word2')),
+ array('intitle:"word1 word2"', 'word1 word2', null),
+ array("intitle:'word1 word2'", 'word1 word2', null),
+ array('word1 intitle:word2', 'word2', array('word1')),
+ array('word1 intitle:word2 word3', 'word2', array('word1', 'word3')),
+ array('word1 intitle:"word2 word3"', 'word2 word3', array('word1')),
+ array("word1 intitle:'word2 word3'", 'word2 word3', array('word1')),
+ array('intitle:word1 intitle:word2', 'word1', array('intitle:word2')),
+ array('intitle: word1 word2', null, array('word1', 'word2')),
+ array('intitle:123', '123', null),
+ array('intitle:"word1 word2" word3"', 'word1 word2', array('word3"')),
+ array("intitle:'word1 word2' word3'", 'word1 word2', array("word3'")),
+ array('intitle:"word1 word2\' word3"', "word1 word2' word3", null),
+ array("intitle:'word1 word2\" word3'", 'word1 word2" word3', null),
+ array("intitle:word1 'word2 word3' word4", 'word1', array('word2 word3', 'word4')),
+ );
+ }
+
+ /**
+ * @dataProvider provideAuthorSearch
+ * @param string $input
+ * @param string $author_value
+ * @param string|null $search_value
+ */
+ public function test__construct_whenInputContainsAuthor_setsAuthorValue($input, $author_value, $search_value) {
+ $search = new FreshRSS_Search($input);
+ $this->assertEquals($author_value, $search->getAuthor());
+ $this->assertEquals($search_value, $search->getSearch());
+ }
+
+ /**
+ * @return array
+ */
+ public function provideAuthorSearch() {
+ return array(
+ array('author:word1', 'word1', null),
+ array('author:word1 word2', 'word1', array('word2')),
+ array('author:"word1 word2"', 'word1 word2', null),
+ array("author:'word1 word2'", 'word1 word2', null),
+ array('word1 author:word2', 'word2', array('word1')),
+ array('word1 author:word2 word3', 'word2', array('word1', 'word3')),
+ array('word1 author:"word2 word3"', 'word2 word3', array('word1')),
+ array("word1 author:'word2 word3'", 'word2 word3', array('word1')),
+ array('author:word1 author:word2', 'word1', array('author:word2')),
+ array('author: word1 word2', null, array('word1', 'word2')),
+ array('author:123', '123', null),
+ array('author:"word1 word2" word3"', 'word1 word2', array('word3"')),
+ array("author:'word1 word2' word3'", 'word1 word2', array("word3'")),
+ array('author:"word1 word2\' word3"', "word1 word2' word3", null),
+ array("author:'word1 word2\" word3'", 'word1 word2" word3', null),
+ array("author:word1 'word2 word3' word4", 'word1', array('word2 word3', 'word4')),
+ );
+ }
+
+ /**
+ * @dataProvider provideInurlSearch
+ * @param string $input
+ * @param string $inurl_value
+ * @param string|null $search_value
+ */
+ public function test__construct_whenInputContainsInurl_setsInurlValue($input, $inurl_value, $search_value) {
+ $search = new FreshRSS_Search($input);
+ $this->assertEquals($inurl_value, $search->getInurl());
+ $this->assertEquals($search_value, $search->getSearch());
+ }
+
+ /**
+ * @return array
+ */
+ public function provideInurlSearch() {
+ return array(
+ array('inurl:word1', 'word1', null),
+ array('inurl: word1', null, array('word1')),
+ array('inurl:123', '123', null),
+ array('inurl:word1 word2', 'word1', array('word2')),
+ array('inurl:"word1 word2"', '"word1', array('word2"')),
+ array("inurl:word1 'word2 word3' word4", 'word1', array('word2 word3', 'word4')),
+ );
+ }
+
+ /**
+ * @dataProvider provideDateSearch
+ * @param string $input
+ * @param string $min_date_value
+ * @param string $max_date_value
+ */
+ public function test__construct_whenInputContainsDate_setsDateValues($input, $min_date_value, $max_date_value) {
+ $search = new FreshRSS_Search($input);
+ $this->assertEquals($min_date_value, $search->getMinDate());
+ $this->assertEquals($max_date_value, $search->getMaxDate());
+ }
+
+ /**
+ * @return array
+ */
+ public function provideDateSearch() {
+ return array(
+ array('date:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', '1172754000', '1210519800'),
+ array('date:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', '1172754000', '1210516199'),
+ array('date:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172757601', '1210519800'),
+ array('date:2007-03-01/2008-05-11', '1172725200', '1210564799'),
+ array('date:2007-03-01/', '1172725200', ''),
+ array('date:/2008-05-11', '', '1210564799'),
+ );
+ }
+
+ /**
+ * @dataProvider providePubdateSearch
+ * @param string $input
+ * @param string $min_pubdate_value
+ * @param string $max_pubdate_value
+ */
+ public function test__construct_whenInputContainsPubdate_setsPubdateValues($input, $min_pubdate_value, $max_pubdate_value) {
+ $search = new FreshRSS_Search($input);
+ $this->assertEquals($min_pubdate_value, $search->getMinPubdate());
+ $this->assertEquals($max_pubdate_value, $search->getMaxPubdate());
+ }
+
+ /**
+ * @return array
+ */
+ public function providePubdateSearch() {
+ return array(
+ array('pubdate:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', '1172754000', '1210519800'),
+ array('pubdate:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', '1172754000', '1210516199'),
+ array('pubdate:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', '1172757601', '1210519800'),
+ array('pubdate:2007-03-01/2008-05-11', '1172725200', '1210564799'),
+ array('pubdate:2007-03-01/', '1172725200', ''),
+ array('pubdate:/2008-05-11', '', '1210564799'),
+ );
+ }
+
+ /**
+ * @dataProvider provideTagsSearch
+ * @param string $input
+ * @param string $tags_value
+ * @param string|null $search_value
+ */
+ public function test__construct_whenInputContainsTags_setsTagsValue($input, $tags_value, $search_value) {
+ $search = new FreshRSS_Search($input);
+ $this->assertEquals($tags_value, $search->getTags());
+ $this->assertEquals($search_value, $search->getSearch());
+ }
+
+ /**
+ * @return array
+ */
+ public function provideTagsSearch() {
+ return array(
+ array('#word1', array('word1'), null),
+ array('# word1', null, array('#', 'word1')),
+ array('#123', array('123'), null),
+ array('#word1 word2', array('word1'), array('word2')),
+ array('#"word1 word2"', array('"word1'), array('word2"')),
+ array('#word1 #word2', array('word1', 'word2'), null),
+ array("#word1 'word2 word3' word4", array('word1'), array('word2 word3', 'word4')),
+ );
+ }
+
+ /**
+ * @dataProvider provideMultipleSearch
+ * @param string $input
+ * @param string $author_value
+ * @param string $min_date_value
+ * @param string $max_date_value
+ * @param string $intitle_value
+ * @param string $inurl_value
+ * @param string $min_pubdate_value
+ * @param string $max_pubdate_value
+ * @param array $tags_value
+ * @param string|null $search_value
+ */
+ public function test__construct_whenInputContainsMultipleKeywords_setsValues($input, $author_value, $min_date_value, $max_date_value, $intitle_value, $inurl_value, $min_pubdate_value, $max_pubdate_value, $tags_value, $search_value) {
+ $search = new FreshRSS_Search($input);
+ $this->assertEquals($author_value, $search->getAuthor());
+ $this->assertEquals($min_date_value, $search->getMinDate());
+ $this->assertEquals($max_date_value, $search->getMaxDate());
+ $this->assertEquals($intitle_value, $search->getIntitle());
+ $this->assertEquals($inurl_value, $search->getInurl());
+ $this->assertEquals($min_pubdate_value, $search->getMinPubdate());
+ $this->assertEquals($max_pubdate_value, $search->getMaxPubdate());
+ $this->assertEquals($tags_value, $search->getTags());
+ $this->assertEquals($search_value, $search->getSearch());
+ $this->assertEquals($input, $search->getRawInput());
+ }
+
+ public function provideMultipleSearch() {
+ return array(
+ array(
+ 'author:word1 date:2007-03-01/2008-05-11 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 #word5',
+ 'word1',
+ '1172725200',
+ '1210564799',
+ 'word2',
+ 'word3',
+ '1172725200',
+ '1210564799',
+ array('word4', 'word5'),
+ null,
+ ),
+ array(
+ 'word6 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 author:word1 #word5 date:2007-03-01/2008-05-11',
+ 'word1',
+ '1172725200',
+ '1210564799',
+ 'word2',
+ 'word3',
+ '1172725200',
+ '1210564799',
+ array('word4', 'word5'),
+ array('word6'),
+ ),
+ array(
+ 'word6 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 author:word1 #word5 word7 date:2007-03-01/2008-05-11',
+ 'word1',
+ '1172725200',
+ '1210564799',
+ 'word2',
+ 'word3',
+ '1172725200',
+ '1210564799',
+ array('word4', 'word5'),
+ array('word6', 'word7'),
+ ),
+ array(
+ 'word6 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 author:word1 #word5 "word7 word8" date:2007-03-01/2008-05-11',
+ 'word1',
+ '1172725200',
+ '1210564799',
+ 'word2',
+ 'word3',
+ '1172725200',
+ '1210564799',
+ array('word4', 'word5'),
+ array('word7 word8', 'word6'),
+ ),
+ );
+ }
+
+}
diff --git a/tests/app/Models/UserQueryTest.php b/tests/app/Models/UserQueryTest.php
new file mode 100644
index 000000000..a0928d5ae
--- /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_DAO_Exception
+ * @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_DAO_Exception
+ * @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());
+ }
+
+}