protected function checkInputValidation($locale, $tests) { i18n::set_locale($locale); $field = new NumericField('Number'); $validator = new RequiredFields('Number'); foreach ($tests as $input => $output) { // Both decimal and thousands B $field->setValue($input); if ($output === false) { $this->assertFalse($field->validate($validator), "Expect validation to fail for input {$input} in locale {$locale}"); $this->assertEquals(0, $field->dataValue(), "Expect invalid value to be rewritten to 0 in locale {$locale}"); // Even invalid values shouldn't be rewritten $this->assertEquals($this->clean($input), $field->Value(), "Expected input {$input} to be saved in the field in locale {$locale}"); } else { $this->assertTrue($field->validate($validator), "Expect validation to succeed for {$input} in locale {$locale}"); $this->assertEquals($output, $field->dataValue(), "Expect value {$input} to be mapped to {$output} in locale {$locale}"); } } }
public function testValidator() { i18n::set_locale('en_US'); $field = new NumericField('Number'); $field->setValue('12.00'); $validator = new RequiredFields('Number'); $this->assertTrue($field->validate($validator)); $field->setValue('12,00'); $this->assertFalse($field->validate($validator)); $field->setValue('0'); $this->assertTrue($field->validate($validator)); $field->setValue(false); $this->assertFalse($field->validate($validator)); i18n::set_locale('de_DE'); $field->setValue('12,00'); $validator = new RequiredFields(); $this->assertTrue($field->validate($validator)); $field->setValue('12.00'); $this->assertFalse($field->validate($validator)); }
public function testValidator() { i18n::set_locale('en_US'); $field = new NumericField('Number'); $field->setValue('12.00'); $validator = new RequiredFields('Number'); $this->assertTrue($field->validate($validator)); $field->setValue('12,00'); $this->assertFalse($field->validate($validator)); $field->setValue('0'); $this->assertTrue($field->validate($validator)); $field->setValue(false); $this->assertFalse($field->validate($validator)); i18n::set_locale('de_DE'); $field->setValue('12,00'); $validator = new RequiredFields(); $this->assertTrue($field->validate($validator)); $field->setValue('12.00'); $this->assertFalse($field->validate($validator)); $field->setValue(0); $this->assertRegExp("#<span[^>]+>\\s*0\\s*<\\/span>#", "" . $field->performReadonlyTransformation()->Field() . ""); }
/** * Test empty values */ public function testEmptyValidator() { i18n::set_locale('en_US'); $field = new NumericField('Number'); $validator = new RequiredFields('Number'); // Treats '0' as given for the sake of required fields $field->setValue('0'); $this->assertTrue($field->validate($validator)); $this->assertEquals(0, $field->dataValue()); // Treat literal 0 $field->setValue(0); $this->assertTrue($field->validate($validator)); $this->assertEquals(0, $field->dataValue()); // Should fail the 'required but not given' test $field->setValue(''); $this->assertFalse($field->validate($validator)); $field->setValue(false); $this->assertFalse($field->validate($validator)); }