019a13e4ca458ef8f01422a2b7d9b8a08304d06d
[lhc/web/wiklou.git] / tests / phpunit / documentation / ReleaseNotesTest.php
1 <?php
2
3 /**
4 * James doesn't like having to manually fix these things.
5 */
6 class ReleaseNotesTest extends MediaWikiTestCase {
7 /**
8 * Verify that at least one Release Notes file exists, have content, and
9 * aren't overly long.
10 *
11 * @group documentation
12 * @coversNothing
13 */
14 public function testReleaseNotesFilesExistAndAreNotMalformed() {
15 global $wgVersion, $IP;
16
17 $notesFiles = glob( "$IP/RELEASE-NOTES-*" );
18
19 $this->assertGreaterThanOrEqual(
20 1,
21 count( $notesFiles ),
22 'Repo has at least one Release Notes file.'
23 );
24
25 $versionParts = explode( '.', explode( '-', $wgVersion )[0] );
26 $this->assertContains(
27 "$IP/RELEASE-NOTES-$versionParts[0].$versionParts[1]",
28 $notesFiles,
29 'Repo has a Release Notes file for the current $wgVersion.'
30 );
31
32 foreach ( $notesFiles as $index => $fileName ) {
33 $this->assertFileLength( "Release Notes", $fileName );
34 }
35
36 // Also test the README and similar files
37 $otherFiles = [ "$IP/COPYING", "$IP/FAQ", "$IP/INSTALL", "$IP/README", "$IP/SECURITY" ];
38
39 foreach ( $otherFiles as $index => $fileName ) {
40 $this->assertFileLength( "Help", $fileName );
41 }
42 }
43
44 private function assertFileLength( $type, $fileName ) {
45 $file = file( $fileName, FILE_IGNORE_NEW_LINES );
46
47 $this->assertFalse(
48 !$file,
49 "$type file '$fileName' is inaccessible."
50 );
51
52 $lines = count( $file );
53
54 for ( $i = 0; $i < $lines; $i++ ) {
55 $line = $file[$i];
56
57 $this->assertLessThanOrEqual(
58 // FILE_IGNORE_NEW_LINES drops the \n at the EOL, so max length is 80 not 81.
59 80,
60 mb_strlen( $line ),
61 "$type file '$fileName' line $i is longer than 80 chars:\n\t'$line'"
62 );
63 }
64 }
65 }