2013-05-11 12:51:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package framework
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class NumericFieldTest extends SapphireTest {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-05-11 12:51:39 +02:00
|
|
|
protected $usesDatabase = false;
|
|
|
|
|
|
|
|
public function testValidator() {
|
|
|
|
i18n::set_locale('en_US');
|
|
|
|
|
|
|
|
$field = new NumericField('Number');
|
|
|
|
$field->setValue('12.00');
|
|
|
|
|
2014-11-12 03:19:12 +01:00
|
|
|
$validator = new RequiredFields();
|
2013-05-11 12:51:39 +02:00
|
|
|
$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);
|
2014-11-12 03:19:12 +01:00
|
|
|
$this->assertTrue($field->validate($validator));
|
2013-05-11 12:51:39 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2014-08-04 04:20:57 +02:00
|
|
|
|
|
|
|
public function testNumberTypeOnInputHtml() {
|
|
|
|
$field = new NumericField('Number');
|
|
|
|
|
|
|
|
$html = $field->Field();
|
|
|
|
$this->assertContains('type="number"', $html, 'number type set');
|
|
|
|
$this->assertContains('step="any"', $html, 'step value set to any');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|