summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/Collaboration/Collaborators/SearchResultTest.php105
-rw-r--r--tests/lib/Comments/FakeManager.php14
-rw-r--r--tests/lib/Comments/ManagerTest.php50
-rw-r--r--tests/lib/DB/MigratorTest.php39
-rw-r--r--tests/lib/Files/Type/DetectionTest.php2
-rw-r--r--tests/lib/L10N/L10nTest.php5
-rw-r--r--tests/lib/LoggerTest.php26
7 files changed, 216 insertions, 25 deletions
diff --git a/tests/lib/Collaboration/Collaborators/SearchResultTest.php b/tests/lib/Collaboration/Collaborators/SearchResultTest.php
new file mode 100644
index 00000000000..90ea90237a1
--- /dev/null
+++ b/tests/lib/Collaboration/Collaborators/SearchResultTest.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Joas Schilling
+ *
+ * @author 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 Test\Collaboration\Collaborators;
+
+
+use OC\Collaboration\Collaborators\Search;
+use OC\Collaboration\Collaborators\SearchResult;
+use OCP\Collaboration\Collaborators\ISearch;
+use OCP\Collaboration\Collaborators\ISearchPlugin;
+use OCP\Collaboration\Collaborators\SearchResultType;
+use OCP\IContainer;
+use OCP\Share;
+use Test\TestCase;
+
+class SearchResultTest extends TestCase {
+ /** @var IContainer|\PHPUnit_Framework_MockObject_MockObject */
+ protected $container;
+ /** @var ISearch */
+ protected $search;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->container = $this->createMock(IContainer::class);
+
+ $this->search = new Search($this->container);
+ }
+
+ public function dataAddResultSet() {
+ return [
+ [[], ['exact' => []]],
+ [['users' => ['exact' => null, 'loose' => []]], ['exact' => ['users' => []], 'users' => []]],
+ [['groups' => ['exact' => null, 'loose' => ['l1']]], ['exact' => ['groups' => []], 'groups' => ['l1']]],
+ [['users' => ['exact' => ['e1'], 'loose' => []]], ['exact' => ['users' => ['e1']], 'users' => []]],
+ ];
+ }
+
+ /**
+ * @dataProvider dataAddResultSet
+ * @param array $toAdd
+ * @param array $expected
+ */
+ public function testAddResultSet(array $toAdd, array $expected) {
+ $result = new SearchResult();
+
+ foreach ($toAdd as $type => $results) {
+ $result->addResultSet(new SearchResultType($type), $results['loose'], $results['exact']);
+ }
+
+ $this->assertEquals($expected, $result->asArray());
+ }
+
+ public function dataHasResult() {
+ $result = ['value' => ['shareWith' => 'l1']];
+ return [
+ [[],'users', 'n1', false],
+ [['users' => ['exact' => null, 'loose' => [$result]]], 'users', 'l1', true],
+ [['users' => ['exact' => null, 'loose' => [$result]]], 'users', 'l2', false],
+ [['users' => ['exact' => null, 'loose' => [$result]]], 'groups', 'l1', false],
+ [['users' => ['exact' => [$result], 'loose' => []]], 'users', 'l1', true],
+ [['users' => ['exact' => [$result], 'loose' => []]], 'users', 'l2', false],
+ [['users' => ['exact' => [$result], 'loose' => []]], 'groups', 'l1', false],
+
+ ];
+ }
+
+ /**
+ * @dataProvider dataHasResult
+ * @param array $toAdd
+ * @param string $type
+ * @param string $id
+ * @param bool $expected
+ */
+ public function testHasResult(array $toAdd, $type, $id, $expected) {
+ $result = new SearchResult();
+
+ foreach ($toAdd as $addType => $results) {
+ $result->addResultSet(new SearchResultType($addType), $results['loose'], $results['exact']);
+ }
+
+ $this->assertSame($expected, $result->hasResult(new SearchResultType($type), $id));
+ }
+
+}
diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php
index 840961fb901..d3dd1dfb58a 100644
--- a/tests/lib/Comments/FakeManager.php
+++ b/tests/lib/Comments/FakeManager.php
@@ -1,12 +1,14 @@
<?php
namespace Test\Comments;
+use OCP\Comments\IComment;
+use OCP\Comments\ICommentsManager;
use OCP\IUser;
/**
* Class FakeManager
*/
-class FakeManager implements \OCP\Comments\ICommentsManager {
+class FakeManager implements ICommentsManager {
public function get($id) {}
@@ -26,17 +28,17 @@ class FakeManager implements \OCP\Comments\ICommentsManager {
public function delete($id) {}
- public function save(\OCP\Comments\IComment $comment) {}
+ public function save(IComment $comment) {}
public function deleteReferencesOfActor($actorType, $actorId) {}
public function deleteCommentsAtObject($objectType, $objectId) {}
- public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user) {}
+ public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) {}
- public function getReadMark($objectType, $objectId, \OCP\IUser $user) {}
+ public function getReadMark($objectType, $objectId, IUser $user) {}
- public function deleteReadMarksFromUser(\OCP\IUser $user) {}
+ public function deleteReadMarksFromUser(IUser $user) {}
public function deleteReadMarksOnObject($objectType, $objectId) {}
@@ -47,4 +49,6 @@ class FakeManager implements \OCP\Comments\ICommentsManager {
public function resolveDisplayName($type, $id) {}
public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) {}
+
+ public function getActorsInTree($id) {}
}
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index b04f3bd567e..671389232e2 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -3,12 +3,13 @@
namespace Test\Comments;
use OC\Comments\Comment;
-use OCP\Comments\CommentsEvent;
+use OC\Comments\ManagerFactory;
+use OCP\Comments\IComment;
use OCP\Comments\ICommentsEventHandler;
use OCP\Comments\ICommentsManager;
+use OCP\Comments\NotFoundException;
use OCP\IDBConnection;
use OCP\IUser;
-use Test\Files\Storage\DummyUser;
use Test\TestCase;
/**
@@ -62,7 +63,7 @@ class ManagerTest extends TestCase {
}
protected function getManager() {
- $factory = new \OC\Comments\ManagerFactory(\OC::$server);
+ $factory = new ManagerFactory(\OC::$server);
return $factory->getManager();
}
@@ -109,7 +110,7 @@ class ManagerTest extends TestCase {
$id = strval($qb->getLastInsertId());
$comment = $manager->get($id);
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$this->assertSame($comment->getId(), $id);
$this->assertSame($comment->getParentId(), '2');
$this->assertSame($comment->getTopmostParentId(), '1');
@@ -152,14 +153,14 @@ class ManagerTest extends TestCase {
// Verifying the root comment
$this->assertTrue(isset($tree['comment']));
- $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($tree['comment'] instanceof IComment);
$this->assertSame($tree['comment']->getId(), strval($headId));
$this->assertTrue(isset($tree['replies']));
$this->assertSame(count($tree['replies']), 3);
// one level deep
foreach ($tree['replies'] as $reply) {
- $this->assertTrue($reply['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($reply['comment'] instanceof IComment);
$this->assertSame($reply['comment']->getId(), strval($id));
$this->assertSame(count($reply['replies']), 0);
$id--;
@@ -174,7 +175,7 @@ class ManagerTest extends TestCase {
// Verifying the root comment
$this->assertTrue(isset($tree['comment']));
- $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($tree['comment'] instanceof IComment);
$this->assertSame($tree['comment']->getId(), strval($id));
$this->assertTrue(isset($tree['replies']));
$this->assertSame(count($tree['replies']), 0);
@@ -200,14 +201,14 @@ class ManagerTest extends TestCase {
// Verifying the root comment
$this->assertTrue(isset($tree['comment']));
- $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($tree['comment'] instanceof IComment);
$this->assertSame($tree['comment']->getId(), strval($headId));
$this->assertTrue(isset($tree['replies']));
$this->assertSame(count($tree['replies']), 2);
// one level deep
foreach ($tree['replies'] as $reply) {
- $this->assertTrue($reply['comment'] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($reply['comment'] instanceof IComment);
$this->assertSame($reply['comment']->getId(), strval($idToVerify));
$this->assertSame(count($reply['replies']), 0);
$idToVerify--;
@@ -223,7 +224,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(is_array($comments));
$this->assertSame(count($comments), 1);
- $this->assertTrue($comments[0] instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comments[0] instanceof IComment);
$this->assertSame($comments[0]->getMessage(), 'nice one');
}
@@ -243,7 +244,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(is_array($comments));
foreach ($comments as $comment) {
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$this->assertSame($comment->getMessage(), 'nice one');
$this->assertSame($comment->getId(), strval($idToVerify));
$idToVerify--;
@@ -282,7 +283,7 @@ class ManagerTest extends TestCase {
$this->assertTrue(is_array($comments));
foreach ($comments as $comment) {
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$this->assertSame($comment->getMessage(), 'nice one');
$this->assertSame($comment->getId(), strval($idToVerify));
$this->assertTrue(intval($comment->getId()) >= 4);
@@ -334,6 +335,7 @@ class ManagerTest extends TestCase {
$this->addDatabaseEntry(0, 0, null, null, $fileIds[$i]);
}
$this->addDatabaseEntry(0, 0, (new \DateTime())->modify('-2 days'), null, $fileIds[0]);
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
@@ -368,6 +370,10 @@ class ManagerTest extends TestCase {
/**
* @dataProvider invalidCreateArgsProvider
* @expectedException \InvalidArgumentException
+ * @param string $aType
+ * @param string $aId
+ * @param string $oType
+ * @param string $oId
*/
public function testCreateCommentInvalidArguments($aType, $aId, $oType, $oId) {
$manager = $this->getManager();
@@ -381,7 +387,7 @@ class ManagerTest extends TestCase {
$objectId = 'bielefeld';
$comment = $this->getManager()->create($actorType, $actorId, $objectType, $objectId);
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$this->assertSame($comment->getActorType(), $actorType);
$this->assertSame($comment->getActorId(), $actorId);
$this->assertSame($comment->getObjectType(), $objectType);
@@ -405,7 +411,7 @@ class ManagerTest extends TestCase {
$id = strval($this->addDatabaseEntry(0, 0));
$comment = $manager->get($id);
- $this->assertTrue($comment instanceof \OCP\Comments\IComment);
+ $this->assertTrue($comment instanceof IComment);
$done = $manager->delete($id);
$this->assertTrue($done);
$manager->get($id);
@@ -515,6 +521,8 @@ class ManagerTest extends TestCase {
/**
* @dataProvider invalidActorArgsProvider
* @expectedException \InvalidArgumentException
+ * @param string $type
+ * @param string $id
*/
public function testDeleteReferencesOfActorInvalidInput($type, $id) {
$manager = $this->getManager();
@@ -551,7 +559,7 @@ class ManagerTest extends TestCase {
public function testDeleteReferencesOfActorWithUserManagement() {
$user = \OC::$server->getUserManager()->createUser('xenia', '123456');
- $this->assertTrue($user instanceof \OCP\IUser);
+ $this->assertTrue($user instanceof IUser);
$manager = \OC::$server->getCommentsManager();
$comment = $manager->create('users', $user->getUID(), 'files', 'file64');
@@ -565,8 +573,8 @@ class ManagerTest extends TestCase {
$user->delete();
$comment = $manager->get($commentID);
- $this->assertSame($comment->getActorType(), \OCP\Comments\ICommentsManager::DELETED_USER);
- $this->assertSame($comment->getActorId(), \OCP\Comments\ICommentsManager::DELETED_USER);
+ $this->assertSame($comment->getActorType(), ICommentsManager::DELETED_USER);
+ $this->assertSame($comment->getActorId(), ICommentsManager::DELETED_USER);
}
public function invalidObjectArgsProvider() {
@@ -581,6 +589,8 @@ class ManagerTest extends TestCase {
/**
* @dataProvider invalidObjectArgsProvider
* @expectedException \InvalidArgumentException
+ * @param string $type
+ * @param string $id
*/
public function testDeleteCommentsAtObjectInvalidInput($type, $id) {
$manager = $this->getManager();
@@ -607,7 +617,7 @@ class ManagerTest extends TestCase {
foreach ($ids as $id) {
try {
$manager->get(strval($id));
- } catch (\OCP\Comments\NotFoundException $e) {
+ } catch (NotFoundException $e) {
$verified++;
}
}
@@ -620,6 +630,7 @@ class ManagerTest extends TestCase {
}
public function testSetMarkRead() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
@@ -636,6 +647,7 @@ class ManagerTest extends TestCase {
}
public function testSetMarkReadUpdate() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
@@ -655,6 +667,7 @@ class ManagerTest extends TestCase {
}
public function testReadMarkDeleteUser() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
@@ -672,6 +685,7 @@ class ManagerTest extends TestCase {
}
public function testReadMarkDeleteObject() {
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php
index e4f45c4bb86..ea718240c5e 100644
--- a/tests/lib/DB/MigratorTest.php
+++ b/tests/lib/DB/MigratorTest.php
@@ -41,6 +41,9 @@ class MigratorTest extends \Test\TestCase {
/** @var string */
private $tableName;
+ /** @var string */
+ private $tableNameTmp;
+
protected function setUp() {
parent::setUp();
@@ -50,11 +53,23 @@ class MigratorTest extends \Test\TestCase {
$this->markTestSkipped('DB migration tests are not supported on OCI');
}
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
- $this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_'));
+ $this->tableName = $this->getUniqueTableName();
+ $this->tableNameTmp = $this->getUniqueTableName();
+ }
+
+ private function getUniqueTableName() {
+ return strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_'));
}
protected function tearDown() {
- $this->connection->exec('DROP TABLE ' . $this->tableName);
+ // Try to delete if exists (IF EXISTS NOT SUPPORTED IN ORACLE)
+ try {
+ $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableNameTmp));
+ } catch (\Doctrine\DBAL\DBALException $e) {}
+
+ try {
+ $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableName));
+ } catch (\Doctrine\DBAL\DBALException $e) {}
parent::tearDown();
}
@@ -200,4 +215,24 @@ class MigratorTest extends \Test\TestCase {
$this->assertTrue(true);
}
+
+ public function testAddingForeignKey() {
+ $startSchema = new Schema([], [], $this->getSchemaConfig());
+ $table = $startSchema->createTable($this->tableName);
+ $table->addColumn('id', 'integer', ['autoincrement' => true]);
+ $table->addColumn('name', 'string');
+ $table->setPrimaryKey(['id']);
+
+ $fkName = "fkc";
+ $tableFk = $startSchema->createTable($this->tableNameTmp);
+ $tableFk->addColumn('fk_id', 'integer');
+ $tableFk->addColumn('name', 'string');
+ $tableFk->addForeignKeyConstraint($this->tableName, array('fk_id'), array('id'), array(), $fkName);
+
+ $migrator = $this->manager->getMigrator();
+ $migrator->migrate($startSchema);
+
+
+ $this->assertTrue($startSchema->getTable($this->tableNameTmp)->hasForeignKey($fkName));
+ }
}
diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php
index 295b9bf9fac..1d01a96fcc0 100644
--- a/tests/lib/Files/Type/DetectionTest.php
+++ b/tests/lib/Files/Type/DetectionTest.php
@@ -84,6 +84,8 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals('application/octet-stream', $this->detection->detectPath('..hidden'));
$this->assertEquals('application/octet-stream', $this->detection->detectPath('foo'));
$this->assertEquals('application/octet-stream', $this->detection->detectPath(''));
+ $this->assertEquals('image/png', $this->detection->detectPath('foo.png.ocTransferId123456789.part'));
+ $this->assertEquals('image/png', $this->detection->detectPath('foo.png.v1234567890'));
}
public function testDetectString() {
diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php
index 6d662efee23..703aa9e227c 100644
--- a/tests/lib/L10N/L10nTest.php
+++ b/tests/lib/L10N/L10nTest.php
@@ -164,4 +164,9 @@ class L10nTest extends TestCase {
$l = \OC::$server->getL10N('lib', 'de');
$this->assertEquals('de', $l->getLanguageCode());
}
+
+ public function testWeekdayName() {
+ $l = \OC::$server->getL10N('lib', 'de');
+ $this->assertEquals('Mo.', $l->l('weekdayName', new \DateTime('2017-11-6'), ['width' => 'abbreviated']));
+ }
}
diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php
index da9cedc9f56..3a30bbd1d3b 100644
--- a/tests/lib/LoggerTest.php
+++ b/tests/lib/LoggerTest.php
@@ -138,6 +138,32 @@ class LoggerTest extends TestCase {
}
}
+ /**
+ * @dataProvider userAndPasswordData
+ */
+ public function testDetectclosure($user, $password) {
+ $a = function($user, $password) {
+ throw new \Exception('test');
+ };
+
+ try {
+ $a($user, $password);
+ } catch (\Exception $e) {
+ $this->logger->logException($e);
+ }
+ $logLines = $this->getLogs();
+
+ foreach($logLines as $logLine) {
+ $log = explode('\n', $logLine);
+ unset($log[1]); // Remove `testDetectclosure(` because we are not testing this here, but the closure on stack trace 0
+ $logLine = implode('\n', $log);
+
+ $this->assertNotContains($user, $logLine);
+ $this->assertNotContains($password, $logLine);
+ $this->assertContains('{closure}(*** sensitive parameters replaced ***)', $logLine);
+ }
+ }
+
public function dataGetLogClass() {
return [
['file', \OC\Log\File::class],