InfoParserTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2023 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2014-2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\App;
  8. use OC;
  9. use OC\App\InfoParser;
  10. use OCP\Cache\CappedMemoryCache;
  11. use Test\TestCase;
  12. class InfoParserTest extends TestCase {
  13. /** @var OCP\Cache\CappedMemoryCache */
  14. private static $cache;
  15. public static function setUpBeforeClass(): void {
  16. self::$cache = new 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. }