InfoCheckerTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 OC\App\InfoParser;
  24. use Test\TestCase;
  25. class InfoCheckerTest extends TestCase {
  26. /** @var InfoChecker */
  27. protected $infoChecker;
  28. public static function setUpBeforeClass() {
  29. \OC::$APPSROOTS[] = [
  30. 'path' => \OC::$SERVERROOT . '/tests/apps',
  31. 'url' => '/apps-test',
  32. 'writable' => false,
  33. ];
  34. }
  35. public static function tearDownAfterClass() {
  36. // remove last element
  37. array_pop(\OC::$APPSROOTS);
  38. }
  39. protected function setUp() {
  40. parent::setUp();
  41. $this->infoChecker = new InfoChecker();
  42. }
  43. public function appInfoData() {
  44. return [
  45. ['testapp_infoxml', []],
  46. ['testapp_version', [
  47. ['type' => 'parseError', 'field' => 'Element \'licence\': This element is not expected. Expected is one of ( description, version ).' . "\n"],
  48. ]],
  49. ['testapp_dependency_missing', [
  50. ['type' => 'parseError', 'field' => 'Element \'info\': Missing child element(s). Expected is one of ( repository, screenshot, dependencies ).' . "\n"],
  51. ]],
  52. ['testapp_name_missing', [
  53. ['type' => 'parseError', 'field' => 'Element \'summary\': This element is not expected. Expected is ( name ).' . "\n"],
  54. ]],
  55. ];
  56. }
  57. /**
  58. * @dataProvider appInfoData
  59. *
  60. * @param $appId
  61. * @param $expectedErrors
  62. */
  63. public function testApps($appId, $expectedErrors) {
  64. $errors = $this->infoChecker->analyse($appId);
  65. libxml_clear_errors();
  66. $this->assertEquals($expectedErrors, $errors);
  67. }
  68. }