function testRequiredRuleFailure() { $rule = new lmbRequiredRule('testfield'); $dataspace = new lmbSet(); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} is required', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($dataspace, $this->error_list); }
function testLocaleDateRuleError() { $rule = new lmbLocaleDateRule('test', new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/en.ini'))); $data = new lmbSet(array('test' => '02jjklklak/sdsdskj34-sdsdsjkjkj78')); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} must have a valid date format', 'validation'), array('Field' => 'test'), array())); $rule->validate($data, $this->error_list); }
function testSizeRangeRuleTooSmall() { $rule = new lmbI18NSizeRangeRule('testfield', 30, 100); $data = new lmbSet(array('testfield' => 'тест')); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} must be greater than {min} and less than {max} characters.', 'validation'), array('Field' => 'testfield'), array('min' => 30, 'max' => 100))); $rule->validate($data, $this->error_list); }
protected function _generateErrorMessage() { for ($i = 0; $i < count($this->field_names); $i++) { $fields[] = '{' . $i . '}'; } return lmb_i18n('Atleast one field required among: {fields}', array('{fields}' => implode(', ', $fields)), 'validation'); }
function testInvalidAndMoreFields() { $dataspace = new lmbSet(); $rule = new lmbAtleastOneFieldRequiredRule(array('field1', 'field2', 'field3')); $this->error_list->expectOnce('addError', array(lmb_i18n('Atleast one field required among: {fields}', array('{fields}' => '{0}, {1}, {2}'), 'validation'), array('field1', 'field2', 'field3'), array())); $rule->validate($dataspace, $this->error_list); }
function testNotValidWithClassRestriction() { $rule = new lmbRequiredObjectRule('testfield', 'Foo'); $dataspace = new lmbSet(); $dataspace->set('testfield', new TestObjectForThisRule()); $this->error_list->expectOnce('addError', array(lmb_i18n('Object {Field} is required', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($dataspace, $this->error_list); }
function testEmailRuleInvalidDomain() { $rule = new lmbEmailRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', 'billgates@micro$oft.com'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} must contain only letters, numbers, hyphens, and periods.', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($dataspace, $this->error_list); }
function testInArrayError() { $rule = new lmbNotInArrayRule('testfield', array('www', 'ftp', 'smtp', 'mail')); $data = new lmbSet(); $data->set('testfield', 'www'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} has not allowed value.', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($data, $this->error_list); }
/** * @see lmbBaseValidationRule :: _doValidate() */ protected function _doValidate($datasource) { $value = $datasource->get($this->field_name); if (is_null($value) || is_string($value) && trim($value) === '') { $error = $this->custom_error ? $this->custom_error : lmb_i18n('{Field} is required', 'validation'); $this->error($error, array('Field' => $this->field_name)); } }
function testSizeRangeRuleTooSmall() { $rule = new lmbSizeRangeRule('testfield', 30, 100); $dataspace = new lmbSet(); $dataspace->set('testfield', '12345678901234567890'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} must be greater than {min} characters.', 'validation'), array('Field' => 'testfield'), array('min' => 30, 'max' => 100))); $rule->validate($dataspace, $this->error_list); }
function testUrlRuleDomain() { $rule = new lmbUrlRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', 'http://www.source--forge.net/'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} may not contain double hyphens (--).', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($dataspace, $this->error_list); }
function testFieldNotValid2() { $rule = new lmbUniqueTableFieldRule('test', 'test_table', 'field1'); $data = new lmbSet(); $data->set('test', "001"); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} must have other value since {Value} already exists', 'web_app'), array('Field' => 'test'), array('Value' => '001'))); $rule->validate($data, $this->error_list); }
function testValidValueRule_Error_Int() { $rule = new lmbValidValueRule('testfield', 1); $data = new lmbSet(); $data->set('testfield', 0); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} value is wrong', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($data, $this->error_list); }
function testNotValidContainsSlash() { $rule = new lmbIdentifierRule('test'); $data = new lmbSet(); $data->set('test', 'test/test'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} must contain only letters and numbers', 'validation'), array('Field' => 'test'), array())); $rule->validate($data, $this->error_list); }
function testPatternRuleFailed() { $rule = new lmbPatternRule('testfield', '/^\\w+$/'); $data = new lmbSet(); $data->set('testfield', 'Simpletest is Cool!'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} value is wrong', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($data, $this->error_list); }
function testNumericRuleTooManyDecimalDigits() { $rule = new lmbNumericPrecisionRule('testfield', 3, 2); $dataspace = new lmbSet(); $dataspace->set('testfield', '111.222'); $this->error_list->expectOnce('addError', array(lmb_i18n('You have entered too many decimal digits ({digits}) in {Field} (max {maxdigits}).', 'validation'), array('Field' => 'testfield'), array('maxdigits' => 2, 'digits' => 3))); $rule->validate($dataspace, $this->error_list); }
function testOnlyDigitsAllowedNumeric() { $rule = new lmbNumericValueRangeRule('testfield', 1, 4); $dataspace = new lmbSet(); $dataspace->set('testfield', '4fdfasd'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} must be a valid number.', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($dataspace, $this->error_list); }
function check($value) { if (!is_null($this->min_length) && lmb_strlen($value) < $this->min_length) { $this->error(lmb_i18n('{Field} must be greater than {min} and less than {max} characters.', 'validation'), array('min' => $this->min_length, 'max' => $this->max_length)); } if (lmb_strlen($value) > $this->max_length) { $this->error(lmb_i18n('{Field} must be less than {max} and greater than {min} characters.', 'validation'), array('min' => $this->min_length, 'max' => $this->max_length)); } }
/** * @see lmbBaseValidationRule :: _doValidate() */ protected function _doValidate($datasource) { $value1 = $datasource->get($this->field_name); $value2 = $datasource->get($this->reference_field); if (isset($value1) && isset($value2) && strcmp($value1, $value2)) { $error = $this->custom_error ? $this->custom_error : lmb_i18n('{Field} does not match {MatchField}.', 'validation'); $this->error($error, array('Field' => $this->field_name, 'MatchField' => $this->reference_field)); } }
/** * @see lmbBaseValidationRule :: _doValidate() */ protected function _doValidate($datasource) { $value = $datasource->get($this->field_name); if (!is_object($value) || $this->class && !$value instanceof $this->class) { $error = $this->custom_error ? $this->custom_error : lmb_i18n('Object {Field} is required', 'validation'); $this->error($error, array('Field' => $this->field_name)); return; } }
function testMatchRuleFailure() { $rule = new lmbMatchRule('testfield', 'testmatch'); $dataspace = new lmbSet(); $dataspace->set('testfield', 'peaches'); $dataspace->set('testmatch', 'cream'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} does not match {MatchField}.', 'validation'), array('Field' => 'testfield', 'MatchField' => 'testmatch'), array())); $rule->validate($dataspace, $this->error_list); }
function testDomainRuleCombination() { $rule = new lmbDomainRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', '.n..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.'); $this->error_list->expectCallCount('addError', 4); $this->error_list->expectArgumentsAt(0, 'addError', array(lmb_i18n('{Field} cannot start with a period.', 'validation'), array('Field' => 'testfield'), array())); $this->error_list->expectArgumentsAt(1, 'addError', array(lmb_i18n('{Field} cannot end with a period.', 'validation'), array('Field' => 'testfield'), array())); $this->error_list->expectArgumentsAt(2, 'addError', array(lmb_i18n('{Field} may not contain double periods (..).', 'validation'), array('Field' => 'testfield'), array())); $this->error_list->expectArgumentsAt(3, 'addError', array(lmb_i18n('{Field} segment {segment} is too large (it must be 63 characters or less).', 'validation'), array('Field' => 'testfield'), array('segment' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'))); $rule->validate($dataspace, $this->error_list); }
function getValue() { if (!isset($this->parameters[0]) || !$this->parameters[0]->getValue()) { throw new WactException('MISSING_FILTER_PARAMETER'); } else { $domain = $this->parameters[0]->getValue(); } $value = $this->base->getValue(); if ($this->isConstant()) { return lmb_i18n($value, $this->_getAttributes(), $domain); } else { $this->raiseUnresolvedBindingError(); } }
function check($value) { $conn = lmbToolkit::instance()->getDefaultDbConnection(); $sql = 'SELECT * FROM ' . $this->table_name . ' WHERE ' . $this->table_field . '=:value:'; $stmt = $conn->newStatement($sql); $stmt->setVarChar('value', $value); $rs = $stmt->getRecordSet(); if ($rs->count() == 0) { return; } if ($this->error_message) { $this->error($this->error_message, array('Value' => $value)); } else { $this->error(lmb_i18n('{Field} must have other value since {Value} already exists', 'web_app'), array('Value' => $value)); } }
function testTranslateSubstituteParametersDefaultContext() { $toolkit = lmbToolkit::save(); $back = new lmbQtDictionaryBackend(); $back->setSearchPath($translations_dir = LIMB_VAR_DIR . '/translations'); $toolkit->setDictionaryBackend($back); $xml = <<<EOD <?xml version="1.0"?> <!DOCTYPE TS><TS> <context> <message> <source>Hello {name}</source> <translation>Привет {name}</translation> </message> </context> </TS> EOD; file_put_contents($translations_dir . '/default.ru_RU.ts', $xml); $toolkit->setLocale('ru_RU'); $this->assertEqual(lmb_i18n('Hello {name}', array('{name}' => 'Bob')), 'Привет Bob'); lmbToolkit::restore(); }
/** * Alias for adding single field error to error list * Fills field array with array('Field' => $this->field_name) that is ok for single field rules * If $custom_error attribute is set will use $custom_error regardless of $message * If $custom_error attribute is not set will apply lmb_i18n function to $message * @param string Error message * @param array Array of values * @see lmbErrorList :: addError() * @return void */ function error($message, $values = array(), $i18n_params = array()) { $error = $this->custom_error ? $this->custom_error : lmb_i18n($message, $i18n_params, 'validation'); parent::error($error, array('Field' => $this->field_name), $values); }