1
0

InfoParserTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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): void {
  31. $this->parserTest($expectedJson, $xmlFile);
  32. }
  33. /**
  34. * @dataProvider providesInfoXml
  35. */
  36. public function testParsingValidXmlWithCache($expectedJson, $xmlFile): void {
  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. ['various-single-item.json', 'various-single-item.xml'],
  48. ];
  49. }
  50. }