aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-08-04 11:53:19 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2025-08-04 11:53:19 +0200
commitf95fef993887d16b756cbdb48271bfe991954a6c (patch)
treeeabed1cb4a6e5b113c1b267b81ac7febd93d3d2d
parentd711d68701318a5652b129c1a81f0f09a0052b70 (diff)
downloadnextcloud-server-fix/ignore-shares-in-encrypt-all.tar.gz
nextcloud-server-fix/ignore-shares-in-encrypt-all.zip
chore(encryption): Adapt tests to code changesfix/ignore-shares-in-encrypt-all
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/encryption/lib/Crypto/EncryptAll.php2
-rw-r--r--apps/encryption/tests/Crypto/EncryptAllTest.php33
-rw-r--r--tests/Core/Command/Encryption/EncryptAllTest.php55
3 files changed, 32 insertions, 58 deletions
diff --git a/apps/encryption/lib/Crypto/EncryptAll.php b/apps/encryption/lib/Crypto/EncryptAll.php
index 424513757d8..4ed75b85a93 100644
--- a/apps/encryption/lib/Crypto/EncryptAll.php
+++ b/apps/encryption/lib/Crypto/EncryptAll.php
@@ -203,7 +203,7 @@ class EncryptAll {
while ($root = array_pop($directories)) {
$content = $this->rootView->getDirectoryContent($root);
foreach ($content as $file) {
- $path = $root . '/' . $file['name'];
+ $path = $root . '/' . $file->getName();
if ($file->isShared()) {
$progress->setMessage("Skip shared file/folder $path");
$progress->advance();
diff --git a/apps/encryption/tests/Crypto/EncryptAllTest.php b/apps/encryption/tests/Crypto/EncryptAllTest.php
index 9b39c62b650..c56e3375a73 100644
--- a/apps/encryption/tests/Crypto/EncryptAllTest.php
+++ b/apps/encryption/tests/Crypto/EncryptAllTest.php
@@ -82,7 +82,7 @@ class EncryptAllTest extends TestCase {
/**
* We need format method to return a string
- * @var OutputFormatterInterface|\PHPUnit\Framework\MockObject\MockObject
+ * @var OutputFormatterInterface&MockObject
*/
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
$outputFormatter->method('isDecorated')->willReturn(false);
@@ -114,6 +114,13 @@ class EncryptAllTest extends TestCase {
);
}
+ protected function createFileInfoMock($type, string $name): FileInfo&MockObject {
+ $fileInfo = $this->createMock(FileInfo::class);
+ $fileInfo->method('getType')->willReturn($type);
+ $fileInfo->method('getName')->willReturn($name);
+ return $fileInfo;
+ }
+
public function testEncryptAll(): void {
/** @var EncryptAll&MockObject $encryptAll */
$encryptAll = $this->getMockBuilder(EncryptAll::class)
@@ -299,8 +306,8 @@ class EncryptAllTest extends TestCase {
'',
null,
[
- ['name' => 'foo', 'type' => 'dir'],
- ['name' => 'bar', 'type' => 'file'],
+ $this->createFileInfoMock(FileInfo::TYPE_FOLDER, 'foo'),
+ $this->createFileInfoMock(FileInfo::TYPE_FILE, 'bar'),
],
],
[
@@ -308,26 +315,17 @@ class EncryptAllTest extends TestCase {
'',
null,
[
- ['name' => 'subfile', 'type' => 'file']
+ $this->createFileInfoMock(FileInfo::TYPE_FILE, 'subfile'),
],
],
]);
- $this->view->expects($this->any())->method('is_dir')
- ->willReturnCallback(
- function ($path) {
- if ($path === '/user1/files/foo') {
- return true;
- }
- return false;
- }
- );
-
$encryptAllCalls = [];
$encryptAll->expects($this->exactly(2))
->method('encryptFile')
- ->willReturnCallback(function (string $path) use (&$encryptAllCalls): void {
+ ->willReturnCallback(function (FileInfo $file, string $path) use (&$encryptAllCalls): bool {
$encryptAllCalls[] = $path;
+ return true;
});
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
@@ -362,8 +360,7 @@ class EncryptAllTest extends TestCase {
$fileInfo = $this->createMock(FileInfo::class);
$fileInfo->expects($this->any())->method('isEncrypted')
->willReturn($isEncrypted);
- $this->view->expects($this->any())->method('getFileInfo')
- ->willReturn($fileInfo);
+ $this->view->expects($this->never())->method('getFileInfo');
if ($isEncrypted) {
@@ -375,7 +372,7 @@ class EncryptAllTest extends TestCase {
}
$this->assertTrue(
- $this->invokePrivate($this->encryptAll, 'encryptFile', ['foo.txt'])
+ $this->invokePrivate($this->encryptAll, 'encryptFile', [$fileInfo, 'foo.txt'])
);
}
diff --git a/tests/Core/Command/Encryption/EncryptAllTest.php b/tests/Core/Command/Encryption/EncryptAllTest.php
index 6332c936a98..15cbe83737d 100644
--- a/tests/Core/Command/Encryption/EncryptAllTest.php
+++ b/tests/Core/Command/Encryption/EncryptAllTest.php
@@ -13,59 +13,36 @@ use OCP\App\IAppManager;
use OCP\Encryption\IEncryptionModule;
use OCP\Encryption\IManager;
use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
class EncryptAllTest extends TestCase {
- /** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */
- protected $config;
+ private IConfig&MockObject $config;
+ private IManager&MockObject $encryptionManager;
+ private IAppManager&MockObject $appManager;
+ private InputInterface&MockObject $consoleInput;
+ private OutputInterface&MockObject $consoleOutput;
+ private QuestionHelper&MockObject $questionHelper;
+ private IEncryptionModule&MockObject $encryptionModule;
- /** @var \PHPUnit\Framework\MockObject\MockObject | \OCP\Encryption\IManager */
- protected $encryptionManager;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IAppManager */
- protected $appManager;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Input\InputInterface */
- protected $consoleInput;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Output\OutputInterface */
- protected $consoleOutput;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Helper\QuestionHelper */
- protected $questionHelper;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IEncryptionModule */
- protected $encryptionModule;
-
- /** @var EncryptAll */
- protected $command;
+ private EncryptAll $command;
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->encryptionManager = $this->getMockBuilder(IManager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->appManager = $this->getMockBuilder(IAppManager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->encryptionModule = $this->getMockBuilder(IEncryptionModule::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->questionHelper = $this->getMockBuilder(QuestionHelper::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
+ $this->config = $this->createMock(IConfig::class);
+ $this->encryptionManager = $this->createMock(IManager::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->encryptionModule = $this->createMock(IEncryptionModule::class);
+ $this->questionHelper = $this->createMock(QuestionHelper::class);
+ $this->consoleInput = $this->createMock(InputInterface::class);
$this->consoleInput->expects($this->any())
->method('isInteractive')
->willReturn(true);
- $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
+ $this->consoleOutput = $this->createMock(OutputInterface::class);
}
public function testEncryptAll(): void {