silverstripe-framework/tests/forms/NumericFieldTest.php

49 lines
1.2 KiB
PHP
Raw Normal View History

<?php
/**
* @package framework
* @subpackage tests
*/
class NumericFieldTest extends SapphireTest {
2014-08-15 08:53:05 +02:00
protected $usesDatabase = false;
public function testValidator() {
i18n::set_locale('en_US');
$field = new NumericField('Number');
$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->assertTrue($field->validate($validator));
$field->setValue(false);
$this->assertTrue($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()."");
}
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');
}
Merge remote-tracking branch 'origin/3.1' Conflicts: .travis.yml README.md admin/code/LeftAndMain.php admin/css/screen.css admin/scss/screen.scss api/RestfulService.php conf/ConfigureFromEnv.php control/injector/ServiceConfigurationLocator.php control/injector/SilverStripeServiceConfigurationLocator.php core/ClassInfo.php core/Object.php css/AssetUploadField.css css/ComplexTableField_popup.css dev/CSSContentParser.php dev/DevelopmentAdmin.php docs/en/changelogs/index.md docs/en/misc/contributing/code.md docs/en/reference/execution-pipeline.md filesystem/GD.php filesystem/ImagickBackend.php filesystem/Upload.php forms/Form.php forms/FormField.php forms/HtmlEditorConfig.php forms/gridfield/GridFieldDetailForm.php forms/gridfield/GridFieldSortableHeader.php lang/en.yml model/Aggregate.php model/DataList.php model/DataObject.php model/DataQuery.php model/Image.php model/MySQLDatabase.php model/SQLQuery.php model/fieldtypes/HTMLText.php model/fieldtypes/Text.php scss/AssetUploadField.scss search/filters/SearchFilter.php security/Authenticator.php security/LoginForm.php security/Member.php security/MemberAuthenticator.php security/MemberLoginForm.php security/Security.php tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php tests/control/HTTPTest.php tests/control/RequestHandlingTest.php tests/filesystem/UploadTest.php tests/forms/FormTest.php tests/forms/NumericFieldTest.php tests/model/DataListTest.php tests/model/DataObjectTest.php tests/model/TextTest.php tests/security/MemberAuthenticatorTest.php tests/security/SecurityDefaultAdminTest.php tests/view/SSViewerCacheBlockTest.php tests/view/SSViewerTest.php
2014-11-18 00:45:54 +01:00
}