2021-01-07 10:26:51 -05:00
< ? php
declare ( strict_types = 1 );
/**
2024-06-03 04:23:34 -04:00
* SPDX - FileCopyrightText : 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2021-01-07 10:26:51 -05:00
*/
2025-05-16 17:04:36 -04:00
namespace OCA\Settings\Tests\SetupChecks ;
2021-01-07 10:26:51 -05:00
use OCA\Settings\SetupChecks\SupportedDatabase ;
2023-11-16 05:48:04 -05:00
use OCP\IDBConnection ;
2021-01-07 10:26:51 -05:00
use OCP\IL10N ;
2025-05-16 17:04:36 -04:00
use OCP\IURLGenerator ;
2024-10-10 06:40:31 -04:00
use OCP\Server ;
2023-10-09 12:03:25 -04:00
use OCP\SetupCheck\SetupResult ;
2021-01-07 10:26:51 -05:00
use Test\TestCase ;
/**
* @ group DB
*/
class SupportedDatabaseTest extends TestCase {
2023-11-16 05:48:04 -05:00
private IL10N $l10n ;
private IUrlGenerator $urlGenerator ;
private IDBConnection $connection ;
private SupportedDatabase $check ;
protected function setUp () : void {
parent :: setUp ();
2025-05-16 17:04:36 -04:00
$this -> l10n = $this -> createMock ( IL10N :: class );
$this -> urlGenerator = $this -> createMock ( IURLGenerator :: class );
2024-10-10 06:40:31 -04:00
$this -> connection = Server :: get ( IDBConnection :: class );
2023-11-16 05:48:04 -05:00
$this -> check = new SupportedDatabase (
$this -> l10n ,
$this -> urlGenerator ,
2024-10-10 06:40:31 -04:00
Server :: get ( IDBConnection :: class )
2023-11-16 05:48:04 -05:00
);
}
2021-01-07 10:26:51 -05:00
public function testPass () : void {
2025-12-01 09:26:37 -05:00
$severities = [ SetupResult :: SUCCESS , SetupResult :: INFO ];
2024-07-01 10:59:47 -04:00
if ( $this -> connection -> getDatabaseProvider () === IDBConnection :: PLATFORM_SQLITE ) {
2025-12-01 09:26:37 -05:00
$severities = [ SetupResult :: WARNING ];
} elseif ( $this -> connection -> getDatabaseProvider ( true ) === IDBConnection :: PLATFORM_ORACLE ) {
$result = $this -> connection -> executeQuery ( 'SELECT VERSION FROM PRODUCT_COMPONENT_VERSION' );
$version = $result -> fetchOne ();
$result -> closeCursor ();
if ( str_starts_with ( $version , '11.' )) {
$severities = [ SetupResult :: WARNING ];
}
2023-11-16 05:48:04 -05:00
}
2025-12-01 09:26:37 -05:00
$this -> assertContains ( $this -> check -> run () -> getSeverity (), $severities , 'Oracle 11 and SQLite expect a warning, other databases should be success or info only' );
2021-01-07 10:26:51 -05:00
}
}