summaryrefslogtreecommitdiffstats
path: root/tests/Unit/Service/ItemServiceTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Service/ItemServiceTest.php')
-rw-r--r--tests/Unit/Service/ItemServiceTest.php239
1 files changed, 149 insertions, 90 deletions
diff --git a/tests/Unit/Service/ItemServiceTest.php b/tests/Unit/Service/ItemServiceTest.php
index 8ec1a5c45..0f79cfd04 100644
--- a/tests/Unit/Service/ItemServiceTest.php
+++ b/tests/Unit/Service/ItemServiceTest.php
@@ -5,10 +5,10 @@
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Tests\Unit\Service;
@@ -20,10 +20,13 @@ use \OCA\News\Db\Item;
use \OCA\News\Db\FeedType;
-class ItemServiceTest extends \PHPUnit_Framework_TestCase {
+class ItemServiceTest extends \PHPUnit_Framework_TestCase
+{
private $mapper;
- /** @var ItemService */
+ /**
+ * @var ItemService
+ */
private $itemService;
private $user;
private $response;
@@ -33,7 +36,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
private $config;
private $systemConfig;
- protected function setUp(){
+ protected function setUp()
+ {
$this->time = 222;
$this->timeFactory = $this->getMockBuilder('\OCA\News\Utility\Time')
->disableOriginalConstructor()
@@ -48,15 +52,19 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()
->getMock();
$this->config = $this->getMockBuilder(
- '\OCA\News\Config\Config')
+ '\OCA\News\Config\Config'
+ )
->disableOriginalConstructor()
->getMock();
$this->systemConfig = $this->getMockBuilder(
- 'OCP\IConfig')
+ 'OCP\IConfig'
+ )
->disableOriginalConstructor()
->getMock();
- $this->itemService = new ItemService($this->mapper,
- $this->timeFactory, $this->config, $this->systemConfig);
+ $this->itemService = new ItemService(
+ $this->mapper,
+ $this->timeFactory, $this->config, $this->systemConfig
+ );
$this->user = 'jack';
$this->id = 3;
$this->updatedSince = 20333;
@@ -67,68 +75,83 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testFindAllNewFeed(){
+ public function testFindAllNewFeed()
+ {
$type = FeedType::FEED;
$this->mapper->expects($this->once())
->method('findAllNewFeed')
- ->with($this->equalTo($this->id),
- $this->equalTo($this->updatedSince),
- $this->equalTo($this->showAll),
- $this->equalTo($this->user))
+ ->with(
+ $this->equalTo($this->id),
+ $this->equalTo($this->updatedSince),
+ $this->equalTo($this->showAll),
+ $this->equalTo($this->user)
+ )
->will($this->returnValue($this->response));
$result = $this->itemService->findAllNew(
$this->id, $type, $this->updatedSince, $this->showAll,
- $this->user);
+ $this->user
+ );
$this->assertEquals($this->response, $result);
}
- public function testFindAllNewFolder(){
+ public function testFindAllNewFolder()
+ {
$type = FeedType::FOLDER;
$this->mapper->expects($this->once())
->method('findAllNewFolder')
- ->with($this->equalTo($this->id),
- $this->equalTo($this->updatedSince),
- $this->equalTo($this->showAll),
- $this->equalTo($this->user))
+ ->with(
+ $this->equalTo($this->id),
+ $this->equalTo($this->updatedSince),
+ $this->equalTo($this->showAll),
+ $this->equalTo($this->user)
+ )
->will($this->returnValue($this->response));
$result = $this->itemService->findAllNew(
$this->id, $type, $this->updatedSince, $this->showAll,
- $this->user);
+ $this->user
+ );
$this->assertEquals($this->response, $result);
}
- public function testFindAllNew(){
+ public function testFindAllNew()
+ {
$type = FeedType::STARRED;
$this->mapper->expects($this->once())
->method('findAllNew')
- ->with( $this->equalTo($this->updatedSince),
- $this->equalTo($type),
- $this->equalTo($this->showAll),
- $this->equalTo($this->user))
+ ->with(
+ $this->equalTo($this->updatedSince),
+ $this->equalTo($type),
+ $this->equalTo($this->showAll),
+ $this->equalTo($this->user)
+ )
->will($this->returnValue($this->response));
$result = $this->itemService->findAllNew(
$this->id, $type, $this->updatedSince, $this->showAll,
- $this->user);
+ $this->user
+ );
$this->assertEquals($this->response, $result);
}
- public function testFindAllFeed(){
+ public function testFindAllFeed()
+ {
$type = FeedType::FEED;
$this->mapper->expects($this->once())
->method('findAllFeed')
- ->with($this->equalTo($this->id),
- $this->equalTo($this->limit),
- $this->equalTo($this->offset),
- $this->equalTo($this->showAll),
- $this->equalTo(false),
- $this->equalTo($this->user),
- $this->equalTo([]))
+ ->with(
+ $this->equalTo($this->id),
+ $this->equalTo($this->limit),
+ $this->equalTo($this->offset),
+ $this->equalTo($this->showAll),
+ $this->equalTo(false),
+ $this->equalTo($this->user),
+ $this->equalTo([])
+ )
->will($this->returnValue($this->response));
$result = $this->itemService->findAll(
@@ -139,17 +162,20 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testFindAllFolder(){
+ public function testFindAllFolder()
+ {
$type = FeedType::FOLDER;
$this->mapper->expects($this->once())
->method('findAllFolder')
- ->with($this->equalTo($this->id),
- $this->equalTo($this->limit),
- $this->equalTo($this->offset),
- $this->equalTo($this->showAll),
- $this->equalTo(true),
- $this->equalTo($this->user),
- $this->equalTo([]))
+ ->with(
+ $this->equalTo($this->id),
+ $this->equalTo($this->limit),
+ $this->equalTo($this->offset),
+ $this->equalTo($this->showAll),
+ $this->equalTo(true),
+ $this->equalTo($this->user),
+ $this->equalTo([])
+ )
->will($this->returnValue($this->response));
$result = $this->itemService->findAll(
@@ -160,17 +186,20 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testFindAll(){
+ public function testFindAll()
+ {
$type = FeedType::STARRED;
$this->mapper->expects($this->once())
->method('findAll')
- ->with( $this->equalTo($this->limit),
- $this->equalTo($this->offset),
- $this->equalTo($type),
- $this->equalTo($this->showAll),
- $this->equalTo(true),
- $this->equalTo($this->user),
- $this->equalTo([]))
+ ->with(
+ $this->equalTo($this->limit),
+ $this->equalTo($this->offset),
+ $this->equalTo($type),
+ $this->equalTo($this->showAll),
+ $this->equalTo(true),
+ $this->equalTo($this->user),
+ $this->equalTo([])
+ )
->will($this->returnValue($this->response));
$result = $this->itemService->findAll(
@@ -181,18 +210,21 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testFindAllSearch(){
+ public function testFindAllSearch()
+ {
$type = FeedType::STARRED;
$search = ['test'];
$this->mapper->expects($this->once())
->method('findAll')
- ->with( $this->equalTo($this->limit),
- $this->equalTo($this->offset),
- $this->equalTo($type),
- $this->equalTo($this->showAll),
- $this->equalTo(true),
- $this->equalTo($this->user),
- $this->equalTo($search))
+ ->with(
+ $this->equalTo($this->limit),
+ $this->equalTo($this->offset),
+ $this->equalTo($type),
+ $this->equalTo($this->showAll),
+ $this->equalTo(true),
+ $this->equalTo($this->user),
+ $this->equalTo($search)
+ )
->will($this->returnValue($this->response));
$result = $this->itemService->findAll(
@@ -204,7 +236,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
- public function testStar(){
+ public function testStar()
+ {
$itemId = 3;
$feedId = 5;
$guidHash = md5('hihi');
@@ -224,7 +257,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
->with(
$this->equalTo($guidHash),
$this->equalTo($feedId),
- $this->equalTo($this->user))
+ $this->equalTo($this->user)
+ )
->will($this->returnValue($item));
$this->mapper->expects($this->once())
@@ -237,7 +271,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testUnstar(){
+ public function testUnstar()
+ {
$itemId = 3;
$feedId = 5;
$guidHash = md5('hihi');
@@ -258,7 +293,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
->with(
$this->equalTo($guidHash),
$this->equalTo($feedId),
- $this->equalTo($this->user))
+ $this->equalTo($this->user)
+ )
->will($this->returnValue($item));
$this->mapper->expects($this->once())
@@ -270,7 +306,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
$this->assertFalse($item->isStarred());
}
- public function testRead(){
+ public function testRead()
+ {
$itemId = 3;
$item = new Item();
$item->setStatus(128);
@@ -285,17 +322,20 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
$this->mapper->expects($this->once())
->method('readItem')
- ->with($this->equalTo($itemId),
- $this->equalTo(true),
- $this->equalTo($this->time),
- $this->equalTo($this->user))
+ ->with(
+ $this->equalTo($itemId),
+ $this->equalTo(true),
+ $this->equalTo($this->time),
+ $this->equalTo($this->user)
+ )
->will($this->returnValue($item));
$this->itemService->read($itemId, true, $this->user);
}
- public function testReadDoesNotExist(){
+ public function testReadDoesNotExist()
+ {
$this->setExpectedException(
'\OCA\News\Service\ServiceNotFoundException'
@@ -307,7 +347,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
$this->itemService->read(1, true, $this->user);
}
- public function testStarDoesNotExist(){
+ public function testStarDoesNotExist()
+ {
$this->setExpectedException(
'\OCA\News\Service\ServiceNotFoundException'
@@ -320,50 +361,60 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testReadAll(){
+ public function testReadAll()
+ {
$highestItemId = 6;
$this->mapper->expects($this->once())
->method('readAll')
- ->with($this->equalTo($highestItemId),
+ ->with(
+ $this->equalTo($highestItemId),
$this->equalTo($this->time),
- $this->equalTo($this->user));
+ $this->equalTo($this->user)
+ );
$this->itemService->readAll($highestItemId, $this->user);
}
- public function testReadFolder(){
+ public function testReadFolder()
+ {
$folderId = 3;
$highestItemId = 6;
$this->mapper->expects($this->once())
->method('readFolder')
- ->with($this->equalTo($folderId),
+ ->with(
+ $this->equalTo($folderId),
$this->equalTo($highestItemId),
$this->equalTo($this->time),
- $this->equalTo($this->user));
+ $this->equalTo($this->user)
+ );
$this->itemService->readFolder($folderId, $highestItemId, $this->user);
}
- public function testReadFeed(){
+ public function testReadFeed()
+ {
$feedId = 3;
$highestItemId = 6;
$this->mapper->expects($this->once())
->method('readFeed')
- ->with($this->equalTo($feedId),
+ ->with(
+ $this->equalTo($feedId),
$this->equalTo($highestItemId),
$this->equalTo($this->time),
- $this->equalTo($this->user));
+ $this->equalTo($this->user)
+ );
$this->itemService->readFeed($feedId, $highestItemId, $this->user);
}
- public function testAutoPurgeOldWillPurgeOld(){
+ public function testAutoPurgeOldWillPurgeOld()
+ {
$this->config->expects($this->once())
->method('getAutoPurgeCount')
->will($this->returnValue(2));
@@ -374,7 +425,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
$this->itemService->autoPurgeOld();
}
- public function testAutoPurgeOldWontPurgeOld(){
+ public function testAutoPurgeOldWontPurgeOld()
+ {
$this->config->expects($this->once())
->method('getAutoPurgeCount')
->will($this->returnValue(-1));
@@ -385,7 +437,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testGetNewestItemId() {
+ public function testGetNewestItemId()
+ {
$this->mapper->expects($this->once())
->method('getNewestItemId')
->with($this->equalTo($this->user))
@@ -396,12 +449,15 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testGetNewestItemIdDoesNotExist() {
+ public function testGetNewestItemIdDoesNotExist()
+ {
$this->mapper->expects($this->once())
->method('getNewestItemId')
->with($this->equalTo($this->user))
- ->will($this->throwException(
- new DoesNotExistException('There are no items'))
+ ->will(
+ $this->throwException(
+ new DoesNotExistException('There are no items')
+ )
);
$this->setExpectedException(
@@ -411,7 +467,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testStarredCount(){
+ public function testStarredCount()
+ {
$star = 18;
$this->mapper->expects($this->once())
@@ -425,7 +482,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testGetUnreadOrStarred(){
+ public function testGetUnreadOrStarred()
+ {
$star = 18;
$this->mapper->expects($this->once())
@@ -439,7 +497,8 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
- public function testDeleteUser() {
+ public function testDeleteUser()
+ {
$this->mapper->expects($this->once())
->method('deleteUser')
->will($this->returnValue($this->user));