Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function __construct(array $parameters) {
$this->secure = false;
}
$this->root = isset($parameters['root']) ? '/' . ltrim($parameters['root']) : '/';
$this->port = $parameters['port'] ?? 21;
$parsedPort = $parameters['port'] ?? null;
$this->port = is_numeric($parsedPort) ? (int)$parsedPort : 21;
$this->utf8Mode = isset($parameters['utf8']) && $parameters['utf8'];
} else {
throw new \Exception('Creating ' . self::class . ' storage failed, required parameters not set');
Expand Down
45 changes: 45 additions & 0 deletions apps/files_external/tests/FtpConstructorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Files_External\Tests;

use OCA\Files_External\Lib\Storage\FTP;
use PHPUnit\Framework\Attributes\DataProvider;
use Test\TestCase;

/**
* The FTP connection is established lazily, so the constructor can be covered
* without a reachable FTP server. The backend tests in Storage/FtpTest.php do
* need one and are run separately.
*/
Comment on lines +16 to +20

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* The FTP connection is established lazily, so the constructor can be covered
* without a reachable FTP server. The backend tests in Storage/FtpTest.php do
* need one and are run separately.
*/

class FtpConstructorTest extends TestCase {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FtpTest would be more appropriate as class name

public static function portProvider(): array {
$parameters = [
'host' => 'somehost',
'user' => 'someuser',
'password' => 'somepassword',
];

return [
'no port given' => [$parameters, 21],
'empty port' => [array_merge($parameters, ['port' => '']), 21],
'null port' => [array_merge($parameters, ['port' => null]), 21],
'non numeric port' => [array_merge($parameters, ['port' => 'ftp']), 21],
'numeric string port' => [array_merge($parameters, ['port' => '2121']), 2121],
'integer port' => [array_merge($parameters, ['port' => 2121]), 2121],
];
}

#[DataProvider('portProvider')]
public function testPort(array $parameters, int $expectedPort): void {
$instance = new FTP($parameters);

$this->assertSame($expectedPort, self::invokePrivate($instance, 'port'));
}
}
Loading