SpecialPageAliasTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Verifies that special page aliases are valid, with no slashes.
  4. *
  5. * @group Language
  6. * @group SpecialPageAliases
  7. * @group SystemTest
  8. * @group medium
  9. * @todo This should be a structure test
  10. *
  11. * @author Katie Filbert < aude.wiki@gmail.com >
  12. */
  13. class SpecialPageAliasTest extends MediaWikiTestCase {
  14. /**
  15. * @coversNothing
  16. * @dataProvider validSpecialPageAliasesProvider
  17. */
  18. public function testValidSpecialPageAliases( $code, $specialPageAliases ) {
  19. foreach ( $specialPageAliases as $specialPage => $aliases ) {
  20. foreach ( $aliases as $alias ) {
  21. $msg = "$specialPage alias '$alias' in $code is valid with no slashes";
  22. $this->assertRegExp( '/^[^\/]*$/', $msg );
  23. }
  24. }
  25. }
  26. public function validSpecialPageAliasesProvider() {
  27. $codes = array_keys( Language::fetchLanguageNames( null, 'mwfile' ) );
  28. $data = [];
  29. foreach ( $codes as $code ) {
  30. $specialPageAliases = $this->getSpecialPageAliases( $code );
  31. if ( $specialPageAliases !== [] ) {
  32. $data[] = [ $code, $specialPageAliases ];
  33. }
  34. }
  35. return $data;
  36. }
  37. /**
  38. * @param string $code
  39. *
  40. * @return array
  41. */
  42. protected function getSpecialPageAliases( $code ) {
  43. $file = Language::getMessagesFileName( $code );
  44. if ( is_readable( $file ) ) {
  45. include $file;
  46. if ( isset( $specialPageAliases ) && $specialPageAliases !== null ) {
  47. return $specialPageAliases;
  48. }
  49. }
  50. return [];
  51. }
  52. }