diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-11-14 00:09:38 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2020-12-08 13:58:12 +0100 |
commit | 8abddeab4f541883721d912f97dec07bffdfc6b8 (patch) | |
tree | 8c176f9ca2fd9e757807481997f265212f154eb2 /tests | |
parent | 3d98707be95322d16f5883d7a945d658d6316146 (diff) |
Remove usage of old Folder code
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Integration/Db/ItemMapperTest.php | 32 | ||||
-rw-r--r-- | tests/Integration/Fixtures/FeedFixture.php | 47 | ||||
-rw-r--r-- | tests/Integration/Fixtures/Fixture.php | 3 | ||||
-rw-r--r-- | tests/Integration/Fixtures/FolderFixture.php | 20 | ||||
-rw-r--r-- | tests/Integration/Fixtures/ItemFixture.php | 35 | ||||
-rw-r--r-- | tests/Integration/IntegrationTest.php | 25 | ||||
-rw-r--r-- | tests/Unit/Controller/FeedControllerTest.php | 151 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderApiControllerTest.php | 1 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderControllerTest.php | 202 | ||||
-rw-r--r-- | tests/Unit/Db/FolderMapperTest.php | 519 | ||||
-rw-r--r-- | tests/Unit/Db/MapperTestUtility.php | 19 | ||||
-rw-r--r-- | tests/Unit/Service/FolderServiceTest.php | 320 | ||||
-rw-r--r-- | tests/Unit/Service/StatusServiceTest.php | 65 |
13 files changed, 646 insertions, 793 deletions
diff --git a/tests/Integration/Db/ItemMapperTest.php b/tests/Integration/Db/ItemMapperTest.php index 28a6c3e11..ea7f306df 100644 --- a/tests/Integration/Db/ItemMapperTest.php +++ b/tests/Integration/Db/ItemMapperTest.php @@ -150,38 +150,6 @@ class ItemMapperTest extends IntegrationTest } - public function testReadFolder() - { - $this->loadFixtures('default'); - - $folderId = $this->findFolderByName('first folder')->getId(); - $this->itemMapper->readFolder( - $folderId, PHP_INT_MAX, 10, $this->user - ); - - $items = $this->itemMapper->findAllItems( - 30, 0, 0, false, false, $this->user - ); - - $this->assertEquals(1, count($items)); - - $item = $this->findItemByTitle('a title1'); - $item = $this->itemMapper->find($this->user, $item->getId()); - - $this->assertEquals(10, $item->getLastModified()); - - $item = $this->findItemByTitle('a title3'); - $item = $this->itemMapper->find($this->user, $item->getId()); - - $this->assertEquals(10, $item->getLastModified()); - - $item = $this->findItemByTitle('a title9'); - $item = $this->itemMapper->find($this->user, $item->getId()); - - $this->assertTrue($item->isUnread()); - } - - public function testReadFeed() { $this->loadFixtures('default'); diff --git a/tests/Integration/Fixtures/FeedFixture.php b/tests/Integration/Fixtures/FeedFixture.php index 77abd3ee0..0c1e31af9 100644 --- a/tests/Integration/Fixtures/FeedFixture.php +++ b/tests/Integration/Fixtures/FeedFixture.php @@ -12,7 +12,6 @@ namespace OCA\News\Tests\Integration\Fixtures; - use OCA\News\Db\Feed; class FeedFixture extends Feed @@ -20,31 +19,33 @@ class FeedFixture extends Feed use Fixture; - public function __construct(array $defaults=[]) + public function __construct(array $defaults = []) { + parent::__construct(); $defaults = array_merge( [ - 'userId' => 'test', - 'urlHash' => 'urlHash', - 'url' => 'http://the.url.com', - 'title' => 'title', - 'faviconLink' => 'http://feed.com/favicon.ico', - 'added' => 3000, - 'folderId' => null, - 'link' => 'http://feed.com/rss', - 'preventUpdate' => false, - 'deletedAt' => 0, - 'articlesPerUpdate' => 40, - 'httpLastModified' => 10, - 'httpEtag' => '', - 'location' => 'http://feed.com/rss', - 'ordering' => 0, - 'fullTextEnabled' => false, - 'pinned' => false, - 'updateMode' => 0, - 'updateErrorCount' => 0, - 'lastUpdateError' => '', - ], $defaults + 'userId' => 'test', + 'urlHash' => 'urlHash', + 'url' => 'http://the.url.com', + 'title' => 'title', + 'faviconLink' => 'http://feed.com/favicon.ico', + 'added' => 3000, + 'folderId' => null, + 'link' => 'http://feed.com/rss', + 'preventUpdate' => false, + 'deletedAt' => 0, + 'articlesPerUpdate' => 40, + 'httpLastModified' => 10, + 'httpEtag' => '', + 'location' => 'http://feed.com/rss', + 'ordering' => 0, + 'fullTextEnabled' => false, + 'pinned' => false, + 'updateMode' => 0, + 'updateErrorCount' => 0, + 'lastUpdateError' => '', + ], + $defaults ); unset($defaults['items']); $this->fillDefaults($defaults); diff --git a/tests/Integration/Fixtures/Fixture.php b/tests/Integration/Fixtures/Fixture.php index 1874c8102..366c93228 100644 --- a/tests/Integration/Fixtures/Fixture.php +++ b/tests/Integration/Fixtures/Fixture.php @@ -15,8 +15,7 @@ namespace OCA\News\Tests\Integration\Fixtures; trait Fixture { - - protected function fillDefaults(array $defaults=[]) + protected function fillDefaults(array $defaults = []) { foreach ($defaults as $key => $value) { $method = 'set' . ucfirst($key); diff --git a/tests/Integration/Fixtures/FolderFixture.php b/tests/Integration/Fixtures/FolderFixture.php index 09c03e5de..ffd6042c0 100644 --- a/tests/Integration/Fixtures/FolderFixture.php +++ b/tests/Integration/Fixtures/FolderFixture.php @@ -12,24 +12,26 @@ namespace OCA\News\Tests\Integration\Fixtures; - use OCA\News\Db\Folder; class FolderFixture extends Folder { use Fixture; - public function __construct(array $defaults=[]) + public function __construct(array $defaults = []) { + parent::__construct(); + $defaults = array_merge( [ - 'parentId' => null, - 'name' => 'folder', - 'userId' => 'test', - 'opened' => true, - 'deletedAt' => 0, - 'lastModified' => 9 - ], $defaults + 'parentId' => null, + 'name' => 'folder', + 'userId' => 'test', + 'opened' => true, + 'deletedAt' => 0, + 'lastModified' => 9 + ], + $defaults ); unset($defaults['feeds']); $this->fillDefaults($defaults); diff --git a/tests/Integration/Fixtures/ItemFixture.php b/tests/Integration/Fixtures/ItemFixture.php index e84b4250b..978b12b55 100644 --- a/tests/Integration/Fixtures/ItemFixture.php +++ b/tests/Integration/Fixtures/ItemFixture.php @@ -12,32 +12,33 @@ namespace OCA\News\Tests\Integration\Fixtures; - use OCA\News\Db\Item; class ItemFixture extends Item { use Fixture; - public function __construct(array $defaults=[]) + public function __construct(array $defaults = []) { + parent::__construct(); $defaults = array_merge( [ - 'url' => 'http://google.de', - 'title' => 'title', - 'author' => 'my author', - 'pubDate' => 2323, - 'body' => 'this is a body', - 'enclosureMime' => 'video/mpeg', - 'enclosureLink' => 'http://google.de/web.webm', - 'mediaThumbnail' => 'https://i3.ytimg.com/vi/Zgge1O9wdPY/hqdefault.jpg', - 'mediaDescription' => 'The best video ever', - 'feedId' => 0, - 'unread' => true, - 'starred' => false, - 'lastModified' => 113, - 'rtl' => false, - ], $defaults + 'url' => 'http://google.de', + 'title' => 'title', + 'author' => 'my author', + 'pubDate' => 2323, + 'body' => 'this is a body', + 'enclosureMime' => 'video/mpeg', + 'enclosureLink' => 'http://google.de/web.webm', + 'mediaThumbnail' => 'https://i3.ytimg.com/vi/Zgge1O9wdPY/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', + 'feedId' => 0, + 'unread' => true, + 'starred' => false, + 'lastModified' => 113, + 'rtl' => false, + ], + $defaults ); if (!array_key_exists('guid', $defaults)) { diff --git a/tests/Integration/IntegrationTest.php b/tests/Integration/IntegrationTest.php index 6ecc3404c..bc309b339 100644 --- a/tests/Integration/IntegrationTest.php +++ b/tests/Integration/IntegrationTest.php @@ -12,6 +12,7 @@ namespace OCA\News\Tests\Integration; +use OCA\News\Db\FolderMapperV2; use OCA\News\Db\Item; use OCP\AppFramework\Db\Entity; use OCP\AppFramework\IAppContainer; @@ -44,7 +45,7 @@ abstract class IntegrationTest extends \Test\TestCase protected $feedMapper; /** - * @var FolderMapper + * @var FolderMapperV2 */ protected $folderMapper; @@ -64,7 +65,7 @@ abstract class IntegrationTest extends \Test\TestCase // set up database layers $this->itemMapper = $this->container->get(ItemMapper::class); $this->feedMapper = $this->container->get(FeedMapper::class); - $this->folderMapper = $this->container->get(FolderMapper::class); + $this->folderMapper = $this->container->get(FolderMapperV2::class); } protected function findItemByTitle($title) @@ -92,16 +93,6 @@ abstract class IntegrationTest extends \Test\TestCase return $result; } - protected function findFolderByName($name) - { - return $this->folderMapper->where( - [ - 'userId' => $this->user, - 'name' => $name - ] - )[0]; - } - protected function findFeedByTitle($title) { return $this->feedMapper->where( @@ -115,7 +106,7 @@ abstract class IntegrationTest extends \Test\TestCase /** * @param string $name loads fixtures from a given file */ - protected function loadFixtures($name) + protected function loadFixtures(string $name) { $fixtures = include __DIR__ . '/Fixtures/data/' . $name . '.php'; if (array_key_exists('folders', $fixtures)) { @@ -184,7 +175,7 @@ abstract class IntegrationTest extends \Test\TestCase */ protected function setupUser($user, $password) { - $userManager = $this->container->query(IUserManager::class); + $userManager = $this->container->get(IUserManager::class); $userManager->createUser($user, $password); $this->loginAsUser($user); @@ -197,7 +188,7 @@ abstract class IntegrationTest extends \Test\TestCase */ protected function tearDownUser($user) { - $userManager = $this->container->query(IUserManager::class); + $userManager = $this->container->get(IUserManager::class); if ($userManager->userExists($user)) { $userManager->get($user)->delete(); @@ -211,7 +202,7 @@ abstract class IntegrationTest extends \Test\TestCase * * @param string $user */ - protected function clearUserNewsDatabase($user) + protected function clearUserNewsDatabase(string $user) { $sql = [ 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` IN @@ -220,7 +211,7 @@ abstract class IntegrationTest extends \Test\TestCase 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?' ]; - $db = $this->container->query(IDBConnection::class); + $db = $this->container->get(IDBConnection::class); foreach ($sql as $query) { $db->prepare($query)->execute([$user]); } diff --git a/tests/Unit/Controller/FeedControllerTest.php b/tests/Unit/Controller/FeedControllerTest.php index f5c51b93e..fb5d0b5b5 100644 --- a/tests/Unit/Controller/FeedControllerTest.php +++ b/tests/Unit/Controller/FeedControllerTest.php @@ -15,7 +15,7 @@ namespace OCA\News\Tests\Unit\Controller; use OCA\News\Controller\FeedController; use OCA\News\Service\FeedService; -use OCA\News\Service\FolderService; +use OCA\News\Service\FolderServiceV2; use OCA\News\Service\ItemService; use OCP\AppFramework\Http; @@ -26,21 +26,49 @@ use OCA\News\Service\Exceptions\ServiceConflictException; use OCP\IConfig; use OCP\IRequest; +use OCP\IUser; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class FeedControllerTest extends TestCase { - + /** + * @var string + */ private $appName; - private $feedService; - private $request; - private $controller; + private $exampleResult; + private $uid; + + /** + * @var MockObject|FolderServiceV2 + */ private $folderService; + /** + * TODO: Remove + * @var MockObject|FeedService + */ + private $feedService; + /** + * TODO: Remove + * @var MockObject|ItemService + */ private $itemService; + + /** + * @var MockObject|IConfig + */ private $settings; - private $exampleResult; + + /** + * @var MockObject|IUser + */ private $user; + /** + * @var FeedController + */ + private $class; + /** * Gets run before each test @@ -48,7 +76,13 @@ class FeedControllerTest extends TestCase public function setUp(): void { $this->appName = 'news'; - $this->user = 'jack'; + $this->uid = 'jack'; + $this->user = $this->getMockBuilder(IUser::class) + ->getMock(); + + $this->user->expects($this->once()) + ->method('getUID') + ->willReturn($this->uid); $this->settings = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); @@ -61,14 +95,15 @@ class FeedControllerTest extends TestCase ->disableOriginalConstructor() ->getMock(); $this->folderService = $this - ->getMockBuilder(FolderService::class) + ->getMockBuilder(FolderServiceV2::class) ->disableOriginalConstructor() ->getMock(); - $this->request = $this->getMockBuilder(IRequest::class) + $request = $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() ->getMock(); - $this->controller = new FeedController( - $this->appName, $this->request, + $this->class = new FeedController( + $this->appName, + $request, $this->folderService, $this->feedService, $this->itemService, @@ -94,18 +129,18 @@ class FeedControllerTest extends TestCase ]; $this->feedService->expects($this->once()) ->method('findAllForUser') - ->with($this->equalTo($this->user)) + ->with($this->uid) ->will($this->returnValue($result['feeds'])); $this->itemService->expects($this->once()) ->method('getNewestItemId') - ->with($this->equalTo($this->user)) + ->with($this->equalTo($this->uid)) ->will($this->throwException(new ServiceNotFoundException(''))); $this->itemService->expects($this->once()) ->method('starredCount') - ->with($this->equalTo($this->user)) + ->with($this->equalTo($this->uid)) ->will($this->returnValue($result['starred'])); - $response = $this->controller->index(); + $response = $this->class->index(); $this->assertEquals($result, $response); } @@ -122,18 +157,18 @@ class FeedControllerTest extends TestCase ]; $this->feedService->expects($this->once()) ->method('findAllForUser') - ->with($this->equalTo($this->user)) + ->with($this->equalTo($this->uid)) ->will($this->returnValue($result['feeds'])); $this->itemService->expects($this->once()) ->method('getNewestItemId') - ->with($this->equalTo($this->user)) + ->with($this->equalTo($this->uid)) ->will($this->returnValue($result['newestItemId'])); $this->itemService->expects($this->once()) ->method('starredCount') - ->with($this->equalTo($this->user)) + ->with($this->equalTo($this->uid)) ->will($this->returnValue($result['starred'])); - $response = $this->controller->index(); + $response = $this->class->index(); $this->assertEquals($result, $response); } @@ -145,8 +180,8 @@ class FeedControllerTest extends TestCase $this->settings->expects($this->exactly(2)) ->method('getUserValue') ->withConsecutive( - [$this->user, $this->appName, 'lastViewedFeedId'], - [$this->user, $this->appName, 'lastViewedFeedType'] + [$this->uid, $this->appName, 'lastViewedFeedId'], + [$this->uid, $this->appName, 'lastViewedFeedType'] ) ->willReturnOnConsecutiveCalls($id, $type); } @@ -165,7 +200,7 @@ class FeedControllerTest extends TestCase $this->activeInitMocks($id, $type); - $response = $this->controller->active(); + $response = $this->class->active(); $this->assertEquals($result, $response); } @@ -180,12 +215,12 @@ class FeedControllerTest extends TestCase $this->feedService->expects($this->once()) ->method('find') - ->with($this->user, $id) + ->with($this->uid, $id) ->will($this->throwException($ex)); $this->activeInitMocks($id, $type); - $response = $this->controller->active(); + $response = $this->class->active(); $this->assertEquals($result, $response); } @@ -200,12 +235,12 @@ class FeedControllerTest extends TestCase $this->folderService->expects($this->once()) ->method('find') - ->with($this->user, $id) + ->with($this->uid, $id) ->will($this->throwException($ex)); $this->activeInitMocks($id, $type); - $response = $this->controller->active(); + $response = $this->class->active(); $this->assertEquals($result, $response); } @@ -220,7 +255,7 @@ class FeedControllerTest extends TestCase $this->activeInitMocks($id, $type); - $response = $this->controller->active(); + $response = $this->class->active(); $this->assertEquals($result, $response); } @@ -238,18 +273,18 @@ class FeedControllerTest extends TestCase ->will($this->returnValue($result['newestItemId'])); $this->feedService->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user), $this->equalTo(false)); + ->with($this->equalTo($this->uid), $this->equalTo(false)); $this->feedService->expects($this->once()) ->method('create') ->with( $this->equalTo('hi'), $this->equalTo(4), - $this->equalTo($this->user), + $this->equalTo($this->uid), $this->equalTo('yo') ) ->will($this->returnValue($result['feeds'][0])); - $response = $this->controller->create('hi', 4, 'yo'); + $response = $this->class->create('hi', 4, 'yo'); $this->assertEquals($result, $response); } @@ -261,7 +296,7 @@ class FeedControllerTest extends TestCase $this->feedService->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user), $this->equalTo(false)); + ->with($this->equalTo($this->uid), $this->equalTo(false)); $this->itemService->expects($this->once()) ->method('getNewestItemId') @@ -272,12 +307,12 @@ class FeedControllerTest extends TestCase ->with( $this->equalTo('hi'), $this->equalTo(4), - $this->equalTo($this->user), + $this->equalTo($this->uid), $this->equalTo('yo') ) ->will($this->returnValue($result['feeds'][0])); - $response = $this->controller->create('hi', 4, 'yo'); + $response = $this->class->create('hi', 4, 'yo'); $this->assertEquals($result, $response); } @@ -289,12 +324,12 @@ class FeedControllerTest extends TestCase $ex = new ServiceNotFoundException($msg); $this->feedService->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user), $this->equalTo(false)); + ->with($this->equalTo($this->uid), $this->equalTo(false)); $this->feedService->expects($this->once()) ->method('create') ->will($this->throwException($ex)); - $response = $this->controller->create('hi', 4, 'test'); + $response = $this->class->create('hi', 4, 'test'); $params = json_decode($response->render(), true); $this->assertEquals($msg, $params['message']); @@ -310,12 +345,12 @@ class FeedControllerTest extends TestCase $ex = new ServiceConflictException($msg); $this->feedService->expects($this->once()) ->method('purgeDeleted') - ->with($this->equalTo($this->user), $this->equalTo(false)); + ->with($this->equalTo($this->uid), $this->equalTo(false)); $this->feedService->expects($this->once()) ->method('create') ->will($this->throwException($ex)); - $response = $this->controller->create('hi', 4, 'test'); + $response = $this->class->create('hi', 4, 'test'); $params = json_decode($response->render(), true); $this->assertEquals($msg, $params['message']); @@ -329,7 +364,7 @@ class FeedControllerTest extends TestCase ->method('markDeleted') ->with($this->equalTo(4)); - $this->controller->delete(4); + $this->class->delete(4); } @@ -341,7 +376,7 @@ class FeedControllerTest extends TestCase ->method('markDeleted') ->will($this->throwException(new ServiceNotFoundException($msg))); - $response = $this->controller->delete(4); + $response = $this->class->delete(4); $params = json_decode($response->render(), true); $this->assertEquals($msg, $params['message']); @@ -365,10 +400,10 @@ class FeedControllerTest extends TestCase $this->feedService->expects($this->once()) ->method('update') - ->with($this->equalTo($this->user), $this->equalTo(4)) + ->with($this->equalTo($this->uid), $this->equalTo(4)) ->will($this->returnValue($feed)); - $response = $this->controller->update(4); + $response = $this->class->update(4); $this->assertEquals($result, $response); } @@ -378,10 +413,10 @@ class FeedControllerTest extends TestCase { $this->feedService->expects($this->once()) ->method('update') - ->with($this->equalTo($this->user), $this->equalTo(4)) + ->with($this->equalTo($this->uid), $this->equalTo(4)) ->will($this->throwException(new ServiceNotFoundException('NO!'))); - $response = $this->controller->update(4); + $response = $this->class->update(4); $render = $response->render(); $this->assertEquals('{"message":"NO!"}', $render); @@ -402,16 +437,16 @@ class FeedControllerTest extends TestCase ->method('importArticles') ->with( $this->equalTo(['json']), - $this->equalTo($this->user) + $this->equalTo($this->uid) ) ->will($this->returnValue($feed)); $this->itemService->expects($this->once()) ->method('starredCount') - ->with($this->equalTo($this->user)) + ->with($this->equalTo($this->uid)) ->will($this->returnValue(3)); - $response = $this->controller->import(['json']); + $response = $this->class->import(['json']); $this->assertEquals($expected, $response); } @@ -423,16 +458,16 @@ class FeedControllerTest extends TestCase ->method('importArticles') ->with( $this->equalTo(['json']), - $this->equalTo($this->user) + $this->equalTo($this->uid) ) ->will($this->returnValue(null)); $this->itemService->expects($this->once()) ->method('starredCount') - ->with($this->equalTo($this->user)) + ->with($this->equalTo($this->uid)) ->will($this->returnValue(3)); - $response = $this->controller->import(['json']); + $response = $this->class->import(['json']); $this->assertEquals(['starred' => 3], $response); } @@ -451,9 +486,9 @@ class FeedControllerTest extends TestCase $this->itemService->expects($this->once()) ->method('readFeed') - ->with($this->equalTo(4), $this->equalTo(5), $this->user); + ->with($this->equalTo(4), $this->equalTo(5), $this->uid); - $response = $this->controller->read(4, 5); + $response = $this->class->read(4, 5); $this->assertEquals($expected, $response); } @@ -464,7 +499,7 @@ class FeedControllerTest extends TestCase ->method('unmarkDeleted') ->with($this->equalTo(4)); - $this->controller->restore(4); + $this->class->restore(4); } @@ -476,7 +511,7 @@ class FeedControllerTest extends TestCase ->method('unmarkDeleted') ->will($this->throwException(new ServiceNotFoundException($msg))); - $response = $this->controller->restore(4); + $response = $this->class->restore(4); $params = json_decode($response->render(), true); $this->assertEquals($msg, $params['message']); @@ -492,14 +527,10 @@ class FeedControllerTest extends TestCase ]; $this->feedService->expects($this->once()) ->method('patch') - ->with( - $this->equalTo(4), - $this->equalTo($this->user), - $this->equalTo($expected) - ) + ->with(4, $this->uid, $expected) ->will($this->returnValue(1)); - $this->controller->patch(4, true, true, 1); + $this->class->patch(4, true, true, 1); } public function testPatchDoesNotExist() @@ -510,7 +541,7 @@ class FeedControllerTest extends TestCase ->method('patch') ->will($this->throwException(new ServiceNotFoundException($msg))); - $response = $this->controller->patch(4, 2); + $response = $this->class->patch(4, 2); $params = json_decode($response->render(), true); $this->assertEquals($msg, $params['message']); diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php index fdf494037..cf66b4c03 100644 --- a/tests/Unit/Controller/FolderApiControllerTest.php +++ b/tests/Unit/Controller/FolderApiControllerTest.php @@ -16,7 +16,6 @@ namespace OCA\News\Tests\Unit\Controller; |