Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / JSParseHelperTest.php
blobc1148ff7046f5ba044ae6f1d9addb32870c8b1be
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use JSParseHelper;
7 /**
8 * @covers \JSParseHelper
9 * @author Dreamy Jazz
11 class JSParseHelperTest extends MaintenanceBaseTestCase {
12 public function getMaintenanceClass() {
13 return JSParseHelper::class;
16 public function testExecuteForMissingFilename() {
17 $this->expectCallToFatalError();
18 $nonExistingFile = $this->getNewTempDirectory() . 'non-existing-test-file.js';
19 $this->expectOutputRegex( '/' . preg_quote( $nonExistingFile, '/' ) . " ERROR: could not read file\n/" );
20 $this->maintenance->setArg( 'files(s)', $nonExistingFile );
21 $this->maintenance->execute();
24 private function getTestJSFile( string $content ): string {
25 $testFilename = $this->getNewTempFile();
26 $testFile = fopen( $testFilename, 'w' );
27 fwrite( $testFile, $content );
28 fclose( $testFile );
29 return $testFilename;
32 public function testExecuteForInvalidJS() {
33 // Get a file which has invalid JS
34 $testFilename = $this->getTestJSFile( "const a =;" );
35 // Run the maintenance script on this file, and expect it to be parsed as invalid.
36 $this->expectCallToFatalError();
37 $this->expectOutputRegex( '/' . preg_quote( $testFilename, '/' ) . ' ERROR/' );
38 $this->maintenance->setArg( 'file(s)', $testFilename );
39 $this->maintenance->execute();
42 public function testExecuteForValidJS() {
43 // Get a file which has valid JS
44 $testFilename = $this->getTestJSFile( "const a = 1;" );
45 // Run the maintenance script on this file, and expect it to parse as okay.
46 $this->expectOutputRegex( '/' . preg_quote( $testFilename, '/' ) . ' OK/' );
47 $this->maintenance->setArg( 'file(s)', $testFilename );
48 $this->maintenance->execute();