diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AppFramework/OCS/BaseResponseTest.php | 39 | ||||
-rw-r--r-- | tests/lib/Encryption/Keys/StorageTest.php | 34 | ||||
-rw-r--r-- | tests/lib/Encryption/UtilTest.php | 44 | ||||
-rw-r--r-- | tests/lib/Http/Client/DnsPinMiddlewareTest.php | 6 | ||||
-rw-r--r-- | tests/lib/InstallerTest.php | 6 | ||||
-rw-r--r-- | tests/lib/Mail/MailerTest.php | 2 |
6 files changed, 91 insertions, 40 deletions
diff --git a/tests/lib/AppFramework/OCS/BaseResponseTest.php b/tests/lib/AppFramework/OCS/BaseResponseTest.php index a1e0c620574..4857b573802 100644 --- a/tests/lib/AppFramework/OCS/BaseResponseTest.php +++ b/tests/lib/AppFramework/OCS/BaseResponseTest.php @@ -28,6 +28,17 @@ namespace Test\AppFramework\Middleware; use OC\AppFramework\OCS\BaseResponse; +class ArrayValue implements \JsonSerializable { + private $array; + public function __construct(array $array) { + $this->array = $array; + } + + public function jsonSerialize(): mixed { + return $this->array; + } +} + class BaseResponseTest extends \Test\TestCase { public function testToXml(): void { /** @var BaseResponse $response */ @@ -56,4 +67,32 @@ class BaseResponseTest extends \Test\TestCase { $writer->outputMemory(true) ); } + + public function testToXmlJsonSerializable(): void { + /** @var BaseResponse $response */ + $response = $this->createMock(BaseResponse::class); + + $writer = new \XMLWriter(); + $writer->openMemory(); + $writer->setIndent(false); + $writer->startDocument(); + + $data = [ + 'hello' => 'hello', + 'information' => new ArrayValue([ + '@test' => 'some data', + 'someElement' => 'withAttribute', + ]), + 'value without key', + 'object' => new \stdClass(), + ]; + + $this->invokePrivate($response, 'toXml', [$data, $writer]); + $writer->endDocument(); + + $this->assertEquals( + "<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element><object/>\n", + $writer->outputMemory(true) + ); + } } diff --git a/tests/lib/Encryption/Keys/StorageTest.php b/tests/lib/Encryption/Keys/StorageTest.php index a47edb3fdd6..eaef7fbaa54 100644 --- a/tests/lib/Encryption/Keys/StorageTest.php +++ b/tests/lib/Encryption/Keys/StorageTest.php @@ -53,6 +53,7 @@ class StorageTest extends TestCase { $this->util = $this->getMockBuilder('OC\Encryption\Util') ->disableOriginalConstructor() + ->setMethodsExcept(['getFileKeyDir']) ->getMock(); $this->view = $this->getMockBuilder(View::class) @@ -583,39 +584,6 @@ class StorageTest extends TestCase { $this->assertSame($expected, $args[0]); } - /** - * @dataProvider dataTestGetFileKeyDir - * - * @param bool $isSystemWideMountPoint - * @param string $storageRoot - * @param string $expected - */ - public function testGetFileKeyDir($isSystemWideMountPoint, $storageRoot, $expected) { - $path = '/user1/files/foo/bar.txt'; - $owner = 'user1'; - $relativePath = '/foo/bar.txt'; - - $this->invokePrivate($this->storage, 'root_dir', [$storageRoot]); - - $this->util->expects($this->once())->method('isSystemWideMountPoint') - ->willReturn($isSystemWideMountPoint); - $this->util->expects($this->once())->method('getUidAndFilename') - ->with($path)->willReturn([$owner, $relativePath]); - - $this->assertSame($expected, - $this->invokePrivate($this->storage, 'getFileKeyDir', ['OC_DEFAULT_MODULE', $path]) - ); - } - - public function dataTestGetFileKeyDir() { - return [ - [false, '', '/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], - [true, '', '/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], - [false, 'newStorageRoot', '/newStorageRoot/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], - [true, 'newStorageRoot', '/newStorageRoot/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], - ]; - } - /** * @dataProvider dataTestBackupUserKeys diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index e236ef54c26..7f5b05d6967 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -13,6 +13,7 @@ use Test\TestCase; class UtilTest extends TestCase { /** * block size will always be 8192 for a PHP stream + * * @see https://bugs.php.net/bug.php?id=21641 */ protected int $headerSize = 8192; @@ -205,4 +206,47 @@ class UtilTest extends TestCase { , []], ]; } + + /** + * @dataProvider dataTestGetFileKeyDir + * + * @param bool $isSystemWideMountPoint + * @param string $storageRoot + * @param string $expected + */ + public function testGetFileKeyDir($isSystemWideMountPoint, $storageRoot, $expected) { + $path = '/user1/files/foo/bar.txt'; + $owner = 'user1'; + $relativePath = '/foo/bar.txt'; + + $util = $this->getMockBuilder(Util::class) + ->onlyMethods(['isSystemWideMountPoint', 'getUidAndFilename', 'getKeyStorageRoot']) + ->setConstructorArgs([ + $this->view, + $this->userManager, + $this->groupManager, + $this->config + ]) + ->getMock(); + + $util->expects($this->once())->method('getKeyStorageRoot') + ->willReturn($storageRoot); + $util->expects($this->once())->method('isSystemWideMountPoint') + ->willReturn($isSystemWideMountPoint); + $util->expects($this->once())->method('getUidAndFilename') + ->with($path)->willReturn([$owner, $relativePath]); + + $this->assertSame($expected, + $util->getFileKeyDir('OC_DEFAULT_MODULE', $path) + ); + } + + public function dataTestGetFileKeyDir() { + return [ + [false, '', '/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], + [true, '', '/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], + [false, 'newStorageRoot', '/newStorageRoot/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], + [true, 'newStorageRoot', '/newStorageRoot/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], + ]; + } } diff --git a/tests/lib/Http/Client/DnsPinMiddlewareTest.php b/tests/lib/Http/Client/DnsPinMiddlewareTest.php index 2fa868e6963..54071f37b1a 100644 --- a/tests/lib/Http/Client/DnsPinMiddlewareTest.php +++ b/tests/lib/Http/Client/DnsPinMiddlewareTest.php @@ -287,7 +287,7 @@ class DnsPinMiddlewareTest extends TestCase { public function testRejectIPv4() { $this->expectException(LocalServerException::class); - $this->expectExceptionMessage('Host violates local access rules'); + $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ static function (RequestInterface $request, array $options) { @@ -334,7 +334,7 @@ class DnsPinMiddlewareTest extends TestCase { public function testRejectIPv6() { $this->expectException(LocalServerException::class); - $this->expectExceptionMessage('Host violates local access rules'); + $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ static function (RequestInterface $request, array $options) { @@ -381,7 +381,7 @@ class DnsPinMiddlewareTest extends TestCase { public function testRejectCanonicalName() { $this->expectException(LocalServerException::class); - $this->expectExceptionMessage('Host violates local access rules'); + $this->expectExceptionMessage('violates local access rules'); $mockHandler = new MockHandler([ static function (RequestInterface $request, array $options) { diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php index 4e622dca6d1..5df3e2eafa9 100644 --- a/tests/lib/InstallerTest.php +++ b/tests/lib/InstallerTest.php @@ -51,7 +51,7 @@ class InstallerTest extends TestCase { $this->appstore = $config->setSystemValue('appstoreenabled', true); $config->setSystemValue('appstoreenabled', true); $installer = new Installer( - \OC::$server->getAppFetcher(), + \OC::$server->get(AppFetcher::class), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), @@ -74,7 +74,7 @@ class InstallerTest extends TestCase { protected function tearDown(): void { $installer = new Installer( - \OC::$server->getAppFetcher(), + \OC::$server->get(AppFetcher::class), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), @@ -98,7 +98,7 @@ class InstallerTest extends TestCase { // Install app $installer = new Installer( - \OC::$server->getAppFetcher(), + \OC::$server->get(AppFetcher::class), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index 418bfe35c6e..0eee7db126a 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -72,7 +72,7 @@ class MailerTest extends TestCase { public function sendmailModeProvider(): array { return [ 'smtp' => ['smtp', ' -bs'], - 'pipe' => ['pipe', ' -t'], + 'pipe' => ['pipe', ' -t -i'], ]; } |