Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_automatedtagging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2019-02-15 18:58:07 +0300
committerRobin Appelman <robin@icewind.nl>2019-02-15 19:32:41 +0300
commitf8d2c16e03597bfe4a0efeb6b957fa0f02b9d6c5 (patch)
tree34316d347ff40ce8b8a8b8f6f364b118166cd2d1 /tests
parentb400f11cd670eb1b44205bb9132510aab27575cd (diff)
use cache insert event for automated tagging
Diffstat (limited to 'tests')
-rw-r--r--tests/CacheWrapperTest.php81
-rw-r--r--tests/OperationTest.php36
-rw-r--r--tests/StorageWrapperTest.php80
3 files changed, 34 insertions, 163 deletions
diff --git a/tests/CacheWrapperTest.php b/tests/CacheWrapperTest.php
deleted file mode 100644
index d3e6e2d..0000000
--- a/tests/CacheWrapperTest.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\FilesAutomatedTagging\Tests;
-
-use OCA\FilesAutomatedTagging\CacheWrapper;
-use Test\TestCase;
-
-class CacheWrapperTest extends TestCase {
-
- /** @var \OCP\Files\Cache\ICache|\PHPUnit_Framework_MockObject_MockObject */
- protected $cache;
- /** @var \OCP\Files\Storage\IStorage|\PHPUnit_Framework_MockObject_MockObject */
- protected $storage;
- /** @var \OCA\FilesAutomatedTagging\Operation|\PHPUnit_Framework_MockObject_MockObject */
- protected $operation;
-
- protected function setUp() {
- parent::setUp();
-
- $this->cache = $this->getMockBuilder('OCP\Files\Cache\ICache')
- ->getMock();
- $this->storage = $this->getMockBuilder('OCP\Files\Storage\IStorage')
- ->getMock();
- $this->operation = $this->getMockBuilder('OCA\FilesAutomatedTagging\Operation')
- ->disableOriginalConstructor()
- ->getMock();
- }
-
- public function dataInsert() {
- return [
- ['/admin', '/files/file', ['data1'], 123, true],
- ['/admin/files/externalstorage', '/file', ['data3'], 123, true],
- ['/admin', '/files', ['data3'], 123, false],
- ['/admin', '/file', ['data2'], -1, false],
- ['/admin', '/cache/file', ['data3'], 123, false],
- ];
- }
-
- /**
- * @dataProvider dataInsert
- *
- * @param string $mountPoint
- * @param string $path
- * @param array $data
- * @param int $fileId
- * @param bool $checkOperations
- */
- public function testInsert($mountPoint, $path, array $data, $fileId, $checkOperations) {
- $test = new CacheWrapper($this->cache, $this->storage, $this->operation, $mountPoint);
-
- $this->cache->expects($this->once())
- ->method('insert')
- ->with($path, $data)
- ->willReturn($fileId);
-
- $this->operation->expects($checkOperations ? $this->once() : $this->never())
- ->method('checkOperations')
- ->with($this->storage, $fileId, $path);
-
- $test->insert($path, $data);
- }
-}
diff --git a/tests/OperationTest.php b/tests/OperationTest.php
index 9ac5786..513db88 100644
--- a/tests/OperationTest.php
+++ b/tests/OperationTest.php
@@ -21,8 +21,11 @@
namespace OCA\FilesAutomatedTagging\Tests;
+use OC\Files\Storage\Home;
+use OC\Files\Storage\Local;
use OCA\FilesAutomatedTagging\Operation;
use OCP\Files\Storage\IStorage;
+use OCP\IConfig;
use Test\TestCase;
class OperationTest extends TestCase {
@@ -35,6 +38,8 @@ class OperationTest extends TestCase {
protected $checkManager;
/** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject */
protected $l;
+ /** @var \OCP\IConfig\\PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
/** @var \OCA\FilesAutomatedTagging\Operation */
protected $operation;
@@ -49,8 +54,11 @@ class OperationTest extends TestCase {
->getMock();
$this->l = $this->getMockBuilder('OCP\IL10N')
->getMock();
+ $this->config = $this->createMock(IConfig::class);
+ $this->config->method('getSystemValue')
+ ->willReturn('instanceid');
$this->operation = new Operation(
- $this->objectMapper, $this->tagManager, $this->checkManager, $this->l
+ $this->objectMapper, $this->tagManager, $this->checkManager, $this->l, $this->config
);
}
@@ -68,7 +76,7 @@ class OperationTest extends TestCase {
[$this->getStorageMock(), 23, 'path2', [
['operation' => '2,3'],
['operation' => '42']
- ],[
+ ], [
[2, 3],
[42],
]],
@@ -103,4 +111,28 @@ class OperationTest extends TestCase {
$this->operation->checkOperations($storage, $fileId, $file);
}
+
+ public function taggingPathDataProvider() {
+ return [
+ [Home::class, 'trash/foo', false],
+ [Home::class, 'files/foo', true],
+ [Home::class, 'files', false],
+ [Local::class, 'foo', true],
+ [Local::class, 'appdata_instanceid/foo', false],
+ ];
+ }
+
+ /**
+ * @dataProvider taggingPathDataProvider
+ * @param string $storageClass
+ * @param string $path
+ * @param bool $expected
+ */
+ public function testIsTaggingPath(string $storageClass, string $path, bool $expected) {
+ $storage = $this->getMockBuilder($storageClass)
+ ->disableOriginalConstructor()
+ ->setMethodsExcept(['instanceOfStorage'])
+ ->getMock();
+ $this->assertEquals($expected, $this->operation->isTaggingPath($storage, $path));
+ }
}
diff --git a/tests/StorageWrapperTest.php b/tests/StorageWrapperTest.php
deleted file mode 100644
index 625dcfc..0000000
--- a/tests/StorageWrapperTest.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\FilesAutomatedTagging\Tests;
-
-use OCA\FilesAutomatedTagging\StorageWrapper;
-use Test\TestCase;
-
-class StorageWrapperTest extends TestCase {
-
- protected function getStorageMock() {
- return $this->getMockBuilder('OCP\Files\Storage\IStorage')
- ->getMock();
- }
-
- protected function getOperationMock() {
- return $this->getMockBuilder('OCA\FilesAutomatedTagging\Operation')
- ->disableOriginalConstructor()
- ->getMock();
- }
-
- public function dataGetCache() {
- return [
- [$this->getStorageMock(), $this->getOperationMock(), 'mountPoint1', 'path1', $this->getStorageMock()],
- [$this->getStorageMock(), $this->getOperationMock(), 'mountPoint2', 'path2', null],
- ];
- }
-
- /**
- * @dataProvider dataGetCache
- *
- * @param \OCP\Files\Storage\IStorage|\PHPUnit_Framework_MockObject_MockObject $constructorStorage
- * @param \OCA\FilesAutomatedTagging\Operation $operation
- * @param string $mountPoint
- * @param string $path
- * @param \OCP\Files\Storage\IStorage|null $storage
- */
- public function testGetCache($constructorStorage, $operation, $mountPoint, $path, $storage) {
- $test = new StorageWrapper([
- 'storage' => $constructorStorage,
- 'operation' => $operation,
- 'mountPoint' => $mountPoint,
- ]);
-
- $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')
- ->getMock();
- if ($storage === null) {
- $usedStorage = $test;
- } else {
- $usedStorage = $storage;
- }
-
- $constructorStorage->expects($this->once())
- ->method('getCache')
- ->with($path, $usedStorage)
- ->willReturn($cache);
-
- $test = $test->getCache($path, $storage);
-
- $this->assertInstanceOf('OCA\FilesAutomatedTagging\CacheWrapper', $test);
- }
-}