| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
class ReleaseNotesTest extends MediaWikiUnitTestCase { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public function testReleaseNotesFilesExistAndAreNotMalformed() { |
| 16 |
global $IP; |
| 17 |
|
| 18 |
$notesFiles = glob( "$IP/RELEASE-NOTES-*" ); |
| 19 |
|
| 20 |
$this->assertGreaterThanOrEqual( |
| 21 |
1, |
| 22 |
count( $notesFiles ), |
| 23 |
'Repo has at least one Release Notes file.' |
| 24 |
); |
| 25 |
|
| 26 |
$versionParts = explode( '.', explode( '-', MW_VERSION )[0] ); |
| 27 |
$this->assertContains( |
| 28 |
"$IP/RELEASE-NOTES-$versionParts[0].$versionParts[1]", |
| 29 |
$notesFiles, |
| 30 |
'Repo has a Release Notes file for the current MW_VERSION.' |
| 31 |
); |
| 32 |
|
| 33 |
foreach ( $notesFiles as $fileName ) { |
| 34 |
$this->assertFileLength( "Release Notes", $fileName ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
public static function provideFilesAtRoot() { |
| 39 |
global $IP; |
| 40 |
|
| 41 |
$rootFiles = [ |
| 42 |
"COPYING", |
| 43 |
"FAQ", |
| 44 |
"HISTORY", |
| 45 |
"INSTALL", |
| 46 |
"SECURITY", |
| 47 |
]; |
| 48 |
|
| 49 |
foreach ( $rootFiles as $rootFile ) { |
| 50 |
yield "$rootFile file" => [ "$IP/$rootFile" ]; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function testRootFilesHaveProperLineLength( $fileName ) { |
| 59 |
$this->assertFileLength( "Help", $fileName ); |
| 60 |
} |
| 61 |
|
| 62 |
private function assertFileLength( $type, $fileName ) { |
| 63 |
$lines = file( $fileName, FILE_IGNORE_NEW_LINES ); |
| 64 |
|
| 65 |
$this->assertNotFalse( |
| 66 |
$lines, |
| 67 |
"$type file '$fileName' is inaccessible." |
| 68 |
); |
| 69 |
|
| 70 |
|
| 71 |
$maxLength = 80; |
| 72 |
|
| 73 |
$errors = []; |
| 74 |
foreach ( $lines as $i => $line ) { |
| 75 |
$length = mb_strlen( $line ); |
| 76 |
if ( $length <= $maxLength || |
| 77 |
|
| 78 |
preg_match( '/^\W*https?:\/\/\S*$/', $line ) |
| 79 |
) { |
| 80 |
continue; |
| 81 |
} |
| 82 |
$num = $i + 1; |
| 83 |
$errors[] = "line $num: length $length > $maxLength:\n$line"; |
| 84 |
} |
| 85 |
|
| 86 |
$this->assertSame( |
| 87 |
[], |
| 88 |
$errors, |
| 89 |
"$type file '$fileName' lines have at most $maxLength characters" |
| 90 |
); |
| 91 |
} |
| 92 |
} |