Index: branches/salvatoreingala/Gadgets/Gadgets_tests.php |
— | — | @@ -570,6 +570,10 @@ |
571 | 571 | |
572 | 572 | //Setting right preferences must succeed |
573 | 573 | $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 ) ); |
574 | 578 | } |
575 | 579 | |
576 | 580 | /** |
Index: branches/salvatoreingala/Gadgets/backend/GadgetPrefs.php |
— | — | @@ -453,11 +453,20 @@ |
454 | 454 | * @return boolean true if $prefs passes validation against $prefsDescription, false otherwise. |
455 | 455 | */ |
456 | 456 | public static function checkPrefsAgainstDescription( $prefsDescription, $prefs ) { |
| 457 | + //Check that all the given preferences pass validation |
457 | 458 | foreach ( $prefsDescription['fields'] as $prefName => $prefDescription ) { |
458 | 459 | if ( !self::checkSinglePref( $prefDescription, $prefs, $prefName ) ) { |
459 | 460 | return false; |
460 | 461 | } |
461 | 462 | } |
| 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 | + |
462 | 471 | return true; |
463 | 472 | } |
464 | 473 | |