2014-11-24 15:24:26 +00: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 19:47:47 +00:00
|
|
|
use OC\App\InfoParser;
|
2015-12-17 16:29:17 +00:00
|
|
|
use Test\TestCase;
|
2014-11-24 15:24:26 +00:00
|
|
|
|
2016-05-20 13:38:20 +00:00
|
|
|
class InfoParserTest extends TestCase {
|
2016-10-07 19:15:52 +00:00
|
|
|
/** @var OC\Cache\CappedMemoryCache */
|
|
|
|
private static $cache;
|
2014-11-24 15:24:26 +00:00
|
|
|
|
2016-10-07 19:15:52 +00:00
|
|
|
public static function setUpBeforeClass() {
|
|
|
|
self::$cache = new OC\Cache\CappedMemoryCache();
|
2014-11-24 15:24:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 19:15:52 +00:00
|
|
|
|
|
|
|
public function parserTest($expectedJson, $xmlFile, $cache = null) {
|
|
|
|
$parser = new InfoParser($cache);
|
|
|
|
|
2014-12-01 20:47:22 +00:00
|
|
|
$expectedData = null;
|
|
|
|
if (!is_null($expectedJson)) {
|
|
|
|
$expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
|
|
|
|
}
|
2016-10-07 19:15:52 +00:00
|
|
|
$data = $parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile");
|
2014-11-24 15:24:26 +00:00
|
|
|
|
2014-11-24 16:26:07 +00:00
|
|
|
$this->assertEquals($expectedData, $data);
|
2014-11-24 15:24:26 +00:00
|
|
|
}
|
2014-11-25 09:22:06 +00:00
|
|
|
|
2016-10-07 19:15:52 +00: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);
|
|
|
|
}
|
|
|
|
|
2014-12-01 20:47:22 +00:00
|
|
|
function providesInfoXml() {
|
|
|
|
return array(
|
|
|
|
array('expected-info.json', 'valid-info.xml'),
|
|
|
|
array(null, 'invalid-info.xml'),
|
2016-10-07 19:15:52 +00:00
|
|
|
array('expected-info.json', 'valid-info.xml'),
|
|
|
|
array(null, 'invalid-info.xml'),
|
2014-12-01 20:47:22 +00:00
|
|
|
);
|
2014-11-25 09:22:06 +00:00
|
|
|
}
|
2014-11-24 15:24:26 +00:00
|
|
|
}
|