infoparser.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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('\OCP\IConfig')
  17. ->disableOriginalConstructor()->getMock();
  18. $clientService = $this->getMock('\OCP\Http\Client\IClientService');
  19. $httpHelper = $this->getMockBuilder('\OC\HTTPHelper')
  20. ->setConstructorArgs([$config, $clientService])
  21. ->setMethods(['getHeaders'])
  22. ->getMock();
  23. $urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
  24. ->disableOriginalConstructor()
  25. ->getMock();
  26. //linkToDocs
  27. $urlGenerator->expects($this->any())
  28. ->method('linkToDocs')
  29. ->will($this->returnCallback(function ($url) {
  30. return "https://docs.example.com/server/go.php?to=$url";
  31. }));
  32. $this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator);
  33. }
  34. /**
  35. * @dataProvider providesInfoXml
  36. */
  37. public function testParsingValidXml($expectedJson, $xmlFile) {
  38. $expectedData = null;
  39. if (!is_null($expectedJson)) {
  40. $expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
  41. }
  42. $data = $this->parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile");
  43. $this->assertEquals($expectedData, $data);
  44. }
  45. function providesInfoXml() {
  46. return array(
  47. array('expected-info.json', 'valid-info.xml'),
  48. array(null, 'invalid-info.xml'),
  49. );
  50. }
  51. }