| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\ResourceLoader\ForeignResourceManager; |
| 4 |
use MediaWiki\ResourceLoader\ForeignResourceNetworkException; |
| 5 |
use PHPUnit\Framework\TestCase; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class ForeignResourceStructureTest extends TestCase { |
| 16 |
|
| 17 |
public function testVerifyIntegrity() { |
| 18 |
global $IP; |
| 19 |
$out = ''; |
| 20 |
$frm = new ForeignResourceManager( |
| 21 |
"{$IP}/resources/lib/foreign-resources.yaml", |
| 22 |
"{$IP}/resources/lib", |
| 23 |
static function ( $text ) use ( &$out ) { |
| 24 |
$out .= $text; |
| 25 |
} |
| 26 |
); |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
$helpUpdate = ' |
| 38 |
To update a foreign resource, run: |
| 39 |
$ php maintenance/manageForeignResources.php update <moduleName> |
| 40 |
'; |
| 41 |
|
| 42 |
try { |
| 43 |
$this->assertTrue( $frm->run( 'verify', 'all' ), "$out\n$helpUpdate" ); |
| 44 |
} catch ( ForeignResourceNetworkException $e ) { |
| 45 |
$this->markTestSkipped( 'Network error: ' . $e->getMessage() ); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
$cdxFile = $frm->getCdxFileLocation(); |
| 51 |
$this->assertFileExists( $cdxFile ); |
| 52 |
$cdxJsonString = file_get_contents( $cdxFile ); |
| 53 |
$serial = preg_match( '/"urn:uuid:[\\da-f\\-]+"/', $cdxJsonString, $matches ); |
| 54 |
$this->assertSame( 1, $serial ); |
| 55 |
$expectedCdx = preg_replace( '/"urn:uuid:[\\da-f\\-]+"/', $matches[0], $frm->generateCdx() ); |
| 56 |
$this->assertJsonStringEqualsJsonFile( $cdxFile, $expectedCdx, |
| 57 |
"foreign-resources.cdx.json does not match foreign-resources.yaml, " |
| 58 |
. "run `manageForeignResources.php make-cdx`" ); |
| 59 |
} |
| 60 |
} |