aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Comments
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Comments')
-rw-r--r--tests/lib/Comments/CommentTest.php31
-rw-r--r--tests/lib/Comments/FakeFactory.php4
-rw-r--r--tests/lib/Comments/FakeManager.php1
-rw-r--r--tests/lib/Comments/ManagerTest.php64
4 files changed, 41 insertions, 59 deletions
diff --git a/tests/lib/Comments/CommentTest.php b/tests/lib/Comments/CommentTest.php
index 988ffbe0e0b..4a320666c83 100644
--- a/tests/lib/Comments/CommentTest.php
+++ b/tests/lib/Comments/CommentTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,11 +9,13 @@ namespace Test\Comments;
use OC\Comments\Comment;
use OCP\Comments\IComment;
+use OCP\Comments\IllegalIDChangeException;
+use OCP\Comments\MessageTooLongException;
use Test\TestCase;
class CommentTest extends TestCase {
/**
- * @throws \OCP\Comments\IllegalIDChangeException
+ * @throws IllegalIDChangeException
*/
public function testSettersValidInput(): void {
$comment = new Comment();
@@ -62,7 +65,7 @@ class CommentTest extends TestCase {
public function testSetIdIllegalInput(): void {
- $this->expectException(\OCP\Comments\IllegalIDChangeException::class);
+ $this->expectException(IllegalIDChangeException::class);
$comment = new Comment();
@@ -71,7 +74,7 @@ class CommentTest extends TestCase {
}
/**
- * @throws \OCP\Comments\IllegalIDChangeException
+ * @throws IllegalIDChangeException
*/
public function testResetId(): void {
$comment = new Comment();
@@ -93,9 +96,7 @@ class CommentTest extends TestCase {
];
}
- /**
- * @dataProvider simpleSetterProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('simpleSetterProvider')]
public function testSimpleSetterInvalidInput($field, $input): void {
$this->expectException(\InvalidArgumentException::class);
@@ -118,9 +119,7 @@ class CommentTest extends TestCase {
];
}
- /**
- * @dataProvider roleSetterProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('roleSetterProvider')]
public function testSetRoleInvalidInput($role, $type, $id): void {
$this->expectException(\InvalidArgumentException::class);
@@ -131,7 +130,7 @@ class CommentTest extends TestCase {
public function testSetUberlongMessage(): void {
- $this->expectException(\OCP\Comments\MessageTooLongException::class);
+ $this->expectException(MessageTooLongException::class);
$comment = new Comment();
$msg = str_pad('', IComment::MAX_MESSAGE_LENGTH + 1, 'x');
@@ -158,11 +157,11 @@ class CommentTest extends TestCase {
/* author: */ 'alice'
],
[
- '@foobar and @barfoo you should know, @foo@bar.com is valid' .
- ' and so is @bar@foo.org@foobar.io I hope that clarifies everything.' .
- ' cc @23452-4333-54353-2342 @yolo!' .
- ' however the most important thing to know is that www.croissant.com/@oil is not valid' .
- ' and won\'t match anything at all',
+ '@foobar and @barfoo you should know, @foo@bar.com is valid'
+ . ' and so is @bar@foo.org@foobar.io I hope that clarifies everything.'
+ . ' cc @23452-4333-54353-2342 @yolo!'
+ . ' however the most important thing to know is that www.croissant.com/@oil is not valid'
+ . ' and won\'t match anything at all',
[
['type' => 'user', 'id' => 'bar@foo.org@foobar.io'],
['type' => 'user', 'id' => '23452-4333-54353-2342'],
@@ -206,12 +205,12 @@ class CommentTest extends TestCase {
}
/**
- * @dataProvider mentionsProvider
*
* @param string $message
* @param array $expectedMentions
* @param ?string $author
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('mentionsProvider')]
public function testMentions(string $message, array $expectedMentions, ?string $author = null): void {
$comment = new Comment();
$comment->setMessage($message);
diff --git a/tests/lib/Comments/FakeFactory.php b/tests/lib/Comments/FakeFactory.php
index 04604ab2b44..0c3241078d7 100644
--- a/tests/lib/Comments/FakeFactory.php
+++ b/tests/lib/Comments/FakeFactory.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,12 +7,13 @@
*/
namespace Test\Comments;
+use OCP\Comments\ICommentsManagerFactory;
use OCP\IServerContainer;
/**
* Class FakeFactory
*/
-class FakeFactory implements \OCP\Comments\ICommentsManagerFactory {
+class FakeFactory implements ICommentsManagerFactory {
public function __construct(IServerContainer $serverContainer) {
}
diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php
index 155bbc59dce..64a25ef46c8 100644
--- a/tests/lib/Comments/FakeManager.php
+++ b/tests/lib/Comments/FakeManager.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index fb2f913f291..bd991a5692a 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -43,7 +43,7 @@ class ManagerTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = Server::get(IDBConnection::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$sql = $this->connection->getDatabasePlatform()->getTruncateTableSQL('`*PREFIX*comments`');
@@ -96,7 +96,7 @@ class ManagerTest extends TestCase {
public function testGetCommentNotFound(): void {
- $this->expectException(\OCP\Comments\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
$manager = $this->getManager();
$manager->get('22');
@@ -116,7 +116,7 @@ class ManagerTest extends TestCase {
$creationDT = new \DateTime('yesterday');
$latestChildDT = new \DateTime();
- $qb = \OCP\Server::get(IDBConnection::class)->getQueryBuilder();
+ $qb = Server::get(IDBConnection::class)->getQueryBuilder();
$qb
->insert('comments')
->values([
@@ -158,7 +158,7 @@ class ManagerTest extends TestCase {
public function testGetTreeNotFound(): void {
- $this->expectException(\OCP\Comments\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
$manager = $this->getManager();
$manager->getTree('22');
@@ -376,9 +376,7 @@ class ManagerTest extends TestCase {
], $amount);
}
- /**
- * @dataProvider dataGetForObjectSince
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForObjectSince')]
public function testGetForObjectSince(?int $lastKnown, string $order, int $limit, int $resultFrom, int $resultTo): void {
$ids = [];
$ids[] = $this->addDatabaseEntry(0, 0);
@@ -424,9 +422,7 @@ class ManagerTest extends TestCase {
];
}
- /**
- * @dataProvider invalidCreateArgsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('invalidCreateArgsProvider')]
public function testCreateCommentInvalidArguments(string|int $aType, string|int $aId, string|int $oType, string|int $oId): void {
$this->expectException(\InvalidArgumentException::class);
@@ -450,7 +446,7 @@ class ManagerTest extends TestCase {
public function testDelete(): void {
- $this->expectException(\OCP\Comments\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
$manager = $this->getManager();
@@ -471,9 +467,7 @@ class ManagerTest extends TestCase {
$manager->get($id);
}
- /**
- * @dataProvider providerTestSave
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerTestSave')]
public function testSave(string $message, string $actorId, string $verb, ?string $parentId, ?string $id = ''): IComment {
$manager = $this->getManager();
$comment = new Comment();
@@ -564,7 +558,7 @@ class ManagerTest extends TestCase {
$manager->delete($comment->getId());
$comment->setMessage('very beautiful, I am really so much impressed!');
- $this->expectException(\OCP\Comments\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
$manager->save($comment);
}
@@ -613,9 +607,7 @@ class ManagerTest extends TestCase {
];
}
- /**
- * @dataProvider invalidActorArgsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('invalidActorArgsProvider')]
public function testDeleteReferencesOfActorInvalidInput(string|int $type, string|int $id): void {
$this->expectException(\InvalidArgumentException::class);
@@ -652,10 +644,10 @@ class ManagerTest extends TestCase {
}
public function testDeleteReferencesOfActorWithUserManagement(): void {
- $user = \OCP\Server::get(IUserManager::class)->createUser('xenia', 'NotAnEasyPassword123456+');
+ $user = Server::get(IUserManager::class)->createUser('xenia', 'NotAnEasyPassword123456+');
$this->assertInstanceOf(IUser::class, $user);
- $manager = \OCP\Server::get(ICommentsManager::class);
+ $manager = Server::get(ICommentsManager::class);
$comment = $manager->create('users', $user->getUID(), 'files', 'file64');
$comment
->setMessage('Most important comment I ever left on the Internet.')
@@ -680,9 +672,7 @@ class ManagerTest extends TestCase {
];
}
- /**
- * @dataProvider invalidObjectArgsProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('invalidObjectArgsProvider')]
public function testDeleteCommentsAtObjectInvalidInput(string|int $type, string|int $id): void {
$this->expectException(\InvalidArgumentException::class);
@@ -1006,9 +996,7 @@ class ManagerTest extends TestCase {
}
}
- /**
- * @dataProvider providerTestReactionAddAndDelete
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerTestReactionAddAndDelete')]
public function testReactionAddAndDelete(array $comments, array $reactionsExpected): void {
$this->skipIfNotSupport4ByteUTF();
$manager = $this->getManager();
@@ -1073,6 +1061,7 @@ class ManagerTest extends TestCase {
* @return array<string, IComment>
*/
private function proccessComments(array $data): array {
+ $this->connection->beginTransaction();
/** @var array<string, IComment> $comments */
$comments = [];
foreach ($data as $comment) {
@@ -1088,12 +1077,11 @@ class ManagerTest extends TestCase {
$comment = $this->testSave($message, $actorId, $verb, $parentId, $id);
$comments[$comment->getMessage() . '#' . $comment->getActorId()] = $comment;
}
+ $this->connection->commit();
return $comments;
}
- /**
- * @dataProvider providerTestRetrieveAllReactions
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerTestRetrieveAllReactions')]
public function testRetrieveAllReactions(array $comments, array $expected): void {
$this->skipIfNotSupport4ByteUTF();
$manager = $this->getManager();
@@ -2355,9 +2343,7 @@ class ManagerTest extends TestCase {
];
}
- /**
- * @dataProvider providerTestRetrieveAllReactionsWithSpecificReaction
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerTestRetrieveAllReactionsWithSpecificReaction')]
public function testRetrieveAllReactionsWithSpecificReaction(array $comments, string $reaction, array $expected): void {
$this->skipIfNotSupport4ByteUTF();
$manager = $this->getManager();
@@ -2410,9 +2396,7 @@ class ManagerTest extends TestCase {
];
}
- /**
- * @dataProvider providerTestGetReactionComment
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerTestGetReactionComment')]
public function testGetReactionComment(array $comments, array $expected, bool $notFound): void {
$this->skipIfNotSupport4ByteUTF();
$manager = $this->getManager();
@@ -2423,7 +2407,7 @@ class ManagerTest extends TestCase {
$expected = array_combine($keys, $expected);
if ($notFound) {
- $this->expectException(\OCP\Comments\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
}
$comment = $processedComments[$expected['message'] . '#' . $expected['actorId']];
$actual = $manager->getReactionComment((int)$comment->getParentId(), $comment->getActorType(), $comment->getActorId(), $comment->getMessage());
@@ -2479,9 +2463,7 @@ class ManagerTest extends TestCase {
];
}
- /**
- * @dataProvider providerTestReactionMessageSize
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerTestReactionMessageSize')]
public function testReactionMessageSize(string $reactionString, bool $valid): void {
$this->skipIfNotSupport4ByteUTF();
if (!$valid) {
@@ -2510,9 +2492,7 @@ class ManagerTest extends TestCase {
];
}
- /**
- * @dataProvider providerTestReactionsSummarizeOrdered
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerTestReactionsSummarizeOrdered')]
public function testReactionsSummarizeOrdered(array $comments, array $expected, bool $isFullMatch): void {
$this->skipIfNotSupport4ByteUTF();
$manager = $this->getManager();