Skip to content
Merged
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
18 changes: 12 additions & 6 deletions tests/unit/Controller/ImportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\IUserFolder;
use OCP\IAddressBook;
use OCP\ICreateContactFromString;
use OCP\IL10N;
Expand Down Expand Up @@ -64,6 +65,11 @@ protected function setUp(): void {
);
}

// IUserFolder only exists since server 36, CI still runs stable33-35
private function createUserFolderMock(): Folder&MockObject {
return $this->createMock(interface_exists(IUserFolder::class) ? IUserFolder::class : Folder::class);
}

public static function provideImportFileData(): array {
return [
// Correct mime type and ending
Expand Down Expand Up @@ -108,7 +114,7 @@ public function testImport(string $mimeType, string $extension): void {
$file->expects(self::once())
->method('getContent')
->willReturn($vCards);
$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createUserFolderMock();
$userFolder->expects(self::once())
->method('getFirstNodeById')
->with(42)
Expand Down Expand Up @@ -194,7 +200,7 @@ public function testImportWithDefaultAddressBook(MockObject $addressBook): void
$file->expects(self::once())
->method('getContent')
->willReturn($vCards);
$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createUserFolderMock();
$userFolder->expects(self::once())
->method('getFirstNodeById')
->with(42)
Expand Down Expand Up @@ -245,7 +251,7 @@ public function testImportWithExisting(): void {
$file->expects(self::once())
->method('getContent')
->willReturn($vCard);
$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createUserFolderMock();
$userFolder->expects(self::once())
->method('getFirstNodeById')
->with(42)
Expand Down Expand Up @@ -412,7 +418,7 @@ public function testImportWithFileNotFound(): void {
$addressBook2,
]);

$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createUserFolderMock();
$userFolder->expects(self::once())
->method('getFirstNodeById')
->with(42)
Expand Down Expand Up @@ -447,7 +453,7 @@ public function testImportWithNotAFile(): void {
]);

$file = $this->createMock(Folder::class);
$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createUserFolderMock();
$userFolder->expects(self::once())
->method('getFirstNodeById')
->with(42)
Expand Down Expand Up @@ -486,7 +492,7 @@ public function testImportWithInvalidFileType(): void {
->willReturn('invalid/mimetype');
$file->method('getExtension')
->willReturn('baz');
$userFolder = $this->createMock(Folder::class);
$userFolder = $this->createUserFolderMock();
$userFolder->expects(self::once())
->method('getFirstNodeById')
->with(42)
Expand Down
Loading