MDL-29401 introduce new frankenstyle PARAM types

New PARAM_COMPONENT, PARAM_AREA and PARAM_PLUGIN + fixing of hopefully all current incorrect parameter types. This should help with diagnosing of incorrectly named 3rd party plugins too.
This commit is contained in:
Petr Skoda
2011-09-25 09:59:55 +02:00
parent dab8148fde
commit aff24313be
50 changed files with 264 additions and 142 deletions
+53
View File
@@ -693,6 +693,59 @@ class moodlelib_test extends UnitTestCase {
',9789,42897');
}
function test_clean_param_component() {
// please note the cleaning of component names is very strict, no guessing here
$this->assertIdentical(clean_param('mod_forum', PARAM_COMPONENT), 'mod_forum');
$this->assertIdentical(clean_param('block_online_users', PARAM_COMPONENT), 'block_online_users');
$this->assertIdentical(clean_param('mod_something2', PARAM_COMPONENT), 'mod_something2');
$this->assertIdentical(clean_param('forum', PARAM_COMPONENT), 'forum');
$this->assertIdentical(clean_param('user', PARAM_COMPONENT), 'user');
$this->assertIdentical(clean_param('rating', PARAM_COMPONENT), 'rating');
$this->assertIdentical(clean_param('mod_2something', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('2mod_something', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('mod_something_xx', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('auth_something__xx', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('mod_Something', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('mod_somethíng', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('auth_xx-yy', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('_auth_xx', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('a2uth_xx', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('auth_xx_', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('auth_xx.old', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('_user', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('2rating', PARAM_COMPONENT), '');
$this->assertIdentical(clean_param('user_', PARAM_COMPONENT), '');
}
function test_clean_param_plugin() {
// please note the cleaning of plugin names is very strict, no guessing here
$this->assertIdentical(clean_param('forum', PARAM_PLUGIN), 'forum');
$this->assertIdentical(clean_param('forum2', PARAM_PLUGIN), 'forum2');
$this->assertIdentical(clean_param('online_users', PARAM_PLUGIN), 'online_users');
$this->assertIdentical(clean_param('online__users', PARAM_PLUGIN), '');
$this->assertIdentical(clean_param('forum ', PARAM_PLUGIN), '');
$this->assertIdentical(clean_param('forum.old', PARAM_PLUGIN), '');
$this->assertIdentical(clean_param('xx-yy', PARAM_PLUGIN), '');
$this->assertIdentical(clean_param('2xx', PARAM_PLUGIN), '');
$this->assertIdentical(clean_param('Xx', PARAM_PLUGIN), '');
$this->assertIdentical(clean_param('_xx', PARAM_PLUGIN), '');
$this->assertIdentical(clean_param('xx_', PARAM_PLUGIN), '');
}
function test_clean_param_area() {
// please note the cleaning of area names is very strict, no guessing here
$this->assertIdentical(clean_param('something', PARAM_AREA), 'something');
$this->assertIdentical(clean_param('something2', PARAM_AREA), 'something2');
$this->assertIdentical(clean_param('some_thing', PARAM_AREA), 'some_thing');
$this->assertIdentical(clean_param('_something', PARAM_AREA), '');
$this->assertIdentical(clean_param('something_', PARAM_AREA), '');
$this->assertIdentical(clean_param('2something', PARAM_AREA), '');
$this->assertIdentical(clean_param('Something', PARAM_AREA), '');
$this->assertIdentical(clean_param('some-thing', PARAM_AREA), '');
$this->assertIdentical(clean_param('somethííng', PARAM_AREA), '');
$this->assertIdentical(clean_param('something.x', PARAM_AREA), '');
}
function test_clean_param_text() {
$this->assertEqual(PARAM_TEXT, PARAM_MULTILANG);
//standard