diff options
Diffstat (limited to 'tests/lib/IntegrityCheck')
5 files changed, 34 insertions, 19 deletions
diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php index c5a4f255397..a8a2596a3d8 100644 --- a/tests/lib/IntegrityCheck/CheckerTest.php +++ b/tests/lib/IntegrityCheck/CheckerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,6 +9,7 @@ namespace Test\IntegrityCheck; use OC\Core\Command\Maintenance\Mimetype\GenerateMimetypeFileBuilder; +use OC\Files\Type\Detection; use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Helpers\AppLocator; use OC\IntegrityCheck\Helpers\EnvironmentHelper; @@ -54,7 +56,7 @@ class CheckerTest extends TestCase { $this->appConfig = $this->createMock(IAppConfig::class); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->appManager = $this->createMock(IAppManager::class); - $this->mimeTypeDetector = $this->createMock(\OC\Files\Type\Detection::class); + $this->mimeTypeDetector = $this->createMock(Detection::class); $this->config->method('getAppValue') ->willReturnArgument(2); @@ -111,7 +113,7 @@ class CheckerTest extends TestCase { $this->fileAccessHelper ->expects($this->once()) ->method('file_put_contents') - ->will($this->throwException(new \Exception('Exception message'))); + ->willThrowException(new \Exception('Exception message')); $keyBundle = file_get_contents(__DIR__ . '/../../data/integritycheck/SomeApp.crt'); $rsaPrivateKey = file_get_contents(__DIR__ . '/../../data/integritycheck/SomeApp.key'); @@ -445,7 +447,7 @@ class CheckerTest extends TestCase { $this->fileAccessHelper ->expects($this->once()) ->method('assertDirectoryExists') - ->will($this->throwException(new \Exception('Exception message'))); + ->willThrowException(new \Exception('Exception message')); $this->fileAccessHelper ->expects($this->once()) ->method('is_writable') @@ -469,7 +471,7 @@ class CheckerTest extends TestCase { $this->fileAccessHelper ->expects($this->once()) ->method('assertDirectoryExists') - ->will($this->throwException(new \Exception('Exception message'))); + ->willThrowException(new \Exception('Exception message')); $this->fileAccessHelper ->expects($this->once()) ->method('is_writable') @@ -713,7 +715,9 @@ class CheckerTest extends TestCase { */ public function testVerifyCoreSignatureWithModifiedMimetypelistSignatureData(): void { $shippedMimetypeAliases = (array)json_decode(file_get_contents(\OC::$SERVERROOT . '/resources/config/mimetypealiases.dist.json')); + $shippedMimetypeNames = (array)json_decode(file_get_contents(\OC::$SERVERROOT . '/resources/config/mimetypenames.dist.json')); $allAliases = array_merge($shippedMimetypeAliases, ['my-custom/mimetype' => 'custom']); + $allMimetypeNames = array_merge($shippedMimetypeNames, ['my-custom/mimetype' => 'Custom Document']); $this->mimeTypeDetector ->method('getOnlyDefaultAliases') @@ -723,9 +727,14 @@ class CheckerTest extends TestCase { ->method('getAllAliases') ->willReturn($allAliases); + $this->mimeTypeDetector + ->method('getAllNamings') + ->willReturn($allMimetypeNames); + $oldMimetypeList = new GenerateMimetypeFileBuilder(); $all = $this->mimeTypeDetector->getAllAliases(); - $newFile = $oldMimetypeList->generateFile($all); + $namings = $this->mimeTypeDetector->getAllNamings(); + $newFile = $oldMimetypeList->generateFile($all, $namings); // When updating the mimetype list the test assets need to be updated as well // 1. Update core/js/mimetypelist.js with the new generated js by running the test with the next line uncommented: @@ -1070,8 +1079,8 @@ class CheckerTest extends TestCase { /** * @param string $channel * @param bool $isCodeSigningEnforced - * @dataProvider channelDataProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('channelDataProvider')] public function testIsCodeCheckEnforced($channel, $isCodeSigningEnforced): void { $this->serverVersion ->expects($this->once()) @@ -1088,8 +1097,8 @@ class CheckerTest extends TestCase { /** * @param string $channel - * @dataProvider channelDataProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('channelDataProvider')] public function testIsCodeCheckEnforcedWithDisabledConfigSwitch($channel): void { $this->serverVersion ->expects($this->once()) diff --git a/tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php b/tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php index 6d3006bb3c4..837b397ac1f 100644 --- a/tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php +++ b/tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -23,7 +24,7 @@ class AppLocatorTest extends TestCase { $this->assertSame(\OC_App::getAppPath('files'), $this->locator->getAppPath('files')); } - + public function testGetAppPathNotExistentApp(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('App not found'); diff --git a/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php b/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php index 379eb178b06..caa5ed2e782 100644 --- a/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php +++ b/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. diff --git a/tests/lib/IntegrityCheck/Helpers/FileAccessHelperTest.php b/tests/lib/IntegrityCheck/Helpers/FileAccessHelperTest.php index 866850b7cff..b8bec35328d 100644 --- a/tests/lib/IntegrityCheck/Helpers/FileAccessHelperTest.php +++ b/tests/lib/IntegrityCheck/Helpers/FileAccessHelperTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,6 +9,8 @@ namespace Test\IntegrityCheck\Helpers; use OC\IntegrityCheck\Helpers\FileAccessHelper; +use OCP\ITempManager; +use OCP\Server; use Test\TestCase; class FileAccessHelperTest extends TestCase { @@ -20,7 +23,7 @@ class FileAccessHelperTest extends TestCase { } public function testReadAndWrite(): void { - $tempManager = \OC::$server->getTempManager(); + $tempManager = Server::get(ITempManager::class); $filePath = $tempManager->getTemporaryFile(); $data = 'SomeDataGeneratedByIntegrityCheck'; @@ -28,7 +31,7 @@ class FileAccessHelperTest extends TestCase { $this->assertSame($data, $this->fileAccessHelper->file_get_contents($filePath)); } - + public function testFile_put_contentsWithException(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('Failed to write into /anabsolutelynotexistingfolder/on/the/system.txt'); @@ -38,10 +41,10 @@ class FileAccessHelperTest extends TestCase { public function testIs_writable(): void { $this->assertFalse($this->fileAccessHelper->is_writable('/anabsolutelynotexistingfolder/on/the/system.txt')); - $this->assertTrue($this->fileAccessHelper->is_writable(\OC::$server->getTempManager()->getTemporaryFile('MyFile'))); + $this->assertTrue($this->fileAccessHelper->is_writable(Server::get(ITempManager::class)->getTemporaryFile('MyFile'))); } - + public function testAssertDirectoryExistsWithException(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('Directory /anabsolutelynotexistingfolder/on/the/system does not exist.'); @@ -50,7 +53,7 @@ class FileAccessHelperTest extends TestCase { } public function testAssertDirectoryExists(): void { - $this->fileAccessHelper->assertDirectoryExists(\OC::$server->getTempManager()->getTemporaryFolder('/testfolder/')); + $this->fileAccessHelper->assertDirectoryExists(Server::get(ITempManager::class)->getTemporaryFolder('/testfolder/')); $this->addToAssertionCount(1); } } diff --git a/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php b/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php index 14cc8851178..dfd0941bd20 100644 --- a/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php +++ b/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2015 ownCloud, Inc. @@ -17,11 +18,11 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase { parent::setUp(); $this->filter = $this->getMockBuilder(ExcludeFileByNameFilterIterator::class) ->disableOriginalConstructor() - ->setMethods(['current']) + ->onlyMethods(['current']) ->getMock(); } - public function fileNameProvider(): array { + public static function fileNameProvider(): array { return [ ['a file', true], ['Thumbs.db', false], @@ -35,14 +36,14 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase { } /** - * @dataProvider fileNameProvider * @param string $fileName * @param bool $expectedResult */ + #[\PHPUnit\Framework\Attributes\DataProvider('fileNameProvider')] public function testAcceptForFiles($fileName, $expectedResult): void { $iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class) ->disableOriginalConstructor() - ->setMethods(['getFilename', 'isDir']) + ->onlyMethods(['getFilename', 'isDir']) ->getMock(); $iteratorMock->method('getFilename') @@ -57,14 +58,14 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase { } /** - * @dataProvider fileNameProvider * @param string $fileName * @param bool $expectedResult */ + #[\PHPUnit\Framework\Attributes\DataProvider('fileNameProvider')] public function testAcceptForDirs($fileName, $expectedResult): void { $iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class) ->disableOriginalConstructor() - ->setMethods(['getFilename', 'isDir']) + ->onlyMethods(['getFilename', 'isDir']) ->getMock(); $iteratorMock->method('getFilename') |