diff options
Diffstat (limited to 'tests/lib/App/InfoParserTest.php')
-rw-r--r-- | tests/lib/App/InfoParserTest.php | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/tests/lib/App/InfoParserTest.php b/tests/lib/App/InfoParserTest.php index 1c429ccc405..449f827df43 100644 --- a/tests/lib/App/InfoParserTest.php +++ b/tests/lib/App/InfoParserTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2023 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2014-2016 ownCloud, Inc. @@ -12,7 +13,7 @@ use OCP\Cache\CappedMemoryCache; use Test\TestCase; class InfoParserTest extends TestCase { - /** @var OCP\Cache\CappedMemoryCache */ + /** @var CappedMemoryCache */ private static $cache; public static function setUpBeforeClass(): void { @@ -31,21 +32,17 @@ class InfoParserTest extends TestCase { $this->assertEquals($expectedData, $data); } - /** - * @dataProvider providesInfoXml - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')] public function testParsingValidXmlWithoutCache($expectedJson, $xmlFile): void { $this->parserTest($expectedJson, $xmlFile); } - /** - * @dataProvider providesInfoXml - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')] public function testParsingValidXmlWithCache($expectedJson, $xmlFile): void { $this->parserTest($expectedJson, $xmlFile, self::$cache); } - public function providesInfoXml(): array { + public static function providesInfoXml(): array { return [ ['expected-info.json', 'valid-info.xml'], [null, 'invalid-info.xml'], @@ -56,4 +53,57 @@ class InfoParserTest extends TestCase { ['various-single-item.json', 'various-single-item.xml'], ]; } + + /** + * Providers for the app data values + */ + public static function appDataProvider(): array { + return [ + [ + ['description' => " \t This is a multiline \n test with \n \t \n \n some new lines "], + ['description' => "This is a multiline \n test with \n \t \n \n some new lines"], + ], + [ + ['description' => " \t This is a multiline \n test with \n \t some new lines "], + ['description' => "This is a multiline \n test with \n \t some new lines"], + ], + [ + ['description' => hex2bin('5065726d657420646520732761757468656e7469666965722064616e732070697769676f20646972656374656d656e74206176656320736573206964656e74696669616e7473206f776e636c6f75642073616e73206c65732072657461706572206574206d657420c3a0206a6f757273206365757820636920656e20636173206465206368616e67656d656e74206465206d6f742064652070617373652e0d0a0d')], + ['description' => "Permet de s'authentifier dans piwigo directement avec ses identifiants owncloud sans les retaper et met à jours ceux ci en cas de changement de mot de passe."], + ], + [ + ['not-a-description' => " \t This is a multiline \n test with \n \t some new lines "], + [ + 'not-a-description' => " \t This is a multiline \n test with \n \t some new lines ", + 'description' => '', + ], + ], + [ + ['description' => [100, 'bla']], + ['description' => ''], + ], + ]; + } + + /** + * Test app info parser + */ + #[\PHPUnit\Framework\Attributes\DataProvider('appDataProvider')] + public function testApplyL10NNoLanguage(array $data, array $expected): void { + $parser = new InfoParser(); + $this->assertSame($expected, $parser->applyL10N($data)); + } + + public function testApplyL10N(): void { + $parser = new InfoParser(); + $data = $parser->parse(\OC::$SERVERROOT . '/tests/data/app/description-multi-lang.xml'); + $this->assertEquals('English', $parser->applyL10N($data, 'en')['description']); + $this->assertEquals('German', $parser->applyL10N($data, 'de')['description']); + } + + public function testApplyL10NSingleLanguage(): void { + $parser = new InfoParser(); + $data = $parser->parse(\OC::$SERVERROOT . '/tests/data/app/description-single-lang.xml'); + $this->assertEquals('English', $parser->applyL10N($data, 'en')['description']); + } } |