aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/appinfo/app.php7
-rw-r--r--apps/files/css/files.css21
-rw-r--r--apps/files/img/delete.pngbin0 -> 209 bytes
-rw-r--r--apps/files/img/delete.svg4
-rw-r--r--apps/files/img/external.pngbin0 -> 369 bytes
-rw-r--r--apps/files/img/external.svg4
-rw-r--r--apps/files/img/folder.pngbin0 -> 160 bytes
-rw-r--r--apps/files/img/folder.svg6
-rw-r--r--apps/files/img/public.pngbin0 -> 297 bytes
-rw-r--r--apps/files/img/public.svg7
-rw-r--r--apps/files/img/share.pngbin0 -> 365 bytes
-rw-r--r--apps/files/img/share.svg6
-rw-r--r--apps/files/img/star.pngbin0 -> 373 bytes
-rw-r--r--apps/files/img/star.svg6
-rw-r--r--apps/files/lib/activity.php88
-rw-r--r--apps/files/lib/activityhelper.php84
-rw-r--r--apps/files/templates/appnavigation.php11
-rw-r--r--apps/files/tests/activitytest.php297
-rw-r--r--apps/files/tests/ajax_rename.php11
19 files changed, 535 insertions, 17 deletions
diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php
index e4cac7c7c14..c483ad31ec5 100644
--- a/apps/files/appinfo/app.php
+++ b/apps/files/appinfo/app.php
@@ -59,6 +59,11 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadshe
\OC::$server->getActivityManager()->registerExtension(function() {
return new \OCA\Files\Activity(
\OC::$server->query('L10NFactory'),
- \OC::$server->getURLGenerator()
+ \OC::$server->getURLGenerator(),
+ \OC::$server->getActivityManager(),
+ new \OCA\Files\ActivityHelper(
+ \OC::$server->getTagManager()
+ ),
+ \OC::$server->getConfig()
);
});
diff --git a/apps/files/css/files.css b/apps/files/css/files.css
index d34013db499..455ccae3f96 100644
--- a/apps/files/css/files.css
+++ b/apps/files/css/files.css
@@ -103,6 +103,27 @@
min-height: 100%;
}
+/* icons for sidebar */
+.nav-icon-files {
+ background-image: url('../img/folder.svg');
+}
+.nav-icon-favorites {
+ background-image: url('../img/star.svg');
+}
+.nav-icon-sharingin,
+.nav-icon-sharingout {
+ background-image: url('../img/share.svg');
+}
+.nav-icon-sharinglinks {
+ background-image: url('../img/public.svg');
+}
+.nav-icon-extstoragemounts {
+ background-image: url('../img/external.svg');
+}
+.nav-icon-trashbin {
+ background-image: url('../img/delete.svg');
+}
+
/* move Deleted Files to bottom of sidebar */
.nav-trashbin {
position: fixed !important;
diff --git a/apps/files/img/delete.png b/apps/files/img/delete.png
new file mode 100644
index 00000000000..b2ab8c5efef
--- /dev/null
+++ b/apps/files/img/delete.png
Binary files differ
diff --git a/apps/files/img/delete.svg b/apps/files/img/delete.svg
new file mode 100644
index 00000000000..b6dc2cc4173
--- /dev/null
+++ b/apps/files/img/delete.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <path opacity=".5" d="m6.5 1-0.5 1h-3c-0.554 0-1 0.446-1 1v1h12v-1c0-0.554-0.446-1-1-1h-3l-0.5-1zm-3.5 4 0.875 9c0.061 0.549 0.5729 1 1.125 1h6c0.55232 0 1.064-0.45102 1.125-1l0.875-9z" fill-rule="evenodd"/>
+</svg>
diff --git a/apps/files/img/external.png b/apps/files/img/external.png
new file mode 100644
index 00000000000..2ac5e9344c3
--- /dev/null
+++ b/apps/files/img/external.png
Binary files differ
diff --git a/apps/files/img/external.svg b/apps/files/img/external.svg
new file mode 100644
index 00000000000..d1940f2f1b3
--- /dev/null
+++ b/apps/files/img/external.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <path opacity=".5" d="m7.4515 1.6186 2.3806 2.2573-3.5709 3.386 2.3806 2.2573 3.5709-3.386 2.3806 2.2573v-6.7725h-7.1422zm-4.7612 1.1286c-0.65945 0-1.1903 0.5034-1.1903 1.1286v9.029c0 0.6253 0.53085 1.1286 1.1903 1.1286h9.522c0.6594 0 1.1903-0.5034 1.1903-1.1286v-3.386l-1.19-1.1287v4.5146h-9.5217v-9.029h4.761l-1.1905-1.1287h-3.5707z"/>
+</svg>
diff --git a/apps/files/img/folder.png b/apps/files/img/folder.png
new file mode 100644
index 00000000000..ada4c4c2f88
--- /dev/null
+++ b/apps/files/img/folder.png
Binary files differ
diff --git a/apps/files/img/folder.svg b/apps/files/img/folder.svg
new file mode 100644
index 00000000000..1a97808443d
--- /dev/null
+++ b/apps/files/img/folder.svg
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.0" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <g opacity=".5" fill-rule="evenodd" transform="matrix(.86667 0 0 .86667 -172.04 -864.43)">
+ <path d="m200.2 998.57c-0.28913 0-0.53125 0.24212-0.53125 0.53125v13.938c0 0.2985 0.23264 0.5312 0.53125 0.5312h15.091c0.2986 0 0.53125-0.2327 0.53125-0.5312l0.0004-8.1661c0-0.289-0.24212-0.5338-0.53125-0.5338h-12.161l-0.0004 6.349c0 0.2771-0.30237 0.5638-0.57937 0.5638s-0.57447-0.2867-0.57447-0.5638l0.0004-7.0055c0-0.2771 0.23357-0.4974 0.51057-0.4974h2.6507l8.3774 0.0003-0.0004-1.7029c0-0.3272-0.24549-0.6047-0.57258-0.6047h-7.5043v-1.7764c0-0.28915-0.23415-0.53125-0.52328-0.53125z" fill-rule="evenodd"/>
+ </g>
+</svg>
diff --git a/apps/files/img/public.png b/apps/files/img/public.png
new file mode 100644
index 00000000000..f49c5fb1ee5
--- /dev/null
+++ b/apps/files/img/public.png
Binary files differ
diff --git a/apps/files/img/public.svg b/apps/files/img/public.svg
new file mode 100644
index 00000000000..23ac51d8367
--- /dev/null
+++ b/apps/files/img/public.svg
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <g opacity=".5" transform="matrix(.67042 -.67042 .67042 .67042 .62542 93.143)">
+ <path style="block-progression:tb;color:#000000;text-transform:none;text-indent:0" d="m69.5-61.5c-1.9217 0-3.5 1.5783-3.5 3.5 0 0.17425 0.0062 0.33232 0.03125 0.5h2.0625c-0.053-0.156-0.094-0.323-0.094-0.5 0-0.8483 0.6517-1.5 1.5-1.5h5c0.8483 0 1.5 0.6517 1.5 1.5s-0.6517 1.5-1.5 1.5h-1.6875c-0.28733 0.79501-0.78612 1.4793-1.4375 2h3.125c1.9217 0 3.5-1.5783 3.5-3.5s-1.5783-3.5-3.5-3.5h-5z"/>
+ <path style="block-progression:tb;color:#000000;text-transform:none;text-indent:0" d="m68.5-54.5c1.9217 0 3.5-1.5783 3.5-3.5 0-0.17425-0.0062-0.33232-0.03125-0.5h-2.0625c0.053 0.156 0.094 0.323 0.094 0.5 0 0.8483-0.6517 1.5-1.5 1.5h-5c-0.8483 0-1.5-0.6517-1.5-1.5s0.6517-1.5 1.5-1.5h1.6875c0.28733-0.79501 0.78612-1.4793 1.4375-2h-3.125c-1.9217 0-3.5 1.5783-3.5 3.5s1.5783 3.5 3.5 3.5h5z"/>
+ </g>
+</svg>
diff --git a/apps/files/img/share.png b/apps/files/img/share.png
new file mode 100644
index 00000000000..61c87e78b6c
--- /dev/null
+++ b/apps/files/img/share.png
Binary files differ
diff --git a/apps/files/img/share.svg b/apps/files/img/share.svg
new file mode 100644
index 00000000000..97f52f2e783
--- /dev/null
+++ b/apps/files/img/share.svg
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <g opacity=".5" transform="translate(0 -1036.4)">
+ <path d="m12.228 1037.4c-1.3565 0-2.4592 1.0977-2.4592 2.4542 0 0.075 0.0084 0.1504 0.0149 0.2236l-4.7346 2.4145c-0.4291-0.3667-0.98611-0.5863-1.5947-0.5863-1.3565 0-2.4542 1.0977-2.4542 2.4543 0 1.3565 1.0977 2.4542 2.4542 2.4542 0.54607 0 1.0528-0.1755 1.4606-0.477l4.8637 2.4741c-0.0024 0.044-0.0099 0.089-0.0099 0.1342 0 1.3565 1.1027 2.4542 2.4592 2.4542s2.4542-1.0977 2.4542-2.4542-1.0977-2.4592-2.4542-2.4592c-0.63653 0-1.218 0.2437-1.6544 0.6409l-4.6953-2.4c0.01892-0.1228 0.03478-0.2494 0.03478-0.3775 0-0.072-0.0089-0.1437-0.0149-0.2137l4.7395-2.4145c0.42802 0.3627 0.98488 0.5813 1.5898 0.5813 1.3565 0 2.4542-1.1027 2.4542-2.4592s-1.0977-2.4542-2.4542-2.4542z"/>
+ </g>
+</svg>
diff --git a/apps/files/img/star.png b/apps/files/img/star.png
new file mode 100644
index 00000000000..6b0ec67ec1c
--- /dev/null
+++ b/apps/files/img/star.png
Binary files differ
diff --git a/apps/files/img/star.svg b/apps/files/img/star.svg
new file mode 100644
index 00000000000..fb3eef1e452
--- /dev/null
+++ b/apps/files/img/star.svg
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <g opacity=".5" transform="matrix(.049689 0 0 .049689 -7.3558 -36.792)">
+ <path d="m330.36 858.43 43.111 108.06 117.64 9.2572-89.445 74.392 27.55 114.75-98.391-62.079-100.62 61.66 28.637-112.76-89.734-76.638 116.09-7.6094z" transform="translate(-21.071,-112.5)"/>
+ </g>
+</svg>
diff --git a/apps/files/lib/activity.php b/apps/files/lib/activity.php
index c376dc7b147..fff49ea4ea5 100644
--- a/apps/files/lib/activity.php
+++ b/apps/files/lib/activity.php
@@ -24,16 +24,20 @@ namespace OCA\Files;
use OC\L10N\Factory;
use OCP\Activity\IExtension;
+use OCP\Activity\IManager;
+use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
class Activity implements IExtension {
const FILTER_FILES = 'files';
+ const FILTER_FAVORITES = 'files_favorites';
const TYPE_SHARE_CREATED = 'file_created';
const TYPE_SHARE_CHANGED = 'file_changed';
const TYPE_SHARE_DELETED = 'file_deleted';
const TYPE_SHARE_RESTORED = 'file_restored';
+ const TYPE_FAVORITES = 'files_favorites';
/** @var IL10N */
protected $l;
@@ -44,14 +48,29 @@ class Activity implements IExtension {
/** @var IURLGenerator */
protected $URLGenerator;
+ /** @var \OCP\Activity\IManager */
+ protected $activityManager;
+
+ /** @var \OCP\IConfig */
+ protected $config;
+
+ /** @var \OCA\Files\ActivityHelper */
+ protected $helper;
+
/**
* @param Factory $languageFactory
* @param IURLGenerator $URLGenerator
+ * @param IManager $activityManager
+ * @param ActivityHelper $helper
+ * @param IConfig $config
*/
- public function __construct(Factory $languageFactory, IURLGenerator $URLGenerator) {
+ public function __construct(Factory $languageFactory, IURLGenerator $URLGenerator, IManager $activityManager, ActivityHelper $helper, IConfig $config) {
$this->languageFactory = $languageFactory;
$this->URLGenerator = $URLGenerator;
$this->l = $this->getL10N();
+ $this->activityManager = $activityManager;
+ $this->helper = $helper;
+ $this->config = $config;
}
/**
@@ -74,6 +93,7 @@ class Activity implements IExtension {
return [
self::TYPE_SHARE_CREATED => (string) $l->t('A new file or folder has been <strong>created</strong>'),
self::TYPE_SHARE_CHANGED => (string) $l->t('A file or folder has been <strong>changed</strong>'),
+ self::TYPE_FAVORITES => (string) $l->t('Limit notifications about creation and changes to your <strong>favorite files</strong> <em>(Stream only)</em>'),
self::TYPE_SHARE_DELETED => (string) $l->t('A file or folder has been <strong>deleted</strong>'),
self::TYPE_SHARE_RESTORED => (string) $l->t('A file or folder has been <strong>restored</strong>'),
];
@@ -229,6 +249,13 @@ class Activity implements IExtension {
*/
public function getNavigation() {
return [
+ 'top' => [
+ self::FILTER_FAVORITES => [
+ 'id' => self::FILTER_FAVORITES,
+ 'name' => (string) $this->l->t('Favorites'),
+ 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => self::FILTER_FAVORITES]),
+ ],
+ ],
'apps' => [
self::FILTER_FILES => [
'id' => self::FILTER_FILES,
@@ -236,7 +263,6 @@ class Activity implements IExtension {
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => self::FILTER_FILES]),
],
],
- 'top' => [],
];
}
@@ -247,7 +273,7 @@ class Activity implements IExtension {
* @return boolean
*/
public function isFilterValid($filterValue) {
- return $filterValue === self::FILTER_FILES;
+ return $filterValue === self::FILTER_FILES || $filterValue === self::FILTER_FAVORITES;
}
/**
@@ -259,7 +285,7 @@ class Activity implements IExtension {
* @return array|false
*/
public function filterNotificationTypes($types, $filter) {
- if ($filter === self::FILTER_FILES) {
+ if ($filter === self::FILTER_FILES || $filter === self::FILTER_FAVORITES) {
return array_intersect([
self::TYPE_SHARE_CREATED,
self::TYPE_SHARE_CHANGED,
@@ -280,9 +306,63 @@ class Activity implements IExtension {
* @return array|false
*/
public function getQueryForFilter($filter) {
+ $user = $this->activityManager->getCurrentUserId();
+ // Display actions from all files
if ($filter === self::FILTER_FILES) {
return ['`app` = ?', ['files']];
}
+
+ if (!$user) {
+ // Remaining filters only work with a user/token
+ return false;
+ }
+
+ // Display actions from favorites only
+ if ($filter === self::FILTER_FAVORITES || in_array($filter, ['all', 'by', 'self']) && $this->userSettingFavoritesOnly($user)) {
+ try {
+ $favorites = $this->helper->getFavoriteFilePaths($user);
+ } catch (\RuntimeException $e) {
+ // Too many favorites, can not put them into one query anymore...
+ return ['`app` = ?', ['files']];
+ }
+
+ /*
+ * Display activities only, when they are not `type` create/change
+ * or `file` is a favorite or in a favorite folder
+ */
+ $parameters = $fileQueryList = [];
+ $parameters[] = 'files';
+
+ $fileQueryList[] = '(`type` <> ? AND `type` <> ?)';
+ $parameters[] = self::TYPE_SHARE_CREATED;
+ $parameters[] = self::TYPE_SHARE_CHANGED;
+
+ foreach ($favorites['items'] as $favorite) {
+ $fileQueryList[] = '`file` = ?';
+ $parameters[] = $favorite;
+ }
+ foreach ($favorites['folders'] as $favorite) {
+ $fileQueryList[] = '`file` LIKE ?';
+ $parameters[] = $favorite . '/%';
+ }
+
+ $parameters[] = 'files';
+
+ return [
+ ' CASE WHEN `app` = ? THEN (' . implode(' OR ', $fileQueryList) . ') ELSE `app` <> ? END ',
+ $parameters,
+ ];
+ }
return false;
}
+
+ /**
+ * Is the file actions favorite limitation enabled?
+ *
+ * @param string $user
+ * @return bool
+ */
+ protected function userSettingFavoritesOnly($user) {
+ return (bool) $this->config->getUserValue($user, 'activity', 'notify_stream_' . self::TYPE_FAVORITES, false);
+ }
}
diff --git a/apps/files/lib/activityhelper.php b/apps/files/lib/activityhelper.php
new file mode 100644
index 00000000000..f9ff722b1c2
--- /dev/null
+++ b/apps/files/lib/activityhelper.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @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\Files;
+
+use OCP\Files\Folder;
+use OCP\ITagManager;
+
+class ActivityHelper {
+ /** If a user has a lot of favorites the query might get too slow and long */
+ const FAVORITE_LIMIT = 50;
+
+ /** @var \OCP\ITagManager */
+ protected $tagManager;
+
+ /**
+ * @param ITagManager $tagManager
+ */
+ public function __construct(ITagManager $tagManager) {
+ $this->tagManager = $tagManager;
+ }
+
+ /**
+ * Returns an array with the favorites
+ *
+ * @param string $user
+ * @return array
+ * @throws \RuntimeException when too many or no favorites where found
+ */
+ public function getFavoriteFilePaths($user) {
+ $tags = $this->tagManager->load('files', [], false, $user);
+ $favorites = $tags->getFavorites();
+
+ if (empty($favorites)) {
+ throw new \RuntimeException('No favorites', 1);
+ } else if (isset($favorites[self::FAVORITE_LIMIT])) {
+ throw new \RuntimeException('Too many favorites', 2);
+ }
+
+ // Can not DI because the user is not known on instantiation
+ $rootFolder = \OC::$server->getUserFolder($user);
+ $folders = $items = [];
+ foreach ($favorites as $favorite) {
+ $nodes = $rootFolder->getById($favorite);
+ if (!empty($nodes)) {
+ /** @var \OCP\Files\Node $node */
+ $node = array_shift($nodes);
+ $path = substr($node->getPath(), strlen($user . '/files/'));
+
+ $items[] = $path;
+ if ($node instanceof Folder) {
+ $folders[] = $path;
+ }
+ }
+ }
+
+ if (empty($items)) {
+ throw new \RuntimeException('No favorites', 1);
+ }
+
+ return [
+ 'items' => $items,
+ 'folders' => $folders,
+ ];
+ }
+}
diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php
index e6237c7f485..f586b0ecb28 100644
--- a/apps/files/templates/appnavigation.php
+++ b/apps/files/templates/appnavigation.php
@@ -1,13 +1,18 @@
<div id="app-navigation">
- <ul>
+ <ul class="with-icon">
<?php foreach ($_['navigationItems'] as $item) { ?>
- <li data-id="<?php p($item['id']) ?>" class="nav-<?php p($item['id']) ?>"><a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"><?php p($item['name']);?></a></li>
+ <li data-id="<?php p($item['id']) ?>" class="nav-<?php p($item['id']) ?>">
+ <a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"
+ class="nav-icon-<?php p($item['id']) ?> svg">
+ <?php p($item['name']);?>
+ </a>
+ </li>
<?php } ?>
</ul>
<div id="app-settings">
<div id="app-settings-header">
<button class="settings-button" data-apps-slide-toggle="#app-settings-content">
- <span class="hidden-visually"><?php p($l->t('Settings'));?></span>
+ <span><?php p($l->t('Settings'));?></span>
</button>
</div>
<div id="app-settings-content">
diff --git a/apps/files/tests/activitytest.php b/apps/files/tests/activitytest.php
new file mode 100644
index 00000000000..1f8d6330e51
--- /dev/null
+++ b/apps/files/tests/activitytest.php
@@ -0,0 +1,297 @@
+<?php
+/**
+ * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ *
+*/
+
+namespace OCA\Files\Tests;
+
+use OCA\Files\Activity;
+use Test\TestCase;
+
+class ActivityTest extends TestCase {
+
+ /** @var \OC\ActivityManager */
+ private $activityManager;
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $request;
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $session;
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $activityHelper;
+
+ /** @var \OCA\Files\Activity */
+ protected $activityExtension;
+
+ 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 testNotificationTypes() {
+ $result = $this->activityExtension->getNotificationTypes('en');
+ $this->assertTrue(is_array($result), 'Asserting getNotificationTypes() returns an array');
+ $this->assertCount(5, $result);
+ $this->assertArrayHasKey(Activity::TYPE_SHARE_CREATED, $result);
+ $this->assertArrayHasKey(Activity::TYPE_SHARE_CHANGED, $result);
+ $this->assertArrayHasKey(Activity::TYPE_FAVORITES, $result);
+ $this->assertArrayHasKey(Activity::TYPE_SHARE_DELETED, $result);
+ $this->assertArrayHasKey(Activity::TYPE_SHARE_RESTORED, $result);
+ }
+
+ public function testDefaultTypes() {
+ $result = $this->activityExtension->getDefaultTypes('stream');
+ $this->assertTrue(is_array($result), 'Asserting getDefaultTypes(stream) returns an array');
+ $this->assertCount(4, $result);
+ $result = array_flip($result);
+ $this->assertArrayHasKey(Activity::TYPE_SHARE_CREATED, $result);
+ $this->assertArrayHasKey(Activity::TYPE_SHARE_CHANGED, $result);
+ $this->assertArrayNotHasKey(Activity::TYPE_FAVORITES, $result);
+ $this->assertArrayHasKey(Activity::TYPE_SHARE_DELETED, $result);
+ $this->assertArrayHasKey(Activity::TYPE_SHARE_RESTORED, $result);
+
+ $result = $this->activityExtension->getDefaultTypes('email');
+ $this->assertFalse($result, 'Asserting getDefaultTypes(email) returns false');
+ }
+
+ public function testTranslate() {
+ $this->assertFalse(
+ $this->activityExtension->translate('files_sharing', '', [], false, false, 'en'),
+ 'Asserting that no translations are set for files_sharing'
+ );
+ }
+
+ public function testGetSpecialParameterList() {
+ $this->assertFalse(
+ $this->activityExtension->getSpecialParameterList('files_sharing', ''),
+ 'Asserting that no special parameters are set for files_sharing'
+ );
+ }
+
+ public function typeIconData() {
+ return [
+ [Activity::TYPE_SHARE_CHANGED, 'icon-change'],
+ [Activity::TYPE_SHARE_CREATED, 'icon-add-color'],
+ [Activity::TYPE_SHARE_DELETED, 'icon-delete-color'],
+ [Activity::TYPE_SHARE_RESTORED, false],
+ [Activity::TYPE_FAVORITES, false],
+ ['unknown type', false],
+ ];
+ }
+
+ /**
+ * @dataProvider typeIconData
+ *
+ * @param string $type
+ * @param mixed $expected
+ */
+ public function testTypeIcon($type, $expected) {
+ $this->assertSame($expected, $this->activityExtension->getTypeIcon($type));
+ }
+
+ public function testGroupParameter() {
+ $this->assertFalse(
+ $this->activityExtension->getGroupParameter(['app' => 'files_sharing']),
+ 'Asserting that no group parameters are set for files_sharing'
+ );
+ }
+
+ public function testNavigation() {
+ $result = $this->activityExtension->getNavigation();
+ $this->assertCount(1, $result['top']);
+ $this->assertArrayHasKey(Activity::FILTER_FAVORITES, $result['top']);
+
+ $this->assertCount(1, $result['apps']);
+ $this->assertArrayHasKey(Activity::FILTER_FILES, $result['apps']);
+ }
+
+ public function testIsFilterValid() {
+ $this->assertTrue($this->activityExtension->isFilterValid(Activity::FILTER_FAVORITES));
+ $this->assertTrue($this->activityExtension->isFilterValid(Activity::FILTER_FILES));
+ $this->assertFalse($this->activityExtension->isFilterValid('unknown filter'));
+ }
+
+ public function filterNotificationTypesData() {
+ return [
+ [
+ Activity::FILTER_FILES,
+ [
+ 'NT0',
+ Activity::TYPE_SHARE_CREATED,
+ Activity::TYPE_SHARE_CHANGED,
+ Activity::TYPE_SHARE_DELETED,
+ Activity::TYPE_SHARE_RESTORED,
+ Activity::TYPE_FAVORITES,
+ ], [
+ Activity::TYPE_SHARE_CREATED,
+ Activity::TYPE_SHARE_CHANGED,
+ Activity::TYPE_SHARE_DELETED,
+ Activity::TYPE_SHARE_RESTORED,
+ ],
+ ],
+ [
+ Activity::FILTER_FILES,
+ [
+ 'NT0',
+ Activity::TYPE_SHARE_CREATED,
+ Activity::TYPE_FAVORITES,
+ ],
+ [
+ Activity::TYPE_SHARE_CREATED,
+ ],
+ ],
+ [
+ Activity::FILTER_FAVORITES,
+ [
+ 'NT0',
+ Activity::TYPE_SHARE_CREATED,
+ Activity::TYPE_SHARE_CHANGED,
+ Activity::TYPE_SHARE_DELETED,
+ Activity::TYPE_SHARE_RESTORED,
+ Activity::TYPE_FAVORITES,
+ ], [
+ Activity::TYPE_SHARE_CREATED,
+ Activity::TYPE_SHARE_CHANGED,
+ Activity::TYPE_SHARE_DELETED,
+ Activity::TYPE_SHARE_RESTORED,
+ ],
+ ],
+ [
+ 'unknown filter',
+ [
+ 'NT0',
+ Activity::TYPE_SHARE_CREATED,
+ Activity::TYPE_SHARE_CHANGED,
+ Activity::TYPE_SHARE_DELETED,
+ Activity::TYPE_SHARE_RESTORED,
+ Activity::TYPE_FAVORITES,
+ ],
+ false,
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider filterNotificationTypesData
+ *
+ * @param string $filter
+ * @param array $types
+ * @param mixed $expected
+ */
+ public function testFilterNotificationTypes($filter, $types, $expected) {
+ $result = $this->activityExtension->filterNotificationTypes($types, $filter);
+ $this->assertEquals($expected, $result);
+ }
+
+ public function queryForFilterData() {
+ return [
+ [
+ new \RuntimeException(),
+ '`app` = ?',
+ ['files']
+ ],
+ [
+ [
+ 'items' => [],
+ 'folders' => [],
+ ],
+ ' CASE WHEN `app` = ? THEN ((`type` <> ? AND `type` <> ?)) ELSE `app` <> ? END ',
+ ['files', Activity::TYPE_SHARE_CREATED, Activity::TYPE_SHARE_CHANGED, 'files']
+ ],
+ [
+ [
+ 'items' => ['file.txt', 'folder'],
+ 'folders' => ['folder'],
+ ],
+ ' CASE WHEN `app` = ? THEN ((`type` <> ? AND `type` <> ?) OR `file` = ? OR `file` = ? OR `file` LIKE ?) ELSE `app` <> ? END ',
+ ['files', Activity::TYPE_SHARE_CREATED, Activity::TYPE_SHARE_CHANGED, 'file.txt', 'folder', 'folder/%', 'files']
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider queryForFilterData
+ *
+ * @param mixed $will
+ * @param string $query
+ * @param array $parameters
+ */
+ public function testQueryForFilter($will, $query, $parameters) {
+ $this->mockUserSession('test');
+
+ $this->config->expects($this->any())
+ ->method('getUserValue')
+ ->willReturnMap([
+ ['test', 'activity', 'notify_stream_' . Activity::TYPE_FAVORITES, false, true],
+ ]);
+ if (is_array($will)) {
+ $this->activityHelper->expects($this->any())
+ ->method('getFavoriteFilePaths')
+ ->with('test')
+ ->willReturn($will);
+ } else {
+ $this->activityHelper->expects($this->any())
+ ->method('getFavoriteFilePaths')
+ ->with('test')
+ ->willThrowException($will);
+ }
+
+ $result = $this->activityExtension->getQueryForFilter('all');
+ $this->assertEquals([$query, $parameters], $result);
+ }
+
+ 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);
+ }
+}
diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php
index 789177bb353..34e7f5085dd 100644
--- a/apps/files/tests/ajax_rename.php
+++ b/apps/files/tests/ajax_rename.php
@@ -38,21 +38,15 @@ class Test_OC_Files_App_Rename extends \Test\TestCase {
*/
private $files;
- private $originalStorage;
-
protected function setUp() {
parent::setUp();
- $this->originalStorage = \OC\Files\Filesystem::getStorage('/');
-
// mock OC_L10n
if (!self::$user) {
self::$user = uniqid();
}
\OC_User::createUser(self::$user, 'password');
- \OC_User::setUserId(self::$user);
-
- \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
+ $this->loginAsUser(self::$user);
$l10nMock = $this->getMock('\OC_L10N', array('t'), array(), '', false);
$l10nMock->expects($this->any())
@@ -72,9 +66,8 @@ class Test_OC_Files_App_Rename extends \Test\TestCase {
protected function tearDown() {
$result = \OC_User::deleteUser(self::$user);
$this->assertTrue($result);
- \OC\Files\Filesystem::tearDown();
- \OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
+ $this->logout();
parent::tearDown();
}