diff options
author | Joas Schilling <coding@schilljs.com> | 2017-03-03 13:12:24 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-03-09 21:07:37 +0100 |
commit | d4200a08cceeb99a41f45f50a41d50e0cb05cab3 (patch) | |
tree | 746cb973a5540aa7780499aeba8ed38020a5bc2d /apps/comments/tests/Unit/Notification | |
parent | 15fa306ae8b9dbf30a08ac50d0afbf3c8a46688f (diff) | |
download | nextcloud-server-d4200a08cceeb99a41f45f50a41d50e0cb05cab3.tar.gz nextcloud-server-d4200a08cceeb99a41f45f50a41d50e0cb05cab3.zip |
Get the user folder of the correct user
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/comments/tests/Unit/Notification')
-rw-r--r-- | apps/comments/tests/Unit/Notification/NotifierTest.php | 102 |
1 files changed, 58 insertions, 44 deletions
diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php index 25b8b4b278d..0b08849030b 100644 --- a/apps/comments/tests/Unit/Notification/NotifierTest.php +++ b/apps/comments/tests/Unit/Notification/NotifierTest.php @@ -28,6 +28,7 @@ use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; use OCP\Files\Folder; +use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\IL10N; use OCP\IURLGenerator; @@ -41,41 +42,33 @@ class NotifierTest extends TestCase { /** @var Notifier */ protected $notifier; - /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */ protected $l10nFactory; - - /** @var Folder|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ + protected $l; + /** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */ protected $folder; - - /** @var ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */ protected $commentsManager; /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ protected $url; - /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ protected $userManager; - - - /** @var string */ - protected $lc = 'tlh_KX'; - - /** @var INotification|\PHPUnit_Framework_MockObject_MockObject */ + /** @var INotification|\PHPUnit_Framework_MockObject_MockObject */ protected $notification; - - /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ - protected $l; - - /** @var IComment|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IComment|\PHPUnit_Framework_MockObject_MockObject */ protected $comment; + /** @var string */ + protected $lc = 'tlh_KX'; protected function setUp() { parent::setUp(); - $this->l10nFactory = $this->getMockBuilder('OCP\L10N\IFactory')->getMock(); - $this->folder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); - $this->commentsManager = $this->getMockBuilder('OCP\Comments\ICommentsManager')->getMock(); + $this->l10nFactory = $this->createMock(IFactory::class); + $this->folder = $this->createMock(IRootFolder::class); + $this->commentsManager = $this->createMock(ICommentsManager::class); $this->url = $this->createMock(IURLGenerator::class); - $this->userManager = $this->getMockBuilder('OCP\IUserManager')->getMock(); + $this->userManager = $this->createMock(IUserManager::class); $this->notifier = new Notifier( $this->l10nFactory, @@ -92,8 +85,8 @@ class NotifierTest extends TestCase { return vsprintf($text, $parameters); })); - $this->notification = $this->getMockBuilder('OCP\Notification\INotification')->getMock(); - $this->comment = $this->getMockBuilder('OCP\Comments\IComment')->getMock(); + $this->notification = $this->createMock(INotification::class); + $this->comment = $this->createMock(IComment::class); } public function testPrepareSuccess() { @@ -102,24 +95,31 @@ class NotifierTest extends TestCase { $message = 'Huraga mentioned you in a comment on “Gre\'thor.odp”'; /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->getMockBuilder('OCP\IUser')->getMock(); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getDisplayName') ->willReturn($displayName); - /** @var Node|\PHPUnit_Framework_MockObject_MockObject */ - $node = $this->getMockBuilder('OCP\Files\Node')->getMock(); + /** @var Node|\PHPUnit_Framework_MockObject_MockObject $node */ + $node = $this->createMock(Node::class); $node ->expects($this->atLeastOnce()) ->method('getName') ->willReturn($fileName); - $this->folder - ->expects($this->once()) + $userFolder = $this->createMock(Folder::class); + $this->folder->expects($this->once()) + ->method('getUserFolder') + ->with('you') + ->willReturn($userFolder); + $userFolder->expects($this->once()) ->method('getById') ->with('678') ->willReturn([$node]); + $this->notification->expects($this->once()) + ->method('getUser') + ->willReturn('you'); $this->notification ->expects($this->once()) ->method('getApp') @@ -172,7 +172,7 @@ class NotifierTest extends TestCase { ->willReturn('users'); $this->commentsManager - ->expects(($this->once())) + ->expects($this->once()) ->method('get') ->willReturn($this->comment); @@ -189,19 +189,26 @@ class NotifierTest extends TestCase { $fileName = 'Gre\'thor.odp'; $message = 'A (now) deleted user mentioned you in a comment on “Gre\'thor.odp”'; - /** @var Node|\PHPUnit_Framework_MockObject_MockObject */ - $node = $this->getMockBuilder('OCP\Files\Node')->getMock(); + /** @var Node|\PHPUnit_Framework_MockObject_MockObject $node */ + $node = $this->createMock(Node::class); $node ->expects($this->atLeastOnce()) ->method('getName') ->willReturn($fileName); - $this->folder - ->expects($this->once()) + $userFolder = $this->createMock(Folder::class); + $this->folder->expects($this->once()) + ->method('getUserFolder') + ->with('you') + ->willReturn($userFolder); + $userFolder->expects($this->once()) ->method('getById') ->with('678') ->willReturn([$node]); + $this->notification->expects($this->once()) + ->method('getUser') + ->willReturn('you'); $this->notification ->expects($this->once()) ->method('getApp') @@ -254,7 +261,7 @@ class NotifierTest extends TestCase { ->willReturn(ICommentsManager::DELETED_USER); $this->commentsManager - ->expects(($this->once())) + ->expects($this->once()) ->method('get') ->willReturn($this->comment); @@ -292,7 +299,7 @@ class NotifierTest extends TestCase { ->method('get'); $this->commentsManager - ->expects(($this->never())) + ->expects($this->never()) ->method('get'); $this->userManager @@ -329,7 +336,7 @@ class NotifierTest extends TestCase { ->method('get'); $this->commentsManager - ->expects(($this->once())) + ->expects($this->once()) ->method('get') ->willThrowException(new NotFoundException()); @@ -347,7 +354,7 @@ class NotifierTest extends TestCase { $displayName = 'Huraga'; /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->getMockBuilder('OCP\IUser')->getMock(); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getDisplayName') ->willReturn($displayName); @@ -390,7 +397,7 @@ class NotifierTest extends TestCase { ->willReturn('users'); $this->commentsManager - ->expects(($this->once())) + ->expects($this->once()) ->method('get') ->willReturn($this->comment); @@ -410,7 +417,7 @@ class NotifierTest extends TestCase { $displayName = 'Huraga'; /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->getMockBuilder('OCP\IUser')->getMock(); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getDisplayName') ->willReturn($displayName); @@ -454,7 +461,7 @@ class NotifierTest extends TestCase { ->willReturn('users'); $this->commentsManager - ->expects(($this->once())) + ->expects($this->once()) ->method('get') ->willReturn($this->comment); @@ -474,17 +481,24 @@ class NotifierTest extends TestCase { $displayName = 'Huraga'; /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->getMockBuilder('OCP\IUser')->getMock(); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getDisplayName') ->willReturn($displayName); - $this->folder - ->expects($this->once()) + $userFolder = $this->createMock(Folder::class); + $this->folder->expects($this->once()) + ->method('getUserFolder') + ->with('you') + ->willReturn($userFolder); + $userFolder->expects($this->once()) ->method('getById') ->with('678') ->willReturn([]); + $this->notification->expects($this->once()) + ->method('getUser') + ->willReturn('you'); $this->notification ->expects($this->once()) ->method('getApp') @@ -520,7 +534,7 @@ class NotifierTest extends TestCase { ->willReturn('users'); $this->commentsManager - ->expects(($this->once())) + ->expects($this->once()) ->method('get') ->willReturn($this->comment); |