InfoCheckerTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\App\CodeChecker;
  22. use OC\App\CodeChecker\InfoChecker;
  23. use Test\TestCase;
  24. class InfoCheckerTest extends TestCase {
  25. /** @var InfoChecker */
  26. protected $infoChecker;
  27. public static function setUpBeforeClass(): void {
  28. \OC::$APPSROOTS[] = [
  29. 'path' => \OC::$SERVERROOT . '/tests/apps',
  30. 'url' => '/apps-test',
  31. 'writable' => false,
  32. ];
  33. }
  34. public static function tearDownAfterClass(): void {
  35. // remove last element
  36. array_pop(\OC::$APPSROOTS);
  37. }
  38. protected function setUp(): void {
  39. parent::setUp();
  40. $this->infoChecker = new InfoChecker();
  41. }
  42. public function appInfoData() {
  43. return [
  44. ['testapp_infoxml', []],
  45. ['testapp_version', [
  46. ['type' => 'parseError', 'field' => 'Element \'licence\': This element is not expected. Expected is one of ( description, version ).' . "\n"],
  47. ]],
  48. ['testapp_dependency_missing', [
  49. ['type' => 'parseError', 'field' => 'Element \'info\': Missing child element(s). Expected is one of ( repository, screenshot, dependencies ).' . "\n"],
  50. ]],
  51. ['testapp_name_missing', [
  52. ['type' => 'parseError', 'field' => 'Element \'summary\': This element is not expected. Expected is ( name ).' . "\n"],
  53. ]],
  54. ];
  55. }
  56. /**
  57. * @dataProvider appInfoData
  58. *
  59. * @param $appId
  60. * @param $expectedErrors
  61. */
  62. public function testApps($appId, $expectedErrors) {
  63. $errors = $this->infoChecker->analyse($appId);
  64. libxml_clear_errors();
  65. $this->assertEquals($expectedErrors, $errors);
  66. }
  67. }