diff options
author | David Guillot <david@guillot.me> | 2018-06-30 23:57:42 +0200 |
---|---|---|
committer | David Guillot <david@guillot.me> | 2018-07-01 23:03:36 +0200 |
commit | 5c4185e22155687740e44d58c5c6bc9dc793cab7 (patch) | |
tree | 31ce8eee7d102d43f5e0c9e6ca21edef0cdf919c /tests/Unit/Controller/ItemApiControllerTest.php | |
parent | a84e80131a891184e234ddeee1ba0606ea898d7b (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/Unit/Controller/ItemApiControllerTest.php')
-rw-r--r-- | tests/Unit/Controller/ItemApiControllerTest.php | 59 |
1 files changed, 39 insertions, 20 deletions
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); } |