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;
|
2015-12-17 16:29:17 +00:00
|
|
|
use Test\TestCase;
|
2014-11-24 15:24:26 +00:00
|
|
|
|
2015-12-17 16:29:17 +00:00
|
|
|
class InfoParser extends TestCase {
|
2014-11-24 15:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\App\InfoParser
|
|
|
|
*/
|
|
|
|
private $parser;
|
|
|
|
|
|
|
|
public function setUp() {
|
2014-11-27 17:19:14 +00:00
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig')
|
2014-11-24 16:26:07 +00:00
|
|
|
->disableOriginalConstructor()->getMock();
|
2015-03-16 10:28:23 +00:00
|
|
|
$clientService = $this->getMock('\OCP\Http\Client\IClientService');
|
2014-11-24 15:24:26 +00:00
|
|
|
$httpHelper = $this->getMockBuilder('\OC\HTTPHelper')
|
2015-03-16 10:28:23 +00:00
|
|
|
->setConstructorArgs([$config, $clientService])
|
|
|
|
->setMethods(['getHeaders'])
|
2014-11-24 15:24:26 +00:00
|
|
|
->getMock();
|
|
|
|
$urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
//linkToDocs
|
2014-11-24 16:26:07 +00:00
|
|
|
$urlGenerator->expects($this->any())
|
2014-11-24 15:24:26 +00:00
|
|
|
->method('linkToDocs')
|
|
|
|
->will($this->returnCallback(function ($url) {
|
2014-11-24 16:26:07 +00:00
|
|
|
return "https://docs.example.com/server/go.php?to=$url";
|
2014-11-24 15:24:26 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
$this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator);
|
|
|
|
}
|
|
|
|
|
2014-12-01 20:47:22 +00: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 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
|
|
|
|
2014-12-01 20:47:22 +00:00
|
|
|
function providesInfoXml() {
|
|
|
|
return array(
|
|
|
|
array('expected-info.json', 'valid-info.xml'),
|
|
|
|
array(null, 'invalid-info.xml'),
|
|
|
|
);
|
2014-11-25 09:22:06 +00:00
|
|
|
}
|
2014-11-24 15:24:26 +00:00
|
|
|
}
|