summaryrefslogtreecommitdiff
path: root/tests/phpunit/languages/SpecialPageAliasTest.php
blob: a6d9d2700f714240aa7b5b9b8fabc8f652098dde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

/**
 * Verifies that special page aliases are valid, with no slashes.
 *
 * @group Language
 * @group SpecialPageAliases
 * @group SystemTest
 * @group medium
 *
 * @author Katie Filbert < aude.wiki@gmail.com >
 */
class SpecialPageAliasTest extends MediaWikiTestCase {

	/**
	 * @dataProvider validSpecialPageAliasesProvider
	 */
	public function testValidSpecialPageAliases( $code, $specialPageAliases ) {
		foreach ( $specialPageAliases as $specialPage => $aliases ) {
			foreach ( $aliases as $alias ) {
				$msg = "$specialPage alias '$alias' in $code is valid with no slashes";
				$this->assertRegExp( '/^[^\/]*$/', $msg );
			}
		}
	}

	public function validSpecialPageAliasesProvider() {
		$codes = array_keys( Language::fetchLanguageNames( 'mwfile' ) );

		$data = array();

		foreach ( $codes as $code ) {
			$specialPageAliases = $this->getSpecialPageAliases( $code );

			if ( $specialPageAliases !== array() ) {
				$data[] = array( $code, $specialPageAliases );
			}
		}

		return $data;
	}

	/**
	 * @param string $code
	 *
	 * @return array
	 */
	protected function getSpecialPageAliases( $code ) {
		$file = Language::getMessagesFileName( $code );

		if ( is_readable( $file ) ) {
			include $file;

			if ( isset( $specialPageAliases ) && $specialPageAliases !== null ) {
				return $specialPageAliases;
			}
		}

		return array();
	}

}