Debian Codegraph @

tests/phpunit/unit/documentation/ReleaseNotesTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * James doesn't like having to manually fix these things.
5 * @group ReleaseNotes
6 */
7 class ReleaseNotesTest extends MediaWikiUnitTestCase {
8 /**
9 * Verify that at least one Release Notes file exists, have content, and
10 * aren't overly long.
11 *
12 * @group documentation
13 * @coversNothing
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 * @dataProvider provideFilesAtRoot
56 * @coversNothing
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 // FILE_IGNORE_NEW_LINES drops the \n at the EOL, so max length is 80 not 81.
71 $maxLength = 80;
72
73 $errors = [];
74 foreach ( $lines as $i => $line ) {
75 $length = mb_strlen( $line );
76 if ( $length <= $maxLength ||
77 // Lines with nothing but a long URL cannot be split further
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 // Use assertSame() instead of assertEqual(), to show the full line in the diff
86 $this->assertSame(
87 [],
88 $errors,
89 "$type file '$fileName' lines have at most $maxLength characters"
90 );
91 }
92 }