Skip to content

Commit

Permalink
fixup! fixup! Remove legacy parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Jan 24, 2019
1 parent 8990184 commit 049511b
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 10 deletions.
17 changes: 7 additions & 10 deletions tests/Controller/APIv1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\Activity\Data;
use OCA\Activity\GroupHelper;
use OCA\Activity\Tests\Mock\Extension;
use OCA\Activity\Tests\Mock\Provider;
use OCA\Activity\Tests\TestCase;
use OCA\Activity\UserSettings;
use OCP\Activity\IExtension;
Expand Down Expand Up @@ -135,15 +136,15 @@ public function getData() {
'date' => null,
'id' => null,
'message' => '',
'subject' => 'Subject2 @User #A/B.txt',
'subject' => 'Subject2 @User #/A/B.txt',
),
array(
'link' => 'link',
'file' => 'file',
'date' => null,
'id' => null,
'message' => '',
'subject' => 'Subject1 #A/B.txt',
'subject' => 'Subject1 #/A/B.txt',
),
)),
array('activity-api-user1', 0, 1, array(
Expand All @@ -153,7 +154,7 @@ public function getData() {
'date' => null,
'id' => null,
'message' => '',
'subject' => 'Subject2 @User #A/B.txt',
'subject' => 'Subject2 @User #/A/B.txt',
),
)),
array('activity-api-user1', 1, 1, array(
Expand All @@ -163,7 +164,7 @@ public function getData() {
'date' => null,
'id' => null,
'message' => '',
'subject' => 'Subject1 #A/B.txt',
'subject' => 'Subject1 #/A/B.txt',
),
)),
array('activity-api-user1', 5, 1, array(
Expand All @@ -173,7 +174,7 @@ public function getData() {
'date' => null,
'id' => null,
'message' => '',
'subject' => 'Subject2 @User #A/B.txt',
'subject' => 'Subject2 @User #/A/B.txt',
),
)),
);
Expand All @@ -199,11 +200,6 @@ public function testGet($user, $start, $count, $expected) {
->will($this->returnCallback(function($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
$languageFactory = $this->createMock(IFactory::class);
$languageFactory->expects(empty($expected) ? $this->never() : $this->atLeastOnce())
->method('get')
->with('activity')
->willReturn($l);

$activityManager = new Manager(
$this->getMockBuilder(IRequest::class)->getMock(),
Expand All @@ -214,6 +210,7 @@ public function testGet($user, $start, $count, $expected) {
$activityManager->registerExtension(function() use ($l) {
return new Extension($l, $this->getMockBuilder(IURLGenerator::class)->getMock());
});
$activityManager->registerProvider(Provider::class);

$currentUser = $this->getMockBuilder(CurrentUser::class)
->disableOriginalConstructor()
Expand Down
195 changes: 195 additions & 0 deletions tests/mock/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Activity\Tests\Mock;

use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;

class Provider implements IProvider {

/**
* @param string $language The language which should be used for translating, e.g. "en"
* @param IEvent $event The current event which should be parsed
* @param IEvent|null $previousEvent A potential previous event which you can combine with the current one.
* To do so, simply use setChildEvent($previousEvent) after setting the
* combined subject on the current event.
* @return IEvent
* @throws \InvalidArgumentException Should be thrown if your provider does not know this event
* @since 11.0.0
*/
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
if ($event->getApp() !== 'app1') {
throw new \InvalidArgumentException();
}

switch ($event->getSubject()) {
case 'subject1':
$event->setParsedSubject(vsprintf('Subject1 #%1$s', $event->getSubjectParameters()));
break;
case 'subject2':
$event->setParsedSubject(vsprintf('Subject2 @%2$s #%1$s', $event->getSubjectParameters()));
break;
case 'subject3':
$event->setParsedSubject(vsprintf('Subject3 #%1$s @%2$s', $event->getSubjectParameters()));
break;

default:
throw new \InvalidArgumentException();
}

return $event;
}


const TYPE_SHARE_CREATED = 'file_created';
const TYPE_SHARE_CHANGED = 'file_changed';
const TYPE_SHARE_DELETED = 'file_deleted';
const TYPE_SHARE_RESTORED = 'file_restored';

/** @var IL10N */
protected $l;

/** @var IURLGenerator */
protected $URLGenerator;

/**
* @param IL10N $l
* @param IURLGenerator $URLGenerator
*/
public function __construct(IL10N $l, $URLGenerator) {
$this->l = $l;
$this->URLGenerator = $URLGenerator;
}

/**
* {@inheritdoc}
*/
public function getNotificationTypes($languageCode) {
return [
'type1' => 'Type1 description',
'type2' => 'Type2 description',
];
}

/**
* {@inheritdoc}
*/
public function filterNotificationTypes($types, $filter) {
switch ($filter) {
case 'filter1':
return array_intersect([
'type1',
], $types);
}
return false;
}

/**
* {@inheritdoc}
*/
public function getDefaultTypes($method) {
if ($method === 'stream') {
return ['type1', 'type2'];
}

return ['type2'];
}

/**
* {@inheritdoc}
*/
public function getSpecialParameterList($app, $text) {
if ($app === 'app1') {
switch ($text) {
case 'subject1':
return [0 => 'file'];
case 'subject2':
return [0 => 'file', 1 => 'username'];
}
}

return false;
}

/**
* {@inheritdoc}
*/
public function getTypeIcon($type) {
switch ($type) {
case 'type1':
return 'icon-type1';

default:
return false;
}
}

/**
* {@inheritdoc}
*/
public function getGroupParameter($activity) {
if ($activity['app'] === 'app1') {
switch ($activity['subject']) {
case 'subject1':
return 0;
}
}

return false;
}

/**
* {@inheritdoc}
*/
public function getNavigation() {
return [
'apps' => [
'files' => [
'id' => 'files',
'name' => (string) $this->l->t('Files'),
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => 'files']),
],
],
'top' => [],
];
}

/**
* {@inheritdoc}
*/
public function isFilterValid($filterValue) {
return $filterValue === 'filter1';
}

/**
* {@inheritdoc}
*/
public function getQueryForFilter($filter) {
if ($filter === 'app1') {
return ['`app` = ?', ['app1']];
}
return false;
}
}

0 comments on commit 049511b

Please sign in to comment.