Skip to content

test: Migrate remaining DAV tests to PHPUnit 10 #53146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/dav/lib/BulkUpload/MultipartRequestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public function __construct(
*/
private function parseBoundaryFromHeaders(string $contentType): string {
try {
if (!str_contains($contentType, ';')) {
throw new \InvalidArgumentException('No semicolon in header');
}
[$mimeType, $boundary] = explode(';', $contentType);
if (!str_contains($boundary, '=')) {
throw new \InvalidArgumentException('No equal in boundary header');
}
[$boundaryKey, $boundaryValue] = explode('=', $boundary);
} catch (\Exception $e) {
throw new BadRequest('Error while parsing boundary in Content-Type header.', Http::STATUS_BAD_REQUEST, $e);
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Avatars/AvatarHomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\DAV\Tests\Unit\Avatars;
namespace OCA\DAV\Tests\unit\Avatars;

use OCA\DAV\Avatars\AvatarHome;
use OCA\DAV\Avatars\AvatarNode;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Avatars/AvatarNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\DAV\Tests\Unit\Avatars;
namespace OCA\DAV\Tests\unit\Avatars;

use OCA\DAV\Avatars\AvatarNode;
use OCP\IAvatar;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Command/DeleteCalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\DAV\Tests\Command;
namespace OCA\DAV\Tests\unit\Command;

use OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CalDAV\CalDavBackend;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Command/ListAddressbooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Tests\Command;
namespace OCA\DAV\Tests\unit\Command;

use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\Command\ListAddressbooks;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Command/ListCalendarSharesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\DAV\Tests\Command;
namespace OCA\DAV\Tests\unit\Command;

use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\Command\ListCalendarShares;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Command/ListCalendarsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Tests\Command;
namespace OCA\DAV\Tests\unit\Command;

use OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CalDAV\CalDavBackend;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Command/MoveCalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Tests\Command;
namespace OCA\DAV\Tests\unit\Command;

use InvalidArgumentException;
use OCA\DAV\CalDAV\CalDavBackend;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-FileCopyrightText: 2018 ownCloud GmbH
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\DAV\Tests\Unit\Command;
namespace OCA\DAV\Tests\unit\Command;

use OCA\DAV\Command\RemoveInvalidShares;
use OCA\DAV\Connector\Sabre\Principal;
Expand Down
74 changes: 23 additions & 51 deletions apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand All @@ -14,6 +15,7 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Class LegacyPublicAuthTest
Expand All @@ -23,36 +25,20 @@
* @package OCA\DAV\Tests\unit\Connector
*/
class LegacyPublicAuthTest extends \Test\TestCase {

/** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
private $session;
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
private $request;
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
private $shareManager;
/** @var LegacyPublicAuth */
private $auth;
/** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
private $throttler;

/** @var string */
private $oldUser;
private ISession&MockObject $session;
private IRequest&MockObject $request;
private IManager&MockObject $shareManager;
private IThrottler&MockObject $throttler;
private LegacyPublicAuth $auth;
private string|false $oldUser;

protected function setUp(): void {
parent::setUp();

$this->session = $this->getMockBuilder(ISession::class)
->disableOriginalConstructor()
->getMock();
$this->request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
$this->shareManager = $this->getMockBuilder(IManager::class)
->disableOriginalConstructor()
->getMock();
$this->throttler = $this->getMockBuilder(IThrottler::class)
->disableOriginalConstructor()
->getMock();
$this->session = $this->createMock(ISession::class);
$this->request = $this->createMock(IRequest::class);
$this->shareManager = $this->createMock(IManager::class);
$this->throttler = $this->createMock(IThrottler::class);

$this->auth = new LegacyPublicAuth(
$this->request,
Expand All @@ -70,7 +56,9 @@ protected function tearDown(): void {

// Set old user
\OC_User::setUserId($this->oldUser);
\OC_Util::setupFS($this->oldUser);
if ($this->oldUser !== false) {
\OC_Util::setupFS($this->oldUser);
}

parent::tearDown();
}
Expand All @@ -86,9 +74,7 @@ public function testNoShare(): void {
}

public function testShareNoPassword(): void {
$share = $this->getMockBuilder(IShare::class)
->disableOriginalConstructor()
->getMock();
$share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn(null);

$this->shareManager->expects($this->once())
Expand All @@ -101,9 +87,7 @@ public function testShareNoPassword(): void {
}

public function testSharePasswordFancyShareType(): void {
$share = $this->getMockBuilder(IShare::class)
->disableOriginalConstructor()
->getMock();
$share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(42);

Expand All @@ -118,9 +102,7 @@ public function testSharePasswordFancyShareType(): void {


public function testSharePasswordRemote(): void {
$share = $this->getMockBuilder(IShare::class)
->disableOriginalConstructor()
->getMock();
$share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_REMOTE);

Expand All @@ -134,9 +116,7 @@ public function testSharePasswordRemote(): void {
}

public function testSharePasswordLinkValidPassword(): void {
$share = $this->getMockBuilder(IShare::class)
->disableOriginalConstructor()
->getMock();
$share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);

Expand All @@ -156,9 +136,7 @@ public function testSharePasswordLinkValidPassword(): void {
}

public function testSharePasswordMailValidPassword(): void {
$share = $this->getMockBuilder(IShare::class)
->disableOriginalConstructor()
->getMock();
$share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);

Expand All @@ -178,9 +156,7 @@ public function testSharePasswordMailValidPassword(): void {
}

public function testInvalidSharePasswordLinkValidSession(): void {
$share = $this->getMockBuilder(IShare::class)
->disableOriginalConstructor()
->getMock();
$share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
$share->method('getId')->willReturn('42');
Expand All @@ -204,9 +180,7 @@ public function testInvalidSharePasswordLinkValidSession(): void {
}

public function testSharePasswordLinkInvalidSession(): void {
$share = $this->getMockBuilder(IShare::class)
->disableOriginalConstructor()
->getMock();
$share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
$share->method('getId')->willReturn('42');
Expand All @@ -231,9 +205,7 @@ public function testSharePasswordLinkInvalidSession(): void {


public function testSharePasswordMailInvalidSession(): void {
$share = $this->getMockBuilder(IShare::class)
->disableOriginalConstructor()
->getMock();
$share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
$share->method('getId')->willReturn('42');
Expand Down
Loading
Loading