ExtensionJsonValidationTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. */
  18. /**
  19. * Validates all loaded extensions and skins using the ExtensionRegistry
  20. * against the extension.json schema in the docs/ folder.
  21. *
  22. * @coversNothing
  23. */
  24. class ExtensionJsonValidationTest extends PHPUnit\Framework\TestCase {
  25. use MediaWikiCoversValidator;
  26. /**
  27. * @var ExtensionJsonValidator
  28. */
  29. protected $validator;
  30. public function setUp() {
  31. parent::setUp();
  32. $this->validator = new ExtensionJsonValidator( [ $this, 'markTestSkipped' ] );
  33. $this->validator->checkDependencies();
  34. if ( !ExtensionRegistry::getInstance()->getAllThings() ) {
  35. $this->markTestSkipped(
  36. 'There are no extensions or skins loaded via the ExtensionRegistry'
  37. );
  38. }
  39. }
  40. public static function providePassesValidation() {
  41. $values = [];
  42. foreach ( ExtensionRegistry::getInstance()->getAllThings() as $thing ) {
  43. $values[] = [ $thing['path'] ];
  44. }
  45. return $values;
  46. }
  47. /**
  48. * @dataProvider providePassesValidation
  49. * @param string $path Path to thing's json file
  50. */
  51. public function testPassesValidation( $path ) {
  52. try {
  53. $this->validator->validate( $path );
  54. // All good
  55. $this->assertTrue( true );
  56. } catch ( ExtensionJsonValidationError $e ) {
  57. $this->assertEquals( false, $e->getMessage() );
  58. }
  59. }
  60. }