public function testAdd()
 {
     $this->manager->expects($this->once())->method('announce')->with('subject', 'message', 'author', $this->anything())->willReturn(['author' => 'author', 'subject' => 'subject', 'message' => 'message', 'time' => time(), 'id' => 10]);
     $this->userManager->expects($this->once())->method('get')->with('author')->willReturn($this->getUserMock('author', 'Author'));
     $controller = $this->getController(['createPublicity']);
     $controller->expects($this->once())->method('createPublicity')->with(10, 'author', $this->anything());
     $response = $controller->add('subject', 'message');
     $this->assertInstanceOf('OCP\\AppFramework\\Http\\JSONResponse', $response);
     $data = $response->getData();
     $this->assertArrayHasKey('time', $data);
     $this->assertInternalType('int', $data['time']);
     unset($data['time']);
     $this->assertEquals(['author' => 'Author', 'author_id' => 'author', 'subject' => 'subject', 'message' => 'message', 'id' => 10], $data);
 }
 /**
  * @dataProvider dataPrepare
  *
  * @param string $author
  * @param string $subject
  * @param string $message
  * @param int $objectId
  * @param string $expectedSubject
  * @param string $expectedMessage
  */
 public function testPrepare($author, $subject, $message, $objectId, $expectedSubject, $expectedMessage)
 {
     /** @var \OC\Notification\INotification|\PHPUnit_Framework_MockObject_MockObject $notification */
     $notification = $this->getMockBuilder('OC\\Notification\\INotification')->disableOriginalConstructor()->getMock();
     $notification->expects($this->once())->method('getApp')->willReturn('announcementcenter');
     $notification->expects($this->once())->method('getSubject')->willReturn('announced');
     $notification->expects($this->once())->method('getSubjectParameters')->willReturn([$author]);
     $notification->expects($this->once())->method('getObjectId')->willReturn($objectId);
     $this->manager->expects($this->once())->method('getAnnouncement')->with($objectId, false)->willReturn(['subject' => $subject, 'message' => $message]);
     $notification->expects($this->once())->method('setParsedMessage')->with($expectedMessage)->willReturnSelf();
     $notification->expects($this->once())->method('setParsedSubject')->with($expectedSubject)->willReturnSelf();
     $return = $this->notifier->prepare($notification, 'en');
     $this->assertEquals($notification, $return);
 }
 /**
  * @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));
 }