diff options
Diffstat (limited to 'tests')
33 files changed, 650 insertions, 924 deletions
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 @@ -<?php -/** - * Nextcloud - News - * - * 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> - * @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 @@ -<?php -/** - * Nextcloud - News - * - * 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 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(); |