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 ;
2023-11-23 04:22:34 -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
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
}
2016-10-07 15:15:52 -04:00
public function parserTest ( $expectedJson , $xmlFile , $cache = null ) {
$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 );
}
2024-09-19 05:10:31 -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')]
2024-09-15 16:32:31 -04:00
public function testParsingValidXmlWithoutCache ( $expectedJson , $xmlFile ) : void {
2016-10-07 15:15:52 -04:00
$this -> parserTest ( $expectedJson , $xmlFile );
}
2025-06-30 10:56:59 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('providesInfoXml')]
2024-09-15 16:32:31 -04:00
public function testParsingValidXmlWithCache ( $expectedJson , $xmlFile ) : void {
2016-10-07 15:15:52 -04:00
$this -> parserTest ( $expectedJson , $xmlFile , self :: $cache );
}
2025-05-12 11:18:04 -04:00
public static function providesInfoXml () : array {
2019-02-22 09:45:55 -05:00
return [
[ 'expected-info.json' , 'valid-info.xml' ],
[ null , 'invalid-info.xml' ],
[ 'navigation-one-item.json' , 'navigation-one-item.xml' ],
2019-02-25 08:52:14 -05:00
[ 'navigation-two-items.json' , 'navigation-two-items.xml' ],
2024-10-28 03:01:22 -04:00
[ '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 {
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' ]);
}
2014-11-24 10:24:26 -05:00
}