summaryrefslogtreecommitdiffstats
path: root/tests/Unit
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-11-14 00:09:38 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2020-12-08 13:58:12 +0100
commit8abddeab4f541883721d912f97dec07bffdfc6b8 (patch)
tree8c176f9ca2fd9e757807481997f265212f154eb2 /tests/Unit
parent3d98707be95322d16f5883d7a945d658d6316146 (diff)
Remove usage of old Folder code
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/Controller/FeedControllerTest.php151
-rw-r--r--tests/Unit/Controller/FolderApiControllerTest.php1
-rw-r--r--tests/Unit/Controller/FolderControllerTest.php202
-rw-r--r--tests/Unit/Db/FolderMapperTest.php519
-rw-r--r--tests/Unit/Db/MapperTestUtility.php19
-rw-r--r--tests/Unit/Service/FolderServiceTest.php320
-rw-r--r--tests/Unit/Service/StatusServiceTest.php65
7 files changed, 584 insertions, 693 deletions
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;
use OCA\News\Controller\FolderApiController;
-use OCA\News\Service\FolderService;
use OCA\News\Service\FolderServiceV2;
use OCA\News\Service\ItemService;
use \OCP\AppFramework\Http;
diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php
index 94c7b1c53..d0216c70f 100644
--- a/tests/Unit/Controller/FolderControllerTest.php
+++ b/tests/Unit/Controller/FolderControllerTest.php
@@ -15,7 +15,7 @@ namespace OCA\News\Tests\Unit\Controller;
use OCA\News\Controller\FolderController;
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,16 +26,24 @@ use \OCA\News\Service\Exceptions\ServiceConflictException;
use \OCA\News\Service\Exceptions\ServiceValidationException;
use OCP\IRequest;
+use OCP\IUser;
+use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-
class FolderControllerTest extends TestCase
{
+ /**
+ * @var MockObject|FolderServiceV2
+ */
private $folderService;
private $itemService;
private $feedService;
- private $controller;
+ /**
+ * @var MockObject|IUser
+ */
+ private $user;
+ private $class;
private $msg;
@@ -45,8 +53,12 @@ class FolderControllerTest extends TestCase
public function setUp(): void
{
$appName = 'news';
- $this->user = 'jack';
- $this->folderService = $this->getMockBuilder(FolderService::class)
+ $this->user = $this->getMockBuilder(IUser::class)
+ ->getMock();
+ $this->user->expects($this->once())
+ ->method('getUID')
+ ->willReturn('jack');
+ $this->folderService = $this->getMockBuilder(FolderServiceV2::class)
->disableOriginalConstructor()
->getMock();
$this->feedService = $this->getMockBuilder(FeedService::class)
@@ -58,8 +70,9 @@ class FolderControllerTest extends TestCase
$request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
- $this->controller = new FolderController(
- $appName, $request,
+ $this->class = new FolderController(
+ $appName,
+ $request,
$this->folderService,
$this->feedService,
$this->itemService,
@@ -75,8 +88,8 @@ class FolderControllerTest extends TestCase
->method('findAllForUser')
->will($this->returnValue($return));
- $response = $this->controller->index();
- $expected = ['folders' => $return];
+ $response = $this->class->index();
+ $expected = ['folders' => [$return[0]->toAPI(), $return[1]->toAPI()]];
$this->assertEquals($expected, $response);
}
@@ -84,27 +97,18 @@ class FolderControllerTest extends TestCase
{
$this->folderService->expects($this->once())
->method('open')
- ->with(
- $this->equalTo(3),
- $this->equalTo(true), $this->equalTo($this->user)
- );
-
- $this->controller->open(3, true);
+ ->with('jack', 3, true);
+ $this->class->open(3, true);
}
-
public function testOpenDoesNotExist()
{
$this->folderService->expects($this->once())
->method('open')
- ->will(
- $this->throwException(
- new ServiceNotFoundException($this->msg)
- )
- );
+ ->will($this->throwException(new ServiceNotFoundException($this->msg)));
- $response = $this->controller->open(5, true);
+ $response = $this->class->open(5, true);
$params = json_decode($response->render(), true);
@@ -117,100 +121,44 @@ class FolderControllerTest extends TestCase
{
$this->folderService->expects($this->once())
->method('open')
- ->with(
- $this->equalTo(5),
- $this->equalTo(false), $this->equalTo($this->user)
- );
-
- $this->controller->open(5, false);
+ ->with('jack', 5, false);
+ $this->class->open(5, false);
}
-
public function testCreate()
{
- $result = ['folders' => [new Folder()]];
+ $folder = new Folder();
+ $result = ['folders' => [$folder->toAPI()]];
$this->folderService->expects($this->once())
- ->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
+ ->method('purgeDeleted');
$this->folderService->expects($this->once())
->method('create')
- ->with(
- $this->equalTo('tech'),
- $this->equalTo($this->user)
- )
- ->will($this->returnValue($result['folders'][0]));
+ ->with('jack', 'tech')
+ ->will($this->returnValue($folder));
- $response = $this->controller->create('tech');
+ $response = $this->class->create('tech');
$this->assertEquals($result, $response);
}
-
- public function testCreateReturnsErrorForInvalidCreate()
- {
- $msg = 'except';
- $ex = new ServiceValidationException($msg);
- $this->folderService->expects($this->once())
- ->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
- $this->folderService->expects($this->once())
- ->method('create')
- ->will($this->throwException($ex));
-
- $response = $this->controller->create('tech');
- $params = json_decode($response->render(), true);
-
- $this->assertEquals(
- $response->getStatus(),
- Http::STATUS_UNPROCESSABLE_ENTITY
- );
- $this->assertEquals($msg, $params['message']);
- }
-
-
- public function testCreateReturnsErrorForDuplicateCreate()
- {
- $msg = 'except';
- $ex = new ServiceConflictException($msg);
- $this->folderService->expects($this->once())
- ->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
- $this->folderService->expects($this->once())
- ->method('create')
- ->will($this->throwException($ex));
-
- $response = $this->controller->create('tech');
- $params = json_decode($response->render(), true);
-
- $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT);
- $this->assertEquals($msg, $params['message']);
- }
-
-
public function testDelete()
{
$this->folderService->expects($this->once())
- ->method('markDeleted')
- ->with(
- $this->equalTo(5),
- $this->equalTo($this->user)
- );
+ ->method('markDelete')
+ ->with('jack', 5, true);
- $this->controller->delete(5);
+ $this->class->delete(5);
}
-
public function testDeleteDoesNotExist()
{
$this->folderService->expects($this->once())
- ->method('markDeleted')
- ->will(
- $this->throwException(new ServiceNotFoundException($this->msg))
- );
+ ->method('markDelete')
+ ->will($this->throwException(new ServiceNotFoundException($this->msg)));
- $response = $this->controller->delete(5);
+ $response = $this->class->delete(5);
$params = json_decode($response->render(), true);
@@ -218,45 +166,21 @@ class FolderControllerTest extends TestCase
$this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND);
}
-
public function testRename()
{
- $result = ['folders' => [new Folder()]];
+ $folder = new Folder();
+ $result = ['folders' => [$folder->toAPI()]];
$this->folderService->expects($this->once())
->method('rename')
- ->with(
- $this->equalTo(4),
- $this->equalTo('tech'),
- $this->equalTo($this->user)
- )
- ->will($this->returnValue($result['folders'][0]));
+ ->with('jack', 4, 'tech')
+ ->will($this->returnValue($folder));
- $response = $this->controller->rename('tech', 4);
+ $response = $this->class->rename('tech', 4);
$this->assertEquals($result, $response);
}
-
- public function testRenameReturnsErrorForInvalidCreate()
- {
- $msg = 'except';
- $ex = new ServiceValidationException($msg);
- $this->folderService->expects($this->once())
- ->method('rename')
- ->will($this->throwException($ex));
-
- $response = $this->controller->rename('tech', 4);
- $params = json_decode($response->render(), true);
-
- $this->assertEquals(
- $response->getStatus(),
- Http::STATUS_UNPROCESSABLE_ENTITY
- );
- $this->assertEquals($msg, $params['message']);
- }
-
-
public function testRenameDoesNotExist()
{
$msg = 'except';
@@ -265,7 +189,7 @@ class FolderControllerTest extends TestCase
->method('rename')
->will($this->throwException($ex));
- $response = $this->controller->rename('tech', 5);
+ $response = $this->class->rename('tech', 5);
$params = json_decode($response->render(), true);
$this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND);
@@ -281,7 +205,7 @@ class FolderControllerTest extends TestCase
->method('rename')
->will($this->throwException($ex));
- $response = $this->controller->rename('tech', 1);
+ $response = $this->class->rename('tech', 1);
$params = json_decode($response->render(), true);
$this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT);
@@ -293,21 +217,17 @@ class FolderControllerTest extends TestCase
public function testRead()
{
$feed = new Feed();
- $expected = ['feeds' => [$feed]];
+ $expected = ['feeds' => [$feed->toAPI()]];
$this->itemService->expects($this->once())
->method('readFolder')
- ->with(
- $this->equalTo(4),
- $this->equalTo(5),
- $this->equalTo($this->user)
- );
+ ->with(4, 5, 'jack');
$this->feedService->expects($this->once())
->method('findAllForUser')
- ->with($this->equalTo($this->user))
+ ->with('jack')
->will($this->returnValue([$feed]));
- $response = $this->controller->read(4, 5);
+ $response = $this->class->read(4, 5);
$this->assertEquals($expected, $response);
}
@@ -315,29 +235,25 @@ class FolderControllerTest extends TestCase
public function testRestore()
{
$this->folderService->expects($this->once())
- ->method('unmarkDeleted')
- ->with(
- $this->equalTo(5),
- $this->equalTo($this->user)
- );
+ ->method('markDelete')
+ ->with('jack', 5, false);
- $this->controller->restore(5);
+ $this->class->restore(5);
}
public function testRestoreDoesNotExist()
{
$this->folderService->expects($this->once())
- ->method('unmarkDeleted')
- ->will(
- $this->throwException(new ServiceNotFoundException($this->msg))
- );
+ ->method('markDelete')
+ ->with('jack', 5, false)
+ ->will($this->throwException(new ServiceNotFoundException($this->msg)));
- $response = $this->controller->restore(5);
+ $response = $this->class->restore(5);
$params = json_decode($response->render(), true);
- $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertEquals($this->msg, $params['message']);
}
diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php
index 803c84ebe..ab2fb3995 100644
--- a/tests/Unit/Db/FolderMapperTest.php
+++ b/tests/Unit/Db/FolderMapperTest.php
@@ -14,25 +14,23 @@
namespace OCA\News\Tests\Unit\Db;
use OCA\News\Db\Folder;
-use OCA\News\Db\FolderMapper;
+use OCA\News\Db\FolderMapperV2;
use OCA\News\Utility\Time;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
class FolderMapperTest extends MapperTestUtility
{
- /** @var FolderMapper */
- private $folderMapper;
+ /** @var FolderMapperV2 */
+ private $class;
/** @var Folder[] */
private $folders;
- /** @var string */
- private $user;
protected function setUp(): void
{
parent::setUp();
- $this->folderMapper = new FolderMapper($this->db, new Time());
+ $this->class = new FolderMapperV2($this->db, new Time());
// create mock folders
$folder1 = new Folder();
@@ -43,351 +41,242 @@ class FolderMapperTest extends MapperTestUtility
$folder2->resetUpdatedFields();
$this->folders = [$folder1, $folder2];
- $this->user = 'hh';
- $this->twoRows = [
- ['id' => $this->folders[0]->getId()],
- ['id' => $this->folders[1]->getId()]
- ];
}
/**
- * @covers \OCA\News\Db\FolderMapper::find
+ * @covers \OCA\News\Db\FolderMapperV2::findAllFromUser
*/
- public function testFind()
- {
- $userId = 'john';
- $id = 3;
- $sql = 'SELECT * FROM `*PREFIX*news_folders` ' .
- 'WHERE `id` = ? ' .
- 'AND `user_id` = ?';
-
- $this->db->expects($this->exactly(1))
- ->method('prepare')
- ->with($sql, null, null)
- ->will(($this->returnValue($this->query)));
-
- $this->query->expects($this->exactly(2))
- ->method('fetch')
- ->willReturnOnConsecutiveCalls(['id' => 4], false);
-
- $this->query->expects($this->exactly(2))
- ->method('bindValue')
- ->withConsecutive([1, 3, 1], [2, $userId, 2]);
-
- $this->query->expects($this->exactly(1))
- ->method('closeCursor');
-
- $this->query->expects($this->once())
- ->method('execute')
- ->with('')
- ->will($this->returnValue([]));
-
- $result = $this->folderMapper->find($userId, $id);
- $this->assertEquals($this->folders[0], $result);
- }
-
-
- public function testF