protected function setUp() { parent::setUp(); $app = $this->getUniqueID('MailQueueHandlerTest'); $this->userManager = $this->getMock('OCP\\IUserManager'); $connection = \OC::$server->getDatabaseConnection(); $query = $connection->prepare('INSERT INTO `*PREFIX*activity_mq` ' . ' (`amq_appid`, `amq_subject`, `amq_subjectparams`, `amq_affecteduser`, `amq_timestamp`, `amq_type`, `amq_latest_send`) ' . ' VALUES(?, ?, ?, ?, ?, ?, ?)'); $query->execute(array($app, 'Test data', 'Param1', 'user1', 150, 'phpunit', 152)); $query->execute(array($app, 'Test data', 'Param1', 'user1', 150, 'phpunit', 153)); $query->execute(array($app, 'Test data', 'Param1', 'user2', 150, 'phpunit', 150)); $query->execute(array($app, 'Test data', 'Param1', 'user2', 150, 'phpunit', 151)); $query->execute(array($app, 'Test data', 'Param1', 'user3', 150, 'phpunit', 154)); $query->execute(array($app, 'Test data', 'Param1', 'user3', 150, 'phpunit', 155)); $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock(); $event->expects($this->any())->method('setApp')->willReturnSelf(); $event->expects($this->any())->method('setType')->willReturnSelf(); $event->expects($this->any())->method('setAffectedUser')->willReturnSelf(); $event->expects($this->any())->method('setTimestamp')->willReturnSelf(); $event->expects($this->any())->method('setSubject')->willReturnSelf(); $this->activityManager = $this->getMockBuilder('OCP\\Activity\\IManager')->disableOriginalConstructor()->getMock(); $this->activityManager->expects($this->any())->method('generateEvent')->willReturn($event); $this->dataHelper = $this->getMockBuilder('OCA\\Activity\\DataHelper')->disableOriginalConstructor()->getMock(); $this->dataHelper->expects($this->any())->method('getParameters')->willReturn([]); $this->message = $this->getMockBuilder('OC\\Mail\\Message')->disableOriginalConstructor()->getMock(); $this->mailer = $this->getMock('OCP\\Mail\\IMailer'); $this->mailer->expects($this->any())->method('createMessage')->willReturn($this->message); $this->mailQueueHandler = new MailQueueHandler($this->getMock('\\OCP\\IDateTimeFormatter'), $connection, $this->dataHelper, $this->mailer, $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(), $this->userManager, $this->activityManager); }
public function testAppActivity() { $this->activityManager->expects($this->once())->method('registerExtension')->willReturnCallback(function ($closure) { $this->assertInstanceOf('\\Closure', $closure); $navigation = $closure(); $this->assertInstanceOf('\\OCA\\AnnouncementCenter\\ActivityExtension', $navigation); }); include __DIR__ . '/../../appinfo/app.php'; }
public function testCreatePublicity() { $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('setApp')->with('announcementcenter')->willReturnSelf(); $event->expects($this->once())->method('setType')->with('announcementcenter')->willReturnSelf(); $event->expects($this->once())->method('setAuthor')->with('author')->willReturnSelf(); $event->expects($this->once())->method('setTimestamp')->with(1337)->willReturnSelf(); $event->expects($this->once())->method('setSubject')->with('announcementsubject#10', ['author'])->willReturnSelf(); $event->expects($this->once())->method('setMessage')->with('announcementmessage#10', ['author'])->willReturnSelf(); $event->expects($this->once())->method('setObject')->with('announcement', 10)->willReturnSelf(); $event->expects($this->exactly(5))->method('setAffectedUser')->willReturnSelf(); $notification = $this->getMockBuilder('OC\\Notification\\INotification')->disableOriginalConstructor()->getMock(); $notification->expects($this->once())->method('setApp')->with('announcementcenter')->willReturnSelf(); $dateTime = new \DateTime(); $dateTime->setTimestamp(1337); $notification->expects($this->once())->method('setDateTime')->with($dateTime)->willReturnSelf(); $notification->expects($this->once())->method('setSubject')->with('announced', ['author'])->willReturnSelf(); $notification->expects($this->once())->method('setObject')->with('announcement', 10)->willReturnSelf(); $notification->expects($this->once())->method('setLink')->willReturnSelf(); $notification->expects($this->exactly(4))->method('setUser')->willReturnSelf(); $controller = $this->getController(); $this->activityManager->expects($this->once())->method('generateEvent')->willReturn($event); $this->notificationManager->expects($this->once())->method('createNotification')->willReturn($notification); $this->userManager->expects($this->once())->method('search')->with('')->willReturn([$this->getUserMock('author', 'User One'), $this->getUserMock('u2', 'User Two'), $this->getUserMock('u3', 'User Three'), $this->getUserMock('u4', 'User Four'), $this->getUserMock('u5', 'User Five')]); $this->activityManager->expects($this->exactly(5))->method('publish'); $this->notificationManager->expects($this->exactly(4))->method('notify'); $this->invokePrivate($controller, 'createPublicity', [10, 'author', 1337]); }
protected function mockUserSession($user) { $mockUser = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock(); $mockUser->expects($this->any())->method('getUID')->willReturn($user); $this->session->expects($this->any())->method('isLoggedIn')->willReturn(true); $this->session->expects($this->any())->method('getUser')->willReturn($mockUser); $this->manager->expects($this->any())->method('getCurrentUserId')->willReturn($user); }
/** * @dataProvider dataTranslate * * @param string $app * @param string $text * @param array $params * @param bool $stripPath * @param bool $highlightParams * @param string $languageCode * @param mixed $managerReturn * @param string $currentUser * @param mixed $expected */ public function testTranslate($app, $text, $params, $stripPath, $highlightParams, $languageCode, $managerReturn, $currentUser, $expected) { if ($managerReturn === null) { $this->manager->expects($this->never())->method('getAnnouncement'); } else { $this->factory->expects($this->any())->method('get')->with('announcementcenter', $languageCode)->willReturn($this->l); $this->activity->expects($this->any())->method('getCurrentUserId')->willReturn($currentUser); if ($managerReturn === false) { $this->manager->expects($this->once())->method('getAnnouncement')->with(10, $highlightParams)->willThrowException(new \InvalidArgumentException()); } else { $this->manager->expects($this->once())->method('getAnnouncement')->with(10, $highlightParams)->willReturn($managerReturn); } } $this->assertSame($expected, $this->extension->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode)); }
/** * @dataProvider dataGetEventFromArray * @param array $activity */ public function testGetEventFromArray(array $activity) { $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('setApp')->with($activity['app'])->willReturnSelf(); $event->expects($this->once())->method('setType')->with($activity['type'])->willReturnSelf(); $event->expects($this->once())->method('setAffectedUser')->with($activity['affecteduser'])->willReturnSelf(); $event->expects($this->once())->method('setAuthor')->with($activity['user'])->willReturnSelf(); $event->expects($this->once())->method('setTimestamp')->with($activity['timestamp'])->willReturnSelf(); $event->expects($this->once())->method('setSubject')->with($activity['subject'], $activity['subjectparams'])->willReturnSelf(); $event->expects($this->once())->method('setMessage')->with($activity['message'], $activity['messageparams'])->willReturnSelf(); $event->expects($this->once())->method('setObject')->with($activity['object_type'], $activity['object_id'], $activity['object_name'])->willReturnSelf(); $event->expects($this->once())->method('setLink')->with($activity['link'])->willReturnSelf(); $this->activityManager->expects($this->once())->method('generateEvent')->willReturn($event); $helper = $this->getHelper(); $instance = $helper->getEventFromArray($activity); $this->assertSame($event, $instance); }
/** * @dataProvider dataAddNotificationsForUser * * @param string $user * @param string $subject * @param array $parameter * @param int $fileId * @param string $path * @param bool $isFile * @param bool $stream * @param bool $email * @param int $type * @param bool $selfSetting * @param bool $selfEmailSetting * @param string $app * @param bool $sentStream * @param bool $sentEmail */ public function testAddNotificationsForUser($user, $subject, $parameter, $fileId, $path, $isFile, $stream, $email, $type, $selfSetting, $selfEmailSetting, $app, $sentStream, $sentEmail) { $this->settings->expects($this->any())->method('getUserSetting')->willReturnMap([[$user, 'setting', 'self', $selfSetting], [$user, 'setting', 'selfemail', $selfEmailSetting]]); $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('setApp')->with($app)->willReturnSelf(); $event->expects($this->once())->method('setType')->with($type)->willReturnSelf(); $event->expects($this->once())->method('setAffectedUser')->with($user)->willReturnSelf(); $event->expects($this->once())->method('setAuthor')->with('user')->willReturnSelf(); $event->expects($this->once())->method('setTimestamp')->willReturnSelf(); $event->expects($this->once())->method('setSubject')->with($subject, $parameter)->willReturnSelf(); $event->expects($this->once())->method('setLink')->willReturnSelf(); if ($fileId) { $event->expects($this->once())->method('setObject')->with('files', $fileId, $path)->willReturnSelf(); } else { $event->expects($this->once())->method('setObject')->with('', $fileId, $path)->willReturnSelf(); } $this->activityManager->expects($this->once())->method('generateEvent')->willReturn($event); $this->data->expects($sentStream ? $this->once() : $this->never())->method('send')->with($event); $this->data->expects($sentEmail ? $this->once() : $this->never())->method('storeMail')->with($event, $this->anything()); $this->invokePrivate($this->filesHooks, 'addNotificationsForUser', [$user, $subject, $parameter, $fileId, $path, $isFile, $stream, $email, $type]); }
/** * @dataProvider dataGetSpecialParameterList * * @param string $app * @param string $text * @param array|bool $managerReturn * @param array $expected */ public function testGetSpecialParameterList($app, $text, $managerReturn, array $expected) { $this->activityManager->expects($this->once())->method('getSpecialParameterList')->with($app, $text)->willReturn($managerReturn); $instance = $this->getHelper(); $this->assertSame($expected, $this->invokePrivate($instance, 'getSpecialParameterList', [$app, $text])); }