summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Guillot <david@guillot.me>2018-06-30 23:57:42 +0200
committerDavid Guillot <david@guillot.me>2018-07-01 23:03:36 +0200
commit5c4185e22155687740e44d58c5c6bc9dc793cab7 (patch)
tree31ce8eee7d102d43f5e0c9e6ca21edef0cdf919c /tests
parenta84e80131a891184e234ddeee1ba0606ea898d7b (diff)
test(api): adapt tests to previous change
All API controllers unit tests now mock IUserSession and IUser to match new expectations
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Controller/FeedApiControllerTest.php54
-rw-r--r--tests/Unit/Controller/FolderApiControllerTest.php40
-rw-r--r--tests/Unit/Controller/ItemApiControllerTest.php59
-rw-r--r--tests/Unit/Controller/UtilityApiControllerTest.php21
4 files changed, 123 insertions, 51 deletions
diff --git a/tests/Unit/Controller/FeedApiControllerTest.php b/tests/Unit/Controller/FeedApiControllerTest.php
index bc91e1df8..9217014d4 100644
--- a/tests/Unit/Controller/FeedApiControllerTest.php
+++ b/tests/Unit/Controller/FeedApiControllerTest.php
@@ -7,8 +7,10 @@
*
* @author Alessandro Cosentino <cosenal@gmail.com>
* @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author David Guillot <david@guillot.me>
* @copyright 2012 Alessandro Cosentino
* @copyright 2012-2014 Bernhard Posselt
+ * @copyright 2018 David Guillot
*/
namespace OCA\News\Tests\Unit\Controller;
@@ -30,6 +32,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
private $itemService;
private $feedAPI;
private $appName;
+ private $userSession;
private $user;
private $request;
private $msg;
@@ -38,7 +41,6 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
- $this->user = 'tom';
$this->loggerParams = ['hi'];
$this->logger = $this->getMockBuilder(
'\OCP\ILogger'
@@ -51,6 +53,22 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
)
->disableOriginalConstructor()
->getMock();
+ $this->userSession = $this->getMockBuilder(
+ '\OCP\IUserSession'
+ )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->user = $this->getMockBuilder(
+ '\OCP\IUser'
+ )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->userSession->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue('123'));
$this->feedService = $this->getMockBuilder(
'\OCA\News\Service\FeedService'
)
@@ -64,10 +82,10 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
$this->feedAPI = new FeedApiController(
$this->appName,
$this->request,
+ $this->userSession,
$this->feedService,
$this->itemService,
$this->logger,
- $this->user,
$this->loggerParams
);
$this->msg = 'hohoho';
@@ -82,15 +100,15 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
$this->itemService->expects($this->once())
->method('starredCount')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($starredCount));
$this->itemService->expects($this->once())
->method('getNewestItemId')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($newestItemId));
$this->feedService->expects($this->once())
->method('findAll')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($feeds));
$response = $this->feedAPI->index();
@@ -112,15 +130,15 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
$this->itemService->expects($this->once())
->method('starredCount')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($starredCount));
$this->itemService->expects($this->once())
->method('getNewestItemId')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo($this->user->getUID()))
->will($this->throwException(new ServiceNotFoundException('')));
$this->feedService->expects($this->once())
->method('findAll')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($feeds));
$response = $this->feedAPI->index();
@@ -140,7 +158,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
->method('delete')
->with(
$this->equalTo(2),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->feedAPI->delete(2);
@@ -171,13 +189,13 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
$this->feedService->expects($this->once())
->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
+ ->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
$this->feedService->expects($this->once())
->method('create')
->with(
$this->equalTo('url'),
$this->equalTo(3),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
)
->will($this->returnValue($feeds[0]));
$this->itemService->expects($this->once())
@@ -201,13 +219,13 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
$this->feedService->expects($this->once())
->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
+ ->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
$this->feedService->expects($this->once())
->method('create')
->with(
$this->equalTo('ho'),
$this->equalTo(3),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
)
->will($this->returnValue($feeds[0]));
$this->itemService->expects($this->once())
@@ -229,7 +247,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
{
$this->feedService->expects($this->once())
->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
+ ->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
$this->feedService->expects($this->once())
->method('create')
->will(
@@ -267,7 +285,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
->with(
$this->equalTo(3),
$this->equalTo(30),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->feedAPI->read(3, 30);
@@ -280,7 +298,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
->method('patch')
->with(
$this->equalTo(3),
- $this->equalTo($this->user),
+ $this->equalTo($this->user->getUID()),
$this->equalTo(['folderId' => 30])
);
@@ -313,7 +331,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
->method('patch')
->with(
$this->equalTo($feedId),
- $this->equalTo($this->user),
+ $this->equalTo($this->user->getUID()),
$this->equalTo(['title' => $feedTitle])
);
@@ -330,7 +348,7 @@ class FeedApiControllerTest extends \PHPUnit_Framework_TestCase
->method('patch')
->with(
$this->equalTo($feedId),
- $this->equalTo($this->user),
+ $this->equalTo($this->user->getUID()),
$this->equalTo(['title' => $feedTitle])
)
->will($this->throwException(new ServiceNotFoundException('hi')));
diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php
index 5a7fc3f93..1a3816b7b 100644
--- a/tests/Unit/Controller/FolderApiControllerTest.php
+++ b/tests/Unit/Controller/FolderApiControllerTest.php
@@ -7,8 +7,10 @@
*
* @author Alessandro Cosentino <cosenal@gmail.com>
* @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author David Guillot <david@guillot.me>
* @copyright 2012 Alessandro Cosentino
* @copyright 2012-2014 Bernhard Posselt
+ * @copyright 2018 David Guillot
*/
namespace OCA\News\Tests\Unit\Controller;
@@ -33,6 +35,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
private $itemService;
private $folderAPI;
private $appName;
+ private $userSession;
private $user;
private $request;
private $msg;
@@ -40,12 +43,27 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->appName = 'news';
- $this->user = 'tom';
$this->request = $this->getMockBuilder(
'\OCP\IRequest'
)
->disableOriginalConstructor()
->getMock();
+ $this->userSession = $this->getMockBuilder(
+ '\OCP\IUserSession'
+ )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->user = $this->getMockBuilder(
+ '\OCP\IUser'
+ )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->userSession->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue('123'));
$this->folderService = $this->getMockBuilder(
'\OCA\News\Service\FolderService'
)
@@ -59,9 +77,9 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
$this->folderAPI = new FolderApiController(
$this->appName,
$this->request,
+ $this->userSession,
$this->folderService,
- $this->itemService,
- $this->user
+ $this->itemService
);
$this->msg = 'test';
}
@@ -73,7 +91,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
$this->folderService->expects($this->once())
->method('findAll')
- ->with($this->equalTo($this->user))
+ ->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($folders));
$response = $this->folderAPI->index();
@@ -94,10 +112,10 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
$this->folderService->expects($this->once())
->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
+ ->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
$this->folderService->expects($this->once())
->method('create')
- ->with($this->equalTo($folderName), $this->equalTo($this->user))
+ ->with($this->equalTo($folderName), $this->equalTo($this->user->getUID()))
->will($this->returnValue($folder));
$response = $this->folderAPI->create($folderName);
@@ -116,7 +134,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
$this->folderService->expects($this->once())
->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
+ ->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
$this->folderService->expects($this->once())
->method('create')
->will($this->throwException(new ServiceConflictException($msg)));
@@ -135,7 +153,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
$this->folderService->expects($this->once())
->method('purgeDeleted')
- ->with($this->equalTo($this->user), $this->equalTo(false));
+ ->with($this->equalTo($this->user->getUID()), $this->equalTo(false));
$this->folderService->expects($this->once())
->method('create')
->will($this->throwException(new ServiceValidationException($msg)));
@@ -155,7 +173,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
$folderId = 23;
$this->folderService->expects($this->once())
->method('delete')
- ->with($this->equalTo($folderId), $this->equalTo($this->user));
+ ->with($this->equalTo($folderId), $this->equalTo($this->user->getUID()));
$this->folderAPI->delete(23);
}
@@ -191,7 +209,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
->with(
$this->equalTo($folderId),
$this->equalTo($folderName),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->folderAPI->update($folderId, $folderName);
@@ -269,7 +287,7 @@ class FolderApiControllerTest extends \PHPUnit_Framework_TestCase
->with(
$this->equalTo(3),
$this->equalTo(30),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->folderAPI->read(3, 30);
diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php
index 929d792bd..ad2b323e7 100644
--- a/tests/Unit/Controller/ItemApiControllerTest.php
+++ b/tests/Unit/Controller/ItemApiControllerTest.php
@@ -7,8 +7,10 @@
*
* @author Alessandro Cosentino <cosenal@gmail.com>
* @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author David Guillot <david@guillot.me>
* @copyright 2012 Alessandro Cosentino
* @copyright 2012-2014 Bernhard Posselt
+ * @copyright 2018 David Guillot
*/
namespace OCA\News\Tests\Unit\Controller;
@@ -26,6 +28,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
private $itemService;
private $itemAPI;
private $api;
+ private $userSession;
private $user;
private $request;
private $msg;
@@ -39,6 +42,22 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
)
->disableOriginalConstructor()
->getMock();
+ $this->userSession = $this->getMockBuilder(
+ '\OCP\IUserSession'
+ )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->user = $this->getMockBuilder(
+ '\OCP\IUser'
+ )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->userSession->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue('123'));
$this->itemService = $this->getMockBuilder(
'\OCA\News\Service\ItemService'
)
@@ -47,8 +66,8 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->itemAPI = new ItemApiController(
$this->appName,
$this->request,
- $this->itemService,
- $this->user
+ $this->userSession,
+ $this->itemService
);
$this->msg = 'hi';
}
@@ -67,7 +86,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(20),
$this->equalTo(true),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
)
->will($this->returnValue($items));
@@ -94,7 +113,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(0),
$this->equalTo(false),
$this->equalTo(false),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
)
->will($this->returnValue($items));
@@ -119,7 +138,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(1),
$this->equalTo('30000000'),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
)
->will($this->returnValue($items));
@@ -140,7 +159,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
->with(
$this->equalTo(2),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->read(2);
@@ -172,7 +191,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
->with(
$this->equalTo(2),
$this->equalTo(false),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->unread(2);
@@ -205,7 +224,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(2),
$this->equalTo('hash'),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->star(2, 'hash');
@@ -238,7 +257,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(2),
$this->equalTo('hash'),
$this->equalTo(false),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->unstar(2, 'hash');
@@ -269,7 +288,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
->method('readAll')
->with(
$this->equalTo(30),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->readAll(30);
@@ -284,14 +303,14 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
->with(
$this->equalTo(2),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemService->expects($this->at(1))
->method('read')
->with(
$this->equalTo(4),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->readMultiple([2, 4]);
}
@@ -307,7 +326,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
->with(
$this->equalTo(4),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->readMultiple([2, 4]);
}
@@ -320,14 +339,14 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
->with(
$this->equalTo(2),
$this->equalTo(false),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemService->expects($this->at(1))
->method('read')
->with(
$this->equalTo(4),
$this->equalTo(false),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->unreadMultiple([2, 4]);
}
@@ -352,7 +371,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(2),
$this->equalTo('a'),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemService->expects($this->at(1))
->method('star')
@@ -360,7 +379,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(4),
$this->equalTo('b'),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->starMultiple($ids);
}
@@ -388,7 +407,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(4),
$this->equalTo('b'),
$this->equalTo(true),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->starMultiple($ids);
}
@@ -413,7 +432,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(2),
$this->equalTo('a'),
$this->equalTo(false),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemService->expects($this->at(1))
->method('star')
@@ -421,7 +440,7 @@ class ItemApiControllerTest extends \PHPUnit_Framework_TestCase
$this->equalTo(4),
$this->equalTo('b'),
$this->equalTo(false),
- $this->equalTo($this->user)
+ $this->equalTo($this->user->getUID())
);
$this->itemAPI->unstarMultiple($ids);
}
diff --git a/tests/Unit/Controller/UtilityApiControllerTest.php b/tests/Unit/Controller/UtilityApiControllerTest.php
index 6237f3c8e..172932b0e 100644
--- a/tests/Unit/Controller/UtilityApiControllerTest.php
+++ b/tests/Unit/Controller/UtilityApiControllerTest.php
@@ -7,8 +7,10 @@
*
* @author Alessandro Cosentino <cosenal@gmail.com>
* @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author David Guillot <david@guillot.me>
* @copyright 2012 Alessandro Cosentino
* @copyright 2012-2014 Bernhard Posselt
+ * @copyright 2018 David Guillot
*/
namespace OCA\News\Tests\Unit\Controller;
@@ -20,6 +22,8 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase
private $settings;
private $request;
+ private $userSession;
+ private $user;
private $newsAPI;
private $updater;
private $appName;
@@ -38,6 +42,19 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase
)
->disableOriginalConstructor()
->getMock();
+ $this->userSession = $this->getMockBuilder(
+ '\OCP\IUserSession'
+ )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->user = $this->getMockBuilder(
+ '\OCP\IUser'
+ )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->userSession->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
$this->updater = $this->getMockBuilder(
'\OCA\News\Utility\Updater'
)
@@ -49,8 +66,8 @@ class UtilityApiControllerTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$this->newsAPI = new UtilityApiController(
- $this->appName, $this->request, $this->updater, $this->settings,
- $this->status
+ $this->appName, $this->request, $this->userSession,
+ $this->updater, $this->settings, $this->status
);
}