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;
|
|
|
|
|
|
|
|
class InfoParser extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\App\InfoParser
|
|
|
|
*/
|
|
|
|
private $parser;
|
|
|
|
|
|
|
|
public function setUp() {
|
2014-11-24 19:26:07 +03:00
|
|
|
$config = $this->getMockBuilder('\OC\AllConfig')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2014-11-24 18:24:26 +03:00
|
|
|
$httpHelper = $this->getMockBuilder('\OC\HTTPHelper')
|
2014-11-24 19:26:07 +03:00
|
|
|
->setConstructorArgs(array($config))
|
|
|
|
->setMethods(array('getHeaders'))
|
2014-11-24 18:24:26 +03:00
|
|
|
->getMock();
|
|
|
|
$urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
//linkToDocs
|
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
|
|
|
}));
|
|
|
|
|
|
|
|
$this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testParsingValidXml() {
|
2014-11-24 19:26:07 +03:00
|
|
|
$expectedData = json_decode(file_get_contents(OC::$SERVERROOT.'/tests/data/app/expected-info.json'), true);
|
2014-11-24 18:24:26 +03:00
|
|
|
$data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/valid-info.xml');
|
|
|
|
|
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
|
|
|
|
|
|
|
public function testParsingInvalidXml() {
|
|
|
|
$data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/invalid-info.xml');
|
|
|
|
$this->assertNull($data);
|
|
|
|
}
|
2014-11-24 18:24:26 +03:00
|
|
|
}
|