InfoParserTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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(): void {
  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. public function providesInfoXml(): array {
  40. return [
  41. ['expected-info.json', 'valid-info.xml'],
  42. [null, 'invalid-info.xml'],
  43. ['expected-info.json', 'valid-info.xml'],
  44. [null, 'invalid-info.xml'],
  45. ['navigation-one-item.json', 'navigation-one-item.xml'],
  46. ['navigation-two-items.json', 'navigation-two-items.xml'],
  47. ];
  48. }
  49. }