You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

infoparser.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @author Thomas Müller
  4. * @copyright 2014 Thomas Müller deepdiver@owncloud.com
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\App;
  9. use OC;
  10. class InfoParser extends \PHPUnit_Framework_TestCase {
  11. /**
  12. * @var \OC\App\InfoParser
  13. */
  14. private $parser;
  15. public function setUp() {
  16. $config = $this->getMockBuilder('\OC\AllConfig')
  17. ->disableOriginalConstructor()->getMock();
  18. $httpHelper = $this->getMockBuilder('\OC\HTTPHelper')
  19. ->setConstructorArgs(array($config))
  20. ->setMethods(array('getHeaders'))
  21. ->getMock();
  22. $urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
  23. ->disableOriginalConstructor()
  24. ->getMock();
  25. //linkToDocs
  26. $urlGenerator->expects($this->any())
  27. ->method('linkToDocs')
  28. ->will($this->returnCallback(function ($url) {
  29. return "https://docs.example.com/server/go.php?to=$url";
  30. }));
  31. $this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator);
  32. }
  33. /**
  34. * @dataProvider providesInfoXml
  35. */
  36. public function testParsingValidXml($expectedJson, $xmlFile) {
  37. $expectedData = null;
  38. if (!is_null($expectedJson)) {
  39. $expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
  40. }
  41. $data = $this->parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile");
  42. $this->assertEquals($expectedData, $data);
  43. }
  44. function providesInfoXml() {
  45. return array(
  46. array('expected-info.json', 'valid-info.xml'),
  47. array(null, 'invalid-info.xml'),
  48. );
  49. }
  50. }