mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-27 04:56:02 +02:00
BUGFIX: Take note of output format when building Location header for RestfulServer (from r108427) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112744 467b73ca-7a2a-4603-9d3b-597d59a354a9
108 lines
2.0 KiB
PHP
108 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*/
|
|
class CurrencyFieldTest extends SapphireTest {
|
|
|
|
function testValidate() {
|
|
$f = new CurrencyField('TestField');
|
|
|
|
$f->setValue('123.45');
|
|
$this->assertTrue(
|
|
$f->validate(new RequiredFields()),
|
|
'Validates positive decimals'
|
|
);
|
|
|
|
$f->setValue('-123.45');
|
|
$this->assertTrue(
|
|
$f->validate(new RequiredFields()),
|
|
'Validates negative decimals'
|
|
);
|
|
|
|
$f->setValue('$123.45');
|
|
$this->assertTrue(
|
|
$f->validate(new RequiredFields()),
|
|
'Validates positive decimals with sign'
|
|
);
|
|
|
|
$f->setValue('-$123.45');
|
|
$this->assertTrue(
|
|
$f->validate(new RequiredFields()),
|
|
'Validates negative decimals with sign'
|
|
);
|
|
|
|
$f->setValue('$-123.45');
|
|
$this->assertTrue(
|
|
$f->validate(new RequiredFields()),
|
|
'Validates negative decimals with sign'
|
|
);
|
|
|
|
$f->setValue('324511434634');
|
|
$this->assertTrue(
|
|
$f->validate(new RequiredFields()),
|
|
'Validates large integers'
|
|
);
|
|
}
|
|
|
|
function testSetValue() {
|
|
$f = new CurrencyField('TestField');
|
|
|
|
$f->setValue('123.45');
|
|
$this->assertEquals(
|
|
$f->value, '$123.45',
|
|
'Prepends dollar sign to positive decimal'
|
|
);
|
|
|
|
$f->setValue('-123.45');
|
|
$this->assertEquals(
|
|
$f->value, '$-123.45',
|
|
'Prepends dollar sign to negative decimal'
|
|
);
|
|
|
|
$f->setValue('$1');
|
|
$this->assertEquals(
|
|
$f->value, '$1.00',
|
|
'Formats small value'
|
|
);
|
|
|
|
$f->setValue('$2.5');
|
|
$this->assertEquals(
|
|
$f->value, '$2.50',
|
|
'Formats small value'
|
|
);
|
|
|
|
$f->setValue('$2500000.13');
|
|
$this->assertEquals(
|
|
$f->value, '$2,500,000.13',
|
|
'Formats large value'
|
|
);
|
|
|
|
$f->setValue('$2.50000013');
|
|
$this->assertEquals(
|
|
$f->value, '$2.50',
|
|
'Truncates long decimal portions'
|
|
);
|
|
}
|
|
|
|
function testDataValue() {
|
|
$f = new CurrencyField('TestField');
|
|
|
|
$f->setValue('$123.45');
|
|
$this->assertEquals(
|
|
$f->dataValue(), 123.45
|
|
);
|
|
|
|
$f->setValue('-$123.45');
|
|
$this->assertEquals(
|
|
$f->dataValue(), -123.45
|
|
);
|
|
|
|
$f->setValue('$-123.45');
|
|
$this->assertEquals(
|
|
$f->dataValue(), -123.45
|
|
);
|
|
}
|
|
}
|