From e6c7c85779c984f45eeab9375e7a64fddd4c40a0 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Fri, 27 Dec 2013 18:02:40 +0100 Subject: [PATCH] Throw exception for unknown field in SpecialListfiles::formatValue() Change-Id: I99fedfb28aaf9b09b5d9fee27020601f3c06e8d4 --- includes/specials/SpecialListfiles.php | 16 ++++++++++++++ .../specials/SpecialListFilesTest.php | 21 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/phpunit/includes/specials/SpecialListFilesTest.php diff --git a/includes/specials/SpecialListfiles.php b/includes/specials/SpecialListfiles.php index b5181401c9..ba3e73f7cb 100644 --- a/includes/specials/SpecialListfiles.php +++ b/includes/specials/SpecialListfiles.php @@ -387,6 +387,20 @@ class ImageListPager extends TablePager { UserCache::singleton()->doQuery( $userIds, array( 'userpage' ), __METHOD__ ); } + /** + * @param string $field + * @param string $value + * @return Message|string|int The return type depends on the value of $field: + * - thumb: string + * - img_timestamp: string + * - img_name: string + * - img_user_text: string + * - img_size: string + * - img_description: string + * - count: int + * - top: Message + * @throws MWException + */ function formatValue( $field, $value ) { switch ( $field ) { case 'thumb': @@ -446,6 +460,8 @@ class ImageListPager extends TablePager { case 'top': // Messages: listfiles-latestversion-yes, listfiles-latestversion-no return $this->msg( 'listfiles-latestversion-' . $value ); + default: + throw new MWException( "Unknown field '$field'" ); } } diff --git a/tests/phpunit/includes/specials/SpecialListFilesTest.php b/tests/phpunit/includes/specials/SpecialListFilesTest.php new file mode 100644 index 0000000000..2689236b67 --- /dev/null +++ b/tests/phpunit/includes/specials/SpecialListFilesTest.php @@ -0,0 +1,21 @@ +formatValue( 'invalid_field', 'invalid_value' ); + } +} -- 2.20.1