'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error1')); $module->setMeta($meta); $options = array( 'test_val1' => array('10'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEmpty($errors, print_r($errors, true)); } function test_check_profileOptions_ext_preg_fail() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_val1'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error1')); $module->setMeta($meta); $options = array( 'test_val1' => array('a'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEquals(array(array('ERROR', 'error1')), $errors); } function test_check_profileOptions_regex() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_reg1'] = array( 'type' => 'regex', 'regex' => 'ab+a', 'error_message' => array('ERROR', 'error1')); $module->setMeta($meta); $options = array( 'test_reg1' => array('abbba'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEmpty($errors, print_r($errors, true)); } function test_check_profileOptions_regex_fail() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_reg1'] = array( 'type' => 'regex', 'regex' => 'ab+a', 'error_message' => array('ERROR', 'error1')); $module->setMeta($meta); $options = array( 'test_reg1' => array('aCa'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEquals(array(array('ERROR', 'error1')), $errors); } function test_check_profileOptions_cmp() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_val1'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error1')); $meta['profile_checks']['test_val2'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error2')); $meta['profile_checks']['test_cmp'] = array( 'type' => 'int_greater', 'cmp_name1' => 'test_val2', 'cmp_name2' => 'test_val1', 'error_message' => array('ERROR', 'errorCMP')); $module->setMeta($meta); $options = array( 'test_val1' => array('10'), 'test_val2' => array('20'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEmpty($errors, print_r($errors, true)); } function test_check_profileOptions_cmp_fail_equal() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_val1'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error1')); $meta['profile_checks']['test_val2'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error2')); $meta['profile_checks']['test_cmp'] = array( 'type' => 'int_greater', 'cmp_name1' => 'test_val2', 'cmp_name2' => 'test_val1', 'error_message' => array('ERROR', 'errorCMP')); $module->setMeta($meta); $options = array( 'test_val1' => array('10'), 'test_val2' => array('10'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEquals(array(array('ERROR', 'errorCMP')), $errors); } function test_check_profileOptions_cmp_fail_smaller() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_val1'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error1')); $meta['profile_checks']['test_val2'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error2')); $meta['profile_checks']['test_cmp'] = array( 'type' => 'int_greater', 'cmp_name1' => 'test_val2', 'cmp_name2' => 'test_val1', 'error_message' => array('ERROR', 'errorCMP')); $module->setMeta($meta); $options = array( 'test_val1' => array('20'), 'test_val2' => array('10'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEquals(array(array('ERROR', 'errorCMP')), $errors); } function test_check_profileOptions_cmpEqual_greater() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_val1'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error1')); $meta['profile_checks']['test_val2'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error2')); $meta['profile_checks']['test_cmp'] = array( 'type' => 'int_greaterOrEqual', 'cmp_name1' => 'test_val2', 'cmp_name2' => 'test_val1', 'error_message' => array('ERROR', 'errorCMP')); $module->setMeta($meta); $options = array( 'test_val1' => array('10'), 'test_val2' => array('20'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEmpty($errors, print_r($errors, true)); } function test_check_profileOptions_cmpEqual_equal() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_val1'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error1')); $meta['profile_checks']['test_val2'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error2')); $meta['profile_checks']['test_cmp'] = array( 'type' => 'int_greaterOrEqual', 'cmp_name1' => 'test_val2', 'cmp_name2' => 'test_val1', 'error_message' => array('ERROR', 'errorCMP')); $module->setMeta($meta); $options = array( 'test_val1' => array('10'), 'test_val2' => array('10'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEmpty($errors, print_r($errors, true)); } function test_check_profileOptions_cmpEqual_fail() { $module = new baseModuleDummy('user'); $meta['profile_checks']['test_val1'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error1')); $meta['profile_checks']['test_val2'] = array( 'type' => 'ext_preg', 'regex' => 'digit', 'error_message' => array('ERROR', 'error2')); $meta['profile_checks']['test_cmp'] = array( 'type' => 'int_greaterOrEqual', 'cmp_name1' => 'test_val2', 'cmp_name2' => 'test_val1', 'error_message' => array('ERROR', 'errorCMP')); $module->setMeta($meta); $options = array( 'test_val1' => array('20'), 'test_val2' => array('10'), ); $errors = $module->check_profileOptions($options, 'user1'); $this->assertEquals(array(array('ERROR', 'errorCMP')), $errors); } } class baseModuleDummy extends baseModule { public function setMeta($meta) { $this->meta = $meta; } /** * {@inheritDoc} * @see baseModule::can_manage() */ public function can_manage() { } /** * {@inheritDoc} * @see baseModule::process_attributes() */ public function process_attributes() { } /** * {@inheritDoc} * @see baseModule::display_html_attributes() */ public function display_html_attributes() { } }