2014-07-03 11:48:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-02 09:57:24 +00:00
|
|
|
namespace Test\Activity;
|
2014-07-03 11:48:15 +00:00
|
|
|
|
2016-05-02 09:57:24 +00:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class ManagerTest extends TestCase {
|
|
|
|
|
|
|
|
/** @var \OC\Activity\Manager */
|
2014-07-03 11:48:15 +00:00
|
|
|
private $activityManager;
|
|
|
|
|
2016-05-02 09:57:24 +00:00
|
|
|
/** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
2015-03-25 16:46:19 +00:00
|
|
|
protected $request;
|
|
|
|
|
2016-05-02 09:57:24 +00:00
|
|
|
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
2015-03-25 16:46:19 +00:00
|
|
|
protected $session;
|
|
|
|
|
2016-05-02 09:57:24 +00:00
|
|
|
/** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2015-03-25 16:46:19 +00:00
|
|
|
protected $config;
|
|
|
|
|
2014-11-10 21:59:50 +00:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2015-03-25 16:46:19 +00:00
|
|
|
$this->request = $this->getMockBuilder('OCP\IRequest')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->session = $this->getMockBuilder('OCP\IUserSession')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->config = $this->getMockBuilder('OCP\IConfig')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2016-05-02 09:57:24 +00:00
|
|
|
$this->activityManager = new \OC\Activity\Manager(
|
2015-03-25 16:46:19 +00:00
|
|
|
$this->request,
|
|
|
|
$this->session,
|
|
|
|
$this->config
|
|
|
|
);
|
|
|
|
|
2015-08-20 08:25:49 +00:00
|
|
|
$this->assertSame([], $this->invokePrivate($this->activityManager, 'getConsumers'));
|
|
|
|
$this->assertSame([], $this->invokePrivate($this->activityManager, 'getExtensions'));
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
$this->activityManager->registerConsumer(function() {
|
|
|
|
return new NoOpConsumer();
|
|
|
|
});
|
2014-07-03 11:48:15 +00:00
|
|
|
$this->activityManager->registerExtension(function() {
|
|
|
|
return new NoOpExtension();
|
|
|
|
});
|
|
|
|
$this->activityManager->registerExtension(function() {
|
|
|
|
return new SimpleExtension();
|
|
|
|
});
|
2015-08-20 08:25:49 +00:00
|
|
|
|
|
|
|
$this->assertNotEmpty($this->invokePrivate($this->activityManager, 'getConsumers'));
|
|
|
|
$this->assertNotEmpty($this->invokePrivate($this->activityManager, 'getConsumers'));
|
|
|
|
$this->assertNotEmpty($this->invokePrivate($this->activityManager, 'getExtensions'));
|
|
|
|
$this->assertNotEmpty($this->invokePrivate($this->activityManager, 'getExtensions'));
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
public function testGetConsumers() {
|
|
|
|
$consumers = $this->invokePrivate($this->activityManager, 'getConsumers');
|
|
|
|
|
|
|
|
$this->assertNotEmpty($consumers);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testGetConsumersInvalidConsumer() {
|
|
|
|
$this->activityManager->registerConsumer(function() {
|
2016-05-02 09:57:24 +00:00
|
|
|
return new \stdClass();
|
2015-07-23 09:00:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->invokePrivate($this->activityManager, 'getConsumers');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetExtensions() {
|
|
|
|
$extensions = $this->invokePrivate($this->activityManager, 'getExtensions');
|
|
|
|
|
|
|
|
$this->assertNotEmpty($extensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testGetExtensionsInvalidExtension() {
|
|
|
|
$this->activityManager->registerExtension(function() {
|
2016-05-02 09:57:24 +00:00
|
|
|
return new \stdClass();
|
2015-07-23 09:00:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->invokePrivate($this->activityManager, 'getExtensions');
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function testNotificationTypes() {
|
|
|
|
$result = $this->activityManager->getNotificationTypes('en');
|
|
|
|
$this->assertTrue(is_array($result));
|
|
|
|
$this->assertEquals(2, sizeof($result));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDefaultTypes() {
|
|
|
|
$result = $this->activityManager->getDefaultTypes('stream');
|
|
|
|
$this->assertTrue(is_array($result));
|
|
|
|
$this->assertEquals(1, sizeof($result));
|
|
|
|
|
|
|
|
$result = $this->activityManager->getDefaultTypes('email');
|
|
|
|
$this->assertTrue(is_array($result));
|
|
|
|
$this->assertEquals(0, sizeof($result));
|
|
|
|
}
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
public function testTypeIcon() {
|
|
|
|
$result = $this->activityManager->getTypeIcon('NT1');
|
|
|
|
$this->assertEquals('icon-nt-one', $result);
|
|
|
|
|
|
|
|
$result = $this->activityManager->getTypeIcon('NT2');
|
|
|
|
$this->assertEquals('', $result);
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function testTranslate() {
|
2016-05-02 09:57:24 +00:00
|
|
|
$result = $this->activityManager->translate('APP0', '', array(), false, false, 'en');
|
2014-07-03 11:48:15 +00:00
|
|
|
$this->assertEquals('Stupid translation', $result);
|
|
|
|
|
2016-05-02 09:57:24 +00:00
|
|
|
$result = $this->activityManager->translate('APP1', '', array(), false, false, 'en');
|
2014-07-03 11:48:15 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:00:17 +00:00
|
|
|
public function testGetSpecialParameterList() {
|
|
|
|
$result = $this->activityManager->getSpecialParameterList('APP0', '');
|
|
|
|
$this->assertEquals(array(0 => 'file', 1 => 'username'), $result);
|
|
|
|
|
|
|
|
$result = $this->activityManager->getSpecialParameterList('APP1', '');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function testGroupParameter() {
|
|
|
|
$result = $this->activityManager->getGroupParameter(array());
|
|
|
|
$this->assertEquals(5, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNavigation() {
|
|
|
|
$result = $this->activityManager->getNavigation();
|
|
|
|
$this->assertEquals(4, sizeof($result['apps']));
|
|
|
|
$this->assertEquals(2, sizeof($result['top']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsFilterValid() {
|
|
|
|
$result = $this->activityManager->isFilterValid('fv01');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
$result = $this->activityManager->isFilterValid('InvalidFilter');
|
2014-07-03 11:48:15 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
public function testFilterNotificationTypes() {
|
|
|
|
$result = $this->activityManager->filterNotificationTypes(array('NT0', 'NT1', 'NT2', 'NT3'), 'fv01');
|
|
|
|
$this->assertTrue(is_array($result));
|
|
|
|
$this->assertEquals(3, sizeof($result));
|
|
|
|
|
|
|
|
$result = $this->activityManager->filterNotificationTypes(array('NT0', 'NT1', 'NT2', 'NT3'), 'InvalidFilter');
|
|
|
|
$this->assertTrue(is_array($result));
|
|
|
|
$this->assertEquals(4, sizeof($result));
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function testQueryForFilter() {
|
2015-02-13 12:08:57 +00:00
|
|
|
// Register twice, to test the created sql part
|
2014-11-28 10:18:15 +00:00
|
|
|
$this->activityManager->registerExtension(function() {
|
|
|
|
return new SimpleExtension();
|
|
|
|
});
|
2015-02-13 12:08:57 +00:00
|
|
|
|
|
|
|
$result = $this->activityManager->getQueryForFilter('fv01');
|
2014-07-03 11:48:15 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
2014-11-28 10:18:15 +00:00
|
|
|
' and ((`app` = ? and `message` like ?) or (`app` = ? and `message` like ?))',
|
|
|
|
array('mail', 'ownCloud%', 'mail', 'ownCloud%')
|
2014-07-03 11:48:15 +00:00
|
|
|
), $result
|
|
|
|
);
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
$result = $this->activityManager->getQueryForFilter('InvalidFilter');
|
|
|
|
$this->assertEquals(array(null, null), $result);
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
2015-03-25 16:46:19 +00:00
|
|
|
|
|
|
|
public function getUserFromTokenThrowInvalidTokenData() {
|
|
|
|
return [
|
|
|
|
[null, []],
|
|
|
|
['', []],
|
|
|
|
['12345678901234567890123456789', []],
|
|
|
|
['1234567890123456789012345678901', []],
|
|
|
|
['123456789012345678901234567890', []],
|
|
|
|
['123456789012345678901234567890', ['user1', 'user2']],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \UnexpectedValueException
|
|
|
|
* @dataProvider getUserFromTokenThrowInvalidTokenData
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
* @param array $users
|
|
|
|
*/
|
|
|
|
public function testGetUserFromTokenThrowInvalidToken($token, $users) {
|
2015-04-01 10:13:49 +00:00
|
|
|
$this->mockRSSToken($token, $token, $users);
|
2015-06-03 10:03:02 +00:00
|
|
|
self::invokePrivate($this->activityManager, 'getUserFromToken');
|
2015-03-25 16:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getUserFromTokenData() {
|
|
|
|
return [
|
|
|
|
[null, '123456789012345678901234567890', 'user1'],
|
|
|
|
['user2', null, 'user2'],
|
|
|
|
['user2', '123456789012345678901234567890', 'user2'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getUserFromTokenData
|
|
|
|
*
|
|
|
|
* @param string $userLoggedIn
|
|
|
|
* @param string $token
|
|
|
|
* @param string $expected
|
|
|
|
*/
|
|
|
|
public function testGetUserFromToken($userLoggedIn, $token, $expected) {
|
|
|
|
if ($userLoggedIn !== null) {
|
|
|
|
$this->mockUserSession($userLoggedIn);
|
|
|
|
}
|
2015-04-01 10:13:49 +00:00
|
|
|
$this->mockRSSToken($token, '123456789012345678901234567890', ['user1']);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->activityManager->getCurrentUserId());
|
|
|
|
}
|
2015-03-25 16:46:19 +00:00
|
|
|
|
2015-04-01 10:13:49 +00:00
|
|
|
protected function mockRSSToken($requestToken, $userToken, $users) {
|
|
|
|
if ($requestToken !== null) {
|
2015-03-25 16:46:19 +00:00
|
|
|
$this->request->expects($this->any())
|
|
|
|
->method('getParam')
|
|
|
|
->with('token', '')
|
2015-04-01 10:13:49 +00:00
|
|
|
->willReturn($requestToken);
|
2015-03-25 16:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->config->expects($this->any())
|
|
|
|
->method('getUsersForUserValue')
|
2015-04-01 10:13:49 +00:00
|
|
|
->with('activity', 'rsstoken', $userToken)
|
|
|
|
->willReturn($users);
|
2015-03-25 16:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2015-08-20 08:25:49 +00:00
|
|
|
|
|
|
|
/**
|
2016-05-02 09:57:24 +00:00
|
|
|
* @expectedException \BadMethodCallException
|
2015-08-20 08:25:49 +00:00
|
|
|
* @expectedExceptionMessage App not set
|
|
|
|
* @expectedExceptionCode 10
|
|
|
|
*/
|
|
|
|
public function testPublishExceptionNoApp() {
|
|
|
|
$event = new \OC\Activity\Event();
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-02 09:57:24 +00:00
|
|
|
* @expectedException \BadMethodCallException
|
2015-08-20 08:25:49 +00:00
|
|
|
* @expectedExceptionMessage Type not set
|
|
|
|
* @expectedExceptionCode 11
|
|
|
|
*/
|
|
|
|
public function testPublishExceptionNoType() {
|
|
|
|
$event = new \OC\Activity\Event();
|
|
|
|
$event->setApp('test');
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-02 09:57:24 +00:00
|
|
|
* @expectedException \BadMethodCallException
|
2015-08-20 08:25:49 +00:00
|
|
|
* @expectedExceptionMessage Affected user not set
|
|
|
|
* @expectedExceptionCode 12
|
|
|
|
*/
|
|
|
|
public function testPublishExceptionNoAffectedUser() {
|
|
|
|
$event = new \OC\Activity\Event();
|
|
|
|
$event->setApp('test')
|
|
|
|
->setType('test_type');
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-02 09:57:24 +00:00
|
|
|
* @expectedException \BadMethodCallException
|
2015-08-20 08:25:49 +00:00
|
|
|
* @expectedExceptionMessage Subject not set
|
|
|
|
* @expectedExceptionCode 13
|
|
|
|
*/
|
|
|
|
public function testPublishExceptionNoSubject() {
|
|
|
|
$event = new \OC\Activity\Event();
|
|
|
|
$event->setApp('test')
|
|
|
|
->setType('test_type')
|
|
|
|
->setAffectedUser('test_affected');
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataPublish() {
|
|
|
|
return [
|
|
|
|
[null],
|
|
|
|
['test_author'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataPublish
|
|
|
|
* @param string $author
|
|
|
|
*/
|
|
|
|
public function testPublish($author) {
|
|
|
|
if ($author !== null) {
|
|
|
|
$authorObject = $this->getMockBuilder('OCP\IUser')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$authorObject->expects($this->once())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn($author);
|
|
|
|
$this->session->expects($this->atLeastOnce())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($authorObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
$event = new \OC\Activity\Event();
|
|
|
|
$event->setApp('test')
|
|
|
|
->setType('test_type')
|
|
|
|
->setSubject('test_subject', [])
|
|
|
|
->setAffectedUser('test_affected');
|
|
|
|
|
|
|
|
$consumer = $this->getMockBuilder('OCP\Activity\IConsumer')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$consumer->expects($this->once())
|
|
|
|
->method('receive')
|
|
|
|
->with($event)
|
|
|
|
->willReturnCallback(function(\OCP\Activity\IEvent $event) use ($author) {
|
|
|
|
$this->assertLessThanOrEqual(time() + 2, $event->getTimestamp(), 'Timestamp not set correctly');
|
|
|
|
$this->assertGreaterThanOrEqual(time() - 2, $event->getTimestamp(), 'Timestamp not set correctly');
|
|
|
|
$this->assertSame($author, $event->getAuthor(), 'Author name not set correctly');
|
|
|
|
});
|
|
|
|
$this->activityManager->registerConsumer(function () use ($consumer) {
|
|
|
|
return $consumer;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPublishAllManually() {
|
|
|
|
$event = new \OC\Activity\Event();
|
|
|
|
$event->setApp('test_app')
|
|
|
|
->setType('test_type')
|
|
|
|
->setAffectedUser('test_affected')
|
|
|
|
->setAuthor('test_author')
|
|
|
|
->setTimestamp(1337)
|
|
|
|
->setSubject('test_subject', ['test_subject_param'])
|
|
|
|
->setMessage('test_message', ['test_message_param'])
|
|
|
|
->setObject('test_object_type', 42, 'test_object_name')
|
|
|
|
->setLink('test_link')
|
|
|
|
;
|
|
|
|
|
|
|
|
$consumer = $this->getMockBuilder('OCP\Activity\IConsumer')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$consumer->expects($this->once())
|
|
|
|
->method('receive')
|
|
|
|
->willReturnCallback(function(\OCP\Activity\IEvent $event) {
|
|
|
|
$this->assertSame('test_app', $event->getApp(), 'App not set correctly');
|
|
|
|
$this->assertSame('test_type', $event->getType(), 'Type not set correctly');
|
|
|
|
$this->assertSame('test_affected', $event->getAffectedUser(), 'Affected user not set correctly');
|
|
|
|
$this->assertSame('test_author', $event->getAuthor(), 'Author not set correctly');
|
|
|
|
$this->assertSame(1337, $event->getTimestamp(), 'Timestamp not set correctly');
|
|
|
|
$this->assertSame('test_subject', $event->getSubject(), 'Subject not set correctly');
|
|
|
|
$this->assertSame(['test_subject_param'], $event->getSubjectParameters(), 'Subject parameter not set correctly');
|
|
|
|
$this->assertSame('test_message', $event->getMessage(), 'Message not set correctly');
|
|
|
|
$this->assertSame(['test_message_param'], $event->getMessageParameters(), 'Message parameter not set correctly');
|
|
|
|
$this->assertSame('test_object_type', $event->getObjectType(), 'Object type not set correctly');
|
|
|
|
$this->assertSame(42, $event->getObjectId(), 'Object ID not set correctly');
|
|
|
|
$this->assertSame('test_object_name', $event->getObjectName(), 'Object name not set correctly');
|
|
|
|
$this->assertSame('test_link', $event->getLink(), 'Link not set correctly');
|
|
|
|
});
|
|
|
|
$this->activityManager->registerConsumer(function () use ($consumer) {
|
|
|
|
return $consumer;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->activityManager->publish($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeprecatedPublishActivity() {
|
|
|
|
$event = new \OC\Activity\Event();
|
|
|
|
$event->setApp('test_app')
|
|
|
|
->setType('test_type')
|
|
|
|
->setAffectedUser('test_affected')
|
|
|
|
->setAuthor('test_author')
|
|
|
|
->setTimestamp(1337)
|
|
|
|
->setSubject('test_subject', ['test_subject_param'])
|
|
|
|
->setMessage('test_message', ['test_message_param'])
|
|
|
|
->setObject('test_object_type', 42, 'test_object_name')
|
|
|
|
->setLink('test_link')
|
|
|
|
;
|
|
|
|
|
|
|
|
$consumer = $this->getMockBuilder('OCP\Activity\IConsumer')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$consumer->expects($this->once())
|
|
|
|
->method('receive')
|
|
|
|
->willReturnCallback(function(\OCP\Activity\IEvent $event) {
|
|
|
|
$this->assertSame('test_app', $event->getApp(), 'App not set correctly');
|
|
|
|
$this->assertSame('test_type', $event->getType(), 'Type not set correctly');
|
|
|
|
$this->assertSame('test_affected', $event->getAffectedUser(), 'Affected user not set correctly');
|
|
|
|
$this->assertSame('test_subject', $event->getSubject(), 'Subject not set correctly');
|
|
|
|
$this->assertSame(['test_subject_param'], $event->getSubjectParameters(), 'Subject parameter not set correctly');
|
|
|
|
$this->assertSame('test_message', $event->getMessage(), 'Message not set correctly');
|
|
|
|
$this->assertSame(['test_message_param'], $event->getMessageParameters(), 'Message parameter not set correctly');
|
|
|
|
$this->assertSame('test_object_name', $event->getObjectName(), 'Object name not set correctly');
|
|
|
|
$this->assertSame('test_link', $event->getLink(), 'Link not set correctly');
|
|
|
|
|
|
|
|
// The following values can not be used via publishActivity()
|
|
|
|
$this->assertLessThanOrEqual(time() + 2, $event->getTimestamp(), 'Timestamp not set correctly');
|
|
|
|
$this->assertGreaterThanOrEqual(time() - 2, $event->getTimestamp(), 'Timestamp not set correctly');
|
|
|
|
$this->assertSame(null, $event->getAuthor(), 'Author not set correctly');
|
|
|
|
$this->assertSame('', $event->getObjectType(), 'Object type should not be set');
|
|
|
|
$this->assertSame(0, $event->getObjectId(), 'Object ID should not be set');
|
|
|
|
});
|
|
|
|
$this->activityManager->registerConsumer(function () use ($consumer) {
|
|
|
|
return $consumer;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->activityManager->publishActivity(
|
|
|
|
$event->getApp(),
|
|
|
|
$event->getSubject(), $event->getSubjectParameters(),
|
|
|
|
$event->getMessage(), $event->getMessageParameters(),
|
|
|
|
$event->getObjectName(),
|
|
|
|
$event->getLink(),
|
|
|
|
$event->getAffectedUser(),
|
|
|
|
$event->getType(),
|
|
|
|
\OCP\Activity\IExtension::PRIORITY_MEDIUM
|
|
|
|
);
|
|
|
|
}
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class SimpleExtension implements \OCP\Activity\IExtension {
|
|
|
|
|
|
|
|
public function getNotificationTypes($languageCode) {
|
|
|
|
return array('NT1', 'NT2');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDefaultTypes($method) {
|
|
|
|
if ($method === 'stream') {
|
|
|
|
return array('DT0');
|
|
|
|
}
|
|
|
|
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
public function getTypeIcon($type) {
|
|
|
|
if ($type === 'NT1') {
|
|
|
|
return 'icon-nt-one';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
|
|
|
if ($app === 'APP0') {
|
|
|
|
return "Stupid translation";
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:00:17 +00:00
|
|
|
public function getSpecialParameterList($app, $text) {
|
|
|
|
if ($app === 'APP0') {
|
|
|
|
return array(0 => 'file', 1 => 'username');
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function getGroupParameter($activity) {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNavigation() {
|
|
|
|
return array(
|
|
|
|
'apps' => array('nav1', 'nav2', 'nav3', 'nav4'),
|
|
|
|
'top' => array('top1', 'top2')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isFilterValid($filterValue) {
|
|
|
|
if ($filterValue === 'fv01') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
public function filterNotificationTypes($types, $filter) {
|
|
|
|
if ($filter === 'fv01') {
|
|
|
|
unset($types[0]);
|
|
|
|
}
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function getQueryForFilter($filter) {
|
2015-02-13 12:08:57 +00:00
|
|
|
if ($filter === 'fv01') {
|
2014-07-03 11:48:15 +00:00
|
|
|
return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NoOpExtension implements \OCP\Activity\IExtension {
|
|
|
|
|
|
|
|
public function getNotificationTypes($languageCode) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
public function getDefaultTypes($method) {
|
2014-07-03 11:48:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
public function getTypeIcon($type) {
|
2014-07-03 11:48:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:00:17 +00:00
|
|
|
public function getSpecialParameterList($app, $text) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function getGroupParameter($activity) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNavigation() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isFilterValid($filterValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-13 12:08:57 +00:00
|
|
|
public function filterNotificationTypes($types, $filter) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
public function getQueryForFilter($filter) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-07-23 09:00:29 +00:00
|
|
|
|
|
|
|
class NoOpConsumer implements \OCP\Activity\IConsumer {
|
|
|
|
|
2015-08-20 08:25:49 +00:00
|
|
|
public function receive(\OCP\Activity\IEvent $event) {
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
}
|
|
|
|
}
|