/** * @dataProvider getData */ public function testGet($user, $start, $count, $expected) { $_GET['start'] = $start; $_GET['count'] = $count; \OC_User::setUserId($user); $sessionUser = \OC::$server->getUserSession()->getUser(); $this->assertInstanceOf('OCP\\IUser', $sessionUser); $this->assertEquals($user, $sessionUser->getUID()); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () { return new Extension(\OCP\Util::getL10N('activity', 'en'), $this->getMock('\\OCP\\IURLGenerator')); }); $this->registerActivityManager($activityManager); $result = \OCA\Activity\Api::get(array('_route' => 'get_cloud_activity')); $this->registerActivityManager($this->oldManager); $this->assertEquals(100, $result->getStatusCode()); $data = $result->getData(); $this->assertEquals(sizeof($expected), sizeof($data)); while (!empty($expected)) { $assertExpected = array_shift($expected); $assertData = array_shift($data); foreach ($assertExpected as $key => $value) { $this->assertArrayHasKey($key, $assertData); if ($value !== null) { $this->assertEquals($value, $assertData[$key]); } } } }
protected function setUp() { parent::setUp(); $this->originalWEBROOT = \OC::$WEBROOT; \OC::$WEBROOT = ''; $this->view = $view = $this->getMockBuilder('\\OC\\Files\\View')->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(); $urlGenerator->expects($this->any())->method('linkTo')->willReturnCallback(function ($app, $file, $params) { $paramStrings = []; foreach ($params as $name => $value) { $paramStrings[] = $name . '=' . urlencode($value); } return '/index.php/apps/' . $app . '?' . implode('&', $paramStrings); }); $activityManager->registerExtension(function () use($activityLanguage, $urlGenerator) { return new Extension($activityLanguage, $urlGenerator); }); $this->userManager = $this->getMock('OCP\\IUserManager'); $this->userManager->expects($this->any())->method('get')->willReturnMap([['user1', $this->getUserMockDisplayName('user1', 'User One')], ['user2', $this->getUserMockDisplayName('user1', 'User Two')], ['user<HTML>', $this->getUserMockDisplayName('user<HTML>', 'User <HTML>')]]); $this->contactsManager = $this->getMockBuilder('OCP\\Contacts\\IManager')->disableOriginalConstructor()->getMock(); /** @var \OC\Files\View $view */ $this->parameterHelper = new \OCA\Activity\ParameterHelper($activityManager, $this->userManager, $urlGenerator, $this->contactsManager, $view, $this->config, $activityLanguage, 'test'); }
public function testQueryForFilter() { $result = $this->activityManager->getQueryForFilter('filter1'); $this->assertEquals(array('`app` = ? and `message` like ?', array('mail', 'ownCloud%')), $result); $result = $this->activityManager->isFilterValid('filter2'); $this->assertFalse($result); }
protected function setUp() { parent::setUp(); $this->activityLanguage = $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $this->data = new Data($activityManager); }
protected function setUp() { parent::setUp(); $this->activityLanguage = $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $this->activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $this->session = $this->getMockBuilder('OCP\\IUserSession')->disableOriginalConstructor()->getMock(); $this->activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $this->data = new Data($this->activityManager, \OC::$server->getDatabaseConnection(), $this->session); }
/** * @dataProvider translationData */ public function testTranslation($text, $params, $stripPath, $highlightParams, $expected) { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $config = $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(); $config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn(true); $dataHelper = new DataHelper($activityManager, new ParameterHelper($activityManager, $this->getMockBuilder('OCP\\IUserManager')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('OC\\Files\\View')->disableOriginalConstructor()->getMock(), $config, $activityLanguage, 'test'), $activityLanguage); $this->assertEquals($expected, (string) $dataHelper->translation('app1', $text, $params, $stripPath, $highlightParams)); }
protected function setUp() { parent::setUp(); $this->request = $this->getMockBuilder('OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->session = $this->getMockBuilder('OCP\\IUserSession')->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(); $this->activityHelper = $this->getMockBuilder('OCA\\Files\\ActivityHelper')->disableOriginalConstructor()->getMock(); $this->activityManager = new \OC\ActivityManager($this->request, $this->session, $this->config); $this->activityExtension = $activityExtension = new Activity(new \OC\L10N\Factory(), $this->getMockBuilder('OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(), $this->activityManager, $this->activityHelper, $this->config); $this->activityManager->registerExtension(function () use($activityExtension) { return $activityExtension; }); }
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); }
protected function setUp() { parent::setUp(); $this->originalWEBROOT = \OC::$WEBROOT; \OC::$WEBROOT = ''; $this->view = $view = $this->getMockBuilder('\\OC\\Files\\View')->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $this->userManager = $this->getMock('OCP\\IUserManager'); $this->userManager->expects($this->any())->method('get')->willReturnMap([['user1', $this->getUserMockDisplayName('user1', 'User One')], ['user2', $this->getUserMockDisplayName('user1', 'User Two')], ['user<HTML>', $this->getUserMockDisplayName('user<HTML>', 'User <HTML>')]]); /** @var \OC\Files\View $view */ $this->parameterHelper = new \OCA\Activity\ParameterHelper($activityManager, $this->userManager, $view, $this->config, $activityLanguage, 'test'); }
/** * @dataProvider getUserFromTokenData * * @param string $userLoggedIn * @param string $token * @param string $expected */ public function testGetUserFromToken($userLoggedIn, $token, $expected) { if ($userLoggedIn !== null) { $this->mockUserSession($userLoggedIn); } $this->mockRSSToken($token, '123456789012345678901234567890', ['user1']); $this->assertEquals($expected, $this->activityManager->getCurrentUserId()); }
/** * @dataProvider getTemplateData */ public function testGetTemplate($constructorActive, $forceActive = null, $rssToken = '') { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $userSettings = $this->getMockBuilder('OCA\\Activity\\UserSettings')->disableOriginalConstructor()->getMock(); $userSettings->expects($this->exactly(2))->method('getUserSetting')->with('test', 'setting', 'self')->willReturn(true); $navigation = new Navigation($activityLanguage, $activityManager, \OC::$server->getURLGenerator(), $userSettings, 'test', $rssToken, $constructorActive); $output = $navigation->getTemplate($forceActive)->fetchPage(); // Get only the template part with the navigation links $navigationLinks = substr($output, strpos($output, '<ul>') + 4); $navigationLinks = substr($navigationLinks, 0, strrpos($navigationLinks, '</li>')); // Remove tabs and new lines $navigationLinks = str_replace(array("\t", "\n"), '', $navigationLinks); // Turn the list of links into an array $navigationEntries = explode('</li>', $navigationLinks); $links = $navigation->getLinkList(); // Check whether all top links are available foreach ($links['top'] as $link) { $found = false; foreach ($navigationEntries as $navigationEntry) { if (strpos($navigationEntry, 'data-navigation="' . $link['id'] . '"') !== false) { $found = true; $this->assertContains('href="' . $link['url'] . '">' . $link['name'] . '</a>', $navigationEntry); if ($forceActive == $link['id'] || $forceActive == null && $constructorActive == $link['id']) { $this->assertStringStartsWith('<li class="active">', $navigationEntry); } else { $this->assertStringStartsWith('<li>', $navigationEntry); } } } $this->assertTrue($found, 'Could not find navigation entry "' . $link['name'] . '"'); } // Check size of app links $this->assertSame(1, sizeof($links['apps'])); $this->assertNotContains('data-navigation="files"', $navigationLinks, 'Files app should not be included when there are no other apps.'); if ($rssToken) { $rssInputField = strpos($output, 'input id="rssurl"'); $this->assertGreaterThan(0, $rssInputField); $endOfInputField = strpos($output, ' />', $rssInputField); $this->assertNotSame(false, strpos(substr($output, $rssInputField, $endOfInputField - $rssInputField), $rssToken)); } }
protected function setUp() { parent::setUp(); $this->request = $this->getMockBuilder('OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->session = $this->getMockBuilder('OCP\\IUserSession')->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(); $this->activityHelper = $this->getMockBuilder('OCA\\Files\\ActivityHelper')->disableOriginalConstructor()->getMock(); $this->activityManager = new \OC\ActivityManager($this->request, $this->session, $this->config); $this->l10nFactory = $this->getMockBuilder('OC\\L10N\\Factory')->disableOriginalConstructor()->getMock(); $deL10n = $this->getMockBuilder('OC_L10N')->disableOriginalConstructor()->getMock(); $deL10n->expects($this->any())->method('t')->willReturnCallback(function ($argument) { return 'translate(' . $argument . ')'; }); $this->l10nFactory->expects($this->any())->method('get')->willReturnMap([['files', null, new \OC_L10N('files', 'en')], ['files', 'en', new \OC_L10N('files', 'en')], ['files', 'de', $deL10n]]); $this->activityExtension = $activityExtension = new Activity($this->l10nFactory, $this->getMockBuilder('OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(), $this->activityManager, $this->activityHelper, $this->config); $this->activityManager->registerExtension(function () use($activityExtension) { return $activityExtension; }); }
public function testQueryForFilter() { $this->activityManager->registerExtension(function () { return new SimpleExtension(); }); $result = $this->activityManager->getQueryForFilter('filter1'); $this->assertEquals(array(' and ((`app` = ? and `message` like ?) or (`app` = ? and `message` like ?))', array('mail', 'ownCloud%', 'mail', 'ownCloud%')), $result); $result = $this->activityManager->isFilterValid('filter2'); $this->assertFalse($result); }
/** * @dataProvider translationData */ public function testTranslation($text, $params, $stripPath, $highlightParams, $expected) { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(); $urlGenerator->expects($this->any())->method('linkTo')->willReturnCallback(function ($app, $file, $params) { $paramStrings = []; foreach ($params as $name => $value) { $paramStrings[] = $name . '=' . urlencode($value); } return '/index.php/apps/' . $app . '?' . implode('&', $paramStrings); }); $activityManager->registerExtension(function () use($activityLanguage, $urlGenerator) { return new Extension($activityLanguage, $urlGenerator); }); $config = $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(); $config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn(true); $dataHelper = new DataHelper($activityManager, new ParameterHelper($activityManager, $this->getMockBuilder('OCP\\IUserManager')->disableOriginalConstructor()->getMock(), $urlGenerator, $this->getMockBuilder('OCP\\Contacts\\IManager')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('OC\\Files\\View')->disableOriginalConstructor()->getMock(), $config, $activityLanguage, 'test'), $activityLanguage); $this->assertEquals($expected, (string) $dataHelper->translation('app1', $text, $params, $stripPath, $highlightParams)); }
/** * @dataProvider groupHelperData */ public function testGroupHelper($allowGrouping, $activities, $expected) { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $helper = new GroupHelper($activityManager, new DataHelper($activityManager, new ParameterHelper($activityManager, $this->getMockBuilder('OCP\\IUserManager')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('OCP\\Contacts\\IManager')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('OC\\Files\\View')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(), $activityLanguage, 'test'), $activityLanguage), $allowGrouping); foreach ($activities as $activity) { $helper->addActivity($activity); } $result = $helper->getActivities(); $clearedResult = array(); foreach ($result as $activity) { unset($activity['subjectformatted']); unset($activity['messageformatted']); unset($activity['timestamp']); $clearedResult[] = $activity; } $this->assertEquals($expected, $clearedResult); }
public function __construct(IRequest $request, IUserSession $session, IConfig $config) { parent::__construct($request, $session, $config); }