2014-11-24 18:24:26 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Thomas Müller
|
|
|
|
* @copyright 2014 Thomas Müller deepdiver@owncloud.com
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\App;
|
|
|
|
|
|
|
|
use OC;
|
2016-09-23 22:47:47 +03:00
|
|
|
use OC\App\InfoParser;
|
2015-12-17 19:29:17 +03:00
|
|
|
use Test\TestCase;
|
2014-11-24 18:24:26 +03:00
|
|
|
|
2016-05-20 16:38:20 +03:00
|
|
|
class InfoParserTest extends TestCase {
|
2016-10-07 22:15:52 +03:00
|
|
|
/** @var OC\Cache\CappedMemoryCache */
|
|
|
|
private static $cache;
|
2014-11-24 18:24:26 +03:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
public static function setUpBeforeClass(): void {
|
2016-10-07 22:15:52 +03:00
|
|
|
self::$cache = new OC\Cache\CappedMemoryCache();
|
2014-11-24 18:24:26 +03:00
|
|
|
}
|
|
|
|
|
2016-10-07 22:15:52 +03:00
|
|
|
|
|
|
|
public function parserTest($expectedJson, $xmlFile, $cache = null) {
|
|
|
|
$parser = new InfoParser($cache);
|
|
|
|
|
2014-12-01 23:47:22 +03:00
|
|
|
$expectedData = null;
|
|
|
|
if (!is_null($expectedJson)) {
|
|
|
|
$expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
|
|
|
|
}
|
2016-10-07 22:15:52 +03:00
|
|
|
$data = $parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile");
|
2014-11-24 18:24:26 +03:00
|
|
|
|
2014-11-24 19:26:07 +03:00
|
|
|
$this->assertEquals($expectedData, $data);
|
2014-11-24 18:24:26 +03:00
|
|
|
}
|
2014-11-25 12:22:06 +03:00
|
|
|
|
2016-10-07 22:15:52 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider providesInfoXml
|
|
|
|
*/
|
|
|
|
public function testParsingValidXmlWithoutCache($expectedJson, $xmlFile) {
|
|
|
|
$this->parserTest($expectedJson, $xmlFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providesInfoXml
|
|
|
|
*/
|
|
|
|
public function testParsingValidXmlWithCache($expectedJson, $xmlFile) {
|
|
|
|
$this->parserTest($expectedJson, $xmlFile, self::$cache);
|
|
|
|
}
|
|
|
|
|
2019-02-22 17:45:55 +03:00
|
|
|
public function providesInfoXml(): array {
|
|
|
|
return [
|
|
|
|
['expected-info.json', 'valid-info.xml'],
|
|
|
|
[null, 'invalid-info.xml'],
|
|
|
|
['expected-info.json', 'valid-info.xml'],
|
|
|
|
[null, 'invalid-info.xml'],
|
|
|
|
['navigation-one-item.json', 'navigation-one-item.xml'],
|
2019-02-25 16:52:14 +03:00
|
|
|
['navigation-two-items.json', 'navigation-two-items.xml'],
|
2019-02-22 17:45:55 +03:00
|
|
|
];
|
2014-11-25 12:22:06 +03:00
|
|
|
}
|
2014-11-24 18:24:26 +03:00
|
|
|
}
|