b19376d388db413b48e572f0e8ec763ee12ad7b7
[lhc/web/wiklou.git] / tests / phpunit / structure / ExtensionJsonValidationTest.php
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 /**
20 * Validates all loaded extensions and skins using the ExtensionRegistry
21 * against the extension.json schema in the docs/ folder.
22 */
23 class ExtensionJsonValidationTest extends PHPUnit_Framework_TestCase {
24
25 /**
26 * @var ExtensionJsonValidator
27 */
28 protected $validator;
29
30 public function setUp() {
31 parent::setUp();
32
33 $this->validator = new ExtensionJsonValidator( [ $this, 'markTestSkipped' ] );
34 $this->validator->checkDependencies();
35
36 if ( !ExtensionRegistry::getInstance()->getAllThings() ) {
37 $this->markTestSkipped(
38 'There are no extensions or skins loaded via the ExtensionRegistry'
39 );
40 }
41 }
42
43 public static function providePassesValidation() {
44 $values = [];
45 foreach ( ExtensionRegistry::getInstance()->getAllThings() as $thing ) {
46 $values[] = [ $thing['path'] ];
47 }
48
49 return $values;
50 }
51
52 /**
53 * @dataProvider providePassesValidation
54 * @param string $path Path to thing's json file
55 */
56 public function testPassesValidation( $path ) {
57 try {
58 $this->validator->validate( $path );
59 // All good
60 $this->assertTrue( true );
61 } catch ( ExtensionJsonValidationError $e ) {
62 $this->assertEquals( false, $e->getMessage() );
63 }
64 }
65 }