tests: Fix url generation mocks and cleanup some phpunit code

Signed-off-by: Julius Knorr <jus@bitgrid.net>
This commit is contained in:
Julius Knorr
2025-01-17 10:59:25 +01:00
parent 7b4586a43a
commit 5fb43086b6
11 changed files with 33 additions and 27 deletions

View File

@@ -284,7 +284,7 @@ class ActivityManagerTest extends TestCase {
$this->assertEquals($event, $actual);
}
public function dataSendToUsers() {
public static function dataSendToUsers() {
return [
[ActivityManager::DECK_OBJECT_BOARD],
[ActivityManager::DECK_OBJECT_CARD],
@@ -344,7 +344,7 @@ class ActivityManagerTest extends TestCase {
$this->invokePrivate($this->activityManager, 'sendToUsers', [$event]);
}
public function dataFindObjectForEntity() {
public static function dataFindObjectForEntity() {
$board = new Board();
$board->setId(1);
$stack = new Stack();

View File

@@ -123,7 +123,7 @@ class DeckProviderTest extends TestCase {
$this->provider->parse('en_US', $event, $event);
}
public function dataEventIcons() {
public static function dataEventIcons() {
return [
[ActivityManager::SUBJECT_LABEL_ASSIGN, 'core', 'actions/tag.svg'],
[ActivityManager::SUBJECT_CARD_CREATE, 'files', 'add-color.svg'],
@@ -166,7 +166,7 @@ class DeckProviderTest extends TestCase {
->with('deck.page.index')
->willReturn('http://localhost/index.php/apps/deck/');
$this->assertEquals(
'http://localhost/index.php/apps/deck/#board/1/card/1',
'http://localhost/index.php/apps/deck/board/1/card/1',
$this->provider->deckUrl('board/1/card/1')
);
}
@@ -202,7 +202,7 @@ class DeckProviderTest extends TestCase {
'type' => 'highlight',
'id' => 1,
'name' => 'Board',
'link' => '#/board/1',
'link' => 'board/1',
],
'user' => [
'type' => 'user',
@@ -319,9 +319,9 @@ class DeckProviderTest extends TestCase {
$expected = [
'board' => [
'type' => 'highlight',
'id' => 1,
'id' => '1',
'name' => 'Board name',
'link' => '#/board/1/',
'link' => 'board/1',
],
];
$actual = $this->invokePrivate($this->provider, 'parseParamForBoard', ['board', $subjectParams, $params]);

View File

@@ -47,7 +47,7 @@ class CardTest extends TestCase {
return $card;
}
public function dataDuedate() {
public static function dataDuedate() {
return [
[(new DateTime()), Card::DUEDATE_NOW],
[(new DateTime())->sub(new DateInterval('P1D')), Card::DUEDATE_OVERDUE],

View File

@@ -58,7 +58,7 @@ class ExceptionMiddlewareTest extends \Test\TestCase {
}
public function dataAfterException() {
public static function dataAfterException() {
return [
[new NoPermissionException('No permission'), 403, 'No permission'],
[new NotFoundException('Not found'), 404, 'Not found']

View File

@@ -76,6 +76,15 @@ class NotifierTest extends \Test\TestCase {
$this->l10nFactory->expects($this->once())
->method('get')
->willReturn($this->l10n);
$this->url->expects($this->any())
->method('linkToRouteAbsolute')
->willReturnCallback(function ($route) {
return match ($route) {
'deck.page.indexBoard' => '/board/123',
'deck.page.indexCard' => '/board/123/card/234',
};
});
}
public function testPrepareWrongApp() {
@@ -178,7 +187,7 @@ class NotifierTest extends \Test\TestCase {
$this->assertEquals($notification, $actualNotification);
}
public function dataPrepareCardAssigned() {
public static function dataPrepareCardAssigned() {
return [
[true], [false]
];
@@ -239,13 +248,13 @@ class NotifierTest extends \Test\TestCase {
'name' => 'Card title',
'boardname' => 'Board title',
'stackname' => null,
'link' => '#/board/123/card/123',
'link' => '/board/123/card/234',
],
'deck-board' => [
'type' => 'deck-board',
'id' => 123,
'name' => 'Board title',
'link' => '#/board/123',
'link' => '/board/123',
]
]);
@@ -266,7 +275,7 @@ class NotifierTest extends \Test\TestCase {
$this->assertEquals($notification, $actualNotification);
}
public function dataPrepareBoardShared() {
public static function dataPrepareBoardShared() {
return [
[true], [false]
];
@@ -321,7 +330,7 @@ class NotifierTest extends \Test\TestCase {
'type' => 'deck-board',
'id' => 123,
'name' => 'Board title',
'link' => '#/board/123',
'link' => '/board/123',
]
]);
@@ -347,11 +356,8 @@ class NotifierTest extends \Test\TestCase {
* @return Stack|MockObject
*/
private function buildMockStack(int $boardId = 999) {
$mockStack = $this->getMockBuilder(Stack::class)
->addMethods(['getBoardId'])
->getMock();
$mockStack->method('getBoardId')->willReturn($boardId);
return $mockStack;
$stack = new Stack();
$stack->setBoardId($boardId);
return $stack;
}
}

View File

@@ -42,7 +42,7 @@ class CardReferenceProviderTest extends TestCase {
private $l10n;
private $userId;
private $provider;
public function setUp() : void {
parent::setUp();

View File

@@ -102,7 +102,7 @@ class FilterStringParserTest extends TestCase {
Assert::assertEquals($expected, $result);
}
public function dataParseDate() {
public static function dataParseDate() {
return [
['date:today', [new DateQueryParameter('date', SearchQuery::COMPARATOR_EQUAL, 'today')], []],
['date:>today', [new DateQueryParameter('date', SearchQuery::COMPARATOR_MORE, 'today')], []],

View File

@@ -29,7 +29,7 @@ namespace OCA\Deck\Search\Query;
use PHPUnit\Framework\TestCase;
class AQueryParameterTest extends TestCase {
public function dataValue() {
public static function dataValue() {
return [
['foo', 'foo'],
['spätial character', 'spätial character'],

View File

@@ -291,7 +291,7 @@ class BoardServiceTest extends TestCase {
));
}
public function dataAddAclExtendPermission() {
public static function dataAddAclExtendPermission() {
return [
[[false, false, false], [false, false, false], [false, false, false]],
[[false, false, false], [true, true, true], [false, false, false]],

View File

@@ -365,7 +365,7 @@ class CardServiceTest extends TestCase {
$this->cardService->rename(123, 'newtitle');
}
public function dataReorder() {
public static function dataReorder() {
return [
[0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]],
[0, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]],

View File

@@ -151,7 +151,7 @@ class PermissionServiceTest extends \Test\TestCase {
$this->assertEquals(false, $this->service->userIsBoardOwner(123));
}
public function dataTestUserCan() {
public static function dataTestUserCan() {
return [
// participant permissions type
['admin', false, false, false, 'user', true, false, false, false],
@@ -183,7 +183,7 @@ class PermissionServiceTest extends \Test\TestCase {
$this->assertFalse($this->service->userCan([], Acl::PERMISSION_EDIT));
}
public function dataCheckPermission() {
public static function dataCheckPermission() {
return [
// see getAcls() for set permissions
[1, Acl::PERMISSION_READ, true],