Passed
Push — nested-vendor ( f8843a )
by Sam
09:43
created

testPerformReadonlyTransformation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Forms\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\Forms\CurrencyField_Readonly;
7
use SilverStripe\ORM\FieldType\DBCurrency;
8
9
class CurrencyFieldReadonlyTest extends SapphireTest
10
{
11
    public function testPerformReadonlyTransformation()
12
    {
13
        $field = new CurrencyField_Readonly('Test', '', '$5.00');
14
        $result = $field->performReadonlyTransformation();
15
        $this->assertInstanceOf(CurrencyField_Readonly::class, $result);
16
        $this->assertNotSame($result, $field, 'Should return a clone of the field');
17
    }
18
19
    public function testFieldWithValue()
20
    {
21
        $field = new CurrencyField_Readonly('Test', '', '$5.00');
22
        $result = $field->Field();
23
24
        $this->assertContains('<input', $result, 'An input should be rendered');
25
        $this->assertContains('readonly', $result, 'The input should be readonly');
26
        $this->assertContains('$5.00', $result, 'The value should be rendered');
27
    }
28
29
    public function testFieldWithOutValue()
30
    {
31
        DBCurrency::config()->update('currency_symbol', 'AUD');
32
        $field = new CurrencyField_Readonly('Test', '', null);
33
        $result = $field->Field();
34
35
        $this->assertContains('<input', $result, 'An input should be rendered');
36
        $this->assertContains('readonly', $result, 'The input should be readonly');
37
        $this->assertContains('AUD0.00', $result, 'The value should be rendered');
38
    }
39
40
    /**
41
     * @todo: Update the expectation when intl for currencies is implemented
42
     */
43
    public function testFieldWithCustomisedCurrencySymbol()
44
    {
45
        DBCurrency::config()->update('currency_symbol', '€');
46
        $field = new CurrencyField_Readonly('Test', '', '€5.00');
47
        $result = $field->Field();
48
49
        $this->assertContains('<input', $result, 'An input should be rendered');
50
        $this->assertContains('readonly', $result, 'The input should be readonly');
51
        $this->assertContains('€5.00', $result, 'The value should be rendered');
52
    }
53
}
54