diff options
author | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2018-03-27 15:35:06 +0200 |
---|---|---|
committer | Bernhard Posselt <BernhardPosselt@users.noreply.github.com> | 2018-03-27 15:35:06 +0200 |
commit | 5b94705cf3918dc7986c6043b1fbe776bf22958f (patch) | |
tree | 4e8059818a0a913d24938e35238913a721fa6373 /tests | |
parent | f3c9d13551cef5968baea99c2f25085baee0ed5f (diff) |
Core: Fix compatibility with nextcloud codestyle (#280)
Diffstat (limited to 'tests')
45 files changed, 1958 insertions, 1103 deletions
diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php index bcf1cb895..3d1ea71f4 100644 --- a/tests/Integration/Db/FeedMapperTest.php +++ b/tests/Integration/Db/FeedMapperTest.php @@ -5,8 +5,8 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @author Daniel Opitz <dev@copynpaste.de> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Daniel Opitz <dev@copynpaste.de> * @copyright Bernhard Posselt 2015 * @copyright Daniel Opitz 2017 */ @@ -17,9 +17,11 @@ use OCA\News\Db\Feed; use OCA\News\Tests\Integration\IntegrationTest; use OCA\News\Tests\Integration\Fixtures\FeedFixture; -class FeedMapperTest extends IntegrationTest { +class FeedMapperTest extends IntegrationTest +{ - public function testFind () { + public function testFind() + { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -32,12 +34,14 @@ class FeedMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotExisting () { + public function testFindNotExisting() + { $this->feedMapper->find(0, $this->user); } - public function testFindAll () { + public function testFindAll() + { $feeds = [ [ 'userId' => $this->user, @@ -59,7 +63,8 @@ class FeedMapperTest extends IntegrationTest { $this->tearDownUser('john'); } - public function testFindAllEmpty () { + public function testFindAllEmpty() + { $feeds = $this->feedMapper->findAll(); $this->assertInternalType('array', $feeds); @@ -67,7 +72,8 @@ class FeedMapperTest extends IntegrationTest { } - public function testFindAllFromUser () { + public function testFindAllFromUser() + { $feeds = [ [ 'userId' => $this->user, @@ -90,7 +96,8 @@ class FeedMapperTest extends IntegrationTest { } - public function testFindAllFromUserNotExisting () { + public function testFindAllFromUserNotExisting() + { $fetched = $this->feedMapper->findAllFromUser('notexistinguser'); $this->assertInternalType('array', $fetched); @@ -98,11 +105,14 @@ class FeedMapperTest extends IntegrationTest { } - public function testFindByUrlHash () { - $feed = new FeedFixture([ + public function testFindByUrlHash() + { + $feed = new FeedFixture( + [ 'urlHash' => 'someTestHash', 'title' => 'Some Test Title' - ]); + ] + ); $feed = $this->feedMapper->insert($feed); $fetched = $this->feedMapper->findByUrlHash($feed->getUrlHash(), $this->user); @@ -114,13 +124,22 @@ class FeedMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\MultipleObjectsReturnedException */ - public function testFindByUrlHashMoreThanOneResult () { - $feed1 = $this->feedMapper->insert(new FeedFixture([ - 'urlHash' => 'someTestHash' - ])); - $feed2 = $this->feedMapper->insert(new FeedFixture([ - 'urlHash' => 'someTestHash' - ])); + public function testFindByUrlHashMoreThanOneResult() + { + $feed1 = $this->feedMapper->insert( + new FeedFixture( + [ + 'urlHash' => 'someTestHash' + ] + ) + ); + $feed2 = $this->feedMapper->insert( + new FeedFixture( + [ + 'urlHash' => 'someTestHash' + ] + ) + ); $this->feedMapper->findByUrlHash($feed1->getUrlHash(), $this->user); } @@ -129,12 +148,14 @@ class FeedMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindByUrlHashNotExisting () { + public function testFindByUrlHashNotExisting() + { $this->feedMapper->findByUrlHash('some random hash', $this->user); } - public function testDelete () { + public function testDelete() + { $this->loadFixtures('default'); $feeds = $this->feedMapper->findAllFromUser($this->user); @@ -157,13 +178,16 @@ class FeedMapperTest extends IntegrationTest { $this->assertCount(0, $items); } - public function testGetToDelete () { - $this->loadFeedFixtures([ + public function testGetToDelete() + { + $this->loadFeedFixtures( + [ ['deletedAt' => 1], ['deletedAt' => 0], ['deletedAt' => 1, 'userId' => 'john'], ['deletedAt' => 1000] - ]); + ] + ); $fetched = $this->feedMapper->getToDelete(); @@ -174,13 +198,16 @@ class FeedMapperTest extends IntegrationTest { $this->tearDownUser('john'); } - public function testGetToDeleteOlderThan () { - $this->loadFeedFixtures([ + public function testGetToDeleteOlderThan() + { + $this->loadFeedFixtures( + [ ['deletedAt' => 1], ['deletedAt' => 0], ['deletedAt' => 1, 'userId' => 'john'], ['deletedAt' => 1000] - ]); + ] + ); $fetched = $this->feedMapper->getToDelete(1000); @@ -191,13 +218,16 @@ class FeedMapperTest extends IntegrationTest { $this->tearDownUser('john'); } - public function testGetToDeleteUser () { - $this->loadFeedFixtures([ + public function testGetToDeleteUser() + { + $this->loadFeedFixtures( + [ ['deletedAt' => 1], ['deletedAt' => 0], ['deletedAt' => 1, 'userId' => 'john'], ['deletedAt' => 1000] - ]); + ] + ); $fetched = $this->feedMapper->getToDelete(2000, $this->user); @@ -208,14 +238,16 @@ class FeedMapperTest extends IntegrationTest { $this->tearDownUser('john'); } - public function testGetToDeleteEmpty () { + public function testGetToDeleteEmpty() + { $fetched = $this->feedMapper->getToDelete(); $this->assertInternalType('array', $fetched); $this->assertCount(0, $fetched); } - public function testDeleteUser () { + public function testDeleteUser() + { $this->loadFixtures('default'); $this->assertCount(4, $this->feedMapper->findAllFromUser($this->user)); @@ -231,7 +263,8 @@ class FeedMapperTest extends IntegrationTest { $this->assertCount(0, $items); } - public function testDeleteUserNotExisting () { + public function testDeleteUserNotExisting() + { $this->feedMapper->deleteUser('notexistinguser'); } } diff --git a/tests/Integration/Db/FolderMapperTest.php b/tests/Integration/Db/FolderMapperTest.php index 4be407566..889ac3e7c 100644 --- a/tests/Integration/Db/FolderMapperTest.php +++ b/tests/Integration/Db/FolderMapperTest.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ @@ -13,10 +13,12 @@ namespace OCA\News\Tests\Integration\Db; use OCA\News\Tests\Integration\IntegrationTest; -class FolderMapperTest extends IntegrationTest { +class FolderMapperTest extends IntegrationTest +{ - public function testFind () { + public function testFind() + { } diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php index 546c43d85..c87a4139f 100644 --- a/tests/Integration/Db/ItemMapperTest.php +++ b/tests/Integration/Db/ItemMapperTest.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ @@ -15,9 +15,11 @@ use OCA\News\Tests\Integration\IntegrationTest; use OCA\News\Tests\Integration\Fixtures\FeedFixture; use OCA\News\Tests\Integration\Fixtures\ItemFixture; -class ItemMapperTest extends IntegrationTest { +class ItemMapperTest extends IntegrationTest +{ - public function testFind() { + public function testFind() + { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -32,17 +34,20 @@ class ItemMapperTest extends IntegrationTest { /** * Same as whereId with easier title search - * @param $title + * + * @param $title * @return mixed */ - private function whereTitleId($title) { + private function whereTitleId($title) + { return $this->findItemByTitle($title)->getId(); } /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFeed() { + public function testFindNotFoundWhenDeletedFeed() + { $this->loadFixtures('default'); $id = $this->whereTitleId('not found feed'); @@ -53,7 +58,8 @@ class ItemMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFolder() { + public function testFindNotFoundWhenDeletedFolder() + { $this->loadFixtures('default'); @@ -62,7 +68,8 @@ class ItemMapperTest extends IntegrationTest { } - private function deleteReadOlderThanThreshold() { + private function deleteReadOlderThanThreshold() + { $this->loadFixtures('default'); $this->itemMapper->deleteReadOlderThanThreshold(1); @@ -77,7 +84,8 @@ class ItemMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdOne() { + public function testDeleteOlderThanThresholdOne() + { $this->loadFixtures('default'); $id = $this->whereTitleId('del1'); @@ -89,7 +97,8 @@ class ItemMapperTest extends IntegrationTest { /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdTwo() { + public function testDeleteOlderThanThresholdTwo() + { $this->loadFixtures('default'); $id = $this->whereTitleId('del2'); @@ -99,7 +108,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testStarredCount () { + public function testStarredCount() + { $this->loadFixtures('default'); $count = $this->itemMapper->starredCount($this->user); @@ -107,7 +117,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testReadAll () { + public function testReadAll() + { $this->loadFixtures('default'); $this->itemMapper->readAll(PHP_INT_MAX, 10, $this->user); @@ -135,7 +146,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testReadFolder () { + public function testReadFolder() + { $this->loadFixtures('default'); $folderId = $this->findFolderByName('first folder')->getId(); @@ -166,7 +178,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testReadFeed () { + public function testReadFeed() + { $this->loadFixtures('default'); $feedId = $this->findFeedByTitle('third feed')->getId(); @@ -196,7 +209,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testDeleteUser () { + public function testDeleteUser() + { $this->loadFixtures('default'); $this->itemMapper->deleteUser($this->user); @@ -205,7 +219,8 @@ class ItemMapperTest extends IntegrationTest { $this->assertEquals(0, $id); } - public function testGetNewestItemId () { + public function testGetNewestItemId() + { $this->loadFixtures('default'); $id = $this->itemMapper->getNewestItemId($this->user); @@ -214,7 +229,8 @@ class ItemMapperTest extends IntegrationTest { $this->assertEquals($itemId, $id); } - public function testFindAllUnreadOrStarred () { + public function testFindAllUnreadOrStarred() + { $this->loadFixtures('default'); $items = $this->itemMapper->findAllUnreadOrStarred($this->user); @@ -222,7 +238,8 @@ class ItemMapperTest extends IntegrationTest { } - public function testReadItem() { + public function testReadItem() + { $this->loadFixtures('readitem'); // assert that all items are unread $feed = $this->feedMapper->where(['userId' => 'john'])[0]; @@ -260,7 +277,8 @@ class ItemMapperTest extends IntegrationTest { } } - public function testUnreadItem() { + public function testUnreadItem() + { $this->loadFixtures('readitem'); // unread an item $feed = $this->feedMapper->where(['userId' => 'test'])[0]; @@ -286,7 +304,8 @@ class ItemMapperTest extends IntegrationTest { } } - protected function tearDown() { + protected function tearDown() + { parent::tearDown(); $this->clearUserNewsDatabase('john'); } diff --git a/tests/Integration/Fixtures/FeedFixture.php b/tests/Integration/Fixtures/FeedFixture.php index 3d7617a57..66461adbc 100644 --- a/tests/Integration/Fixtures/FeedFixture.php +++ b/tests/Integration/Fixtures/FeedFixture.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ @@ -15,13 +15,16 @@ namespace OCA\News\Tests\Integration\Fixtures; use OCA\News\Db\Feed; -class FeedFixture extends Feed { +class FeedFixture extends Feed +{ use Fixture; - public function __construct(array $defaults=[]) { + public function __construct(array $defaults=[]) + { parent::__construct(); - $defaults = array_merge([ + $defaults = array_merge( + [ 'userId' => 'test', 'urlHash' => 'urlHash', 'url' => 'http://the.url.com', @@ -42,7 +45,8 @@ class FeedFixture extends Feed { 'updateMode' => 0, 'updateErrorCount' => 0, 'lastUpdateError' => '', - ], $defaults); + ], $defaults + ); unset($defaults['items']); $this->fillDefaults($defaults); } diff --git a/tests/Integration/Fixtures/Fixture.php b/tests/Integration/Fixtures/Fixture.php index f17beb25c..1874c8102 100644 --- a/tests/Integration/Fixtures/Fixture.php +++ b/tests/Integration/Fixtures/Fixture.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ @@ -13,9 +13,11 @@ namespace OCA\News\Tests\Integration\Fixtures; -trait Fixture { +trait Fixture +{ - protected function fillDefaults(array $defaults=[]) { + protected function fillDefaults(array $defaults=[]) + { foreach ($defaults as $key => $value) { $method = 'set' . ucfirst($key); $this->$method($value); diff --git a/tests/Integration/Fixtures/FolderFixture.php b/tests/Integration/Fixtures/FolderFixture.php index 150557b8b..2564e8b71 100644 --- a/tests/Integration/Fixtures/FolderFixture.php +++ b/tests/Integration/Fixtures/FolderFixture.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ @@ -15,19 +15,23 @@ namespace OCA\News\Tests\Integration\Fixtures; use OCA\News\Db\Folder; -class FolderFixture extends Folder { +class FolderFixture extends Folder +{ use Fixture; - public function __construct(array $defaults=[]) { + public function __construct(array $defaults=[]) + { parent::__construct(); - $defaults = array_merge([ + $defaults = array_merge( + [ 'parentId' => 0, 'name' => 'folder', 'userId' => 'test', 'opened' => true, 'deletedAt' => 0, 'lastModified' => 9 - ], $defaults); + ], $defaults + ); unset($defaults['feeds']); $this->fillDefaults($defaults); } diff --git a/tests/Integration/Fixtures/ItemFixture.php b/tests/Integration/Fixtures/ItemFixture.php index 0832b0ef4..450b56f82 100644 --- a/tests/Integration/Fixtures/ItemFixture.php +++ b/tests/Integration/Fixtures/ItemFixture.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ @@ -15,12 +15,15 @@ namespace OCA\News\Tests\Integration\Fixtures; use OCA\News\Db\Item; -class ItemFixture extends Item { +class ItemFixture extends Item +{ use Fixture; - public function __construct(array $defaults=[]) { + public function __construct(array $defaults=[]) + { parent::__construct(); - $defaults = array_merge([ + $defaults = array_merge( + [ 'url' => 'http://google.de', 'title' => 'title', 'author' => 'my author', @@ -33,7 +36,8 @@ class ItemFixture extends Item { 'starred' => false, 'lastModified' => 113, 'rtl' => false, - ], $defaults); + ], $defaults + ); if (!array_key_exists('guid', $defaults)) { $defaults['guid'] = $defaults['title']; diff --git a/tests/Integration/Fixtures/data/default.php b/tests/Integration/Fixtures/data/default.php index 862515b12..41935b5c6 100644 --- a/tests/Integration/Fixtures/data/default.php +++ b/tests/Integration/Fixtures/data/default.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ diff --git a/tests/Integration/Fixtures/data/readitem.php b/tests/Integration/Fixtures/data/readitem.php index 8f953a845..425492741 100644 --- a/tests/Integration/Fixtures/data/readitem.php +++ b/tests/Integration/Fixtures/data/readitem.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ diff --git a/tests/Integration/IntegrationTest.php b/tests/Integration/IntegrationTest.php index f14a1263b..751cbe5fd 100644 --- a/tests/Integration/IntegrationTest.php +++ b/tests/Integration/IntegrationTest.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2015 */ @@ -32,24 +32,34 @@ use OCA\News\Db\ItemMapper; use OCA\News\Db\FolderMapper; -abstract class IntegrationTest extends \Test\TestCase { +abstract class IntegrationTest extends \Test\TestCase +{ protected $user = 'test'; protected $userPassword = 'test'; - /** @var ItemMapper */ + /** + * @var ItemMapper + */ protected $itemMapper; - /** @var FeedMapper */ + /** + * @var FeedMapper + */ protected $feedMapper; - /** @var FolderMapper */ + /** + * @var FolderMapper + */ protected $folderMapper; - /** @var IAppContainer */ + /** + * @var IAppContainer + */ protected $container; - protected function setUp() { + protected function setUp() + { parent::setUp(); $app = new Application(); $this->container = $app->getContainer(); @@ -62,7 +72,8 @@ abstract class IntegrationTest extends \Test\TestCase { $this->folderMapper = $this->container->query(FolderMapper::class); } - protected function findItemByTitle($title) { + protected function findItemByTitle($title) + { // db logic in app code, negligible since its a test $items = $this->itemMapper->where(['title' => $title]); $feeds = $this->feedMapper->where(['userId' => $this->user]); @@ -72,10 +83,12 @@ abstract class IntegrationTest extends \Test\TestCase { $feedIds[$feed->getId()] = true; } - $result = array_filter($items, + $result = array_filter( + $items, function (Item $item) use ($feedIds) { - return array_key_exists($item->getFeedId(), $feedIds); - }); + return array_key_exists($item->getFeedId(), $feedIds); + } + ); // ok so this is funny: array_filter preserves indices, meaning that // you can't use 0 as key for the first element return from it :D @@ -84,24 +97,31 @@ abstract class IntegrationTest extends \Test\TestCase { return $result; } - protected function findFolderByName($name) { - return $this->folderMapper->where([ + protected function findFolderByName($name) + { + return $this->folderMapper->where( + [ 'userId' => $this->user, 'name' => $name - ])[0]; + ] + )[0]; } - protected function findFeedByTitle($title) { - return $this->feedMapper->where([ + protected function findFeedByTitle($title) + { + return $this->feedMapper->where( + [ 'userId' => $this->user, 'title' => $title - ])[0]; + ] + )[0]; } /** * @param string $name loads fixtures from a given file */ - protected function loadFixtures($name) { + protected function loadFixtures($name) + { $fixtures = include __DIR__ . '/Fixtures/data/' . $name . '.php'; if (array_key_exists('folders', $fixtures)) { $this->loadFolderFixtures($fixtures['folders']); @@ -111,7 +131,8 @@ abstract class IntegrationTest extends \Test\TestCase { } } - protected function loadFolderFixtures(array $folderFixtures=[]) { + protected function loadFolderFixtures(array $folderFixtures=[]) + { foreach ($folderFixtures as $folderFixture) { $folder = new FolderFixture($folderFixture); $folderId = $this->loadFixture($folder); @@ -119,19 +140,21 @@ abstract class IntegrationTest extends \Test\TestCase { } } - protected function loadFeedFixtures(array $feedFixtures=[], $folderId=0) { + protected function loadFeedFixtures(array $feedFixtures=[], $folderId=0) + { foreach ($feedFixtures as $feedFixture) { $feed = new FeedFixture($feedFixture); $feed->setFolderId($folderId); $feedId = $this->loadFixture($feed); if (!empty($feedFixture['items'])) { - $this->loadItemFixtures($feedFixture['items'], $feedId); - } + $this->loadItemFixtures($feedFixture['items'], $feedId); + } } } - protected function loadItemFixtures(array $itemFixtures=[], $feedId) { + protected function loadItemFixtures(array $itemFixtures=[], $feedId) + { foreach ($itemFixtures as $itemFixture) { $item = new ItemFixture($itemFixture); $item->setFeedId($feedId); @@ -141,10 +164,12 @@ abstract class IntegrationTest extends \Test\TestCase { /** * Saves a fixture in a database and returns the saved result - * @param Entity $fixture + * + * @param Entity $fixture * @return int the id */ - protected function loadFixture(Entity $fixture) { + protected function loadFixture(Entity $fixture) + { if ($fixture instanceof FeedFixture) { return $this->feedMapper->insert($fixture)->getId(); } elseif ($fixture instanceof ItemFixture) { @@ -158,10 +183,12 @@ abstract class IntegrationTest extends \Test\TestCase { /** * Creates and logs in a new ownCloud user + * * @param $user * @param $password */ - protected function setupUser($user, $password) { + protected function setupUser($user, $password) + { $userManager = $this->container->query(IUserManager::class); $userManager->createUser($user, $password); @@ -170,9 +197,11 @@ abstract class IntegrationTest extends \Test\TestCase { /** * Removes a user and his News app database entries from the database + * * @param $user */ - protected function tearDownUser($user) { + protected function tearDownUser($user) + { $userManager = $this->container->query(IUserManager::class); if ($userManager->userExists($user)) { @@ -184,9 +213,11 @@ abstract class IntegrationTest extends \Test\TestCase { /** * Deletes all news entries of a given user + * * @param string $user */ - protected function clearUserNewsDatabase($user) { + protected function clearUserNewsDatabase($user) + { $sql = [ 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` IN (SELECT `id` FROM `*PREFIX*news_feeds` WHERE `user_id` = ?)', @@ -200,7 +231,8 @@ abstract class IntegrationTest extends \Test\TestCase { } } - protected function tearDown() { + protected function tearDown() + { parent::tearDown(); $this->tearDownUser($this->user); } diff --git a/tests/Unit/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php index da9dd4522..42d3c6e62 100644 --- a/tests/Unit/Config/ConfigTest.php +++ b/tests/Unit/Config/ConfigTest.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\Config; @@ -17,16 +17,19 @@ use OCA\News\Config\Config; use PHPUnit_Framework_TestCase; -class ConfigTest extends PHPUnit_Framework_TestCase { +class ConfigTest extends PHPUnit_Framework_TestCase +{ private $fileSystem; private $config; private $configPath; private $loggerParams; - public function setUp() { + public function setUp() + { $this->logger = $this->getMockBuilder( - 'OCP\ILogger') + 'OCP\ILogger' + ) ->disableOriginalConstructor() ->getMock(); $this->fileSystem = $this->getMockBuilder('OCP\Files\Folder')->getMock(); @@ -38,7 +41,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testDefaults() { + public function testDefaults() + { $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); $this->assertEquals(200, $this->config->getAutoPurgeCount()); $this->assertEquals(10, $this->config->getMaxRedirects()); @@ -49,7 +53,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testRead () { + public function testRead() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -57,9 +62,11 @@ class ConfigTest extends PHPUnit_Framework_TestCase { ->will($this->returnValue($file)); $file->expects($this->once()) ->method('getContent') - ->will($this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true' - )); + ->will( + $this->returnValue( + 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true' + ) + ); $this->config->read($this->configPath); @@ -69,7 +76,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testReadIgnoresVeryLowPurgeInterval () { + public function testReadIgnoresVeryLowPurgeInterval() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -86,7 +94,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { - public function testReadBool () { + public function testReadBool() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -94,8 +103,10 @@ class ConfigTest extends PHPUnit_Framework_TestCase { ->will($this->returnValue($file)); $file->expects($this->once()) ->method('getContent') - ->will($this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false') + ->will( + $this->returnValue( + 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false' + ) ); $this->config->read($this->configPath); @@ -105,7 +116,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testReadLogsInvalidValue() { + public function testReadLogsInvalidValue() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -116,15 +128,20 @@ class ConfigTest extends PHPUnit_Framework_TestCase { ->will($this->returnValue('autoPurgeCounts = 3')); $this->logger->expects($this->once()) ->method('warning') - ->with($this->equalTo('Configuration value "autoPurgeCounts" ' . - 'does not exist. Ignored value.'), - $this->equalTo($this->loggerParams)); + ->with( + $this->equalTo( + 'Configuration value "autoPurgeCounts" ' . + 'does not exist. Ignored value.' + ), + $this->equalTo($this->loggerParams) + ); $this->config->read($this->configPath); } - public function testReadLogsInvalidINI() { + public function testReadLogsInvalidINI() + { $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->fileSystem->expects($this->once()) ->method('get') @@ -135,14 +152,17 @@ class ConfigTest extends PHPUnit_Framework_TestCase { ->will($this->returnValue('')); $this->logger->expects($this->once()) ->method('warning') - ->with($this->equalTo('Configuration invalid. Ignoring values.'), - $this->equalTo($this->loggerParams)); + ->with( + $this->equalTo('Configuration invalid. Ignoring values.'), + $this->equalTo($this->loggerParams) + ); $this->config->read($this->configPath); } - public function testWrite () { + public function testWrite() + { $json = 'autoPurgeMinimumInterval = 60' . "\n" . 'autoPurgeCount = 3' . "\n" . 'maxRedirects = 10' . "\n" . @@ -168,7 +188,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { - public function testReadingNonExistentConfigWillWriteDefaults() { + public function testReadingNonExistentConfigWillWriteDefaults() + { $this->fileSystem->expects($this->once()) ->method('nodeExists') ->with($this->equalTo($this->configPath)) @@ -200,7 +221,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testNoLowMinimumAutoPurgeInterval() { + public function testNoLowMinimumAutoPurgeInterval() + { $this->config->setAutoPurgeMinimumInterval(59); $interval = $this->config->getAutoPurgeMinimumInterval(); @@ -208,21 +230,24 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } - public function testMinimumAutoPurgeInterval() { + public function testMinimumAutoPurgeInterval() + { $this->config->setAutoPurgeMinimumInterval(61); $interval = $this->config->getAutoPurgeMinimumInterval(); $this->assertSame(61, $interval); } - public function testMaxRedirects() { + public function testMaxRedirects() + { $this->config->setMaxRedirects(21); $redirects = $this->config->getMaxRedirects(); $this->assertSame(21, $redirects); } - public function testFeedFetcherTimeout() { + public function testFeedFetcherTimeout() + { $this->config->setFeedFetcherTimeout(2); $timout = $this->config->getFeedFetcherTimeout(); diff --git a/tests/Unit/Controller/AdminControllerTest.php b/tests/Unit/Controller/AdminControllerTest.php index 33926d0d2..a2b7f304a 100644 --- a/tests/Unit/Controller/AdminControllerTest.php +++ b/tests/Unit/Controller/AdminControllerTest.php @@ -5,18 +5,18 @@ * 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\Controller; - use OCA\News\Controller\AdminController; -class AdminControllerTest extends \PHPUnit_Framework_TestCase { +class AdminControllerTest extends \PHPUnit_Framework_TestCase +{ private $appName; private $request; @@ -28,28 +28,35 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase { /** * Gets run before each test */ - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->config = $this->getMockBuilder( - '\OCA\News\Config\Config') + '\OCA\News\Config\Config' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); $this->configPath = 'my.ini'; - $this->controller = new AdminController($this->appName, $this->request, - $this->config, $this->itemService, $this->configPath); + $this->controller = new AdminController( + $this->appName, $this->request, + $this->config, $this->itemService, $this->configPath + ); } - public function testIndex() { + public function testIndex() + { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, @@ -92,7 +99,8 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdate() { + public function testUpdate() + { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, diff --git a/tests/Unit/Controller/EntityApiSerializerTest.php b/tests/Unit/Controller/EntityApiSerializerTest.php index 261d5f7c4..49b7e0b8d 100644 --- a/tests/Unit/Controller/EntityApiSerializerTest.php +++ b/tests/Unit/Controller/EntityApiSerializerTest.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\Controller; @@ -19,15 +19,18 @@ use \OCP\AppFramework\Db\Entity; use \OCA\News\Db\Item; -class TestEntity extends Entity { +class TestEntity extends Entity +{ } -class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { +class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase +{ - public function testSerializeSingle() { + public function testSerializeSingle() + { $item = new Item(); $item->setUnread(true); @@ -38,7 +41,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testSerializeMultiple() { + public function testSerializeMultiple() + { $item = new Item(); $item->setUnread(true); @@ -54,7 +58,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testResponseNoChange() { + public function testResponseNoChange() + { $response = new Response(); $serializer = new EntityApiSerializer('items'); @@ -64,7 +69,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testCompleteArraysTransformed() { + public function testCompleteArraysTransformed() + { $item = new Item(); $item->setUnread(true); @@ -86,7 +92,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testNoEntityNoChange() { + public function testNoEntityNoChange() + { $serializer = new EntityApiSerializer('items'); $in = [ @@ -102,7 +109,8 @@ class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase { } - public function testEntitiesNoChange() { + public function testEntitiesNoChange() + { $serializer = new EntityApiSerializer('items'); $in = [ diff --git a/tests/Unit/Controller/ExportControllerTest.php b/tests/Unit/Controller/ExportControllerTest.php index 6701b38a6..592582b3a 100644 --- a/tests/Unit/Controller/ExportControllerTest.php +++ b/tests/Unit/Controller/ExportControllerTest.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\Controller; @@ -22,7 +22,8 @@ use \OCA\News\Db\Item; use \OCA\News\Db\Feed; -class ExportControllerTest extends \PHPUnit_Framework_TestCase { +class ExportControllerTest extends \PHPUnit_Framework_TestCase +{ private $appName; private $request; @@ -36,32 +37,39 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { /** * Gets run before each test */ - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->user = 'john'; $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); $this->feedService = $this->getMockBuilder( - '\OCA\News\Service\FeedService') + '\OCA\News\Service\FeedService' + ) ->disableOriginalConstructor() ->getMock(); $this->folderService = $this->getMockBuilder( - '\OCA\News\Service\FolderService') + '\OCA\News\Service\FolderService' + ) ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder('\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); $this->opmlExporter = new OPMLExporter(); - $this->controller = new ExportController($this->appName, $this->request, + $this->controller = new ExportController( + $this->appName, $this->request, $this->folderService, $this->feedService, - $this->itemService, $this->opmlExporter, $this->user); + $this->itemService, $this->opmlExporter, $this->user + ); } - public function testOpmlExportNoFeeds(){ + public function testOpmlExportNoFeeds() + { $opml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<opml version=\"2.0\">\n" . @@ -86,7 +94,8 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { } - public function testGetAllArticles(){ + public function testGetAllArticles() + { $item1 = new Item(); $item1->setFeedId(3); $item2 = new Item(); @@ -119,14 +128,16 @@ class ExportControllerTest extends \PHPUnit_Framework_TestCase { $headers ['Content-Disposition'] ); - $this->assertEquals('[{"guid":null,"url":null,"title":null,' . + $this->assertEquals( + '[{"guid":null,"url":null,"title":null,' . '"author":null,"pubDate":null,"updatedDate":null,"body":null,"enclosureMime":null,' . '"enclosureLink":null,"unread":false,"starred":false,' . '"feedLink":"http:\/\/goo","rtl":null},{"guid":null,"url":null,' . '"title":null,"author":null,"pubDate":null,"updatedDate":null,"body":null,' . '"enclosureMime":null,"enclosureLink":null,"unread":false,' . '"starred":false,"feedLink":"http:\/\/gee","rtl":null}]', - $return->render()); + $return->render() + ); } } diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index 8c0b25873..bc91e1df8 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.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\Controller; @@ -23,7 +23,8 @@ use \OCA\News\Db\Feed; use \OCA\News\Db\Item; -class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { +class FeedApiControllerTest extends \PHPUnit_Framework_TestCase +{ private $feedService; private $itemService; @@ -35,24 +36,29 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { private $logger; private $loggerParams; - protected function setUp() { + protected function setUp() + { $this->user = 'tom'; $this->loggerParams = ['hi']; $this->logger = $this->getMockBuilder( - '\OCP\ILogger') + '\OCP\ILogger' + ) ->disableOriginalConstructor() ->getMock(); $this->appName = 'news'; $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->feedService = $this->getMockBuilder( - '\OCA\News\Service\FeedService') + '\OCA\News\Service\FeedService' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); $this->feedAPI = new FeedApiController( @@ -68,7 +74,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndex() { + public function testIndex() + { $feeds = [new Feed()]; $starredCount = 3; $newestItemId = 2; @@ -88,15 +95,18 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->index(); - $this->assertEquals([ + $this->assertEquals( + [ 'feeds' => [$feeds[0]->toAPI()], 'starredCount' => $starredCount, 'newestItemId' => $newestItemId - ], $response); + ], $response + ); } - public function testIndexNoNewestItemId() { + public function testIndexNoNewestItemId() + { $feeds = [new Feed()]; $starredCount = 3; @@ -115,29 +125,36 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->index(); - $this->assertEquals([ + $this->assertEquals( + [ 'feeds' => [$feeds[0]->toAPI()], 'starredCount' => $starredCount, - ], $response); + ], $response + ); } - public function testDelete() { + public function testDelete() + { $this->feedService->expects($this->once()) ->method('delete') ->with( $this->equalTo(2), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->feedAPI->delete(2); } - public function testDeleteDoesNotExist() { + public function testDeleteDoesNotExist() + { $this->feedService->expects($this->once()) ->method('delete') - ->will($this->throwException( - new ServiceNotFoundException($this->msg)) + ->will( + $this->throwException( + new ServiceNotFoundException($this->msg) + ) ); $response = $this->feedAPI->delete(2); @@ -148,7 +165,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreate() { + public function testCreate() + { $feeds = [new Feed()]; $this->feedService->expects($this->once()) @@ -159,7 +177,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo('url'), $this->equalTo(3), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->returnValue($feeds[0])); $this->itemService->expects($this->once()) ->method('getNewestItemId') @@ -167,14 +186,17 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->create('url', 3); - $this->assertEquals([ + $this->assertEquals( + [ 'feeds' => [$feeds[0]->toAPI()], 'newestItemId' => 3 - ], $response); + ], $response + ); } - public function testCreateNoItems() { + public function testCreateNoItems() + { $feeds = [new Feed()]; $this->feedService->expects($this->once()) @@ -185,7 +207,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo('ho'), $this->equalTo(3), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->returnValue($feeds[0])); $this->itemService->expects($this->once()) ->method('getNewestItemId') @@ -193,14 +216,17 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->feedAPI->create('ho', 3); - $this->assertEquals([ + $this->assertEquals( + [ 'feeds' => [$feeds[0]->toAPI()] - ], $response); + ], $response + ); } - public function testCreateExists() { + public function testCreateExists() + { $this->feedService->expects($this->once()) ->method('purgeDeleted') ->with($this->equalTo($this->user), $this->equalTo(false)); @@ -218,7 +244,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateError() { + public function testCreateError() + { $this->feedService->expects($this->once()) ->method('create') ->will( @@ -233,31 +260,36 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testRead() { + public function testRead() + { $this->itemService->expects($this->once()) ->method('readFeed') ->with( $this->equalTo(3), $this->equalTo(30), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->feedAPI->read(3, 30); } - public function testMove() { + public function testMove() + { $this->feedService->expects($this->once()) ->method('patch') ->with( $this->equalTo(3), $this->equalTo($this->user), - $this->equalTo(['folderId' => 30])); + $this->equalTo(['folderId' => 30]) + ); $this->feedAPI->move(3, 30); } - public function testMoveDoesNotExist() { + public function testMoveDoesNotExist() + { $this->feedService->expects($this->once()) ->method('patch') ->will( @@ -272,7 +304,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testRename() { + public function testRename() + { $feedId = 3; $feedTitle = 'test'; @@ -281,13 +314,15 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($feedId), $this->equalTo($this->user), - $this->equalTo(['title' => $feedTitle])); + $this->equalTo(['title' => $feedTitle]) + ); $this->feedAPI->rename($feedId, $feedTitle); } - public function testRenameError() { + public function testRenameError() + { $feedId = 3; $feedTitle = 'test'; @@ -296,7 +331,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($feedId), $this->equalTo($this->user), - $this->equalTo(['title' => $feedTitle])) + $this->equalTo(['title' => $feedTitle]) + ) ->will($this->throwException(new ServiceNotFoundException('hi'))); $result = $this->feedAPI->rename($feedId, $feedTitle); @@ -308,7 +344,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testfromAllUsers(){ + public function testfromAllUsers() + { $feed = new Feed(); $feed->setUrl(3); $feed->setId(1); @@ -322,7 +359,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdate() { + public function testUpdate() + { $feedId = 3; $userId = 'hi'; @@ -334,7 +372,8 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateError() { + public function testUpdateError() + { $feedId = 3; $userId = 'hi'; $this->feedService->expects($this->once()) @@ -342,8 +381,10 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { ->will($this->throwException(new \Exception($this->msg))); $this->logger->expects($this->once()) ->method('debug') - ->with($this->equalTo('Could not update feed ' . $this->msg), - $this->equalTo($this->loggerParams)); + ->with( + $this->equalTo('Could not update feed ' . $this->msg), + $this->equalTo($this->loggerParams) + ); $this->feedAPI->update($userId, $feedId); diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 4018e2174..8bff9b2eb 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.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\Controller; @@ -22,7 +22,8 @@ use OCA\News\Service\ServiceNotFoundException; use OCA\News\Service\ServiceConflictException; -class FeedControllerTest extends \PHPUnit_Framework_TestCase { +class FeedControllerTest extends \PHPUnit_Framework_TestCase +{ private $appName; private $feedService; @@ -38,11 +39,13 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { /** * Gets run before each test */ - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->user = 'jack'; $this->settings = $this->getMockBuilder( - '\OCP\IConfig') + '\OCP\IConfig' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this @@ -58,15 +61,18 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); - $this->controller = new FeedController($this->appName, $this->request, - $this->folderService, - $this->feedService, - $this->itemService, - $this->settings, - $this->user); + $this->controller = new FeedController( + $this->appName, $this->request, + $this->folderService, + $this->feedService, + $this->itemService, + $this->settings, + $this->user + ); $this->exampleResult = [ 'activeFeed' => [ 'id' => 0, @@ -76,7 +82,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndex(){ + public function testIndex() + { $result = [ 'feeds' => [ ['a feed'], @@ -102,7 +109,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndexHighestItemIdExists(){ + public function testIndexHighestItemIdExists() + { $result = [ 'feeds' => [ ['a feed'], @@ -130,23 +138,29 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { - private function activeInitMocks($id, $type){ + private function activeInitMocks($id, $type) + { $this->settings->expects($this->at(0)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedId')) + $this->equalTo('lastViewedFeedId') + ) ->will($this->returnValue($id)); $this->settings->expects($this->at(1)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedType')) + $this->equalTo('lastViewedFeedType') + ) ->will($this->returnValue($type)); } - public function testActive(){ + public function testActive() + { $id = 3; $type = FeedType::STARRED; $result = [ @@ -164,7 +178,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testActiveFeedDoesNotExist(){ + public function testActiveFeedDoesNotExist() + { $id = 3; $type = FeedType::FEED; $ex = new ServiceNotFoundException('hiu'); @@ -183,7 +198,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testActiveFolderDoesNotExist(){ + public function testActiveFolderDoesNotExist() + { $id = 3; $type = FeedType::FOLDER; $ex = new ServiceNotFoundException('hiu'); @@ -202,7 +218,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testActiveActiveIsNull(){ + public function testActiveActiveIsNull() + { $id = 3; $type = null; $result = $this->exampleResult; @@ -216,7 +233,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreate(){ + public function testCreate() + { $result = [ 'feeds' => [new Feed()], 'newestItemId' => 3 @@ -230,10 +248,12 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($this->user), $this->equalTo(false)); $this->feedService->expects($this->once()) ->method('create') - ->with($this->equalTo('hi'), + ->with( + $this->equalTo('hi'), $this->equalTo(4), $this->equalTo($this->user), - $this->equalTo('yo')) + $this->equalTo('yo') + ) ->will($this->returnValue($result['feeds'][0])); $response = $this->controller->create('hi', 4, 'yo'); @@ -242,7 +262,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateNoItems(){ + public function testCreateNoItems() + { $result = ['feeds' => [new Feed()]]; $this->feedService->expects($this->once()) @@ -255,10 +276,12 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { $this->feedService->expects($this->once()) ->method('create') - ->with($this->equalTo('hi'), + ->with( + $this->equalTo('hi'), $this->equalTo(4), $this->equalTo($this->user), - $this->equalTo('yo')) + $this->equalTo('yo') + ) ->will($this->returnValue($result['feeds'][0])); $response = $this->controller->create('hi', 4, 'yo'); @@ -267,7 +290,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateReturnsErrorForInvalidCreate(){ + public function testCreateReturnsErrorForInvalidCreate() + { $msg = 'except'; $ex = new ServiceNotFoundException($msg); $this->feedService->expects($this->once()) @@ -287,7 +311,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateReturnsErrorForDuplicateCreate(){ + public function testCreateReturnsErrorForDuplicateCreate() + { $msg = 'except'; $ex = new ServiceConflictException($msg); $this->feedService->expects($this->once()) @@ -305,7 +330,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testDelete(){ + public function testDelete() + { $this->feedService->expects($this->once()) ->method('markDeleted') ->with($this->equalTo(4)); @@ -314,7 +340,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testDeleteDoesNotExist(){ + public function testDeleteDoesNotExist() + { $msg = 'hehe'; $this->feedService->expects($this->once()) @@ -329,7 +356,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdate(){ + public function testUpdate() + { $feed = new Feed(); $feed->setId(3); $feed->setUnreadCount(44); @@ -353,7 +381,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateReturnsJSONError(){ + public function testUpdateReturnsJSONError() + { $this->feedService->expects($this->once()) ->method('update') ->with($this->equalTo(4), $this->equalTo($this->user)) @@ -367,7 +396,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testImport() { + public function testImport() + { $feed = new Feed(); $expected = [ @@ -377,8 +407,10 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { $this->feedService->expects($this->once()) ->method('importArticles') - ->with($this->equalTo(['json']), - $this->equalTo($this->user)) + ->with( + $this->equalTo(['json']), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $this->itemService->expects($this->once()) @@ -392,11 +424,14 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testImportCreatesNoAdditionalFeed() { + public function testImportCreatesNoAdditionalFeed() + { $this->feedService->expects($this->once()) ->method('importArticles') - ->with($this->equalTo(['json']), - $this->equalTo($this->user)) + ->with( + $this->equalTo(['json']), + $this->equalTo($this->user) + ) ->will($this->returnValue(null)); $this->itemService->expects($this->once()) @@ -410,7 +445,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testReadFeed(){ + public function testReadFeed() + { $expected = [ 'feeds' => [ [ @@ -429,7 +465,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testRestore() { + public function testRestore() + { $this->feedService->expects($this->once()) ->method('unmarkDeleted') ->with($this->equalTo(4)); @@ -438,7 +475,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { } - public function testRestoreDoesNotExist(){ + public function testRestoreDoesNotExist() + { $msg = 'hehe'; $this->feedService->expects($this->once()) @@ -452,7 +490,8 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } - public function testPatch() { + public function testPatch() + { $expected = [ 'pinned' => true, 'fullTextEnabled' => true, @@ -460,15 +499,18 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase { ]; $this->feedService->expects($this->once()) ->method('patch') - ->with($this->equalTo(4), - $this->equalTo($this->user), - $this->equalTo($expected)) + ->with( + $this->equalTo(4), + $this->equalTo($this->user), + $this->equalTo($expected) + ) ->will($this->returnValue(1)); $this->controller->patch(4, true, true, 1); } - public function testPatchDoesNotExist(){ + public function testPatchDoesNotExist() + { $msg = 'hehe'; $this->feedService->expects($this->once()) diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php index df050911b..5a7fc3f93 100644 --- a/tests/Unit/Controller/FolderApiControllerTest.php +++ b/tests/Unit/Controller/FolderApiControllerTest.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\Controller; @@ -26,7 +26,8 @@ use \OCA\News\Db\Feed; use \OCA\News\Db\Item; -class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { +class FolderApiControllerTest extends \PHPUnit_Framework_TestCase +{ private $folderService; private $itemService; @@ -36,19 +37,23 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { private $request; private $msg; - protected function setUp() { + protected function setUp() + { $this->appName = 'news'; $this->user = 'tom'; $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->folderService = $this->getMockBuilder( - '\OCA\News\Service\FolderService') + '\OCA\News\Service\FolderService' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); $this->folderAPI = new FolderApiController( @@ -62,7 +67,8 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndex() { + public function testIndex() + { $folders = [new Folder()]; $this->folderService->expects($this->once()) @@ -72,13 +78,16 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->folderAPI->index(); - $this->assertEquals([ + $this->assertEquals( + [ 'folders' => [$folders[0]->toAPI()] - ], $response); + ], $response + ); } - public function testCreate() { + public function testCreate() + { $folderName = 'test'; $folder = new Folder(); $folder->setName($folderName); @@ -93,13 +102,16 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->folderAPI->create($folderName); - $this->assertEquals([ + $this->assertEquals( + [ 'folders' => [$folder->toAPI()] - ], $response); + ], $response + ); } - public function testCreateAlreadyExists() { + public function testCreateAlreadyExists() + { $msg = 'exists'; $this->folderService->expects($this->once()) @@ -117,7 +129,8 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testCreateInvalidFolderName() { + public function testCreateInvalidFolderName() + { $msg = 'exists'; $this->folderService->expects($this->once()) @@ -137,7 +150,8 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testDelete() { + public function testDelete() + { $folderId = 23; $this->folderService->expects($this->once()) ->method('delete') @@ -147,7 +161,8 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testDeleteDoesNotExist() { + public function testDeleteDoesNotExist() + { $folderId = 23; $this->folderService->expects($this->once()) @@ -166,20 +181,24 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdate() { + public function testUpdate() + { $folderId = 23; $folderName = 'test'; $this->folderService->expects($this->once()) ->method('rename') - ->with($this->equalTo($folderId), + ->with( + $this->equalTo($folderId), $this->equalTo($folderName), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->folderAPI->update($folderId, $folderName); } - public function testUpdateDoesNotExist() { + public function testUpdateDoesNotExist() + { $folderId = 23; $folderName = 'test'; @@ -199,7 +218,8 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateExists() { + public function testUpdateExists() + { $folderId = 23; $folderName = 'test'; @@ -219,7 +239,8 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateInvalidFolderName() { + public function testUpdateInvalidFolderName() + { $folderId = 23; $folderName = ''; @@ -241,13 +262,15 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testRead() { + public function testRead() + { $this->itemService->expects($this->once()) ->method('readFolder') ->with( $this->equalTo(3), $this->equalTo(30), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->folderAPI->read(3, 30); } diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php index a46228ae0..ba69fcac7 100644 --- a/tests/Unit/Controller/FolderControllerTest.php +++ b/tests/Unit/Controller/FolderControllerTest.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\Controller; @@ -23,7 +23,8 @@ use \OCA\News\Service\ServiceConflictException; use \OCA\News\Service\ServiceValidationException; -class FolderControllerTest extends \PHPUnit_Framework_TestCase { +class FolderControllerTest extends \PHPUnit_Framework_TestCase +{ private $appName; private $folderService; @@ -41,21 +42,28 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { { $this->appName = 'news'; $this->user = 'jack'; - $this->folderService = $this->getMockBuilder('\OCA\News\Service\FolderService') + $this->folderService = $this->getMockBuilder( + '\OCA\News\Service\FolderService' + ) ->disableOriginalConstructor() ->getMock(); - $this->feedService = $this->getMockBuilder('\OCA\News\Service\FeedService') + $this->feedService = $this->getMockBuilder( + '\OCA\News\Service\FeedService' + ) ->disableOriginalConstructor() ->getMock(); - $this->itemService = $this->getMockBuilder('\OCA\News\Service\ItemService') + $this->itemService = $this->getMockBuilder( + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); - $this->request = $this->getMockBuilder('\OCP\IRequest') + $this->request = $this->getMockBuilder( + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->controller = new FolderController( - $this->appName, - $this->request, + $this->appName, $this->request, $this->folderService, $this->feedService, $this->itemService, @@ -82,14 +90,14 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { ->method('open') ->with( $this->equalTo(3), - $this->equalTo(true), - $this->equalTo($this->user) + $this->equalTo(true), $this->equalTo($this->user) ); $this->controller->open(3, true); } + public function testOpenDoesNotExist() { $this->folderService->expects($this->once()) @@ -108,14 +116,14 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } + public function testCollapse() { $this->folderService->expects($this->once()) ->method('open') ->with( $this->equalTo(5), - $this->equalTo(false), - $this->equalTo($this->user) + $this->equalTo(false), $this->equalTo($this->user) ); $this->controller->open(5, false); @@ -221,9 +229,11 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { $this->folderService->expects($this->once()) ->method('rename') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo('tech'), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->returnValue($result['folders'][0])); $response = $this->controller->rename('tech', 4); @@ -243,8 +253,10 @@ class FolderControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->controller->rename('tech', 4); $params = json_decode($response->render(), true); - $this->assertEquals($response->getStatus(), - Http::STATUS_UNPROCESSABLE_ENTITY); + $this->assertEquals( + $response->getStatus(), + Http::STATUS_UNPROCESSABLE_ENTITY + ); $this->assertEquals($msg, $params['message']); } diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index e30bc349a..929d792bd 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.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\Controller; @@ -20,7 +20,8 @@ use \OCA\News\Service\ServiceNotFoundException; use \OCA\News\Db\Item; -class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { +class ItemApiControllerTest extends \PHPUnit_Framework_TestCase +{ private $itemService; private $itemAPI; @@ -29,15 +30,18 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { private $request; private $msg; - protected function setUp() { + protected function setUp() + { $this->user = 'tom'; $this->appName = 'news'; $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); $this->itemAPI = new ItemApiController( @@ -50,7 +54,8 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndex() { + public function testIndex() + { $items = [new Item()]; $this->itemService->expects($this->once()) @@ -68,13 +73,16 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->itemAPI->index(1, 2, true, 30, 20, true); - $this->assertEquals([ + $this->assertEquals( + [ 'items' => [$items[0]->toApi()] - ], $response); + ], $response + ); } - public function testIndexDefaultBatchSize() { + public function testIndexDefaultBatchSize() + { $items = [new Item()]; $this->itemService->expects($this->once()) @@ -92,13 +100,16 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->itemAPI->index(1, 2, false); - $this->assertEquals([ + $this->assertEquals( + [ 'items' => [$items[0]->toApi()] - ], $response); + ], $response + ); } - public function testUpdated() { + public function testUpdated() + { $items = [new Item()]; $this->itemService->expects($this->once()) @@ -114,13 +125,16 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { $response = $this->itemAPI->updated(1, 2, 30); - $this->assertEquals([ + $this->assertEquals( + [ 'items' => [$items[0]->toApi()] - ], $response); + ], $response + ); } - public function testRead() { + public function testRead() + { $this->itemService->expects($this->once()) ->method('read') ->with( @@ -133,11 +147,14 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testReadDoesNotExist() { + public function testReadDoesNotExist() + { $this->itemService->expects($this->once()) ->method('read') - ->will($this->throwException( - new ServiceNotFoundException($this->msg)) + ->will( + $this->throwException( + new ServiceNotFoundException($this->msg) + ) ); $response = $this->itemAPI->read(2); @@ -148,7 +165,8 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUnread() { + public function testUnread() + { $this->itemService->expects($this->once()) ->method('read') ->with( @@ -161,11 +179,14 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUnreadDoesNotExist() { + public function testUnreadDoesNotExist() + { $this->itemService->expects($this->once()) ->method('read') - ->will($this->throwException( - new ServiceNotFoundException($this->msg)) + ->will( + $this->throwException( + new ServiceNotFoundException($this->msg) + ) ); $response = $this->itemAPI->unread(2); @@ -176,7 +197,8 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testStar() { + public function testStar() + { $this->itemService->expects($this->once()) ->method('star') ->with( @@ -190,11 +212,14 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testStarDoesNotExist() { + public function testStarDoesNotExist() + { $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException( - new ServiceNotFoundException($this->msg)) + ->will( + $this->throwException( + new ServiceNotFoundException($this->msg) + ) ); $response = $this->itemAPI->star(2, 'test'); @@ -205,7 +230,8 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUnstar() { + public function testUnstar() + { $this->itemService->expects($this->once()) ->method('star') ->with( @@ -219,11 +245,14 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testUnstarDoesNotExist() { + public function testUnstarDoesNotExist() + { $this->itemService->expects($this->once()) ->method('star') - ->will($this->throwException( - new ServiceNotFoundException($this->msg)) + ->will( + $this->throwException( + new ServiceNotFoundException($this->msg) + ) ); $response = $this->itemAPI->unstar(2, 'test'); @@ -234,62 +263,78 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testReadAll() { + public function testReadAll() + { $this->itemService->expects($this->once()) ->method('readAll') ->with( $this->equalTo(30), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemAPI->readAll(30); } - public function testReadMultiple() { + public function testReadMultiple() + { $this->itemService->expects($this->at(0)) ->method('read') - ->with($this->equalTo(2), + ->with( + $this->equalTo(2), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemService->expects($this->at(1)) ->method('read') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemAPI->readMultiple([2, 4]); } - public function testReadMultipleDoesntCareAboutException() { + public function testReadMultipleDoesntCareAboutException() + { $this->itemService->expects($this->at(0)) ->method('read') ->will($this->throwException(new ServiceNotFoundException(''))); $this->itemService->expects($this->at(1)) ->method('read') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemAPI->readMultiple([2, 4]); } - public function testUnreadMultiple() { + public function testUnreadMultiple() + { $this->itemService->expects($this->at(0)) ->method('read') - ->with($this->equalTo(2), + ->with( + $this->equalTo(2), $this->equalTo(false), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemService->expects($this->at(1)) ->method('read') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo(false), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemAPI->unreadMultiple([2, 4]); } - public function testStarMultiple() { + public function testStarMultiple() + { $ids = [ [ 'feedId' => 2, @@ -303,21 +348,26 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { $this->itemService->expects($this->at(0)) ->method('star') - ->with($this->equalTo(2), + ->with( + $this->equalTo(2), $this->equalTo('a'), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemService->expects($this->at(1)) ->method('star') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo('b'), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemAPI->starMultiple($ids); } - public function testStarMultipleDoesntCareAboutException() { + public function testStarMultipleDoesntCareAboutException() + { $ids = [ [ 'feedId' => 2, @@ -334,15 +384,18 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { ->will($this->throwException(new ServiceNotFoundException(''))); $this->itemService->expects($this->at(1)) ->method('star') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo('b'), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemAPI->starMultiple($ids); } - public function testUnstarMultiple() { + public function testUnstarMultiple() + { $ids = [ [ 'feedId' => 2, @@ -356,16 +409,20 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase { $this->itemService->expects($this->at(0)) ->method('star') - ->with($this->equalTo(2), + ->with( + $this->equalTo(2), $this->equalTo('a'), $this->equalTo(false), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemService->expects($this->at(1)) ->method('star') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo('b'), $this->equalTo(false), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemAPI->unstarMultiple($ids); } diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index 1c85748d5..d99b9be21 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.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\Controller; @@ -22,7 +22,8 @@ use \OCA\News\Db\FeedType; use \OCA\News\Service\ServiceNotFoundException; -class ItemControllerTest extends \PHPUnit_Framework_TestCase { +class ItemControllerTest extends \PHPUnit_Framework_TestCase +{ private $appName; private $settings; @@ -36,11 +37,13 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { /** * Gets run before each test */ - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->user = 'jackob'; $this->settings = $this->getMockBuilder( - '\OCP\IConfig') + '\OCP\IConfig' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = @@ -52,17 +55,21 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); - $this->controller = new ItemController($this->appName, $this->request, - $this->feedService, $this->itemService, $this->settings, - $this->user); + $this->controller = new ItemController( + $this->appName, $this->request, + $this->feedService, $this->itemService, $this->settings, + $this->user + ); $this->newestItemId = 12312; } - public function testRead(){ + public function testRead() + { $this->itemService->expects($this->once()) ->method('read') ->with(4, true, $this->user); @@ -71,7 +78,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { } - public function testReadDoesNotExist(){ + public function testReadDoesNotExist() + { $msg = 'hi'; $this->itemService->expects($this->once()) @@ -86,51 +94,64 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { } - public function testReadMultiple() { + public function testReadMultiple() + { $this->itemService->expects($this->at(0)) ->method('read') - ->with($this->equalTo(2), + ->with( + $this->equalTo(2), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->itemService->expects($this->at(1)) ->method('read') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->controller->readMultiple([2, 4]); } - public function testReadMultipleDontStopOnException() { + public function testReadMultipleDontStopOnException() + { $this->itemService->expects($this->at(0)) ->method('read') - ->with($this->equalTo(2), + ->with( + $this->equalTo(2), $this->equalTo(true), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->throwException(new ServiceNotFoundException('yo'))); $this->itemService->expects($this->at(1)) ->method('read') - ->with($this->equalTo(4), + ->with( + $this->equalTo(4), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->controller->readMultiple([2, 4]); } - public function testStar(){ + public function testStar() + { $this->itemService->expects($this->once()) ->method('star') ->with( $this->equalTo(4), $this->equalTo('test'), $this->equalTo(true), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $this->controller->star(4, 'test', true); } - public function testStarDoesNotExist(){ + public function testStarDoesNotExist() + { $msg = 'ho'; $this->itemService->expects($this->once()) @@ -145,15 +166,18 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { } - public function testReadAll(){ + public function testReadAll() + { $feed = new Feed(); $expected = ['feeds' => [$feed]]; $this->itemService->expects($this->once()) ->method('readAll') - ->with($this->equalTo(5), - $this->equalTo($this->user)); + ->with( + $this->equalTo(5), + $this->equalTo($this->user) + ); $this->feedService->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) @@ -164,35 +188,45 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { } - private function itemsApiExpects($id, $type, $oldestFirst='1'){ + private function itemsApiExpects($id, $type, $oldestFirst='1') + { $this->settings->expects($this->at(0)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('showAll')) + $this->equalTo('showAll') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(1)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('oldestFirst')) + $this->equalTo('oldestFirst') + ) ->will($this->returnValue($oldestFirst)); $this->settings->expects($this->at(2)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('lastViewedFeedId'), - $this->equalTo($id)); + $this->equalTo($id) + ); $this->settings->expects($this->at(3)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('lastViewedFeedType'), - $this->equalTo($type)); + $this->equalTo($type) + ); } - public function testIndex(){ + public function testIndex() + { $feeds = [new Feed()]; $result = [ 'items' => [new Item()], @@ -228,7 +262,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo(true), $this->equalTo(false), $this->equalTo($this->user), - $this->equalTo([])) + $this->equalTo([]) + ) ->will($this->returnValue($result['items'])); $response = $this->controller->index(FeedType::FEED, 2, 3); @@ -236,7 +271,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndexSearch(){ + public function testIndexSearch() + { $feeds = [new Feed()]; $result = [ 'items' => [new Item()], @@ -272,29 +308,35 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo(true), $this->equalTo(false), $this->equalTo($this->user), - $this->equalTo(['test', 'search'])) + $this->equalTo(['test', 'search']) + ) ->will($this->returnValue($result['items'])); - $response = $this->controller->index(FeedType::FEED, 2, 3, - 0, null, null, 'test%20%20search%20'); + $response = $this->controller->index( + FeedType::FEED, 2, 3, + 0, null, null, 'test%20%20search%20' + ); $this->assertEquals($result, $response); } - public function testItemsOffsetNotZero(){ + public function testItemsOffsetNotZero() + { $result = ['items' => [new Item()]]; $this->itemsApiExpects(2, FeedType::FEED); $this->itemService->expects($this->once()) ->method('findAll') - ->with($this->equalTo(2), + ->with( + $this->equalTo(2), $this->equalTo(FeedType::FEED), $this->equalTo(3), $this->equalTo(10), $this->equalTo(true), $this->equalTo(true), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->returnValue($result['items'])); $this->feedService->expects($this->never()) @@ -305,7 +347,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { } - public function testGetItemsNoNewestItemsId(){ + public function testGetItemsNoNewestItemsId() + { $this->itemsApiExpects(2, FeedType::FEED); $this->itemService->expects($this->once()) @@ -318,7 +361,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { } - public function testNewItems(){ + public function testNewItems() + { $feeds = [new Feed()]; $result = [ 'items' => [new Item()], @@ -329,9 +373,11 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->settings->expects($this->once()) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('showAll')) + $this->equalTo('showAll') + ) ->will($this->returnValue('1')); $this->feedService->expects($this->once()) @@ -356,7 +402,8 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { $this->equalTo(FeedType::FEED), $this->equalTo(3), $this->equalTo(true), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->returnValue($result['items'])); $response = $this->controller->newItems(FeedType::FEED, 2, 3); @@ -364,12 +411,15 @@ class ItemControllerTest extends \PHPUnit_Framework_TestCase { } - public function testGetNewItemsNoNewestItemsId(){ + public function testGetNewItemsNoNewestItemsId() + { $this->settings->expects($this->once()) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('showAll')) + $this->equalTo('showAll') + ) ->will($this->returnValue('1')); $this->itemService->expects($this->once()) diff --git a/tests/Unit/Controller/JSONHttpErrorTest.php b/tests/Unit/Controller/JSONHttpErrorTest.php index d7dcaa90a..a77566e04 100644 --- a/tests/Unit/Controller/JSONHttpErrorTest.php +++ b/tests/Unit/Controller/JSONHttpErrorTest.php @@ -5,24 +5,27 @@ * 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\Controller; use OCA\News\Controller\JSONHttpError; -class Test { +class Test +{ use JSONHttpError; } -class JSONHttpErrorTest extends \PHPUnit_Framework_TestCase { +class JSONHttpErrorTest extends \PHPUnit_Framework_TestCase +{ - public function testError() { + public function testError() + { $ex = new \Exception('hi'); $test = new Test(); $result = $test->error($ex, 3); diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 0ab433f05..b90c200d4 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.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\Controller; @@ -17,7 +17,8 @@ use OCA\News\Controller\PageController; use \OCA\News\Db\FeedType; -class PageControllerTest extends \PHPUnit_Framework_TestCase { +class PageControllerTest extends \PHPUnit_Framework_TestCase +{ private $settings; private $appName; @@ -35,7 +36,8 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { /** * Gets run before each test */ - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->user = 'becka'; $this->configData = [ @@ -49,52 +51,67 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { 'homepage' => 'https://github.com/owncloud/test' ]; $this->l10n = $this->request = $this->getMockBuilder( - '\OCP\IL10n') + '\OCP\IL10n' + ) ->disableOriginalConstructor() ->getMock(); $this->settings = $this->getMockBuilder( - '\OCP\IConfig') + '\OCP\IConfig' + ) ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->urlGenerator = $this->getMockBuilder( - '\OCP\IURLGenerator') + '\OCP\IURLGenerator' + ) ->disableOriginalConstructor() ->getMock(); $this->appConfig = $this->getMockBuilder( - '\OCA\News\Config\Config') + '\OCA\News\Config\Config' + ) ->disableOriginalConstructor() ->getMock(); $this->config = $this->getMockBuilder( - '\OCA\News\Config\Config') + '\OCA\News\Config\Config' + ) ->disableOriginalConstructor() ->getMock(); $this->recommended = $this->getMockBuilder( - '\OCA\News\Explore\RecommendedSites') + '\OCA\News\Explore\RecommendedSites' + ) ->disableOriginalConstructor() ->getMock(); $this->status = $this->getMockBuilder( - '\OCA\News\Service\StatusService') + '\OCA\News\Service\StatusService' + ) ->disableOriginalConstructor() ->getMock(); - $this->controller = new PageController($this->appName, $this->request, + $this->controller = new PageController( + $this->appName, $this->request, $this->settings, $this->urlGenerator, $this->config, $this->l10n, $this->recommended, $this->status, - $this->user); + $this->user + ); } - public function testIndex(){ + public function testIndex() + { $this->status->expects($this->once()) ->method('getStatus') - ->will($this->returnValue([ - 'warnings' => [ + ->will( + $this->returnValue( + [ + 'warnings' => [ 'improperlyConfiguredCron' => false - ] - ])); + ] + ] + ) + ); $response = $this->controller->index(); $this->assertEquals('index', $response->getTemplateName()); @@ -102,14 +119,19 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { } - public function testIndexNoCorrectCronAjax(){ + public function testIndexNoCorrectCronAjax() + { $this->status->expects($this->once()) ->method('getStatus') - ->will($this->returnValue([ - 'warnings' => [ + ->will( + $this->returnValue( + [ + 'warnings' => [ 'improperlyConfiguredCron' => true - ] - ])); + ] + ] + ) + ); $response = $this->controller->index(); @@ -117,7 +139,8 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { } - public function testSettings() { + public function testSettings() + { $result = [ 'settings' => [ 'showAll' => true, @@ -135,41 +158,53 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { ->will($this->returnValue('de')); $this->settings->expects($this->at(0)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('showAll')) + $this->equalTo('showAll') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(1)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('compact')) + $this->equalTo('compact') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(2)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll')) + $this->equalTo('preventReadOnScroll') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(3)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('oldestFirst')) + $this->equalTo('oldestFirst') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(4)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('compactExpand')) + $this->equalTo('compactExpand') + ) ->will($this->returnValue('1')); $this->config->expects($this->once()) ->method('getExploreUrl') ->will($this->returnValue(' ')); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') - ->with($this->equalTo('news.page.explore'), - $this->equalTo(['lang' => 'en'])) + ->with( + $this->equalTo('news.page.explore'), + $this->equalTo(['lang' => 'en']) + ) ->will($this->returnValue('test')); @@ -178,7 +213,8 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { } - public function testSettingsExploreUrlSet() { + public function testSettingsExploreUrlSet() + { $result = [ 'settings' => [ 'showAll' => true, @@ -196,33 +232,43 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { ->will($this->returnValue('de')); $this->settings->expects($this->at(0)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('showAll')) + $this->equalTo('showAll') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(1)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('compact')) + $this->equalTo('compact') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(2)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll')) + $this->equalTo('preventReadOnScroll') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(3)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('oldestFirst')) + $this->equalTo('oldestFirst') + ) ->will($this->returnValue('1')); $this->settings->expects($this->at(4)) ->method('getUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), - $this->equalTo('compactExpand')) + $this->equalTo('compactExpand') + ) ->will($this->returnValue('1')); $this->config->expects($this->once()) ->method('getExploreUrl') @@ -235,57 +281,73 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($result, $response); } - public function testUpdateSettings() { + public function testUpdateSettings() + { $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('showAll'), - $this->equalTo('1')); + $this->equalTo('1') + ); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('compact'), - $this->equalTo('1')); + $this->equalTo('1') + ); $this->settings->expects($this->at(2)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('preventReadOnScroll'), - $this->equalTo('0')); + $this->equalTo('0') + ); $this->settings->expects($this->at(3)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('oldestFirst'), - $this->equalTo('1')); + $this->equalTo('1') + ); $this->settings->expects($this->at(4)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('compactExpand'), - $this->equalTo('1')); + $this->equalTo('1') + ); $this->controller->updateSettings(true, true, false, true, true); } - public function testExplore(){ + public function testExplore() + { $in = 'test'; $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('lastViewedFeedId'), - $this->equalTo(0)); + $this->equalTo(0) + ); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with($this->equalTo($this->user), + ->with( + $this->equalTo($this->user), $this->equalTo($this->appName), $this->equalTo('lastViewedFeedType'), - $this->equalTo(FeedType::EXPLORE)); + $this->equalTo(FeedType::EXPLORE) + ); $this->recommended->expects($this->once()) ->method('forLanguage') diff --git a/tests/Unit/Controller/UserApiControllerTest.php b/tests/Unit/Controller/UserApiControllerTest.php index af49e59f1..e2868ebe1 100644 --- a/tests/Unit/Controller/UserApiControllerTest.php +++ b/tests/Unit/Controller/UserApiControllerTest.php @@ -5,17 +5,18 @@ * 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\Controller; use OCA\News\Controller\UserApiController; -class UserApiControllerTest extends \PHPUnit_Framework_TestCase { +class UserApiControllerTest extends \PHPUnit_Framework_TestCase +{ private $request; private $appName; @@ -25,26 +26,32 @@ class UserApiControllerTest extends \PHPUnit_Framework_TestCase { private $user; private $file; - protected function setUp() { + protected function setUp() + { $this->appName = 'news'; $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->rootFolder = $this->getMockBuilder( - '\OCP\Files\IRootFolder') + '\OCP\Files\IRootFolder' + ) ->disableOriginalConstructor() ->getMock(); $this->file = $this->getMockBuilder( - '\OCP\Files\File') + '\OCP\Files\File' + ) ->disableOriginalConstructor() ->getMock(); $this->userSession = $this->getMockBuilder( - '\OCP\IUserSession') + '\OCP\IUserSession' + ) ->disableOriginalConstructor() ->getMock(); $this->user = $this->getMockBuilder( - '\OCP\IUser') + '\OCP\IUser' + ) ->disableOriginalConstructor() ->getMock(); $this->controller = new UserApiController( @@ -55,7 +62,8 @@ class UserApiControllerTest extends \PHPUnit_Framework_TestCase { } - private function expectUser($uid, $displayName, $lastLogin) { + private function expectUser($uid, $displayName, $lastLogin) + { $this->userSession->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -70,16 +78,21 @@ class UserApiControllerTest extends \PHPUnit_Framework_TestCase { ->will($this->returnValue($displayName)); } - private function expectImg($isJpg, $isPng, $user, $exists, $data) { + private function expectImg($isJpg, $isPng, $user, $exists, $data) + { $jpg = '/' . $user . '/' . 'avatar.jpg'; $png = '/' . $user . '/' . 'avatar.png'; $this->rootFolder->expects($this->any()) ->method('nodeExists') - ->will($this->returnValueMap([ - [$jpg, $isJpg], - [$png, $isPng] - ])); + ->will( + $this->returnValueMap( + [ + [$jpg, $isJpg], + [$png, $isPng] + ] + ) + ); $this->rootFolder->expects($this->any()) ->method('get') ->will($this->returnValue($this->file)); @@ -88,7 +101,8 @@ class UserApiControllerTest extends \PHPUnit_Framework_TestCase { ->will($this->returnValue($data)); } - public function testGetJpeg() { + public function testGetJpeg() + { $this->expectUser('john', 'John', 123); $this->expectImg(true, false, 'john', true, 'hi'); @@ -106,7 +120,8 @@ class UserApiControllerTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($expected, $result); } - public function testGetPng() { + public function testGetPng() + { $this->expectUser('john', 'John', 123); $this->expectImg(false, true, 'john', false, 'hi'); @@ -124,7 +139,8 @@ class UserApiControllerTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($expected, $result); } - public function testNoAvatar() { + public function testNoAvatar() + { $this->expectUser('john', 'John', 123); $this->expectImg(false, false, 'john', false, 'hi'); diff --git a/tests/Unit/Controller/UtilityApiControllerTest.php b/tests/Unit/Controller/UtilityApiControllerTest.php index f45502d39..6237f3c8e 100644 --- a/tests/Unit/Controller/UtilityApiControllerTest.php +++ b/tests/Unit/Controller/UtilityApiControllerTest.php @@ -5,17 +5,18 @@ * 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\Controller; use OCA\News\Controller\UtilityApiController; -class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase { +class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase +{ private $settings; private $request; @@ -24,22 +25,27 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase { private $appName; private $status; - protected function setUp() { + protected function setUp() + { $this->appName = 'news'; $this->settings = $this->getMockBuilder( - '\OCP\IConfig') + '\OCP\IConfig' + ) ->disableOriginalConstructor() ->getMock(); $this->request = $this->getMockBuilder( - '\OCP\IRequest') + '\OCP\IRequest' + ) ->disableOriginalConstructor() ->getMock(); $this->updater = $this->getMockBuilder( - '\OCA\News\Utility\Updater') + '\OCA\News\Utility\Updater' + ) ->disableOriginalConstructor() ->getMock(); $this->status = $this->getMockBuilder( - '\OCA\News\Service\StatusService') + '\OCA\News\Service\StatusService' + ) ->disableOriginalConstructor() ->getMock(); $this->newsAPI = new UtilityApiController( @@ -49,11 +55,14 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testGetVersion(){ + public function testGetVersion() + { $this->settings->expects($this->once()) ->method('getAppValue') - ->with($this->equalTo($this->appName), - $this->equalTo('installed_version')) + ->with( + $this->equalTo($this->appName), + $this->equalTo('installed_version') + ) ->will($this->returnValue('1.0')); $response = $this->newsAPI->version(); @@ -63,21 +72,24 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase { } - public function testBeforeUpdate(){ + public function testBeforeUpdate() + { $this->updater->expects($this->once()) ->method('beforeUpdate'); $this->newsAPI->beforeUpdate(); } - public function testAfterUpdate(){ + public function testAfterUpdate() + { $this->updater->expects($this->once()) ->method('afterUpdate'); $this->newsAPI->afterUpdate(); } - public function testStatus(){ + public function testStatus() + { $in = 'hi'; $this->status->expects($this->once()) ->method('getStatus') diff --git a/tests/Unit/Db/FeedTest.php b/tests/Unit/Db/FeedTest.php index 9b0c96f86..5e4e2a5a5 100644 --- a/tests/Unit/Db/FeedTest.php +++ b/tests/Unit/Db/FeedTest.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\Db; @@ -16,10 +16,12 @@ namespace OCA\News\Tests\Unit\Db; use OCA\News\Db\Feed; -class FeedTest extends \PHPUnit_Framework_TestCase { +class FeedTest extends \PHPUnit_Framework_TestCase +{ - private function createFeed() { + private function createFeed() + { $feed = new Feed(); $feed->setId(3); $feed->setHttpLastModified(44); @@ -43,10 +45,12 @@ class FeedTest extends \PHPUnit_Framework_TestCase { return $feed; } - public function testToAPI() { + public function testToAPI() + { $feed = $this->createFeed(); - $this->assertEquals([ + $this->assertEquals( + [ 'id' => 3, 'url' => 'http://google.com/some/weird/path', 'title' => 'title', @@ -59,14 +63,17 @@ class FeedTest extends \PHPUnit_Framework_TestCase { 'link' => 'https://www.google.com/some/weird/path', 'updateErrorCount' => 2, 'lastUpdateError' => 'hi' - ], $feed->toAPI()); + ], $feed->toAPI() + ); } - public function testSerialize() { + public function testSerialize() + { $feed = $this->createFeed(); - $this->assertEquals([ + $this->assertEquals( + [ 'id' => 3, 'url' => 'http://google.com/some/weird/path', 'title' => 'title', @@ -90,25 +97,29 @@ class FeedTest extends \PHPUnit_Framework_TestCase { 'lastUpdateError' => 'hi', 'basicAuthUser' => 'user', 'basicAuthPassword' => 'password' - ], $feed->jsonSerialize()); + ], $feed->jsonSerialize() + ); } - public function testSetXSSUrl() { + public function testSetXSSUrl() + { $feed = new Feed(); $feed->setUrl('javascript:alert()'); $this->assertEquals('', $feed->getUrl()); } - public function testSetUrlUpdatesHash() { + public function testSetUrlUpdatesHash() + { $feed = new Feed(); $feed->setUrl('http://test'); $this->assertEquals(md5('http://test'), $feed->getUrlHash()); } - public function testSetXSSLink() { + public function testSetXSSLink() + { $feed = new Feed(); $feed->setLink('javascript:alert()'); $this->assertEquals('', $feed->getLink()); diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php index 87b276d7c..bf7b1cae0 100644 --- a/tests/Unit/Db/FolderMapperTest.php +++ b/tests/Unit/Db/FolderMapperTest.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\Db; @@ -43,7 +43,8 @@ class FolderMapperTest extends MapperTestUtility } - public function testFind(){ + public function testFind() + { $userId = 'john'; $id = 3; $rows = [['id' => $this->folders[0]->getId()]]; @@ -59,7 +60,8 @@ class FolderMapperTest extends MapperTestUtility } - public function testFindNotFound(){ + public function testFindNotFound() + { $userId = 'john'; $id = 3; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . @@ -75,7 +77,8 @@ class FolderMapperTest extends MapperTestUtility } - public function testFindMoreThanOneResultFound(){ + public function testFindMoreThanOneResultFound() + { $userId = 'john'; $id = 3; $rows = $this->twoRows; @@ -93,7 +96,8 @@ class FolderMapperTest extends MapperTestUtility - public function testFindAllFromUser(){ + public function testFindAllFromUser() + { $userId = 'john'; $rows = $this->twoRows; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . @@ -107,7 +111,8 @@ class FolderMapperTest extends MapperTestUtility } - public function testFindByName(){ + public function testFindByName() + { $folderName = 'heheh'; $userId = 'john'; $rows = $this->twoRows; @@ -122,7 +127,8 @@ class FolderMapperTest extends MapperTestUtility } - public function testDelete(){ + public function testDelete() + { $folder = new Folder(); $folder->setId(3); @@ -143,7 +149,8 @@ class FolderMapperTest extends MapperTestUtility } - public function testGetPurgeDeleted(){ + public function testGetPurgeDeleted() + { $rows = $this->twoRows; $deleteOlderThan = 110; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . @@ -157,7 +164,8 @@ class FolderMapperTest extends MapperTestUtility - public function testGetPurgeDeletedUser(){ + public function testGetPurgeDeletedUser() + { $rows = $this->twoRows; $deleteOlderThan = 110; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . @@ -173,7 +181,8 @@ class FolderMapperTest extends MapperTestUtility } - public function testGetAllPurgeDeletedUser(){ + public function testGetAllPurgeDeletedUser() + { $rows = $this->twoRows; $sql = 'SELECT * FROM `*PREFIX*news_folders` ' . @@ -186,7 +195,8 @@ class FolderMapperTest extends MapperTestUtility } - public function testDeleteFromUser(){ + public function testDeleteFromUser() + { $userId = 'john'; $sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?'; diff --git a/tests/Unit/Db/FolderTest.php b/tests/Unit/Db/FolderTest.php index 39352425e..4db59cef2 100644 --- a/tests/Unit/Db/FolderTest.php +++ b/tests/Unit/Db/FolderTest.php @@ -5,32 +5,37 @@ * 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\Db; use OCA\News\Db\Folder; -class FolderTest extends \PHPUnit_Framework_TestCase { +class FolderTest extends \PHPUnit_Framework_TestCase +{ - public function testToAPI() { + public function testToAPI() + { $folder = new Folder(); $folder->setId(3); $folder->setName('name'); - $this->assertEquals([ + $this->assertEquals( + [ 'id' => 3, 'name' => 'name' - ], $folder->toAPI()); + ], $folder->toAPI() + ); } - public function testSerialize() { + public function testSerialize() + { $folder = new Folder(); $folder->setId(3); $folder->setName('john'); @@ -39,13 +44,15 @@ class FolderTest extends \PHPUnit_Framework_TestCase { $folder->setOpened(true); $folder->setDeletedAt(9); - $this->assertEquals([ + $this->assertEquals( + [ 'id' => 3, 'parentId' => 4, 'name' => 'john', 'userId' => 'abc', 'opened' => true, 'deletedAt' => 9, - ], $folder->jsonSerialize()); + ], $folder->jsonSerialize() + ); } }
\ No newline at end of file diff --git a/tests/Unit/Db/ItemTest.php b/tests/Unit/Db/ItemTest.php index cceca4b8b..f86c2c8a9 100644 --- a/tests/Unit/Db/ItemTest.php +++ b/tests/Unit/Db/ItemTest.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\Db; @@ -16,46 +16,55 @@ namespace OCA\News\Tests\Unit\Db; use OCA\News\Db\Feed; use OCA\News\Db\Item; -class ItemTest extends \PHPUnit_Framework_TestCase { +class ItemTest extends \PHPUnit_Framework_TestCase +{ - /** @var Item */ + /** + * @var Item + */ private $item; - protected function setUp(){ + protected function setUp() + { $this->item = new Item(); $this->item->setStatus(0); } - public function testSetRead(){ + public function testSetRead() + { $this->item->setUnread(false); $this->assertFalse($this->item->isUnread()); } - public function testSetUnread(){ + public function testSetUnread() + { $this->item->setUnread(true); $this->assertTrue($this->item->isUnread()); } - public function testSetStarred(){ + public function testSetStarred() + { $this->item->setStarred(true); $this->assertTrue($this->item->isStarred()); } - public function testSetUnstarred(){ + public function testSetUnstarred() + { $this->item->setStarred(false); $this->assertFalse($this->item->isStarred()); } - public function testToAPI() { + public function testToAPI() + { $item = new Item(); $item->setId(3); $item->setGuid('guid'); @@ -77,7 +86,8 @@ class ItemTest extends \PHPUnit_Framework_TestCase { $item->setFingerprint('fingerprint'); $item->setContentHash('contentHash'); - $this->assertEquals([ + $this->assertEquals( + [ 'id' => 3, 'guid' => 'guid', 'guidHash' => 'hash', @@ -96,11 +106,13 @@ class ItemTest extends \PHPUnit_Framework_TestCase { 'rtl' => true, 'fingerprint' => 'fingerprint', 'contentHash' => 'contentHash' - ], $item->toAPI()); + ], $item->toAPI() + ); } - public function testJSONSerialize() { + public function testJSONSerialize() + { $item = new Item(); $item->setId(3); $item->setGuid('guid'); @@ -121,7 +133,8 @@ class ItemTest extends \PHPUnit_Framework_TestCase { $item->setStarred(true); $item->setLastModified(321); - $this->assertEquals([ + $this->assertEquals( + [ 'id' => 3, 'guid' => 'guid', 'guidHash' => 'hash', @@ -140,10 +153,12 @@ class ItemTest extends \PHPUnit_Framework_TestCase { 'rtl' => true, 'intro' => 'this is a test', 'fingerprint' => 'fingerprint' - ], $item->jsonSerialize()); + ], $item->jsonSerialize() + ); } - public function testToExport() { + public function testToExport() + { $item = new Item(); $item->setId(3); $item->setGuid('guid'); @@ -167,7 +182,8 @@ class ItemTest extends \PHPUnit_Framework_TestCase { $feed->setLink('http://test'); $feeds = ["feed1" => $feed]; - $this->assertEquals([ + $this->assertEquals( + [ 'guid' => 'guid', 'url' => 'https://google', 'title' => 'title', @@ -181,11 +197,13 @@ class ItemTest extends \PHPUnit_Framework_TestCase { 'starred' => true, 'feedLink' => 'http://test', 'rtl' => true - ], $item->toExport($feeds)); + ], $item->toExport($feeds) + ); } - private function createImportItem($isRead) { + private function createImportItem($isRead) + { $item = new Item(); $item->setGuid('guid'); $item->setGuidHash('guid'); @@ -210,7 +228,8 @@ class ItemTest extends \PHPUnit_Framework_TestCase { } - public function testSearchIndex() { + public function testSearchIndex() + { $item = new Item(); $item->setBody('<a>somEthäng</a>'); $item->setUrl('http://link'); @@ -222,7 +241,8 @@ class ItemTest extends \PHPUnit_Framework_TestCase { } - public function testFromImport() { + public function testFromImport() + { $item = $this->createImportItem(false); $import = [ @@ -246,7 +266,8 @@ class ItemTest extends \PHPUnit_Framework_TestCase { } - public function testFromImportRead() { + public function testFromImportRead() + { $item = $this->createImportItem(true); $import = [ @@ -271,7 +292,8 @@ class ItemTest extends \PHPUnit_Framework_TestCase { - public function testSetAuthor(){ + public function testSetAuthor() + { $item = new Item(); $item->setAuthor('<a>my link</li>'); $this->assertEquals('my link', $item->getAuthor()); @@ -279,7 +301,8 @@ class ItemTest extends \PHPUnit_Framework_TestCase { } - public function testSetTitle(){ + public function testSetTitle() + { $item = new Item(); $item->setTitle('<a>my link</li>'); $this->assertEquals('my link', $item->getTitle()); @@ -287,28 +310,34 @@ class ItemTest extends \PHPUnit_Framework_TestCase { } - public function testSetXSSUrl() { + public function testSetXSSUrl() + { $item = new Item(); $item->setUrl('javascript:alert()'); $this->assertEquals('', $item->getUrl()); } - public function testSetMagnetUrl() { + public function testSetMagnetUrl() + { $item = new Item(); $item->setUrl('magnet://link.com'); $this->assertEquals('magnet://link.com', $item->getUrl()); } - public function testMakeLinksInBodyOpenNewTab() { + public function testMakeLinksInBodyOpenNewTab() + { $item = new Item(); $item->setBody("<a href=\"test\">ha</a>"); - $this->assertEquals("<a target=\"_blank\" rel=\"noreferrer\" href=\"test\">ha</a>", - $item->getBody()); + $this->assertEquals( + "<a target=\"_blank\" rel=\"noreferrer\" href=\"test\">ha</a>", + $item->getBody() + ); } - public function testComputeFingerPrint() { + public function testComputeFingerPrint() + { $title = 'a'; $body = 'b'; $url = 'http://google.com'; @@ -321,8 +350,10 @@ class ItemTest extends \PHPUnit_Framework_TestCase { $item->setEnclosureLink($link); $item->generateSearchIndex(); - $this->assertEquals(md5($title . $url . $body . $link), - $item->getFingerprint()); + $this->assertEquals( + md5($title . $url . $body . $link), + $item->getFingerprint() + ); } } diff --git a/tests/Unit/Db/MapperFactoryTest.php b/tests/Unit/Db/MapperFactoryTest.php index f7c1ffa08..94a49f850 100644 --- a/tests/Unit/Db/MapperFactoryTest.php +++ b/tests/Unit/Db/MapperFactoryTest.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\Db; @@ -23,30 +23,35 @@ use OCP\IDBConnection; use OCA\News\Db\Mysql\ItemMapper as MysqlMapper; -class MapperFactoryTest extends PHPUnit_Framework_TestCase { - - private $db; - private $settings; - - public function setUp() { - $this->db = $this->getMockBuilder(IDBConnection::class) - ->disableOriginalConstructor() - ->getMock(); - } - - public function testGetItemMapperSqlite() { - $factory = new MapperFactory($this->db, 'sqlite', new Time()); - $this->assertTrue($factory->build() instanceof ItemMapper); - } - - public function testGetItemMapperPostgres() { - $factory = new MapperFactory($this->db, 'pgsql', new Time()); - $this->assertTrue($factory->build() instanceof ItemMapper); - } - - public function testGetItemMapperMysql() { - $factory = new MapperFactory($this->db, 'mysql', new Time()); - $this->assertTrue($factory->build() instanceof MysqlMapper); - } +class MapperFactoryTest extends PHPUnit_Framework_TestCase +{ + + private $db; + private $settings; + + public function setUp() + { + $this->db = $this->getMockBuilder(IDBConnection::class) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testGetItemMapperSqlite() + { + $factory = new MapperFactory($this->db, 'sqlite', new Time()); + $this->assertTrue($factory->build() instanceof ItemMapper); + } + + public function testGetItemMapperPostgres() + { + $factory = new MapperFactory($this->db, 'pgsql', new Time()); + $this->assertTrue($factory->build() instanceof ItemMapper); + } + + public function testGetItemMapperMysql() + { + $factory = new MapperFactory($this->db, 'mysql', new Time()); + $this->assertTrue($factory->build() instanceof MysqlMapper); + } } diff --git a/tests/Unit/Db/MapperTestUtility.php b/tests/Unit/Db/MapperTestUtility.php index 2448d8ddc..caef6527c 100644 --- a/tests/Unit/Db/MapperTestUtility.php +++ b/tests/Unit/Db/MapperTestUtility.php @@ -3,7 +3,7 @@ /** * ownCloud - App Framework * - * @author Bernhard Posselt + * @author Bernhard Posselt * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com * * This library is free software; you can redistribute it and/or @@ -18,7 +18,6 @@ * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * */ @@ -27,7 +26,8 @@ namespace OCA\News\Tests\Unit\Db; /** * Simple utility class for testing mappers */ -abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { +abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase +{ protected $db; private $query; private $queryAt; @@ -40,11 +40,13 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { * Run this function before the actual test to either set or initialize the * db. After this the db can be accessed by using $this->db */ - protected function setUp(){ + protected function setUp() + { parent::setUp(); $this->db = $this->getMockBuilder( - '\OCP\IDBConnection') + '\OCP\IDBConnection' + ) ->disableOriginalConstructor() ->getMock(); @@ -57,40 +59,47 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { /** * Checks if an array is associative - * @param array $array + * + * @param array $array * @return bool true if associative */ - private function isAssocArray(array $array) { + private function isAssocArray(array $array) + { return array_values($array) !== $array; } /** * Returns the correct PDO constant based on the value type - * @param $value + * + * @param $value * @return PDO constant */ - private function getPDOType($value) { + private function getPDOType($value) + { switch (gettype($value)) { - case 'integer': - return \PDO::PARAM_INT; - case 'boolean': - return \PDO::PARAM_BOOL; - default: - return \PDO::PARAM_STR; + case 'integer': + return \PDO::PARAM_INT; + case 'boolean': + return \PDO::PARAM_BOOL; + default: + return \PDO::PARAM_STR; } } /** * Create mocks and set expected results for database queries - * @param string $sql the sql query that you expect to receive - * @param array $arguments the expected arguments for the prepare query - * method - * @param array $returnRows the rows that should be returned for the result - * of the database query. If not provided, it wont be assumed that fetch - * will be called on the result + * + * @param string $sql the sql query that you expect to receive + * @param array $arguments the expected arguments for the prepare query + * method + * @param array $returnRows the rows that should be returned for the result + * of the database query. If not provided, it wont + * be assumed that fetch will be called on the + * result */ protected function setMapperResult($sql, $arguments=array(), $returnRows=array(), - $limit=null, $offset=null, $expectClose=false){ + $limit=null, $offset=null, $expectClose=false + ) { if($limit === null && $offset === null) { $this->db->expects($this->at($this->prepareAt)) ->method('prepare') @@ -104,16 +113,20 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { } elseif($limit === null && $offset !== null) { $this->db->expects($this->at($this->prepareAt)) ->method('prepare') - ->with($this->equalTo($sql), + ->with( + $this->equalTo($sql), $this->equalTo(null), - $this->equalTo($offset)) + $this->equalTo($offset) + ) ->will(($this->returnValue($this->query))); } else { $this->db->expects($this->at($this->prepareAt)) ->method('prepare') - ->with($this->equalTo($sql), + ->with( + $this->equalTo($sql), $this->equalTo($limit), - $this->equalTo($offset)) + $this->equalTo($offset) + ) ->will(($this->returnValue($this->query))); } @@ -124,29 +137,33 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { $this->query->expects($this->any()) ->method('fetch') - ->will($this->returnCallback( - function() use ($iterators, $fetchAt){ - $iterator = $iterators[$fetchAt]; - $result = $iterator->next(); + ->will( + $this->returnCallback( + function () use ($iterators, $fetchAt) { + $iterator = $iterators[$fetchAt]; + $result = $iterator->next(); - if($result === false) { - $fetchAt++; - } + if($result === false) { + $fetchAt++; + } - $this->queryAt++; + $this->queryAt++; - return $result; - } - )); + return $result; + } + ) + ); if ($this->isAssocArray($arguments)) { foreach($arguments as $key => $argument) { $pdoConstant = $this->getPDOType($argument); $this->query->expects($this->at($this->queryAt)) ->method('bindValue') - ->with($this->equalTo($key), + ->with( + $this->equalTo($key), $this->equalTo($argument), - $this->equalTo($pdoConstant)); + $this->equalTo($pdoConstant) + ); $this->queryAt++; } } else { @@ -155,9 +172,11 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { $pdoConstant = $this->getPDOType($argument); $this->query->expects($this->at($this->queryAt)) ->method('bindValue') - ->with($this->equalTo($index), + ->with( + $this->equalTo($index), $this->equalTo($argument), - $this->equalTo($pdoConstant)); + $this->equalTo($pdoConstant) + ); $index++; $this->queryAt++; } @@ -165,9 +184,13 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { $this->query->expects($this->at($this->queryAt)) ->method('execute') - ->will($this->returnCallback(function($sql, $p=null, $o=null, $s=null) { + ->will( + $this->returnCallback( + function ($sql, $p=null, $o=null, $s=null) { - })); + } + ) + ); $this->queryAt++; @@ -188,17 +211,20 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { } -class ArgumentIterator { +class ArgumentIterator +{ private $arguments; - public function __construct($arguments){ + public function __construct($arguments) + { $this->arguments = $arguments; } - public function next(){ + public function next() + { $result = array_shift($this->arguments); - if($result === null){ + if($result === null) { return false; } else { return $result; diff --git a/tests/Unit/Fetcher/FeedFetcherTest.php b/tests/Unit/Fetcher/FeedFetcherTest.php index ae0895d15..500463e01 100644 --- a/tests/Unit/Fetcher/FeedFetcherTest.php +++ b/tests/Unit/Fetcher/FeedFetcherTest.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\Fetcher; @@ -20,7 +20,8 @@ use OCP\Http\Client\IClientService; use PicoFeed\Processor\ItemPostProcessor; -class FeedFetcherTest extends \PHPUnit_Framework_TestCase { +class FeedFetcherTest extends \PHPUnit_Framework_TestCase +{ private $fetcher; private $parser; @@ -58,43 +59,53 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { private $location; private $feedLanguage; - protected function setUp(){ + protected function setUp() + { $this->l10n = $this->getMockBuilder( - '\OCP\IL10N') + '\OCP\IL10N' + ) ->disableOriginalConstructor() ->getMock(); $this->reader = $this->getMockBuilder( - '\PicoFeed\Reader\Reader') + '\PicoFeed\Reader\Reader' + ) ->disableOriginalConstructor() ->getMock(); $this->parser = $this->getMockBuilder( - '\PicoFeed\Parser\Parser') + '\PicoFeed\Parser\Parser' + ) ->disableOriginalConstructor() ->getMock(); $this->client = $this->getMockBuilder( - '\PicoFeed\Client\Client') + '\PicoFeed\Client\Client' + ) ->disableOriginalConstructor() ->getMock(); $this->parsedFeed = $this->getMockBuilder( - '\PicoFeed\Parser\Feed') + '\PicoFeed\Parser\Feed' + ) ->disableOriginalConstructor() ->getMock(); $this->item = $this->getMockBuilder( - '\PicoFeed\Parser\Item') + '\PicoFeed\Parser\Item' + ) ->disableOriginalConstructor() ->getMock(); $this->faviconFetcher = $this->getMockBuilder( - '\PicoFeed\Reader\Favicon') + '\PicoFeed\Reader\Favicon' + ) ->disableOriginalConstructor() ->getMock(); $this->faviconFactory = $this->getMockBuilder( - '\OCA\News\Utility\PicoFeedFaviconFactory') + '\OCA\News\Utility\PicoFeedFaviconFactory' + ) ->disableOriginalConstructor() ->getMock(); $this->time = 2323; $timeFactory = $this->getMockBuilder( - '\OCA\News\Utility\Time') + '\OCA\News\Utility\Time' + ) ->disableOriginalConstructor() ->getMock(); $timeFactory->expects($this->any()) @@ -108,11 +119,12 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $clientService = $this->getMockBuilder(IClientService::class) ->getMock(); $this->fetcher = new FeedFetcher( - $this->reader, - $this->faviconFactory, - $this->l10n, - $timeFactory, - $clientService); + $this->reader, + $this->faviconFactory, + $this->l10n, + $timeFactory, + $clientService + ); $this->url = 'http://tests'; $this->permalink = 'http://permalink'; @@ -140,13 +152,15 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - public function testCanHandle(){ + public function testCanHandle() + { $url = 'google.de'; $this->assertTrue($this->fetcher->canHandle($url)); } - private function setUpReader($url='', $modified=true, $noParser=false) { + private function setUpReader($url='', $modified=true, $noParser=false) + { $this->reader->expects($this->once()) ->method('discover') ->with($this->equalTo($url)) @@ -178,9 +192,11 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { if ($noParser) { $this->reader->expects($this->once()) ->method('getParser') - ->will($this->throwException( - new \PicoFeed\Reader\SubscriptionNotFoundException() - )); + ->will( + $this->throwException( + new \PicoFeed\Reader\SubscriptionNotFoundException() + ) + ); } else { $this->reader->expects($this->once()) ->method('getParser') @@ -200,20 +216,23 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - private function expectFeed($method, $return, $count = 1) { + private function expectFeed($method, $return, $count = 1) + { $this->parsedFeed->expects($this->exactly($count)) ->method($method) ->will($this->returnValue($return)); } - private function expectItem($method, $return, $count = 1) { + private function expectItem($method, $return, $count = 1) + { $this->item->expects($this->exactly($count)) ->method($method) ->will($this->returnValue($return)); } - private function createItem($enclosureType=null) { + private function createItem($enclosureType=null) + { $this->expectItem('getUrl', $this->permalink); $this->expectItem('getTitle', $this->title); $this->expectItem('getId', $this->guid); @@ -223,11 +242,11 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { date_default_timezone_set('America/Los_Angeles'); - $pubdate = \Datetime::createFromFormat('U',$this->pub); + $pubdate = \Datetime::createFromFormat('U', $this->pub); $this->expectItem('getPublishedDate', $pubdate); $item->setPubDate($this->pub); - $update = \Datetime::createFromFormat('U',$this->updated); + $update = \Datetime::createFromFormat('U', $this->updated); $this->expectItem('getUpdatedDate', $update); $item->setUpdatedDate($this->updated); @@ -256,7 +275,8 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - private function createFeed($hasFavicon=false) { + private function createFeed($hasFavicon=false) + { $this->expectFeed('getTitle', $this->feedTitle); $this->expectFeed('getSiteUrl', $this->feedLink); @@ -283,12 +303,14 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { return $feed; } - public function testNoFetchIfNotModified(){ + public function testNoFetchIfNotModified() + { $this->setUpReader($this->url, false);; $result = $this->fetcher->fetch($this->url, false); } - public function testFetch(){ + public function testFetch() + { $this->setUpReader($this->url); $item = $this->createItem(); $feed = $this->createFeed(); @@ -299,7 +321,8 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - public function testAudioEnclosure(){ + public function testAudioEnclosure() + { $this->setUpReader($this->url); $item = $this->createItem('audio/ogg'); $feed = $this->createFeed(); @@ -310,7 +333,8 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - public function testVideoEnclosure(){ + public function testVideoEnclosure() + { $this->setUpReader($this->url); $item = $this->createItem('video/ogg'); $feed = $this->createFeed(); @@ -322,7 +346,8 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { - public function testFavicon() { + public function testFavicon() + { $this->setUpReader($this->url); $feed = $this->createFeed(true); @@ -333,7 +358,8 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $this->assertEquals([$feed, [$item]], $result); } - public function testFullText() { + public function testFullText() + { $this->setUpReader($this->url); $feed = $this->createFeed(); @@ -345,13 +371,14 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - public function testNoFavicon() { + public function testNoFavicon() + { $this->setUpReader($this->url); $feed = $this->createFeed(false); $this->faviconFetcher->expects($this->never()) - ->method('find'); + ->method('find'); $item = $this->createItem(); $this->expectFeed('getItems', [$this->item]); @@ -361,20 +388,24 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { } - public function testRtl() { + public function testRtl() + { $this->setUpReader($this->url); $this->expectFeed('getLanguage', 'he-IL'); $this->expectItem('getLanguage', ''); $feed = $this->createFeed(); $item = $this->createItem(null); $this->expectFeed('getItems', [$this->item]); - list($feed, $items) = $this->fetcher->fetch($this->url, false, null, - null, true); + list($feed, $items) = $this->fetcher->fetch( + $this->url, false, null, + null, true + ); $this->assertTrue($items[0]->getRtl()); } - public function testRtlItemPrecedence() { + public function testRtlItemPrecedence() + { $this->setUpReader($this->url); $this->expectFeed('getLanguage', 'de-DE'); $this->expectItem('getLanguage', 'he-IL'); @@ -382,12 +413,15 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $feed = $this->createFeed(); $item = $this->createItem(null); $this->expectFeed('getItems', [$this->item]); - list($feed, $items) = $this->fetcher->fetch($this->url, false, null, - null, true); + list($feed, $items) = $this->fetcher->fetch( + $this->url, false, null, + null, true + ); $this->assertTrue($items[0]->getRtl()); } - public function testNegativeRtlItemPrecedence() { + public function testNegativeRtlItemPrecedence() + { $this->setUpReader($this->url); $this->expectFeed('getLanguage', 'he-IL'); $this->expectItem('getLanguage', 'de-DE'); @@ -395,8 +429,10 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $feed = $this->createFeed(); $item = $this->createItem(null); $this->expectFeed('getItems', [$this->item]); - list($feed, $items) = $this->fetcher->fetch($this->url, false, null, - null, true); + list($feed, $items) = $this->fetcher->fetch( + $this->url, false, null, + null, true + ); $this->assertFalse($items[0]->getRtl()); } diff --git a/tests/Unit/Fetcher/FetcherTest.php b/tests/Unit/Fetcher/FetcherTest.php index 67619f71d..971e35890 100644 --- a/tests/Unit/Fetcher/FetcherTest.php +++ b/tests/Unit/Fetcher/FetcherTest.php @@ -1,43 +1,45 @@ <?php /** -* Nextcloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * Nextcloud - News + * + * @author Alessandro Cosentino + * @author Bernhard Posselt + * @copyright 2012 Alessandro Cosentino cosenal@gmail.com + * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ namespace OCA\News\Tests\Unit\Fetcher; use OCA\News\Fetcher\Fetcher; -class FetcherTest extends \PHPUnit_Framework_TestCase { +class FetcherTest extends \PHPUnit_Framework_TestCase +{ private $fetcher; - protected function setUp(){ + protected function setUp() + { $this->fetcher = new Fetcher(); } - public function testFetch(){ + public function testFetch() + { $url = 'hi'; $mockFetcher = $this->getMockBuilder('\OCA\News\Fetcher\IFeedFetcher') ->disableOriginalConstructor() @@ -48,18 +50,21 @@ class FetcherTest extends \PHPUnit_Framework_TestCase { ->will($this->returnValue(true)); $mockFetcher->expects($this->once()) ->method('fetch') - ->with($this->equalTo($url), - $this->equalTo(true), - $this->equalTo(1), - $this->equalTo(2), - $this->equalTo(3)); + ->with( + $this->equalTo($url), + $this->equalTo(true), + $this->equalTo(1), + $this->equalTo(2), + $this->equalTo(3) + ); $this->fetcher->registerFetcher($mockFetcher); $this->fetcher->fetch($url, true, 1, 2, 3); } - public function testNoFetchers(){ + public function testNoFetchers() + { $url = 'hi'; $mockFetcher = $this->getMockBuilder('\OCA\News\Fetcher\IFeedFetcher') ->disableOriginalConstructor() @@ -83,7 +88,8 @@ class FetcherTest extends \PHPUnit_Framework_TestCase { $this->assertEquals([null, []], $result); } - public function testMultipleFetchers(){ + public function testMultipleFetchers() + { $url = 'hi'; $mockFetcher = $this->getMockBuilder('\OCA\News\Fetcher\IFeedFetcher') ->disableOriginalConstructor() @@ -107,7 +113,8 @@ class FetcherTest extends \PHPUnit_Framework_TestCase { } - public function testMultipleFetchersOnlyOneShouldHandle(){ + public function testMultipleFetchersOnlyOneShouldHandle() + { $url = 'hi'; $return = 'zeas'; $mockFetcher = $this->getMockBuilder('\OCA\News\Fetcher\IFeedFetcher') diff --git a/tests/Unit/Fetcher/YoutubeFetcherTest.php b/tests/Unit/Fetcher/YoutubeFetcherTest.php index 64dcf5f98..28ddc2dc1 100644 --- a/tests/Unit/Fetcher/YoutubeFetcherTest.php +++ b/tests/Unit/Fetcher/YoutubeFetcherTest.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2012, 2014 */ @@ -15,33 +15,39 @@ use \OCA\News\Db\Feed; use OCA\News\Fetcher\YoutubeFetcher; -class YoutubeFetcherTest extends \PHPUnit_Framework_TestCase { +class YoutubeFetcherTest extends \PHPUnit_Framework_TestCase +{ private $fetcher; private $feedFetcher; - public function setUp() { + public function setUp() + { $this->feedFetcher = $this->getMockBuilder( - '\OCA\News\Fetcher\FeedFetcher') + '\OCA\News\Fetcher\FeedFetcher' + ) ->disableOriginalConstructor() ->getMock(); $this->fetcher = new YoutubeFetcher($this->feedFetcher); } - public function testCanHandleFails() { + public function testCanHandleFails() + { $url = 'http://youtube.com'; $this->assertFalse($this->fetcher->canHandle($url)); } - public function testCanHandle() { + public function testCanHandle() + { $url = 'http://youtube.com/test/?test=a&list=b&b=c'; $this->assertTrue($this->fetcher->canHandle($url)); } - public function testPlaylistUrl() { + public function testPlaylistUrl() + { $url = 'http://youtube.com/something/weird?a=b&list=sobo3&c=1'; $transformedUrl = 'http://gdata.youtube.com/feeds/api/playlists/sobo3'; $favicon = true; diff --git a/tests/Unit/Http/TextDownloadResponseTest.php b/tests/Unit/Http/TextDownloadResponseTest.php index 84e5c8c60..96fa74ffc 100644 --- a/tests/Unit/Http/TextDownloadResponseTest.php +++ b/tests/Unit/Http/TextDownloadResponseTest.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 */ @@ -17,17 +17,20 @@ namespace OCA\News\Tests\Unit\Http; use OCA\News\Http\TextDownloadResponse; -class TextDownloadResponseTest extends \PHPUnit_Framework_TestCase { +class TextDownloadResponseTest extends \PHPUnit_Framework_TestCase +{ - protected function setUp() { + protected function setUp() + { $this->response = new TextDownloadResponse( 'sometext', 'file', 'content' ); } - public function testRender() { + public function testRender() + { $this->assertEquals('sometext', $this->response->render()); } diff --git a/tests/Unit/Http/TextResponseTest.php b/tests/Unit/Http/TextResponseTest.php index 972b6cc3f..cd7738de5 100644 --- a/tests/Unit/Http/TextResponseTest.php +++ b/tests/Unit/Http/TextResponseTest.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 */ @@ -17,26 +17,31 @@ namespace OCA\News\Tests\Unit\Http; use OCA\News\Http\TextResponse; -class TextResponseTest extends \PHPUnit_Framework_TestCase { +class TextResponseTest extends \PHPUnit_Framework_TestCase +{ - protected function setUp() { + protected function setUp() + { $this->response = new TextResponse('sometext'); } - public function testRender() { + public function testRender() + { $this->assertEquals('sometext', $this->response->render()); } - public function testContentTypeDefaultsToText(){ + public function testContentTypeDefaultsToText() + { $headers = $this->response->getHeaders(); $this->assertEquals('text/plain', $headers['Content-type']); } - public function testContentTypeIsSetableViaConstructor(){ + public function testContentTypeIsSetableViaConstructor() + { $response = new TextResponse('sometext', 'html'); $headers = $response->getHeaders(); diff --git a/tests/Unit/Migration/MigrateStatusFlagsTest.php b/tests/Unit/Migration/MigrateStatusFlagsTest.php index dfb35b507..8b391b812 100644 --- a/tests/Unit/Migration/MigrateStatusFlagsTest.php +++ b/tests/Unit/Migration/MigrateStatusFlagsTest.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Daniel Opitz <dev@copynpaste.de> + * @author Daniel Opitz <dev@copynpaste.de> * @copyright Daniel Opitz 2017 */ @@ -18,22 +18,31 @@ use OCP\IDBConnection; use OCP\Migration\IOutput; use Test\TestCase; -class MigrateStatusFlagsTest extends TestCase { +class MigrateStatusFlagsTest extends TestCase +{ - /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject + */ protected $db; - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var IConfig|\PHPUnit_Framework_MockObject_MockObject + */ protected $config; - /** @var IOutput|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var IOutput|\PHPUnit_Framework_MockObject_MockObject + */ protected $output; - protected function setUp() { + protected function setUp() + { $this->db = $this->createMock(IDBConnection::class); $this->config = $this->createMock(IConfig::class); $this->output = $this->createMock(IOutput::class); } - public function testRun() { + public function testRun() + { $statement = $this->createMock(Statement::class); $statement->expects($this->exactly(1)) ->method('execute') @@ -61,7 +70,8 @@ class MigrateStatusFlagsTest extends TestCase { /** * @expectedException \Exception */ - public function testRunException() { + public function testRunException() + { $statement = $this->createMock(Statement::class); $statement->expects($this->exactly(1)) ->method('execute') @@ -86,7 +96,8 @@ class MigrateStatusFlagsTest extends TestCase { $migration->run($this->output); } - public function testRunNewerVersion() { + public function testRunNewerVersion() + { $this->config->expects($this->exactly(1)) ->method('getAppValue') ->with('news', 'installed_version', '0.0.0') diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php index 08e25db8c..d5c5e0bfa 100644 --- a/tests/Unit/Service/FeedServiceTest.php +++ b/tests/Unit/Service/FeedServiceTest.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 */ @@ -23,7 +23,8 @@ use OCA\News\Fetcher\Fetcher; use OCA\News\Fetcher\FetcherException; -class FeedServiceTest extends \PHPUnit_Framework_TestCase { +class FeedServiceTest extends \PHPUnit_Framework_TestCase +{ private $feedMapper; private $feedService; @@ -40,9 +41,11 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { private $logger; private $loggerParams; - protected function setUp(){ + protected function setUp() + { $this->logger = $this->getMockBuilder( - '\OCP\ILogger') + '\OCP\ILogger' + ) ->disableOriginalConstructor() ->getMock(); $this->loggerParams = ['hi']; @@ -74,21 +77,25 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->disableOriginalConstructor() ->getMock(); $config = $this->getMockBuilder( - '\OCA\News\Config\Config') + '\OCA\News\Config\Config' + ) ->disableOriginalConstructor() ->getMock(); $config->expects($this->any()) ->method('getAutoPurgeMinimumInterval') ->will($this->returnValue($this->autoPurgeMinimumInterval)); - $this->feedService = new FeedService($this->feedMapper, + $this->feedService = new FeedService( + $this->feedMapper, $this->fetcher, $this->itemMapper, $this->logger, $this->l10n, - $timeFactory, $config, $this->purifier, $this->loggerParams); + $timeFactory, $config, $this->purifier, $this->loggerParams + ); $this->user = 'jack'; } - public function testFindAll(){ + public function testFindAll() + { $this->feedMapper->expects($this->once()) ->method('findAllFromUser') ->with($this->equalTo($this->user)) @@ -99,7 +106,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testCreateDoesNotFindFeed(){ + public function testCreateDoesNotFindFeed() + { $ex = new FetcherException('hi'); $url = 'test'; $this->fetcher->expects($this->once()) @@ -112,7 +120,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedService->create($url, 1, $this->user); } - public function testCreate(){ + public function testCreate() + { $url = 'http://test'; $folderId = 10; $createdFeed = new Feed(); @@ -152,7 +161,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($item2->getGuidHash()), $this->equalTo($item2->getFeedId()), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->throwException($ex)); $this->purifier->expects($this->at(0)) ->method('purify') @@ -166,7 +176,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($item1->getGuidHash()), $this->equalTo($item1->getFeedId()), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->throwException($ex)); $this->purifier->expects($this->at(1)) ->method('purify') @@ -176,8 +187,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->method('insert') ->with($this->equalTo($return[1][0])); - $feed = $this->feedService->create($url, $folderId, $this->user, null, - 'user', 'pass'); + $feed = $this->feedService->create( + $url, $folderId, $this->user, null, + 'user', 'pass' + ); $this->assertEquals($feed->getFolderId(), $folderId); $this->assertEquals($feed->getUrl(), $url); @@ -187,7 +200,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testCreateItemGuidExistsAlready(){ + public function testCreateItemGuidExistsAlready() + { $url = 'http://test'; $folderId = 10; $ex = new DoesNotExistException('yo'); @@ -206,8 +220,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->once()) ->method('findByUrlHash') - ->with($this->equalTo($createdFeed->getUrlHash()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($createdFeed->getUrlHash()), + $this->equalTo($this->user) + ) ->will($this->throwException($ex)); $this->fetcher->expects($this->once()) ->method('fetch') @@ -222,7 +238,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($item2->getGuidHash()), $this->equalTo($item2->getFeedId()), - $this->equalTo($this->user)) + $this->equalTo($this->user) + ) ->will($this->throwException($ex)); $this->purifier->expects($this->at(0)) ->method('purify') @@ -236,7 +253,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->with( $this->equalTo($item1->getGuidHash()), $this->equalTo($item1->getFeedId()), - $this->equalTo($this->user)); + $this->equalTo($this->user) + ); $feed = $this->feedService->create($url, $folderId, $this->user); @@ -246,7 +264,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateCreatesNewEntry(){ + public function testUpdateCreatesNewEntry() + { $feed = new Feed(); $feed->setId(3); $feed->setArticlesPerUpdate(1); @@ -267,8 +286,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->at(0)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $this->fetcher->expects($this->once()) ->method('fetch') @@ -284,9 +305,11 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($feed)); $this->itemMapper->expects($this->once()) ->method('findByGuidHash') - ->with($this->equalTo($items[0]->getGuidHash()), - $this->equalTo($items[0]->getFeedId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($items[0]->getGuidHash()), + $this->equalTo($items[0]->getFeedId()), + $this->equalTo($this->user) + ) ->will($this->throwException($ex)); $this->purifier->expects($this->at(0)) ->method('purify') @@ -307,7 +330,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($return, $feed); } - public function testForceUpdateUpdatesEntry(){ + public function testForceUpdateUpdatesEntry() + { $feed = new Feed(); $feed->setId(3); $feed->setArticlesPerUpdate(1); @@ -328,8 +352,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->at(0)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $this->fetcher->expects($this->once()) ->method('fetch') @@ -345,9 +371,11 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($feed)); $this->itemMapper->expects($this->once()) ->method('findByGuidHash') - ->with($this->equalTo($items[0]->getGuidHash()), - $this->equalTo($items[0]->getFeedId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($items[0]->getGuidHash()), + $this->equalTo($items[0]->getFeedId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($items[0])); $this->purifier->expects($this->at(0)) ->method('purify') @@ -368,7 +396,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($return, $feed); } - private function createUpdateFeed() { + private function createUpdateFeed() + { $feed = new Feed(); $feed->setId(3); $feed->setArticlesPerUpdate(1); @@ -380,7 +409,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { return $feed; } - private function createUpdateItem() { + private function createUpdateItem() + { $item = new Item(); $item->setGuidHash(md5('hi')); $item->setFeedId(3); @@ -393,7 +423,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { return $item; } - private function createUpdateItem2() { + private function createUpdateItem2() + { $item = new Item(); $item->setGuidHash(md5('hi')); $item->setFeedId(3); @@ -406,7 +437,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { return $item; } - public function testUpdateUpdatesWhenUpdateddateIsNewer() { + public function testUpdateUpdatesWhenUpdateddateIsNewer() + { $feed = $this->createUpdateFeed(); $item = $this->createUpdateItem(); $item2 = $this->createUpdateItem2(); @@ -443,7 +475,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateSetsUnreadIfModeIsOne() { + public function testUpdateSetsUnreadIfModeIsOne() + { $feed = $this->createUpdateFeed(); $feed->setUpdateMode(1); $item = $this->createUpdateItem(); @@ -482,7 +515,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateUpdatesArticlesPerFeedCount() { + public function testUpdateUpdatesArticlesPerFeedCount() + { $feed = new Feed(); $feed->setId(3); $feed->setUrlHash('yo'); @@ -514,7 +548,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedService->update($feed->getId(), $this->user); } - public function testUpdateFails(){ + public function testUpdateFails() + { $feed = new Feed(); $feed->setId(3); $feed->setUpdateErrorCount(0); @@ -529,8 +564,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->at(0)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $this->fetcher->expects($this->once()) ->method('fetch') @@ -554,7 +591,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateDoesNotFindEntry() { + public function testUpdateDoesNotFindEntry() + { $feed = new Feed(); $feed->setId(3); @@ -562,8 +600,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->at(0)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->throwException($ex)); $this->setExpectedException( @@ -573,7 +613,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUpdatePassesFullText() { + public function testUpdatePassesFullText() + { $feed = new Feed(); $feed->setId(3); $feed->setUrl('https://goo.com'); @@ -585,17 +626,21 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->at(0)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $this->fetcher->expects($this->once()) ->method('fetch') - ->with($this->equalTo($feed->getUrl()), - $this->equalTo(false), - $this->equalTo($feed->getHttpLastModified()), - $this->equalTo($feed->getHttpEtag()), - $this->equalTo($feed->getFullTextEnabled())) + ->with( + $this->equalTo($feed->getUrl()), + $this->equalTo(false), + $this->equalTo($feed->getHttpLastModified()), + $this->equalTo($feed->getHttpEtag()), + $this->equalTo($feed->getFullTextEnabled()) + ) ->will($this->throwException($ex)); $this->setExpectedException( @@ -605,7 +650,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateDoesNotFindUpdatedEntry() { + public function testUpdateDoesNotFindUpdatedEntry() + { $feed = new Feed(); $feed->setId(3); $feed->setArticlesPerUpdate(1); @@ -624,8 +670,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->at(0)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $this->feedMapper->expects($this->at(1)) ->method('update') @@ -635,15 +683,19 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { ->will($this->returnValue($fetchReturn)); $this->itemMapper->expects($this->once()) ->method('findByGuidHash') - ->with($this->equalTo($item->getGuidHash()), - $this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($item->getGuidHash()), + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($item2));; $this->feedMapper->expects($this->at(2)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->throwException($ex)); $this->setExpectedException( @@ -653,7 +705,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateDoesntUpdateIfFeedIsPrevented() { + public function testUpdateDoesntUpdateIfFeedIsPrevented() + { $feedId = 3; $feed = new Feed(); $feed->setFolderId(16); @@ -662,8 +715,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($feedId), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feedId), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $this->fetcher->expects($this->never()) ->method('fetch'); @@ -672,7 +727,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUpdateDoesntUpdateIfNoFeed() { + public function testUpdateDoesntUpdateIfNoFeed() + { $feedId = 3; $feed = new Feed(); $feed->setFolderId(16); @@ -680,8 +736,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($feedId), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feedId), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $this->fetcher->expects($this->once()) ->method('fetch') @@ -692,7 +750,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testMove(){ + public function testMove() + { $feedId = 3; $folderId = 4; $feed = new Feed(); @@ -714,7 +773,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testRenameFeed(){ + public function testRenameFeed() + { $feedId = 3; $feedTitle = "New Feed Title"; $feed = new Feed(); @@ -736,7 +796,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testImportArticles(){ + public function testImportArticles() + { $url = 'http://nextcloud/nofeed'; $feed = new Feed(); @@ -792,7 +853,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testImportArticlesCreatesOwnFeedWhenNotFound(){ + public function testImportArticlesCreatesOwnFeedWhenNotFound() + { $url = 'http://nextcloud/args'; $feed = new Feed(); @@ -878,7 +940,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testMarkDeleted() { + public function testMarkDeleted() + { $id = 3; $feed = new Feed(); $feed2 = new Feed(); @@ -896,7 +959,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUnmarkDeleted() { + public function testUnmarkDeleted() + { $id = 3; $feed = new Feed(); $feed2 = new Feed(); @@ -914,7 +978,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testPurgeDeleted(){ + public function testPurgeDeleted() + { $feed1 = new Feed(); $feed1->setId(3); $feed2 = new Feed(); @@ -937,7 +1002,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testPurgeDeletedWithoutInterval(){ + public function testPurgeDeletedWithoutInterval() + { $feed1 = new Feed(); $feed1->setId(3); $feed2 = new Feed(); @@ -959,7 +1025,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testfindAllFromAllUsers() { + public function testfindAllFromAllUsers() + { $expected = 'hi'; $this->feedMapper->expects($this->once()) ->method('findAll') @@ -969,7 +1036,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testDeleteUser() { + public function testDeleteUser() + { $this->feedMapper->expects($this->once()) ->method('deleteUser') ->will($this->returnValue($this->user)); @@ -978,12 +1046,15 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testOrdering () { + public function testOrdering() + { $feed = Feed::fromRow(['id' => 3]); $this->feedMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $feed->setOrdering(2); @@ -995,18 +1066,23 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testPatchEnableFullText() { - $feed = Feed::fromRow([ + public function testPatchEnableFullText() + { + $feed = Feed::fromRow( + [ 'id' => 3, 'http_etag' => 'a', 'http_last_modified' => 1, 'full_text_enabled' => false - ]); + ] + ); $feed2 = Feed::fromRow(['id' => 3]); $this->feedMapper->expects($this->at(0)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $feed2->setFullTextEnabled(true); @@ -1018,8 +1094,10 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { $this->feedMapper->expects($this->at(2)) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->throwException(new DoesNotExistException(''))); $this->setExpectedException( @@ -1033,7 +1111,8 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { /** * @expectedException OCA\News\Service\ServiceNotFoundException */ - public function testPatchDoesNotExist () { + public function testPatchDoesNotExist() + { $feed = Feed::fromRow(['id' => 3]); $this->feedMapper->expects($this->once()) ->method('find') @@ -1043,12 +1122,15 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase { } - public function testSetPinned () { + public function testSetPinned() + { $feed = Feed::fromRow(['id' => 3, 'pinned' => false]); $this->feedMapper->expects($this->once()) ->method('find') - ->with($this->equalTo($feed->getId()), - $this->equalTo($this->user)) + ->with( + $this->equalTo($feed->getId()), + $this->equalTo($this->user) + ) ->will($this->returnValue($feed)); $feed->setPinned(true); diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php index 68dcda3f1..10ba91a87 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.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; @@ -17,7 +17,8 @@ use \OCA\News\Db\Folder; use OCA\News\Service\FolderService; -class FolderServiceTest extends \PHPUnit_Framework_TestCase { +class FolderServiceTest extends \PHPUnit_Framework_TestCase +{ private $folderMapper; private $folderService; @@ -26,7 +27,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { private $autoPurgeMinimumInterval; private $l10n; - protected function setUp(){ + protected function setUp() + { $this->l10n = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor() ->getMock(); @@ -38,24 +40,28 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { ->method('getTime') ->will($this->returnValue($this->time)); $this->folderMapper = $this->getMockBuilder( - '\OCA\News\Db\FolderMapper') + '\OCA\News\Db\FolderMapper' + ) ->disableOriginalConstructor() ->getMock(); $this->autoPurgeMinimumInterval = 10; $config = $this->getMockBuilder( - '\OCA\News\Config\Config') + '\OCA\News\Config\Config' + ) ->disableOriginalConstructor() ->getMock(); $config->expects($this->any()) ->method('getAutoPurgeMinimumInterval') ->will($this->returnValue($this->autoPurgeMinimumInterval)); $this->folderService = new FolderService( - $this->folderMapper, $this->l10n, $timeFactory, $config); + $this->folderMapper, $this->l10n, $timeFactory, $config + ); $this->user = 'hi'; } - public function testFindAll(){ + public function testFindAll() + { $userId = 'jack'; $return = 'hi'; $this->folderMapper->expects($this->once()) @@ -69,7 +75,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testCreate(){ + public function testCreate() + { $folder = new Folder(); $folder->setName('hey'); $folder->setParentId(5); @@ -92,7 +99,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testCreateThrowsExWhenFolderNameExists(){ + public function testCreateThrowsExWhenFolderNameExists() + { $folderName = 'hihi'; $rows = [['id' => 1]]; @@ -112,7 +120,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { /** * @expectedException \OCA\News\Service\ServiceValidationException */ - public function testCreateThrowsExWhenFolderNameEmpty(){ + public function testCreateThrowsExWhenFolderNameEmpty() + { $folderName = ''; $this->folderMapper->expects($this->once()) @@ -124,7 +133,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testOpen(){ + public function testOpen() + { $folder = new Folder(); $this->folderMapper->expects($this->once()) @@ -143,7 +153,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testRename(){ + public function testRename() + { $folder = new Folder(); $folder->setName('jooohn'); @@ -157,9 +168,9 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { ->with($this->equalTo($folder)); $this->folderMapper->expects($this->once()) - ->method('findByName') - ->with('bogus', '') - ->will($this->returnValue([])); + ->method('findByName') + ->with('bogus', '') + ->will($this->returnValue([])); $this->folderService->rename(3, 'bogus', ''); @@ -167,7 +178,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testRenameThrowsExWhenFolderNameExists(){ + public function testRenameThrowsExWhenFolderNameExists() + { $folderName = 'hihi'; $rows = [['id' => 1]]; @@ -185,7 +197,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testRenameThrowsExWhenFolderNameEmpty(){ + public function testRenameThrowsExWhenFolderNameEmpty() + { $folderName = ''; $this->folderMapper->expects($this->once()) @@ -200,7 +213,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testMarkDeleted() { + public function testMarkDeleted() + { $id = 3; $folder = new Folder(); $folder2 = new Folder(); @@ -218,7 +232,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testUnmarkDeleted() { + public function testUnmarkDeleted() + { $id = 3; $folder = new Folder(); $folder2 = new Folder(); @@ -235,7 +250,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { $this->folderService->unmarkDeleted($id, $this->user); } - public function testPurgeDeleted(){ + public function testPurgeDeleted() + { $folder1 = new Folder(); $folder1->setId(3); $folder2 = new Folder(); @@ -258,7 +274,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testPurgeDeletedNoInterval(){ + public function testPurgeDeletedNoInterval() + { $folder1 = new Folder(); $folder1->setId(3); $folder2 = new Folder(); @@ -280,7 +297,8 @@ class FolderServiceTest extends \PHPUnit_Framework_TestCase { } - public function testDeleteUser() { + public function testDeleteUser() + { $this->folderMapper->expects($this->once()) ->method('deleteUser') ->will($this->returnValue($this->user)); 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)); diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php index 46242434b..668d54903 100644 --- a/tests/Unit/Service/ServiceTest.php +++ b/tests/Unit/Service/ServiceTest.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,18 +20,22 @@ use \OCP\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; -class TestService extends Service { - public function __construct($mapper){ +class TestService extends Service +{ + public function __construct($mapper) + { parent::__construct($mapper); } } -class ServiceTest extends \PHPUnit_Framework_TestCase { +class ServiceTest extends \PHPUnit_Framework_TestCase +{ protected $mapper; protected $newsService; - protected function setUp(){ + protected function setUp() + { $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); @@ -39,7 +43,8 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { } - public function testDelete(){ + public function testDelete() + { $id = 5; $user = 'ken'; $folder = new Folder(); @@ -57,7 +62,8 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { } - public function testFind(){ + public function testFind() + { $id = 3; $user = 'ken'; @@ -69,7 +75,8 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { } - public function testFindDoesNotExist(){ + public function testFindDoesNotExist() + { $ex = new DoesNotExistException('hi'); $this->mapper->expects($this->once()) @@ -83,7 +90,8 @@ class ServiceTest extends \PHPUnit_Framework_TestCase { } - public function testFindMultiple(){ + public function testFindMultiple() + { $ex = new MultipleObjectsReturnedException('hi'); $this->mapper->expects($this->once()) diff --git a/tests/Unit/Service/StatusServiceTest.php b/tests/Unit/Service/StatusServiceTest.php index ca1029504..aa2cbde0e 100644 --- a/tests/Unit/Service/StatusServiceTest.php +++ b/tests/Unit/Service/StatusServiceTest.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; @@ -17,36 +17,45 @@ use \OCA\News\Db\FeedType; use OCA\News\Service\StatusService; -class StatusServiceTest extends \PHPUnit_Framework_TestCase { +class StatusServiceTest extends \PHPUnit_Framework_TestCase +{ private $settings; private $config; private $service; private $appName; - public function setUp(){ + public function setUp() + { $this->appName = 'news'; $this->settings = $this->getMockBuilder( - '\OCP\IConfig') + '\OCP\IConfig' + ) ->disableOriginalConstructor() ->getMock(); $this->config = $this->getMockBuilder( - '\OCA\News\Config\Config') + '\OCA\News\Config\Config' + ) ->disableOriginalConstructor() ->getMock(); - $this->db = $this->getMockBuilder("\OCP\IDBConnection") - ->disableOriginalConstructor() - ->getMock(); - $this->service = new StatusService($this->settings, $this->db, - $this->config, $this->appName); + $this->db = $this->getMockBuilder("\OCP\IDBConnection") + ->disableOriginalConstructor() + ->getMock(); + $this->service = new StatusService( + $this->settings, $this->db, + $this->config, $this->appName + ); } private function beforeStatus($cronMode='cron', $cronEnabled=true, - $version='1.0') { + $version='1.0' + ) { $this->settings->expects($this->at(0)) ->method('getAppValue') - ->with($this->equalTo($this->appName), - $this->equalTo('installed_version')) + ->with( + $this->equalTo($this->appName), + $this->equalTo('installed_version') + ) ->will($this->returnValue($version)); $this->settings->expects($this->at(1)) @@ -64,7 +73,8 @@ class StatusServiceTest extends \PHPUnit_Framework_TestCase { } - public function testGetStatus(){ + public function testGetStatus() + { $this->beforeStatus(); $response = $this->service->getStatus(); @@ -73,7 +83,8 @@ class StatusServiceTest extends \PHPUnit_Framework_TestCase { } - public function testGetStatusNoCorrectCronAjax(){ + public function testGetStatusNoCorrectCronAjax() + { $this->beforeStatus('ajax'); $response = $this->service->getStatus(); @@ -82,7 +93,8 @@ class StatusServiceTest extends \PHPUnit_Framework_TestCase { - public function testGetStatusNoCorrectCronTurnedOff(){ + public function testGetStatusNoCorrectCronTurnedOff() + { $this->beforeStatus('ajax', false); $response = $this->service->getStatus(); diff --git a/tests/Unit/Utility/OPMLExporterTest.php b/tests/Unit/Utility/OPMLExporterTest.php index cf33b779b..7f2c7dfdf 100644 --- a/tests/Unit/Utility/OPMLExporterTest.php +++ b/tests/Unit/Utility/OPMLExporterTest.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\Utility; @@ -18,13 +18,15 @@ use \OCA\News\Db\Feed; use OCA\News\Utility\OPMLExporter; -class OPMLExporterTest extends \PHPUnit_Framework_TestCase { +class OPMLExporterTest extends \PHPUnit_Framework_TestCase +{ private $exporter; private $feed1; private $feed2; - protected function setUp() { + protected function setUp() + { $this->exporter = new OPMLExporter(); $this->folder1 = new Folder(); $this->folder1->setId(3); @@ -46,7 +48,8 @@ class OPMLExporterTest extends \PHPUnit_Framework_TestCase { } - private function getAttribute($item, $name) { + private function getAttribute($item, $name) + { // used to fix scrutinizer errors if ($item instanceof \DOMElement) { return $item->getAttribute($name); @@ -56,7 +59,8 @@ class OPMLExporterTest extends \PHPUnit_Framework_TestCase { } - public function testBuildEmpty(){ + public function testBuildEmpty() + { $result = $this->exporter->build([], []); $xpath = new \DOMXpath($result); @@ -64,41 +68,60 @@ class OPMLExporterTest extends \PHPUnit_Framework_TestCase { } - public function testBuildReturnsFolders() { + public function testBuildReturnsFolders() + { $result = $this->exporter->build([$this->folder1, $this->folder2], []); $xpath = new \DOMXpath($result); $elems = $xpath->query('/opml/body/outline'); $this->assertEquals(2, $elems->length); - $this->assertEquals($this->folder1->getName(), - $this->getAttribute($elems->item(0), 'title')); - $this->assertEquals($this->folder1->getName(), - $this->getAttribute($elems->item(0), 'text')); - $this->assertEquals($this->folder2->getName(), - $this->getAttribute($elems->item(1), 'title')); - $this->assertEquals($this->folder2->getName(), - $this->getAttribute($elems->item(1), 'text')); + $this->assertEquals( + $this->folder1->getName(), + $this->getAttribute($elems->item(0), 'title') + ); + $this->assertEquals( + $this->folder1->getName(), + $this->getAttribute($elems->item(0), 'text') + ); + $this->assertEquals( + $this->folder2->getName(), + $this->getAttribute($elems->item(1), 'title') + ); + $this->assertEquals( + $this->folder2->getName(), + $this->getAttribute($elems->item(1), 'text') + ); } - public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() { + public function testBuildReturnsOnlyOneFeedIfParentFolderNotThere() + { $result = $this->exporter->build([], [$this->feed1, $this->feed2]); $xpath = new \DOMXpath($result); $elems = $xpath->query('//outline'); $this->assertEquals(1, $elems->length); - $this->assertEquals($this->feed1->getTitle(), - $this->getAttribute($elems->item(0), 'title')); - $this->assertEquals($this->feed1->getTitle(), - $this->getAttribute($elems->item(0), 'text')); - $this->assertEquals($this->feed1->getUrl(), - $this->getAttribute($elems->item(0), 'xmlUrl')); - $this->assertEquals('', - $this->getAttribute($elems->item(0), 'htmlUrl')); + $this->assertEquals( + $this->feed1->getTitle(), + $this->getAttribute($elems->item(0), 'title') + ); + $this->assertEquals( + $this->feed1->getTitle(), + $this->getAttribute($elems->item(0), 'text') + ); + $this->assertEquals( + $this->feed1->getUrl(), + $this->getAttribute($elems->item(0), 'xmlUrl') + ); + $this->assertEquals( + '', + $this->getAttribute($elems->item(0), 'htmlUrl') + ); } - public function testBuildReturnsFeedsAndFolders() { + public function testBuildReturnsFeedsAndFolders() + { $result = $this->exporter->build( [$this->folder1, $this->folder2], [$this->feed1, $this->feed2] @@ -109,13 +132,20 @@ class OPMLExporterTest extends \PHPUnit_Framework_TestCase { $this->assertEquals(3, $elems->length); - $this->assertEquals($this->folder1->getName(), - $this->getAttribute($elems->item(0), 'title')); - $this->assertEquals($this->folder2->getName(), - $this->getAttribute($elems->item(1), 'text')); - $this->assertEquals($this->feed1->getUrl(), - $this->getAttribute($elems->item(2), 'xmlUrl')); - $this->assertEquals($this->feed2->getLink(), + $this->assertEquals( + $this->folder1->getName(), + $this->getAttribute($elems->item(0), 'title') + ); + $this->assertEquals( + $this->folder2->getName(), + $this->getAttribute($elems->item(1), 'text') + ); + $this->assertEquals( + $this->feed1->getUrl(), + $this->getAttribute($elems->item(2), 'xmlUrl') + ); + $this->assertEquals( + $this->feed2->getLink(), $this->getAttribute($elems->item(1)->childNodes->item(0), 'htmlUrl') ); } diff --git a/tests/Unit/Utility/ProxyConfigParserTest.php b/tests/Unit/Utility/ProxyConfigParserTest.php index cc7833c31..a2a92fd38 100644 --- a/tests/Unit/Utility/ProxyConfigParserTest.php +++ b/tests/Unit/Utility/ProxyConfigParserTest.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\Utility; @@ -16,22 +16,26 @@ namespace OCA\News\Tests\Unit\Utility; use OCA\News\Utility\ProxyConfigParser; -class ProxyConfigParserTest extends \PHPUnit_Framework_TestCase { +class ProxyConfigParserTest extends \PHPUnit_Framework_TestCase +{ private $config; private $feedService; private $itemService; private $parser; - protected function setUp() { + protected function setUp() + { $this->config = $this->getMockBuilder( - '\OCP\IConfig') + '\OCP\IConfig' + ) ->disableOriginalConstructor() ->getMock(); $this->parser = new ProxyConfigParser($this->config); } - private function setExpectedProxy($proxy=null, $userpasswd=null) { + private function setExpectedProxy($proxy=null, $userpasswd=null) + { $this->config->expects($this->at(0)) ->method('getSystemValue') ->with($this->equalTo('proxy')) @@ -42,7 +46,8 @@ class ProxyConfigParserTest extends \PHPUnit_Framework_TestCase { ->will($this->returnValue($userpasswd)); } - public function testParsesNoProxy() { + public function testParsesNoProxy() + { $expected = [ 'host' => null, 'port' => null, @@ -55,7 +60,8 @@ class ProxyConfigParserTest extends \PHPUnit_Framework_TestCase { } - public function testParsesHost() { + public function testParsesHost() + { $expected = [ 'host' => 'http://google.com/mytest', 'port' => null, @@ -68,7 +74,8 @@ class ProxyConfigParserTest extends \PHPUnit_Framework_TestCase { } - public function testParsesHostAndPort() { + public function testParsesHostAndPort() + { $expected = [ 'host' => 'http://google.com/mytest', 'port' => 89, @@ -81,7 +88,8 @@ class ProxyConfigParserTest extends \PHPUnit_Framework_TestCase { } - public function testParsesUser() { + public function testParsesUser() + { $expected = [ 'host' => null, 'port' => null, diff --git a/tests/Unit/Utility/UpdaterTest.php b/tests/Unit/Utility/UpdaterTest.php index 76ebe74f7..87bbe31b9 100644 --- a/tests/Unit/Utility/UpdaterTest.php +++ b/tests/Unit/Utility/UpdaterTest.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\Utility; @@ -16,32 +16,40 @@ namespace OCA\News\Tests\Unit\Utility; use OCA\News\Utility\Updater; -class UpdaterTest extends \PHPUnit_Framework_TestCase { +class UpdaterTest extends \PHPUnit_Framework_TestCase +{ private $folderService; private $feedService; private $itemService; private $updater; - protected function setUp() { + protected function setUp() + { $this->folderService = $this->getMockBuilder( - '\OCA\News\Service\FolderService') + '\OCA\News\Service\FolderService' + ) ->disableOriginalConstructor() ->getMock(); $this->feedService = $this->getMockBuilder( - '\OCA\News\Service\FeedService') + '\OCA\News\Service\FeedService' + ) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') + '\OCA\News\Service\ItemService' + ) ->disableOriginalConstructor() ->getMock(); - $this->updater = new Updater($this->folderService, + $this->updater = new Updater( + $this->folderService, $this->feedService, - $this->itemService); + $this->itemService + ); } - public function testBeforeUpdate() { + public function testBeforeUpdate() + { $this->folderService->expects($this->once()) ->method('purgeDeleted'); $this->feedService->expects($this->once()) @@ -50,13 +58,15 @@ class UpdaterTest extends \PHPUnit_Framework_TestCase { } - public function testAfterUpdate() { + public function testAfterUpdate() + { $this->itemService->expects($this->once()) ->method('autoPurgeOld'); $this->updater->afterUpdate(); } - public function testUpdate() { + public function testUpdate() + { $this->feedService->expects($this->once()) ->method('updateAll'); $this->updater->update(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ffebf1ae5..8afaf96fa 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,7 +5,7 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> * @copyright Bernhard Posselt 2012, 2014 */ |