InfoParserTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. use OC\App\InfoParser;
  11. use Test\TestCase;
  12. class InfoParserTest extends TestCase {
  13. /** @var OC\Cache\CappedMemoryCache */
  14. private static $cache;
  15. public static function setUpBeforeClass() {
  16. self::$cache = new OC\Cache\CappedMemoryCache();
  17. }
  18. public function parserTest($expectedJson, $xmlFile, $cache = null) {
  19. $parser = new InfoParser($cache);
  20. $expectedData = null;
  21. if (!is_null($expectedJson)) {
  22. $expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
  23. }
  24. $data = $parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile");
  25. $this->assertEquals($expectedData, $data);
  26. }
  27. /**
  28. * @dataProvider providesInfoXml
  29. */
  30. public function testParsingValidXmlWithoutCache($expectedJson, $xmlFile) {
  31. $this->parserTest($expectedJson, $xmlFile);
  32. }
  33. /**
  34. * @dataProvider providesInfoXml
  35. */
  36. public function testParsingValidXmlWithCache($expectedJson, $xmlFile) {
  37. $this->parserTest($expectedJson, $xmlFile, self::$cache);
  38. }
  39. function providesInfoXml() {
  40. return array(
  41. array('expected-info.json', 'valid-info.xml'),
  42. array(null, 'invalid-info.xml'),
  43. array('expected-info.json', 'valid-info.xml'),
  44. array(null, 'invalid-info.xml'),
  45. );
  46. }
  47. }