HelperFormElementTest.php 4.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/26/16
 * Time: 2:56 PM
 */

namespace qfq;

use qfq\HelperFormElement;

require_once(__DIR__ . '/../../qfq/helper/HelperFormElement.php');
require_once(__DIR__ . '/../../qfq/Constants.php');

class HelperFormElementTest extends \PHPUnit_Framework_TestCase {

19
20
21
22
23
24
25
26
27
28
29
30
31
32
    public function testExplodeParameter() {
        $a = array();

        HelperFormElement::explodeParameter($a);
        $this->assertEquals(array(), $a, "Both arrays should be equal and empty");

        $a = ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete"];
        $b = ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete", 'work' => 12, 'list' => '1:new,2:edit,3:delete'];

        HelperFormElement::explodeParameter($a);
        $this->assertEquals($b, $a, "Both arrays should be equal");
    }

    public function testExplodeParameterInArrayElements() {
33
        $a = array();
34
        HelperFormElement::explodeParameterInArrayElements($a);
35
36
37
38
39
        $this->assertEquals(array(), $a, "Both arrays should be equal and empty");

        $a = [0 => ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete"]];
        $b = [0 => ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete", 'work' => 12, 'list' => '1:new,2:edit,3:delete']];

40
        HelperFormElement::explodeParameterInArrayElements($a);
41
42
43
        $this->assertEquals($b, $a, "Both arrays should be equal");
    }

44

45
    /**
46
     * @expectedException \qfq\UserFormException
47
48
     *
     */
49
    public function testExplodeFieldParameterException() {
50
51

        $a = [0 => ['id' => 111, 'name' => 'hello', 'collision' => 'dummy', 'parameter' => "work=12\ncollision=1:new,2:edit,3:delete"]];
52
        HelperFormElement::explodeParameterInArrayElements($a);
53
54
55

    }

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    public function testduplicateRetypeElements() {

        $a = [0 => [FE_NAME => 'hello', FE_LABEL => 'my label', FE_NOTE => 'my note']];
        $b = HelperFormElement::duplicateRetypeElements($a);
        $this->assertEquals($a, $b, "Both arrays should be equal");

        $a = [0 => [FE_NAME => 'hello', FE_LABEL => 'my label', FE_NOTE => 'my note', FE_RETYPE => '']];
        $b = HelperFormElement::duplicateRetypeElements($a);
        $this->assertEquals(count($a) + 1, count($b), "Both arrays should be same count");
        $this->assertEquals('1', $b[0][FE_RETYPE], "FE_RETYPE should be set to '1'");

        $a = [0 => [FE_NAME => 'hello', FE_LABEL => 'my label', FE_NOTE => 'my note', FE_RETYPE => '0']];
        $b = HelperFormElement::duplicateRetypeElements($a);
        $this->assertEquals($a, $b, "Both arrays should be same count");
        $this->assertEquals('0', $b[0][FE_RETYPE], "FE_RETYPE should be unchanged");

        $a = [0 => [FE_NAME => 'hello', FE_LABEL => 'my label', FE_NOTE => 'my note', FE_RETYPE => '1']];
        $b = HelperFormElement::duplicateRetypeElements($a);
        $this->assertEquals(count($a) + 1, count($b), "Both arrays should be same count");
        $this->assertEquals('1', $b[0][FE_RETYPE], "FE_RETYPE should be unchanged");
        $this->assertEquals($b[0][FE_NAME] . RETYPE_FE_NAME_EXTENSION, $b[1][FE_NAME], "New name should be extended by: " . RETYPE_FE_NAME_EXTENSION);
        $this->assertEquals($b[0][FE_LABEL], $b[1][FE_LABEL], "Both text should be equal");
        $this->assertEquals($b[0][FE_NOTE], $b[1][FE_NOTE], "Both text should be equal");

        $a = [0 => [FE_NAME => 'hello', FE_LABEL => 'my label', FE_NOTE => 'my note', FE_RETYPE => '1', FE_RETYPE_LABEL => '', FE_RETYPE_NOTE => '']];
        $b = HelperFormElement::duplicateRetypeElements($a);
        $this->assertEquals('', $b[1][FE_LABEL], "String should be empty");
        $this->assertEquals('', $b[1][FE_NOTE], "String should be empty");

        $a = [0 => [FE_NAME => 'hello', FE_LABEL => 'my label', FE_NOTE => 'my note', FE_RETYPE => '1', FE_RETYPE_LABEL => 'new label', FE_RETYPE_NOTE => 'new note']];
        $b = HelperFormElement::duplicateRetypeElements($a);

        $this->assertEquals('my label', $b[0][FE_LABEL], "String should be equal");
        $this->assertEquals('my note', $b[0][FE_NOTE], "String should be equal");
        $this->assertEquals('new label', $b[1][FE_LABEL], "String should be equal");
        $this->assertEquals('new note', $b[1][FE_NOTE], "String should be equal");

    }


96
}