aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Collaboration/Collaborators/UserPluginTest.php2
-rw-r--r--tests/lib/Comments/FakeManager.php4
-rw-r--r--tests/lib/Comments/ManagerTest.php49
-rw-r--r--tests/lib/Log/FileTest.php30
-rw-r--r--tests/lib/LoggerTest.php33
5 files changed, 105 insertions, 13 deletions
diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php
index 2c8297014d2..0d9d89c7f8b 100644
--- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php
@@ -656,7 +656,7 @@ class UserPluginTest extends TestCase {
[
'core' => [
'shareapi_allow_share_dialog_user_enumeration' => 'no',
- 'shareapi_restrict_user_enumeration_full_match_ignore_second_display_name' => 'yes',
+ 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn' => 'yes',
],
]
],
diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php
index 5406df96a96..0d615fd2632 100644
--- a/tests/lib/Comments/FakeManager.php
+++ b/tests/lib/Comments/FakeManager.php
@@ -141,4 +141,8 @@ class FakeManager implements ICommentsManager {
public function getLastCommentDateByActor(string $objectType, string $objectId, string $verb, string $actorType, array $actors): array {
return [];
}
+
+ public function deleteMessageExpiredAtObject(string $objectType, string $objectId): bool {
+ return true;
+ }
}
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index 6bcd0dec8ed..7c6971476c7 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -14,6 +14,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IInitialStateService;
use OCP\IUser;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -37,7 +38,7 @@ class ManagerTest extends TestCase {
$this->connection->prepare($sql)->execute();
}
- protected function addDatabaseEntry($parentId, $topmostParentId, $creationDT = null, $latestChildDT = null, $objectId = null) {
+ protected function addDatabaseEntry($parentId, $topmostParentId, $creationDT = null, $latestChildDT = null, $objectId = null, $expireDate = null) {
if (is_null($creationDT)) {
$creationDT = new \DateTime();
}
@@ -63,6 +64,7 @@ class ManagerTest extends TestCase {
'latest_child_timestamp' => $qb->createNamedParameter($latestChildDT, 'datetime'),
'object_type' => $qb->createNamedParameter('files'),
'object_id' => $qb->createNamedParameter($objectId),
+ 'expire_date' => $qb->createNamedParameter($expireDate, 'datetime'),
])
->execute();
@@ -701,6 +703,51 @@ class ManagerTest extends TestCase {
$this->assertTrue($wasSuccessful);
}
+ public function testDeleteMessageExpiredAtObject(): void {
+ $ids = [];
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours'));
+
+ $manager = new Manager(
+ $this->connection,
+ $this->createMock(LoggerInterface::class),
+ $this->createMock(IConfig::class),
+ Server::get(ITimeFactory::class),
+ new EmojiHelper($this->connection),
+ $this->createMock(IInitialStateService::class)
+ );
+
+ // just to make sure they are really set, with correct actor data
+ $comment = $manager->get((string) $ids[1]);
+ $this->assertSame($comment->getObjectType(), 'files');
+ $this->assertSame($comment->getObjectId(), 'file64');
+
+ $deleted = $manager->deleteMessageExpiredAtObject('files', 'file64');
+ $this->assertTrue($deleted);
+
+ $deleted = 0;
+ $exists = 0;
+ foreach ($ids as $id) {
+ try {
+ $manager->get((string) $id);
+ $exists++;
+ } catch (NotFoundException $e) {
+ $deleted++;
+ }
+ }
+ $this->assertSame($exists, 3);
+ $this->assertSame($deleted, 3);
+
+ // actor info is gone from DB, but when database interaction is alright,
+ // we still expect to get true back
+ $deleted = $manager->deleteMessageExpiredAtObject('files', 'file64');
+ $this->assertFalse($deleted);
+ }
+
public function testSetMarkRead() {
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
$user = $this->createMock(IUser::class);
diff --git a/tests/lib/Log/FileTest.php b/tests/lib/Log/FileTest.php
index 937b3c75448..703c4280f24 100644
--- a/tests/lib/Log/FileTest.php
+++ b/tests/lib/Log/FileTest.php
@@ -1,6 +1,8 @@
<?php
/**
*
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
@@ -18,6 +20,7 @@
namespace Test\Log;
use OC\Log\File;
+use OCP\IConfig;
use OCP\ILogger;
use Test\TestCase;
@@ -36,7 +39,7 @@ class FileTest extends TestCase {
$config = \OC::$server->getSystemConfig();
$this->restore_logfile = $config->getValue("logfile");
$this->restore_logdateformat = $config->getValue('logdateformat');
-
+
$config->setValue("logfile", $config->getValue('datadirectory') . "/logtest.log");
$this->logFile = new File($config->getValue('datadirectory') . '/logtest.log', '', $config);
}
@@ -55,7 +58,28 @@ class FileTest extends TestCase {
$this->logFile = new File($this->restore_logfile, '', $config);
parent::tearDown();
}
-
+
+ public function testLogging() {
+ $config = \OC::$server->get(IConfig::class);
+ # delete old logfile
+ unlink($config->getSystemValue('logfile'));
+
+ # set format & write log line
+ $config->setSystemValue('logdateformat', 'u');
+ $this->logFile->write('code', ['something' => 'extra', 'message' => 'Testing logging'], ILogger::ERROR);
+
+ # read log line
+ $handle = @fopen($config->getSystemValue('logfile'), 'r');
+ $line = fread($handle, 1000);
+ fclose($handle);
+
+ # check log has data content
+ $values = (array) json_decode($line, true);
+ $this->assertArrayNotHasKey('message', $values['data']);
+ $this->assertEquals('extra', $values['data']['something']);
+ $this->assertEquals('Testing logging', $values['message']);
+ }
+
public function testMicrosecondsLogTimestamp() {
$config = \OC::$server->getConfig();
# delete old logfile
@@ -69,7 +93,7 @@ class FileTest extends TestCase {
$handle = @fopen($config->getSystemValue('logfile'), 'r');
$line = fread($handle, 1000);
fclose($handle);
-
+
# check timestamp has microseconds part
$values = (array) json_decode($line);
$microseconds = $values['time'];
diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php
index 9b44fe198e2..bec2119a8ad 100644
--- a/tests/lib/LoggerTest.php
+++ b/tests/lib/LoggerTest.php
@@ -1,6 +1,9 @@
<?php
/**
* Copyright (c) 2014 Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
@@ -9,29 +12,32 @@
namespace Test;
use OC\Log;
+use OC\SystemConfig;
use OCP\ILogger;
use OCP\Log\IWriter;
+use OCP\Support\CrashReport\IRegistry;
+use PHPUnit\Framework\MockObject\MockObject;
class LoggerTest extends TestCase implements IWriter {
- /** @var \OC\SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var SystemConfig|MockObject */
private $config;
- /** @var \OCP\Support\CrashReport\IRegistry|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IRegistry|MockObject */
private $registry;
- /** @var \OCP\ILogger */
+ /** @var ILogger */
private $logger;
/** @var array */
- private $logs = [];
+ private array $logs = [];
protected function setUp(): void {
parent::setUp();
$this->logs = [];
- $this->config = $this->createMock(\OC\SystemConfig::class);
- $this->registry = $this->createMock(\OCP\Support\CrashReport\IRegistry::class);
+ $this->config = $this->createMock(SystemConfig::class);
+ $this->registry = $this->createMock(IRegistry::class);
$this->logger = new Log($this, $this->config, null, $this->registry);
}
@@ -63,12 +69,23 @@ class LoggerTest extends TestCase implements IWriter {
$this->assertEquals($expected, $this->getLogs());
}
- private function getLogs() {
+ public function testLoggingWithDataArray(): void {
+ $writerMock = $this->createMock(IWriter::class);
+ $logFile = new Log($writerMock, $this->config);
+ $writerMock->expects($this->once())->method('write')->with('no app in context', ['something' => 'extra', 'message' => 'Testing logging with john']);
+ $logFile->error('Testing logging with {user}', ['something' => 'extra', 'user' => 'john']);
+ }
+
+ private function getLogs(): array {
return $this->logs;
}
public function write(string $app, $message, int $level) {
- $this->logs[] = "$level $message";
+ $textMessage = $message;
+ if (is_array($message)) {
+ $textMessage = $message['message'];
+ }
+ $this->logs[] = $level . " " . $textMessage;
}
public function userAndPasswordData(): array {