예제 #1
0
파일: feedtest.php 프로젝트: ynott/activity
 /**
  * @dataProvider showData
  *
  * @param string $acceptHeader
  * @param string $expectedHeader
  */
 public function testShow($acceptHeader, $expectedHeader)
 {
     $this->mockUserSession('test');
     $this->data->expects($this->any())->method('get')->willReturn(['data' => []]);
     if ($acceptHeader !== null) {
         $this->request->expects($this->any())->method('getHeader')->willReturn($acceptHeader);
     }
     $templateResponse = $this->controller->show();
     $this->assertTrue($templateResponse instanceof TemplateResponse, 'Asserting type of return is \\OCP\\AppFramework\\Http\\TemplateResponse');
     $headers = $templateResponse->getHeaders();
     $this->assertArrayHasKey('Content-Type', $headers);
     $this->assertEquals($expectedHeader, $headers['Content-Type']);
     $renderedResponse = $templateResponse->render();
     $this->assertNotEmpty($renderedResponse);
     $l = Util::getL10N('activity');
     $description = (string) $l->t('Your feed URL is invalid');
     $this->assertNotContains($description, $renderedResponse);
 }
예제 #2
0
 /**
  * @dataProvider receiveData
  *
  * @param string $type
  * @param string $author
  * @param string $affectedUser
  * @param string $subject
  * @param array|false $expected
  */
 public function testReceiveEmail($type, $author, $affectedUser, $subject, $expected)
 {
     $time = time();
     $consumer = new Consumer($this->data, $this->userSettings);
     $event = \OC::$server->getActivityManager()->generateEvent();
     $event->setApp('test')->setType($type)->setAffectedUser($affectedUser)->setAuthor($author)->setTimestamp($time)->setSubject($subject, ['subjectParam1', 'subjectParam2'])->setMessage('message', ['messageParam1', 'messageParam2'])->setObject('', 0, 'file')->setLink('link');
     if ($expected === false) {
         $this->data->expects($this->never())->method('storeMail');
     } else {
         $this->data->expects($this->once())->method('storeMail')->with($event, $time + 10);
     }
     $consumer->receive($event);
 }
예제 #3
0
 /**
  * @dataProvider dataGet
  * @param int $time
  * @param string $objectType
  * @param int $objectId
  * @param array $additionalArgs
  * @param bool $loadPreviews
  * @param int $numGetPreviewCalls
  * @param array $expected
  */
 public function testGet($time, $objectType, $objectId, array $additionalArgs, $loadPreviews, $numGetPreviewCalls, array $expected)
 {
     $controller = $this->getController(['readParameters', 'generateHeaders', 'getPreview']);
     $controller->expects($this->any())->method('generateHeaders')->willReturnArgument(0);
     $controller->expects($this->once())->method('readParameters');
     $controller->expects($this->exactly($numGetPreviewCalls))->method('getPreview')->willReturn(['preview']);
     $this->invokePrivate($controller, 'loadPreviews', [$loadPreviews]);
     $this->data->expects($this->once())->method('get')->willReturn(['data' => [array_merge(['timestamp' => $time, 'object_type' => $objectType, 'object_id' => $objectId], $additionalArgs)], 'headers' => ['X-Activity-First-Known' => 23], 'has_more' => false]);
     /** @var \OC_OCS_Result $result */
     $result = $this->invokePrivate($controller, 'get', [[]]);
     $this->assertInstanceOf('\\OC_OCS_Result', $result);
     $this->assertSame(100, $result->getStatusCode());
     $this->assertSame([$expected], $result->getData());
 }
예제 #4
0
 /**
  * @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]);
 }