FieldTextTest::test1()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
/*
4
 * Copyright (C) 2015 Michael Herold <[email protected]>
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace hemio\form;
21
22
/**
23
 * Description of InputText
24
 *
25
 * @author Michael Herold <[email protected]>
26
 */
27
class FieldTextTest extends \Helpers {
28
29
    public function test1() {
30
31
        $inputName = 'form_test_input1';
32
33
        $post = [
34
            $inputName => 'New-X-value'
35
        ];
36
37
        $stored = [
38
            'input1' => 'DB-X-value'
39
        ];
40
41
        $form = new FormPost('test', $post, null, $stored);
42
43
        $input1 = new FieldText('input1', _('Title'));
44
        $input1->setDefaultValue('Default-X-value');
45
        $input1->setValueTransformation('remove_strange_x', function ($value) {
46
            return str_replace('-X-', ' ', $value);
47
        });
48
        $form->addChild($input1);
49
50
        $this->assertEquals($inputName, $input1->getHtmlName());
51
52
        $this->assertEquals('New value', $input1->getValueToUse(), 'Wrong valueToUse');
53
        $this->assertEquals('DB value', $input1->getValueStored(), 'Wrong valueStored');
54
        $this->assertEquals('New value', $input1->getValueUser(), 'Wrong valueUser');
55
        $this->assertEquals('Default value', $input1->getValueDefault(), 'Wrong valueDefault');
56
    }
57
58
}
59