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