summaryrefslogtreecommitdiff
path: root/tests/phpunit/languages/SpecialPageAliasTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/languages/SpecialPageAliasTest.php')
-rw-r--r--tests/phpunit/languages/SpecialPageAliasTest.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/phpunit/languages/SpecialPageAliasTest.php b/tests/phpunit/languages/SpecialPageAliasTest.php
new file mode 100644
index 00000000..f6d6bc96
--- /dev/null
+++ b/tests/phpunit/languages/SpecialPageAliasTest.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * Verifies that special page aliases are valid, with no slashes.
+ *
+ * @group Language
+ * @group SpecialPageAliases
+ * @group SystemTest
+ * @group medium
+ *
+ * @licence GNU GPL v2+
+ * @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();
+ }
+
+}