2014-11-24 10:24:26 -05:00
< ? php
2025-06-30 09:04:05 -04:00
2025-09-29 06:34:49 -04:00
declare ( strict_types = 1 );
2014-11-24 10:24:26 -05:00
/**
2024-05-10 09:09:14 -04:00
* SPDX - FileCopyrightText : 2016 - 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX - FileCopyrightText : 2014 - 2016 ownCloud , Inc .
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2014-11-24 10:24:26 -05:00
*/
namespace Test\App ;
use OC ;
2016-09-23 15:47:47 -04:00
use OC\App\InfoParser ;
2022-06-29 09:34:06 -04:00
use OCP\Cache\CappedMemoryCache ;
2015-12-17 11:29:17 -05:00
use Test\TestCase ;
2014-11-24 10:24:26 -05:00
2016-05-20 09:38:20 -04:00
class InfoParserTest extends TestCase {
2025-09-29 06:34:49 -04:00
private static CappedMemoryCache $cache ;
2014-11-24 10:24:26 -05:00
2026-04-28 13:29:54 -04:00
#[\Override]
2019-11-21 10:40:38 -05:00
public static function setUpBeforeClass () : void {
2022-06-29 09:34:06 -04:00
self :: $cache = new CappedMemoryCache ();
2014-11-24 10:24:26 -05:00
}
2026-05-02 12:27:19 -04:00
protected function parserTest ( $expectedJson , $xmlFile , $cache = null ) {
2016-10-07 15:15:52 -04:00
$parser = new InfoParser ( $cache );
2014-12-01 15:47:22 -05:00
$expectedData = null ;
if ( ! is_null ( $expectedJson )) {
$expectedData = json_decode ( file_get_contents ( OC :: $SERVERROOT . " /tests/data/app/ $expectedJson " ), true );
}
2016-10-07 15:15:52 -04:00
$data = $parser -> parse ( OC :: $SERVERROOT . " /tests/data/app/ $xmlFile " );
2014-11-24 10:24:26 -05:00
2014-11-24 11:26:07 -05:00
$this -> assertEquals ( $expectedData , $data );
2014-11-24 10:24:26 -05:00
}
2014-11-25 04:22:06 -05:00
2025-06-30 10:56:59 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')]
2016-10-07 15:15:52 -04:00
public function testParsingValidXmlWithoutCache ( $expectedJson , $xmlFile ) : void {
$this -> parserTest ( $expectedJson , $xmlFile );
}
2025-06-30 10:56:59 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')]
2016-10-07 15:15:52 -04:00
public function testParsingValidXmlWithCache ( $expectedJson , $xmlFile ) : void {
$this -> parserTest ( $expectedJson , $xmlFile , self :: $cache );
}
2026-05-02 12:27:19 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('appDataProvider')]
public function testApplyL10N ( array $data , array $expected , string $language ) : void {
$parser = new InfoParser ();
2026-05-12 16:22:40 -04:00
$this -> assertEqualsCanonicalizing ( $expected , $parser -> applyL10N ( $data , $language ));
2026-05-02 12:27:19 -04:00
}
2025-05-12 11:18:04 -04:00
public static function providesInfoXml () : array {
2019-02-22 09:45:55 -05:00
return [
2026-05-12 16:22:40 -04:00
'Only one value in each list' => [ 'appinfo-multi-once.json' , 'appinfo-multi-once.xml' ],
'Only one value in each list with attributes' => [ 'appinfo-attributes-once.json' , 'appinfo-attributes-once.xml' ],
'Multiple values in each list' => [ 'appinfo-multi-twice.json' , 'appinfo-multi-twice.xml' ],
'Valid info' => [ 'expected-info.json' , 'valid-info.xml' ],
'Invalid info' => [ null , 'invalid-info.xml' ],
'Navigation one item' => [ 'navigation-one-item.json' , 'navigation-one-item.xml' ],
'Navigation two items' => [ 'navigation-two-items.json' , 'navigation-two-items.xml' ],
'Various single item' => [ 'various-single-item.json' , 'various-single-item.xml' ],
2019-02-22 09:45:55 -05:00
];
2014-11-25 04:22:06 -05:00
}
2025-06-17 05:28:04 -04:00
/**
* Providers for the app data values
*/
public static function appDataProvider () : array {
2026-05-02 12:27:19 -04:00
$FULL_TRANSLATED = [
'name' => [
[ '@attributes' => [ 'lang' => 'en' ], '@value' => 'App' ],
[ '@attributes' => [ 'lang' => 'fr' ], '@value' => 'Application' ]
],
'summary' => [
'Summary' ,
[ '@attributes' => [ 'lang' => 'fr' ], '@value' => 'Résumé' ]
],
'description' => [
[ '@attributes' => [ 'lang' => 'en' ], '@value' => 'Description' ],
[ '@attributes' => [ 'lang' => 'fr' ], '@value' => 'Description (fr)' ]
]
];
2025-06-17 05:28:04 -04:00
return [
2026-05-02 12:27:19 -04:00
// test trimming
2025-06-17 05:28:04 -04:00
[
[ 'description' => " \t This is a multiline \n test with \n \t \n \n some new lines " ],
2026-05-12 16:22:40 -04:00
[ 'description' => " This is a multiline \n test with \n \t \n \n some new lines " , 'summary' => '' , 'name' => '' ],
2026-05-02 12:27:19 -04:00
'en'
2025-06-17 05:28:04 -04:00
],
[
[ 'description' => " \t This is a multiline \n test with \n \t some new lines " ],
2026-05-12 16:22:40 -04:00
[ 'description' => " This is a multiline \n test with \n \t some new lines " , 'summary' => '' , 'name' => '' ],
2026-05-02 12:27:19 -04:00
'en'
2025-06-17 05:28:04 -04:00
],
[
[ 'description' => hex2bin ( '5065726d657420646520732761757468656e7469666965722064616e732070697769676f20646972656374656d656e74206176656320736573206964656e74696669616e7473206f776e636c6f75642073616e73206c65732072657461706572206574206d657420c3a0206a6f757273206365757820636920656e20636173206465206368616e67656d656e74206465206d6f742064652070617373652e0d0a0d' )],
2026-05-12 16:22:40 -04:00
[ '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. " , 'summary' => '' , 'name' => '' ],
2026-05-02 12:27:19 -04:00
'fr'
],
// test proper translation handling
// just strings:
[
[ 'name' => 'App' , 'summary' => 'Summary' , 'description' => 'Description' ],
[ 'name' => 'App' , 'summary' => 'Summary' , 'description' => 'Description' ],
'en'
2025-06-17 05:28:04 -04:00
],
2026-05-02 12:27:19 -04:00
// translated and requesting English:
2025-06-17 05:28:04 -04:00
[
2026-05-02 12:27:19 -04:00
$FULL_TRANSLATED ,
[ 'name' => 'App' , 'summary' => 'Summary' , 'description' => 'Description' ],
'en'
2025-06-17 05:28:04 -04:00
],
2026-05-02 12:27:19 -04:00
// translated and requesting translation:
2025-06-17 05:28:04 -04:00
[
2026-05-02 12:27:19 -04:00
$FULL_TRANSLATED ,
[ 'name' => 'Application' , 'summary' => 'Résumé' , 'description' => 'Description (fr)' ],
'fr'
2025-06-17 05:28:04 -04:00
],
2026-05-02 12:27:19 -04:00
// translated but requesting non existing translation, should fallback to English:
[
$FULL_TRANSLATED ,
[ 'name' => 'App' , 'summary' => 'Summary' , 'description' => 'Description' ],
'de'
]
2025-06-17 05:28:04 -04:00
];
}
2014-11-24 10:24:26 -05:00
}