From 60ab4941cc7e6ede095e9e4aee3c2bf9a5c3bff6 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sun, 20 Sep 2020 22:03:05 +0200 Subject: Move to nextcloud config and update phpunit Signed-off-by: Sean Molenaar --- tests/Integration/Db/FeedMapperTest.php | 57 ++--- tests/Integration/Db/FolderMapperTest.php | 53 ----- tests/Integration/Db/ItemMapperTest.php | 36 +-- tests/Unit/Config/ConfigTest.php | 261 --------------------- tests/Unit/Controller/AdminControllerTest.php | 161 ++++++------- tests/Unit/Controller/ExportControllerTest.php | 2 +- tests/Unit/Controller/FeedApiControllerTest.php | 32 +-- tests/Unit/Controller/FeedControllerTest.php | 10 +- tests/Unit/Controller/FolderApiControllerTest.php | 24 +- tests/Unit/Controller/FolderControllerTest.php | 2 +- tests/Unit/Controller/ItemApiControllerTest.php | 38 +-- tests/Unit/Controller/ItemControllerTest.php | 6 +- tests/Unit/Controller/JSONHttpErrorTest.php | 2 +- tests/Unit/Controller/PageControllerTest.php | 241 +++++++------------ tests/Unit/Controller/UserApiControllerTest.php | 12 +- tests/Unit/Controller/UtilityApiControllerTest.php | 2 +- tests/Unit/Db/FolderMapperTest.php | 2 +- tests/Unit/Db/ItemTest.php | 30 +-- tests/Unit/Db/MapperFactoryTest.php | 8 +- tests/Unit/Db/MapperTestUtility.php | 6 +- tests/Unit/Fetcher/FeedFetcherTest.php | 11 +- tests/Unit/Fetcher/FetcherTest.php | 2 +- tests/Unit/Fetcher/YoutubeFetcherTest.php | 2 +- tests/Unit/Http/TextDownloadResponseTest.php | 4 +- tests/Unit/Http/TextResponseTest.php | 4 +- tests/Unit/Migration/MigrateStatusFlagsTest.php | 18 +- tests/Unit/Service/FeedServiceTest.php | 73 ++++-- tests/Unit/Service/FolderServiceTest.php | 44 +++- tests/Unit/Service/ItemServiceTest.php | 214 ++++++++--------- tests/Unit/Service/ServiceTest.php | 2 +- tests/Unit/Service/StatusServiceTest.php | 197 +++++++++++----- tests/Unit/Utility/OPMLExporterTest.php | 10 +- tests/Unit/Utility/UpdaterTest.php | 8 +- 33 files changed, 650 insertions(+), 924 deletions(-) delete mode 100644 tests/Integration/Db/FolderMapperTest.php delete mode 100644 tests/Unit/Config/ConfigTest.php (limited to 'tests') diff --git a/tests/Integration/Db/FeedMapperTest.php b/tests/Integration/Db/FeedMapperTest.php index 3d1ea71f4..626b8f9a9 100644 --- a/tests/Integration/Db/FeedMapperTest.php +++ b/tests/Integration/Db/FeedMapperTest.php @@ -20,7 +20,7 @@ use OCA\News\Tests\Integration\Fixtures\FeedFixture; class FeedMapperTest extends IntegrationTest { - public function testFind() + public function testFind() { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -31,16 +31,14 @@ class FeedMapperTest extends IntegrationTest $this->assertEquals($feed->getLink(), $fetched->getLink()); } - /** - * @expectedException OCP\AppFramework\Db\DoesNotExistException - */ - public function testFindNotExisting() + public function testFindNotExisting() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->feedMapper->find(0, $this->user); } - public function testFindAll() + public function testFindAll() { $feeds = [ [ @@ -56,23 +54,23 @@ class FeedMapperTest extends IntegrationTest $fetched = $this->feedMapper->findAll(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testFindAllEmpty() + public function testFindAllEmpty() { $feeds = $this->feedMapper->findAll(); - $this->assertInternalType('array', $feeds); + $this->assertIsArray($feeds); $this->assertCount(0, $feeds); } - public function testFindAllFromUser() + public function testFindAllFromUser() { $feeds = [ [ @@ -88,7 +86,7 @@ class FeedMapperTest extends IntegrationTest $fetched = $this->feedMapper->findAllFromUser($this->user); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(1, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); @@ -96,16 +94,16 @@ class FeedMapperTest extends IntegrationTest } - public function testFindAllFromUserNotExisting() + public function testFindAllFromUserNotExisting() { $fetched = $this->feedMapper->findAllFromUser('notexistinguser'); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(0, $fetched); } - public function testFindByUrlHash() + public function testFindByUrlHash() { $feed = new FeedFixture( [ @@ -124,8 +122,9 @@ class FeedMapperTest extends IntegrationTest /** * @expectedException OCP\AppFramework\Db\MultipleObjectsReturnedException */ - public function testFindByUrlHashMoreThanOneResult() + public function testFindByUrlHashMoreThanOneResult() { + $this->expectException('OCP\AppFramework\Db\MultipleObjectsReturnedException'); $feed1 = $this->feedMapper->insert( new FeedFixture( [ @@ -148,13 +147,14 @@ class FeedMapperTest extends IntegrationTest /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindByUrlHashNotExisting() + public function testFindByUrlHashNotExisting() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->feedMapper->findByUrlHash('some random hash', $this->user); } - public function testDelete() + public function testDelete() { $this->loadFixtures('default'); @@ -178,7 +178,7 @@ class FeedMapperTest extends IntegrationTest $this->assertCount(0, $items); } - public function testGetToDelete() + public function testGetToDelete() { $this->loadFeedFixtures( [ @@ -191,14 +191,14 @@ class FeedMapperTest extends IntegrationTest $fetched = $this->feedMapper->getToDelete(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(3, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteOlderThan() + public function testGetToDeleteOlderThan() { $this->loadFeedFixtures( [ @@ -211,14 +211,14 @@ class FeedMapperTest extends IntegrationTest $fetched = $this->feedMapper->getToDelete(1000); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteUser() + public function testGetToDeleteUser() { $this->loadFeedFixtures( [ @@ -231,22 +231,22 @@ class FeedMapperTest extends IntegrationTest $fetched = $this->feedMapper->getToDelete(2000, $this->user); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(2, $fetched); $this->assertContainsOnlyInstancesOf(Feed::class, $fetched); $this->tearDownUser('john'); } - public function testGetToDeleteEmpty() + public function testGetToDeleteEmpty() { $fetched = $this->feedMapper->getToDelete(); - $this->assertInternalType('array', $fetched); + $this->assertIsArray($fetched); $this->assertCount(0, $fetched); } - public function testDeleteUser() + public function testDeleteUser() { $this->loadFixtures('default'); @@ -263,7 +263,10 @@ class FeedMapperTest extends IntegrationTest $this->assertCount(0, $items); } - public function testDeleteUserNotExisting() + /** + * @coversNothing + */ + public function testDeleteUserNotExisting() { $this->feedMapper->deleteUser('notexistinguser'); } diff --git a/tests/Integration/Db/FolderMapperTest.php b/tests/Integration/Db/FolderMapperTest.php deleted file mode 100644 index 889ac3e7c..000000000 --- a/tests/Integration/Db/FolderMapperTest.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @copyright Bernhard Posselt 2015 - */ - -namespace OCA\News\Tests\Integration\Db; - -use OCA\News\Tests\Integration\IntegrationTest; - -class FolderMapperTest extends IntegrationTest -{ - - - public function testFind() - { - - } - - - /* TBD - public function testFindByName () { - - } - - - public function testFindAllFromUser () { - - } - - - public function testDelete () { - - } - - - public function testGetToDelete () { - - } - - - public function testDeleteUser () { - - }*/ - - - -} diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php index e510aab96..026834e6b 100644 --- a/tests/Integration/Db/ItemMapperTest.php +++ b/tests/Integration/Db/ItemMapperTest.php @@ -18,7 +18,7 @@ use OCA\News\Tests\Integration\Fixtures\ItemFixture; class ItemMapperTest extends IntegrationTest { - public function testFind() + public function testFind() { $feed = new FeedFixture(); $feed = $this->feedMapper->insert($feed); @@ -38,7 +38,7 @@ class ItemMapperTest extends IntegrationTest * @param $title * @return mixed */ - private function whereTitleId($title) + private function whereTitleId($title) { return $this->findItemByTitle($title)->getId(); } @@ -46,8 +46,9 @@ class ItemMapperTest extends IntegrationTest /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFeed() + public function testFindNotFoundWhenDeletedFeed() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('not found feed'); @@ -58,8 +59,9 @@ class ItemMapperTest extends IntegrationTest /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testFindNotFoundWhenDeletedFolder() + public function testFindNotFoundWhenDeletedFolder() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); @@ -68,7 +70,7 @@ class ItemMapperTest extends IntegrationTest } - private function deleteReadOlderThanThreshold() + private function deleteReadOlderThanThreshold() { $this->loadFixtures('default'); @@ -84,8 +86,9 @@ class ItemMapperTest extends IntegrationTest /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdOne() + public function testDeleteOlderThanThresholdOne() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('del1'); @@ -97,8 +100,9 @@ class ItemMapperTest extends IntegrationTest /** * @expectedException OCP\AppFramework\Db\DoesNotExistException */ - public function testDeleteOlderThanThresholdTwo() + public function testDeleteOlderThanThresholdTwo() { + $this->expectException('OCP\AppFramework\Db\DoesNotExistException'); $this->loadFixtures('default'); $id = $this->whereTitleId('del2'); @@ -108,7 +112,7 @@ class ItemMapperTest extends IntegrationTest } - public function testStarredCount() + public function testStarredCount() { $this->loadFixtures('default'); @@ -117,7 +121,7 @@ class ItemMapperTest extends IntegrationTest } - public function testReadAll() + public function testReadAll() { $this->loadFixtures('default'); @@ -146,7 +150,7 @@ class ItemMapperTest extends IntegrationTest } - public function testReadFolder() + public function testReadFolder() { $this->loadFixtures('default'); @@ -178,7 +182,7 @@ class ItemMapperTest extends IntegrationTest } - public function testReadFeed() + public function testReadFeed() { $this->loadFixtures('default'); @@ -209,7 +213,7 @@ class ItemMapperTest extends IntegrationTest } - public function testDeleteUser() + public function testDeleteUser() { $this->loadFixtures('default'); @@ -219,7 +223,7 @@ class ItemMapperTest extends IntegrationTest $this->assertEquals(0, $id); } - public function testGetNewestItemId() + public function testGetNewestItemId() { $this->loadFixtures('default'); @@ -229,7 +233,7 @@ class ItemMapperTest extends IntegrationTest $this->assertEquals($itemId, $id); } - public function testFindAllUnreadOrStarred() + public function testFindAllUnreadOrStarred() { $this->loadFixtures('default'); @@ -238,7 +242,7 @@ class ItemMapperTest extends IntegrationTest } - public function testReadItem() + public function testReadItem() { $this->loadFixtures('readitem'); // assert that all items are unread @@ -277,7 +281,7 @@ class ItemMapperTest extends IntegrationTest } } - public function testUnreadItem() + public function testUnreadItem() { $this->loadFixtures('readitem'); // unread an item diff --git a/tests/Unit/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php deleted file mode 100644 index 60a292afc..000000000 --- a/tests/Unit/Config/ConfigTest.php +++ /dev/null @@ -1,261 +0,0 @@ - - * @author Bernhard Posselt - * @copyright 2012 Alessandro Cosentino - * @copyright 2012-2014 Bernhard Posselt - */ - -namespace OCA\News\Tests\Unit\Config; - -use OCA\News\Config\Config; -use OCP\Files\File; -use OCP\Files\Folder; -use OCP\ILogger; -use PHPUnit\Framework\TestCase; - -class ConfigTest extends TestCase -{ - - private $fileSystem; - private $config; - private $configPath; - private $loggerParams; - - public function setUp() - { - $this->logger = $this->getMockBuilder('OCA\News\Utility\PsrLogger') - ->disableOriginalConstructor() - ->getMock(); - $this->fileSystem = $this->getMockBuilder(Folder::class)->getMock(); - $this->loggerParams = ['hi']; - $this->config = new Config( - $this->fileSystem, - $this->logger, - $this->loggerParams - ); - $this->configPath = 'config.json'; - } - - - public function testDefaults() - { - $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval()); - $this->assertEquals(200, $this->config->getAutoPurgeCount()); - $this->assertEquals(10, $this->config->getMaxRedirects()); - $this->assertEquals(60, $this->config->getFeedFetcherTimeout()); - $this->assertEquals(3600, $this->config->getUpdateInterval()); - $this->assertEquals(true, $this->config->getUseCronUpdates()); - $this->assertEquals('', $this->config->getExploreUrl()); - $this->assertEquals(1024*1024*100, $this->config->getMaxSize()); - } - - - public function testRead() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will( - $this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true' - ) - ); - - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(true, $this->config->getUseCronUpdates()); - } - - - public function testReadIgnoresVeryLowPurgeInterval() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will($this->returnValue('autoPurgeMinimumInterval = 59')); - - $this->config->read($this->configPath); - - $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval()); - } - - - - public function testReadBool() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will( - $this->returnValue( - 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false' - ) - ); - - $this->config->read($this->configPath); - - $this->assertSame(3, $this->config->getAutoPurgeCount()); - $this->assertSame(false, $this->config->getUseCronUpdates()); - } - - - public function testReadLogsInvalidValue() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->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) - ); - - $this->config->read($this->configPath); - } - - - public function testReadLogsInvalidINI() - { - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('getContent') - ->will($this->returnValue('')); - $this->logger->expects($this->once()) - ->method('warning') - ->with( - $this->equalTo('Configuration invalid. Ignoring values.'), - $this->equalTo($this->loggerParams) - ); - - $this->config->read($this->configPath); - } - - - public function testWrite() - { - $json = 'autoPurgeMinimumInterval = 60' . "\n" . - 'autoPurgeCount = 3' . "\n" . - 'maxRedirects = 10' . "\n" . - 'maxSize = 399' . "\n" . - 'exploreUrl = http://google.de' . "\n" . - 'feedFetcherTimeout = 60' . "\n" . - 'updateInterval = 3600' . "\n" . - 'useCronUpdates = true'; - $this->config->setAutoPurgeCount(3); - $this->config->setMaxSize(399); - $this->config->setExploreUrl('http://google.de'); - - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('putContent') - ->with($this->equalTo($json)); - - $this->config->write($this->configPath); - } - - - - public function testReadingNonExistentConfigWillWriteDefaults() - { - $this->fileSystem->expects($this->once()) - ->method('nodeExists') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue(false)); - - $this->config->setUseCronUpdates(false); - - $json = 'autoPurgeMinimumInterval = 60' . "\n" . - 'autoPurgeCount = 200' . "\n" . - 'maxRedirects = 10' . "\n" . - 'maxSize = 104857600' . "\n" . - 'exploreUrl = ' . "\n" . - 'feedFetcherTimeout = 60' . "\n" . - 'updateInterval = 3600' . "\n" . - 'useCronUpdates = false'; - - $this->fileSystem->expects($this->once()) - ->method('newFile') - ->with($this->equalTo($this->configPath)); - $file = $this->getMockBuilder(File::class)->getMock(); - $this->fileSystem->expects($this->once()) - ->method('get') - ->with($this->equalTo($this->configPath)) - ->will($this->returnValue($file)); - $file->expects($this->once()) - ->method('putContent') - ->with($this->equalTo($json)); - - $this->config->read($this->configPath, true); - } - - - public function testNoLowMinimumAutoPurgeInterval() - { - $this->config->setAutoPurgeMinimumInterval(59); - $interval = $this->config->getAutoPurgeMinimumInterval(); - - $this->assertSame(60, $interval); - } - - - public function testMinimumAutoPurgeInterval() - { - $this->config->setAutoPurgeMinimumInterval(61); - $interval = $this->config->getAutoPurgeMinimumInterval(); - - $this->assertSame(61, $interval); - } - - public function testMaxRedirects() - { - $this->config->setMaxRedirects(21); - $redirects = $this->config->getMaxRedirects(); - - $this->assertSame(21, $redirects); - } - - public function testFeedFetcherTimeout() - { - $this->config->setFeedFetcherTimeout(2); - $timout = $this->config->getFeedFetcherTimeout(); - - $this->assertSame(2, $timout); - } -} diff --git a/tests/Unit/Controller/AdminControllerTest.php b/tests/Unit/Controller/AdminControllerTest.php index b0b551006..81490bb6f 100644 --- a/tests/Unit/Controller/AdminControllerTest.php +++ b/tests/Unit/Controller/AdminControllerTest.php @@ -13,82 +13,84 @@ namespace OCA\News\Tests\Unit\Controller; -use OCA\News\Config\Config; use OCA\News\Controller\AdminController; use OCA\News\Service\ItemService; +use OCP\IConfig; use OCP\IRequest; use PHPUnit\Framework\TestCase; class AdminControllerTest extends TestCase { - + /** + * @var string + */ private $appName; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IRequest + */ private $request; + + /** + * @var AdminController + */ private $controller; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $config; - private $configPath; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|ItemService + */ private $itemService; /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() ->getMock(); - $this->config = $this->getMockBuilder(Config::class) + $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $this->itemService = $this->getMockBuilder(ItemService::class) ->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); } - - public function testIndex() + /** + * Test \OCA\News\Controller\AdminController::index + */ + public function testIndex() { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, 'maxRedirects' => 3, 'feedFetcherTimeout' => 4, - 'useCronUpdates' => 5, - 'maxSize' => 7, + 'useCronUpdates' => false, 'exploreUrl' => 'test', - 'updateInterval' => 3600 + 'updateInterval' => 3601 ]; - $this->config->expects($this->once()) - ->method('getAutoPurgeMinimumInterval') - ->will($this->returnValue($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('getAutoPurgeCount') - ->will($this->returnValue($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('getMaxRedirects') - ->will($this->returnValue($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('getFeedFetcherTimeout') - ->will($this->returnValue($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('getMaxSize') - ->will($this->returnValue($expected['maxSize'])); - $this->config->expects($this->once()) - ->method('getExploreUrl') - ->will($this->returnValue($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('getUpdateInterval') - ->will($this->returnValue($expected['updateInterval'])); + $map = [ + ['news','autoPurgeMinimumInterval', 60, 1], + ['news','autoPurgeCount', 200, 2], + ['news','maxRedirects', 10, 3], + ['news','feedFetcherTimeout', 60, 4], + ['news','useCronUpdates', true, false,], + ['news','exploreUrl', '', 'test'], + ['news','updateInterval', 3600, 3601] + ]; + $this->config->expects($this->exactly(count($map))) + ->method('getAppValue') + ->will($this->returnValueMap($map)); $response = $this->controller->index(); $data = $response->getParams(); @@ -101,75 +103,48 @@ class AdminControllerTest extends TestCase } - public function testUpdate() + public function testUpdate() { $expected = [ 'autoPurgeMinimumInterval' => 1, 'autoPurgeCount' => 2, 'maxRedirects' => 3, 'feedFetcherTimeout' => 4, - 'useCronUpdates' => 5, - 'maxSize' => 7, + 'useCronUpdates' => false, 'exploreUrl' => 'test', - 'updateInterval' => 3600 + 'updateInterval' => 3601 ]; - $this->config->expects($this->once()) - ->method('setAutoPurgeMinimumInterval') - ->with($this->equalTo($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('setAutoPurgeCount') - ->with($this->equalTo($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('setMaxRedirects') - ->with($this->equalTo($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('setFeedFetcherTimeout') - ->with($this->equalTo($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('setUseCronUpdates') - ->with($this->equalTo($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('setExploreUrl') - ->with($this->equalTo($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('setUpdateInterval') - ->with($this->equalTo($expected['updateInterval'])); - $this->config->expects($this->once()) - ->method('write') - ->with($this->equalTo($this->configPath)); - - $this->config->expects($this->once()) - ->method('getAutoPurgeMinimumInterval') - ->will($this->returnValue($expected['autoPurgeMinimumInterval'])); - $this->config->expects($this->once()) - ->method('getAutoPurgeCount') - ->will($this->returnValue($expected['autoPurgeCount'])); - $this->config->expects($this->once()) - ->method('getMaxRedirects') - ->will($this->returnValue($expected['maxRedirects'])); - $this->config->expects($this->once()) - ->method('getFeedFetcherTimeout') - ->will($this->returnValue($expected['feedFetcherTimeout'])); - $this->config->expects($this->once()) - ->method('getUseCronUpdates') - ->will($this->returnValue($expected['useCronUpdates'])); - $this->config->expects($this->once()) - ->method('getMaxSize') - ->will($this->returnValue($expected['maxSize'])); - $this->config->expects($this->once()) - ->method('getExploreUrl') - ->will($this->returnValue($expected['exploreUrl'])); - $this->config->expects($this->once()) - ->method('getUpdateInterval') - ->will($this->returnValue($expected['updateInterval'])); + $this->config->expects($this->exactly(count($expected))) + ->method('setAppValue') + ->withConsecutive( + ['news','autoPurgeMinimumInterval', 1], + ['news','autoPurgeCount', 2], + ['news','maxRedirects', 3], + ['news','feedFetcherTimeout', 4], + ['news','useCronUpdates', false], + ['news','exploreUrl', 'test'], + ['news','updateInterval', 3601] + ); + + $map = [ + ['news','autoPurgeMinimumInterval', 60, 1], + ['news','autoPurgeCount', 200, 2], + ['news','maxRedirects', 10, 3], + ['news','feedFetcherTimeout', 60, 4], + ['news','useCronUpdates', true, false,], + ['news','exploreUrl', '', 'test'], + ['news','updateInterval', 3600, 3601] + ]; + $this->config->expects($this->exactly(count($map))) + ->method('getAppValue') + ->will($this->returnValueMap($map)); $response = $this->controller->update( $expected['autoPurgeMinimumInterval'], $expected['autoPurgeCount'], $expected['maxRedirects'], $expected['feedFetcherTimeout'], - $expected['maxSize'], $expected['useCronUpdates'], $expected['exploreUrl'], $expected['updateInterval'] diff --git a/tests/Unit/Controller/ExportControllerTest.php b/tests/Unit/Controller/ExportControllerTest.php index 84ded5c6f..94ffa1ed1 100644 --- a/tests/Unit/Controller/ExportControllerTest.php +++ b/tests/Unit/Controller/ExportControllerTest.php @@ -41,7 +41,7 @@ class ExportControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'john'; diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php index cc387161d..c889a54b3 100644 --- a/tests/Unit/Controller/FeedApiControllerTest.php +++ b/tests/Unit/Controller/FeedApiControllerTest.php @@ -44,7 +44,7 @@ class FeedApiControllerTest extends TestCase private $logger; private $loggerParams; - protected function setUp() + protected function setUp(): void { $this->loggerParams = ['hi']; $this->logger = $this->getMockBuilder(ILogger::class) @@ -85,7 +85,7 @@ class FeedApiControllerTest extends TestCase } - public function testIndex() + public function testIndex() { $feeds = [new Feed()]; $starredCount = 3; @@ -116,7 +116,7 @@ class FeedApiControllerTest extends TestCase } - public function testIndexNoNewestItemId() + public function testIndexNoNewestItemId() { $feeds = [new Feed()]; $starredCount = 3; @@ -145,7 +145,7 @@ class FeedApiControllerTest extends TestCase } - public function testDelete() + public function testDelete() { $this->feedService->expects($this->once()) ->method('delete') @@ -158,7 +158,7 @@ class FeedApiControllerTest extends TestCase } - public function testDeleteDoesNotExist() + public function testDeleteDoesNotExist() { $this->feedService->expects($this->once()) ->method('delete') @@ -176,7 +176,7 @@ class FeedApiControllerTest extends TestCase } - public function testCreate() + public function testCreate() { $feeds = [new Feed()]; @@ -206,7 +206,7 @@ class FeedApiControllerTest extends TestCase } - public function testCreateNoItems() + public function testCreateNoItems() { $feeds = [new Feed()]; @@ -236,7 +236,7 @@ class FeedApiControllerTest extends TestCase - public function testCreateExists() + public function testCreateExists() { $this->feedService->expects($this->once()) ->method('purgeDeleted') @@ -255,7 +255,7 @@ class FeedApiControllerTest extends TestCase } - public function testCreateError() + public function testCreateError() { $this->feedService->expects($this->once()) ->method('create') @@ -271,7 +271,7 @@ class FeedApiControllerTest extends TestCase } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('readFeed') @@ -285,7 +285,7 @@ class FeedApiControllerTest extends TestCase } - public function testMove() + public function testMove() { $this->feedService->expects($this->once()) ->method('patch') @@ -299,7 +299,7 @@ class FeedApiControllerTest extends TestCase } - public function testMoveDoesNotExist() + public function testMoveDoesNotExist() { $this->feedService->expects($this->once()) ->method('patch') @@ -315,7 +315,7 @@ class FeedApiControllerTest extends TestCase } - public function testRename() + public function testRename() { $feedId = 3; $feedTitle = 'test'; @@ -332,7 +332,7 @@ class FeedApiControllerTest extends TestCase } - public function testRenameError() + public function testRenameError() { $feedId = 3; $feedTitle = 'test'; @@ -370,7 +370,7 @@ class FeedApiControllerTest extends TestCase } - public function testUpdate() + public function testUpdate() { $feedId = 3; $userId = 'hi'; @@ -383,7 +383,7 @@ class FeedApiControllerTest extends TestCase } - public function testUpdateError() + public function testUpdateError() { $feedId = 3; $userId = 'hi'; diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index 4703d307a..9a3114da0 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -45,7 +45,7 @@ class FeedControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jack'; @@ -398,7 +398,7 @@ class FeedControllerTest extends TestCase } - public function testImport() + public function testImport() { $feed = new Feed(); @@ -426,7 +426,7 @@ class FeedControllerTest extends TestCase } - public function testImportCreatesNoAdditionalFeed() + public function testImportCreatesNoAdditionalFeed() { $this->feedService->expects($this->once()) ->method('importArticles') @@ -467,7 +467,7 @@ class FeedControllerTest extends TestCase } - public function testRestore() + public function testRestore() { $this->feedService->expects($this->once()) ->method('unmarkDeleted') @@ -492,7 +492,7 @@ class FeedControllerTest extends TestCase $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } - public function testPatch() + public function testPatch() { $expected = [ 'pinned' => true, diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php index 3a93a460a..311212169 100644 --- a/tests/Unit/Controller/FolderApiControllerTest.php +++ b/tests/Unit/Controller/FolderApiControllerTest.php @@ -44,7 +44,7 @@ class FolderApiControllerTest extends TestCase private $request; private $msg; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) @@ -79,7 +79,7 @@ class FolderApiControllerTest extends TestCase } - public function testIndex() + public function testIndex() { $folders = [new Folder()]; @@ -98,7 +98,7 @@ class FolderApiControllerTest extends TestCase } - public function testCreate() + public function testCreate() { $folderName = 'test'; $folder = new Folder(); @@ -122,7 +122,7 @@ class FolderApiControllerTest extends TestCase } - public function testCreateAlreadyExists() + public function testCreateAlreadyExists() { $msg = 'exists'; @@ -141,7 +141,7 @@ class FolderApiControllerTest extends TestCase } - public function testCreateInvalidFolderName() + public function testCreateInvalidFolderName() { $msg = 'exists'; @@ -162,7 +162,7 @@ class FolderApiControllerTest extends TestCase } - public function testDelete() + public function testDelete() { $folderId = 23; $this->folderService->expects($this->once()) @@ -173,7 +173,7 @@ class FolderApiControllerTest extends TestCase } - public function testDeleteDoesNotExist() + public function testDeleteDoesNotExist() { $folderId = 23; @@ -193,7 +193,7 @@ class FolderApiControllerTest extends TestCase } - public function testUpdate() + public function testUpdate() { $folderId = 23; $folderName = 'test'; @@ -209,7 +209,7 @@ class FolderApiControllerTest extends TestCase $this->folderAPI->update($folderId, $folderName); } - public function testUpdateDoesNotExist() + public function testUpdateDoesNotExist() { $folderId = 23; $folderName = 'test'; @@ -230,7 +230,7 @@ class FolderApiControllerTest extends TestCase } - public function testUpdateExists() + public function testUpdateExists() { $folderId = 23; $folderName = 'test'; @@ -251,7 +251,7 @@ class FolderApiControllerTest extends TestCase } - public function testUpdateInvalidFolderName() + public function testUpdateInvalidFolderName() { $folderId = 23; $folderName = ''; @@ -274,7 +274,7 @@ class FolderApiControllerTest extends TestCase } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('readFolder') diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php index b9e0485a4..abe1ebd7a 100644 --- a/tests/Unit/Controller/FolderControllerTest.php +++ b/tests/Unit/Controller/FolderControllerTest.php @@ -44,7 +44,7 @@ class FolderControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jack'; diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php index 5733a0c87..412b9dd51 100644 --- a/tests/Unit/Controller/ItemApiControllerTest.php +++ b/tests/Unit/Controller/ItemApiControllerTest.php @@ -39,7 +39,7 @@ class ItemApiControllerTest extends TestCase private $request; private $msg; - protected function setUp() + protected function setUp(): void { $this->user = 'tom'; $this->appName = 'news'; @@ -71,7 +71,7 @@ class ItemApiControllerTest extends TestCase } - public function testIndex() + public function testIndex() { $item = new Item(); $item->setId(5); @@ -102,7 +102,7 @@ class ItemApiControllerTest extends TestCase } - public function testIndexDefaultBatchSize() + public function testIndexDefaultBatchSize() { $item = new Item(); $item->setId(5); @@ -133,7 +133,7 @@ class ItemApiControllerTest extends TestCase } - public function testUpdated() + public function testUpdated() { $item = new Item(); $item->setId(5); @@ -162,7 +162,7 @@ class ItemApiControllerTest extends TestCase } - public function testRead() + public function testRead() { $this->itemService->expects($this->once()) ->method('read') @@ -176,7 +176,7 @@ class ItemApiControllerTest extends TestCase } - public function testReadDoesNotExist() + public function testReadDoesNotExist() { $this->itemService->expects($this->once()) ->method('read') @@ -194,7 +194,7 @@ class ItemApiControllerTest extends TestCase } - public function testUnread() + public function testUnread() { $this->itemService->expects($this->once()) ->method('read') @@ -208,7 +208,7 @@ class ItemApiControllerTest extends TestCase } - public function testUnreadDoesNotExist() + public function testUnreadDoesNotExist() { $this->itemService->expects($this->once()) ->method('read') @@ -226,7 +226,7 @@ class ItemApiControllerTest extends TestCase } - public function testStar() + public function testStar() { $this->itemService->expects($this->once()) ->method('star') @@ -241,7 +241,7 @@ class ItemApiControllerTest extends TestCase } - public function testStarDoesNotExist() + public function testStarDoesNotExist() { $this->itemService->expects($this->once()) ->method('star') @@ -259,7 +259,7 @@ class ItemApiControllerTest extends TestCase } - public function testUnstar() + public function testUnstar() { $this->itemService->expects($this->once()) ->method('star') @@ -274,7 +274,7 @@ class ItemApiControllerTest extends TestCase } - public function testUnstarDoesNotExist() + public function testUnstarDoesNotExist() { $this->itemService->expects($this->once()) ->method('star') @@ -292,7 +292,7 @@ class ItemApiControllerTest extends TestCase } - public function testReadAll() + public function testReadAll() { $this->itemService->expects($this->once()) ->method('readAll') @@ -306,7 +306,7 @@ class ItemApiControllerTest extends TestCase - public function testReadMultiple() + public function testReadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -326,7 +326,7 @@ class ItemApiControllerTest extends TestCase } - public function testReadMultipleDoesntCareAboutException() + public function testReadMultipleDoesntCareAboutException() { $this->itemService->expects($this->at(0)) ->method('read') @@ -342,7 +342,7 @@ class ItemApiControllerTest extends TestCase } - public function testUnreadMultiple() + public function testUnreadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -362,7 +362,7 @@ class ItemApiControllerTest extends TestCase } - public function testStarMultiple() + public function testStarMultiple() { $ids = [ [ @@ -395,7 +395,7 @@ class ItemApiControllerTest extends TestCase } - public function testStarMultipleDoesntCareAboutException() + public function testStarMultipleDoesntCareAboutException() { $ids = [ [ @@ -423,7 +423,7 @@ class ItemApiControllerTest extends TestCase } - public function testUnstarMultiple() + public function testUnstarMultiple() { $ids = [ [ diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php index b24d74148..9dbcf15ce 100644 --- a/tests/Unit/Controller/ItemControllerTest.php +++ b/tests/Unit/Controller/ItemControllerTest.php @@ -43,7 +43,7 @@ class ItemControllerTest extends TestCase /** * Gets run before each test */ - public function setUp() + public function setUp(): void { $this->appName = 'news'; $this->user = 'jackob'; @@ -96,7 +96,7 @@ class ItemControllerTest extends TestCase } - public function testReadMultiple() + public function testReadMultiple() { $this->itemService->expects($this->at(0)) ->method('read') @@ -116,7 +116,7 @@ class ItemControllerTest extends TestCase } - public function testReadMultipleDontStopOnException() + public function testReadMultipleDontStopOnException() { $this->itemService->expects($this->at(0)) ->method('read') diff --git a/tests/Unit/Controller/JSONHttpErrorTest.php b/tests/Unit/Controller/JSONHttpErrorTest.php index bf043bf54..c02b60c9e 100644 --- a/tests/Unit/Controller/JSONHttpErrorTest.php +++ b/tests/Unit/Controller/JSONHttpErrorTest.php @@ -26,7 +26,7 @@ class JSONHttpErrorTest extends TestCase { - public function testError() + public function testError() { $ex = new \Exception('hi'); $test = new Test(); diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index ce7a3e73d..69fed0d77 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -13,7 +13,7 @@ namespace OCA\News\Tests\Unit\Controller; -use OCA\News\Config\Config; +use OC\L10N\L10N; use OCA\News\Controller\PageController; use \OCA\News\Db\FeedType; use OCA\News\Explore\RecommendedSites; @@ -28,26 +28,51 @@ use PHPUnit\Framework\TestCase; class PageControllerTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IConfig + */ private $settings; - private $appName; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IRequest + */ private $request; + + /** + * @var PageController + */ private $controller; - private $user; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|L10N + */ private $l10n; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator + */ private $urlGenerator; - private $appConfig; + + /** + * @var array + */ private $configData; - private $config; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|RecommendedSites + */ private $recommended; + + /** + * @var \PHPUnit\Framework\MockObject\MockObject|StatusService + */ private $status; /** * Gets run before each test */ - public function setUp() + public function setUp(): void { - $this->appName = 'news'; - $this->user = 'becka'; $this->configData = [ 'name' => 'AppTest', 'id' => 'apptest', @@ -70,12 +95,6 @@ class PageControllerTest extends TestCase $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class) ->disableOriginalConstructor() ->getMock(); - $this->appConfig = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); - $this->config = $this->getMockBuilder(Config::class) - ->disableOriginalConstructor() - ->getMock(); $this->recommended = $this->getMockBuilder(RecommendedSites::class) ->disableOriginalConstructor() ->getMock(); @@ -83,10 +102,14 @@ class PageControllerTest extends TestCase ->disableOriginalConstructor() ->getMock(); $this->controller = new PageController( - $this->appName, $this->request, - $this->settings, $this->urlGenerator, $this->config, - $this->l10n, $this->recommended, $this->status, - $this->user + 'news', + $this->request, + $this->settings, + $this->urlGenerator, + $this->l10n, + $this->recommended, + $this->status, + 'becka' ); } @@ -95,15 +118,7 @@ class PageControllerTest extends TestCase { $this->status->expects($this->once()) ->method('getStatus') - ->will( - $this->returnValue( - [ - 'warnings' => [ - 'improperlyConfiguredCron' => false - ] - ] - ) - ); + ->will($this->returnValue(['warnings' => ['improperlyConfiguredCron' => false]])); $response = $this->controller->index(); $this->assertEquals('index', $response->getTemplateName()); @@ -130,8 +145,10 @@ class PageControllerTest extends TestCase $this->assertEquals(true, $response->getParams()['warnings']['improperlyConfiguredCron']); } - - public function testSettings() + /** + * @covers \OCA\News\Controller\PageController::settings + */ + public function testSettings() { $result = [ 'settings' => [ @@ -148,55 +165,23 @@ class PageControllerTest extends TestCase $this->l10n->expects($this->once()) ->method('getLanguageCode') ->will($this->returnValue('de')); - $this->settings->expects($this->at(0)) + $this->settings->expects($this->exactly(5)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] ) ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(2)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(3)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(4)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand') - ) - ->will($this->returnValue('1')); - $this->config->expects($this->once()) - ->method('getExploreUrl') + $this->settings->expects($this->once()) + ->method('getAppValue') + ->with('news', 'exploreUrl') ->will($this->returnValue(' ')); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') - ->with( - $this->equalTo('news.page.explore'), - $this->equalTo(['lang' => 'en']) - ) + ->with('news.page.explore', ['lang' => 'en']) ->will($this->returnValue('test')); @@ -205,7 +190,7 @@ class PageControllerTest extends TestCase } - public function testSettingsExploreUrlSet() + public function testSettingsExploreUrlSet() { $result = [ 'settings' => [ @@ -222,48 +207,19 @@ class PageControllerTest extends TestCase $this->l10n->expects($this->once()) ->method('getLanguageCode') ->will($this->returnValue('de')); - $this->settings->expects($this->at(0)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(1)) + $this->settings->expects($this->exactly(5)) ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact') + ->withConsecutive( + ['becka', 'news', 'showAll'], + ['becka', 'news', 'compact'], + ['becka', 'news', 'preventReadOnScroll'], + ['becka', 'news', 'oldestFirst'], + ['becka', 'news', 'compactExpand'] ) ->will($this->returnValue('1')); - $this->settings->expects($this->at(2)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(3)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst') - ) - ->will($this->returnValue('1')); - $this->settings->expects($this->at(4)) - ->method('getUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand') - ) - ->will($this->returnValue('1')); - $this->config->expects($this->once()) - ->method('getExploreUrl') + $this->settings->expects($this->once()) + ->method('getAppValue') + ->with('news', 'exploreUrl') ->will($this->returnValue('abc')); $this->urlGenerator->expects($this->never()) ->method('getAbsoluteURL'); @@ -273,83 +229,50 @@ class PageControllerTest extends TestCase $this->assertEquals($result, $response); } - public function testUpdateSettings() + /** + * @covers \OCA\News\Controller\PageController::updateSettings + */ + public function testUpdateSettings() { $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('showAll'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'showAll', '1'); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compact'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'compact', '1'); $this->settings->expects($this->at(2)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('preventReadOnScroll'), - $this->equalTo('0') - ); + ->with('becka', 'news', 'preventReadOnScroll', '0'); $this->settings->expects($this->at(3)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('oldestFirst'), - $this->equalTo('1') - ); + ->with('becka', 'news', 'oldestFirst', '1'); $this->settings->expects($this->at(4)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('compactExpand'), - $this->equalTo('1') - ); - $this->controller->updateSettings(true, true, false, true, true); + ->with('becka', 'news', 'compactExpand', '1'); + $this->controller->updateSettings(true, true, false, true, true); } - public function testExplore() { $in = 'test'; $this->settings->expects($this->at(0)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedId'), - $this->equalTo(0) - ); + ->with('becka', 'news', 'lastViewedFeedId', 0); $this->settings->expects($this->at(1)) ->method('setUserValue') - ->with( - $this->equalTo($this->user), - $this->equalTo($this->appName), - $this->equalTo('lastViewedFeedType'), - $this->equalTo(FeedType::EXPLORE) - ); + ->with('becka', 'news', 'lastViewedFeedType', FeedType::EXPLORE); $this->recommended->expects($this->once()) ->method('forLanguage') - ->with($this->equalTo('en')) + ->with('en') ->will($this->returnValue($in)); - $out = $this->controller->explore('en'); $this->assertEquals($in, $out); + } } diff --git a/tests/Unit/Controller/UserApiControllerTest.php b/tests/Unit/Controller/UserApiControllerTest.php index d9df73fe7..dd0140c81 100644 --- a/tests/Unit/Controller/UserApiControllerTest.php +++ b/tests/Unit/Controller/UserApiControllerTest.php @@ -33,7 +33,7 @@ class UserApiControllerTest extends TestCase private $user; private $file; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->request = $this->getMockBuilder(IRequest::class) @@ -59,7 +59,7 @@ class UserApiControllerTest extends TestCase } - private function expectUser($uid, $displayName, $lastLogin) + private function expectUser($uid, $displayName, $lastLogin) { $this->userSession->expects($this->any()) ->method('getUser') @@ -75,7 +75,7 @@ class UserApiControllerTest extends 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'; @@ -98,7 +98,7 @@ class UserApiControllerTest extends TestCase ->will($this->returnValue($data)); } - public function testGetJpeg() + public function testGetJpeg() { $this->expectUser('john', 'John', 123); $this->expectImg(true, false, 'john', true, 'hi'); @@ -117,7 +117,7 @@ class UserApiControllerTest extends TestCase $this->assertEquals($expected, $result); } - public function testGetPng() + public function testGetPng() { $this->expectUser('john', 'John', 123); $this->expectImg(false, true, 'john', false, 'hi'); @@ -136,7 +136,7 @@ class UserApiControllerTest extends 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 37070b160..32a66b2e8 100644 --- a/tests/Unit/Controller/UtilityApiControllerTest.php +++ b/tests/Unit/Controller/UtilityApiControllerTest.php @@ -37,7 +37,7 @@ class UtilityApiControllerTest extends TestCase private $appName; private $status; - protected function setUp() + protected function setUp(): void { $this->appName = 'news'; $this->settings = $this->getMockBuilder(IConfig::class) diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php index 11c411b5e..f8544da65 100644 --- a/tests/Unit/Db/FolderMapperTest.php +++ b/tests/Unit/Db/FolderMapperTest.php @@ -28,7 +28,7 @@ class FolderMapperTest extends MapperTestUtility /** @var string */ private $user; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/Db/ItemTest.php b/tests/Unit/Db/ItemTest.php index 6b63f8685..c9a353ea7 100644 --- a/tests/Unit/Db/ItemTest.php +++ b/tests/Unit/Db/ItemTest.php @@ -22,11 +22,11 @@ class ItemTest extends TestCase { /** - * @var Item + * @var Item */ private $item; - protected function setUp() + protected function setUp(): void { $this->item = new Item(); $this->item->setStatus(0); @@ -65,7 +65,7 @@ class ItemTest extends TestCase } - public function testToAPI() + public function testToAPI() { $item = new Item(); $item->setId(3); @@ -117,7 +117,7 @@ class ItemTest extends TestCase } - public function testJSONSerialize() + public function testJSONSerialize() { $item = new Item(); $item->setId(3); @@ -167,7 +167,7 @@ class ItemTest extends TestCase ); } - public function testToExport() + public function testToExport() { $item = new Item(); $item->setId(3); @@ -216,7 +216,7 @@ class ItemTest extends TestCase } - private function createImportItem($isRead) + private function createImportItem($isRead) { $item = new Item(); $item->setGuid('guid'); @@ -242,7 +242,7 @@ class ItemTest extends TestCase } - public function testSearchIndex() + public f