r91781 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91780‎ | r91781 | r91782 >
Date:07:57, 9 July 2011
Author:salvatoreingala
Status:deferred
Tags:
Comment:
- Fixed checkPrefsAgainstDescription, that didn't reject unexisting preferences; added corresponding test.
Modified paths:
  • /branches/salvatoreingala/Gadgets/Gadgets_tests.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/Gadgets_tests.php
@@ -570,6 +570,10 @@
571571
572572 //Setting right preferences must succeed
573573 $this->assertTrue( $g->setPrefs( $prefs2 ) );
 574+
 575+ //Adding a field not in the description must fail
 576+ $prefs2['someUnexistingPreference'] = 'bar';
 577+ $this->assertFalse( GadgetPrefs::checkPrefsAgainstDescription( $prefsDescription, $prefs2 ) );
574578 }
575579
576580 /**
Index: branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php
@@ -453,11 +453,20 @@
454454 * @return boolean true if $prefs passes validation against $prefsDescription, false otherwise.
455455 */
456456 public static function checkPrefsAgainstDescription( $prefsDescription, $prefs ) {
 457+ //Check that all the given preferences pass validation
457458 foreach ( $prefsDescription['fields'] as $prefName => $prefDescription ) {
458459 if ( !self::checkSinglePref( $prefDescription, $prefs, $prefName ) ) {
459460 return false;
460461 }
461462 }
 463+
 464+ //Check that $prefs contains no preferences that are not described in $prefsDescription
 465+ foreach ( $prefs as $prefName => $value ) {
 466+ if ( !isset( $prefsDescription['fields'][$prefName] ) ) {
 467+ return false;
 468+ }
 469+ }
 470+
462471 return true;
463472 }
464473

Status & tagging log