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-04-19 13:19:39 +03:00
|
|
|
use OCP\IURLGenerator;
|
2015-12-17 19:29:17 +03:00
|
|
|
use Test\TestCase;
|
2014-11-24 18:24:26 +03:00
|
|
|
|
2015-12-17 19:29:17 +03:00
|
|
|
class InfoParser extends TestCase {
|
2014-11-24 18:24:26 +03:00
|
|
|
|
2016-04-19 13:19:39 +03:00
|
|
|
/** @var \OC\App\InfoParser */
|
2014-11-24 18:24:26 +03:00
|
|
|
private $parser;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
$urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2016-04-19 13:19:39 +03:00
|
|
|
/** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
|
2014-11-24 19:26:07 +03:00
|
|
|
$urlGenerator->expects($this->any())
|
2014-11-24 18:24:26 +03:00
|
|
|
->method('linkToDocs')
|
|
|
|
->will($this->returnCallback(function ($url) {
|
2014-11-24 19:26:07 +03:00
|
|
|
return "https://docs.example.com/server/go.php?to=$url";
|
2014-11-24 18:24:26 +03:00
|
|
|
}));
|
|
|
|
|
2016-04-19 13:19:39 +03:00
|
|
|
$this->parser = new \OC\App\InfoParser($urlGenerator);
|
2014-11-24 18:24:26 +03:00
|
|
|
}
|
|
|
|
|
2014-12-01 23:47:22 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider providesInfoXml
|
|
|
|
*/
|
|
|
|
public function testParsingValidXml($expectedJson, $xmlFile) {
|
|
|
|
$expectedData = null;
|
|
|
|
if (!is_null($expectedJson)) {
|
|
|
|
$expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
|
|
|
|
}
|
|
|
|
$data = $this->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
|
|
|
|
2014-12-01 23:47:22 +03:00
|
|
|
function providesInfoXml() {
|
|
|
|
return array(
|
|
|
|
array('expected-info.json', 'valid-info.xml'),
|
|
|
|
array(null, 'invalid-info.xml'),
|
|
|
|
);
|
2014-11-25 12:22:06 +03:00
|
|
|
}
|
2014-11-24 18:24:26 +03:00
|
|
|
}
|