Completed
Push — 1.0 ( 2aa723...3dc7ce )
by joanhey
8s
created

UtilTest::testCamelcase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 9.4285
1
<?php
2
/**
3
 * KumbiaPHP web & app Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://wiki.kumbiaphp.com/Licencia
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Kumbia
16
 * @package    Session
17
 * @copyright  Copyright (c) 2005 - 2016 Kumbia Team (http://www.kumbiaphp.com)
18
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
19
 */
20
21
/**
22
 * @category Test
23
 *
24
 * @runTestsInSeparateProcesses
25
 */
26
class UtilTest extends PHPUnit_Framework_TestCase
27
{
28
    public function underescoreDataProvider()
29
    {
30
        return array(
31
            array('Hello World', 'Hello_World'),
32
            array('', ''),
33
            array('-_ae123$%&', '-_ae123$%&'),
34
            array(' ', '_'),
35
            array('  ', '__'),
36
            array('---', '---'),
37
            array(
38
                'If you did not receive a copy of the license and are unable to',
39
                'If_you_did_not_receive_a_copy_of_the_license_and_are_unable_to',
40
            ),
41
        );
42
    }
43
44
    public function dashDataProvider()
45
    {
46
        return array(
47
            array('Hello World', 'Hello-World'),
48
            array('', ''),
49
            array('-_ae123$%&', '-_ae123$%&'),
50
            array(' ', '-'),
51
            array('  ', '--'),
52
            array('---', '---'),
53
            array('___', '___'),
54
            array(
55
                'If you did not receive a copy of the license and are unable to',
56
                'If-you-did-not-receive-a-copy-of-the-license-and-are-unable-to',
57
            ),
58
        );
59
    }
60
61
    public function humanizeDataProvider()
62
    {
63
        return array(
64
            array('Hello-World', 'Hello World'),
65
            array('Hello_World', 'Hello World'),
66
            array('', ''),
67
            array('-_ae123$%&', '  ae123$%&'),
68
            array(' ', ' '),
69
            array('  ', '  '),
70
            array('---', '   '),
71
            array('___', '   '),
72
            array('-__---___', '         '),
73
            array(
74
                'If you-did_not receive a-copy of the-license_and_are unable to',
75
                'If you did not receive a copy of the license and are unable to',
76
            ),
77
        );
78
    }
79
80
    public function encomillarDataProvider()
81
    {
82
        return array(
83
            array('a,b,c', '"a","b","c"'),
84
            array('a, b, c', '"a"," b"," c"'),
85
            array(' a , b , c ', '" a "," b "," c "'),
86
            array('hello , world,123', '"hello "," world","123"'),
87
        );
88
    }
89
90
    public function camelcaseDataProvider()
91
    {
92
        return array(
93
            array('a_b_c', 'ABC', 'aBC'),
94
            array('users', 'Users', 'users'),
95
            array('table_name', 'TableName', 'tableName'),
96
            array('table__name', 'TableName', 'tableName'),
97
            array('table___name', 'TableName', 'tableName'),
98
            array('table_name1', 'TableName1', 'tableName1'),
99
            array('table_name_1', 'TableName1', 'tableName1'),
100
            array('table_1_name', 'Table1Name', 'table1Name'),
101
            array('table_1name', 'Table1name', 'table1name'),
102
            array('table1_name', 'Table1Name', 'table1Name'),
103
            array('table1_2name', 'Table12name', 'table12name'),
104
            array('table_1_2_name', 'Table12Name', 'table12Name'),
105
            array('table_12_name', 'Table12Name', 'table12Name'),
106
            array('table12_name', 'Table12Name', 'table12Name'),
107
            array('table12name', 'Table12name', 'table12name'),
108
        );
109
    }
110
111
    public function smallcaseDataProvider()
112
    {
113
        return array(
114
            array('ABC', 'a_b_c'),
115
            array('Users', 'users'),
116
            array('TableName', 'table_name'),
117
            array('TableName1', 'table_name1'),
118
            array('Table1Name', 'table1_name'),
119
            array('Table12name', 'table12name'),
120
            array('Table12Name', 'table12_name'),
121
        );
122
    }
123
124
    public function getParamsDataProvider()
125
    {
126
        return array(
127
            array(array(), array()),
128
            array(array('a: b'), array('a' => 'b')),
129
            array(array('a: b', 'c: d'), array('a' => 'b', 'c' => 'd')),
130
            array(
131
                array('param1: value1', 'param2:  value2'),
132
                array('param1' => 'value1', 'param2' => ' value2')
133
            ),
134
            array(
135
                array('param1 : value1', 'param2 :  value2'),
136
                array('param1 ' => 'value1', 'param2 ' => ' value2')
137
            ),
138
            array(
139
                array('value1', 'value2'),
140
                array('value1', 'value2'),
141
            ),
142
        );
143
    }
144
145
    /**
146
     * @dataProvider underescoreDataProvider
147
     */
148
    public function testUnderescore($original, $expected)
149
    {
150
        $result = Util::underscore($original);
151
152
        $this->assertSame($expected, $result);
153
    }
154
155
    /**
156
     * @dataProvider dashDataProvider
157
     */
158
    public function testDash($original, $expected)
159
    {
160
        $result = Util::dash($original);
161
162
        $this->assertSame($expected, $result);
163
    }
164
165
    /**
166
     * @dataProvider humanizeDataProvider
167
     */
168
    public function testHumanize($original, $expected)
169
    {
170
        $result = Util::humanize($original);
171
172
        $this->assertSame($expected, $result);
173
    }
174
175
    /**
176
     * @dataProvider encomillarDataProvider
177
     */
178
    public function testEncomillar($original, $expected)
179
    {
180
        $result = Util::encomillar($original);
181
182
        $this->assertSame($expected, $result);
183
    }
184
185
    /**
186
     * @dataProvider camelcaseDataProvider
187
     */
188
    public function testCamelcase($original, $expected, $expectedLowerCase)
189
    {
190
        $result = Util::camelcase($original);
191
        $resultLowerCase = Util::camelcase($original, true);
192
193
        $this->assertSame($expected, $result);
194
        $this->assertSame($expectedLowerCase, $resultLowerCase);
195
    }
196
197
    /**
198
     * @dataProvider smallcaseDataProvider
199
     */
200
    public function testSmallcase($original, $expected)
201
    {
202
        $result = Util::smallcase($original);
203
204
        $this->assertSame($expected, $result);
205
    }
206
207
    /**
208
     * @dataProvider getParamsDataProvider
209
     */
210
    public function testGetParams($original, $expected)
211
    {
212
        $result = Util::getParams($original);
213
214
        $this->assertEquals($expected, $result);
215
    }
216
}
217