forked from joomla-framework/string
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormaliseTest.php
More file actions
269 lines (250 loc) · 7.77 KB
/
Copy pathNormaliseTest.php
File metadata and controls
269 lines (250 loc) · 7.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
/**
* @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\String\Tests;
use Joomla\String\Normalise;
use PHPUnit\Framework\TestCase;
/**
* NormaliseTest
*
* @since 1.0
*/
class NormaliseTest extends TestCase
{
/**
* Method to seed data to testFromCamelCase.
*
* @return \Generator
*
* @since 1.0
*/
public function seedTestFromCamelCase(): \Generator
{
// Note: string, expected
yield ['FooBarABCDef', ['Foo', 'Bar', 'ABC', 'Def']];
yield ['JFooBar', ['J', 'Foo', 'Bar']];
yield ['J001FooBar002', ['J001', 'Foo', 'Bar002']];
yield ['abcDef', ['abc', 'Def']];
yield ['abc_defGhi_Jkl', ['abc_def', 'Ghi_Jkl']];
yield ['ThisIsA_NASAAstronaut', ['This', 'Is', 'A_NASA', 'Astronaut']];
yield ['JohnFitzgerald_Kennedy', ['John', 'Fitzgerald_Kennedy']];
}
/**
* Method to seed data to testFromCamelCase.
*
* @return \Generator
*
* @since 1.0
*/
public function seedTestFromCamelCase_nongrouped(): \Generator
{
yield ['Foo Bar', 'FooBar'];
yield ['foo Bar', 'fooBar'];
yield ['Foobar', 'Foobar'];
yield ['foobar', 'foobar'];
}
/**
* Method to seed data to testToCamelCase.
*
* @return \Generator
*
* @since 1.0
*/
public function seedTestToCamelCase(): \Generator
{
yield ['FooBar', 'Foo Bar'];
yield ['FooBar', 'Foo-Bar'];
yield ['FooBar', 'Foo_Bar'];
yield ['FooBar', 'foo bar'];
yield ['FooBar', 'foo-bar'];
yield ['FooBar', 'foo_bar'];
}
/**
* Method to seed data to testToDashSeparated.
*
* @return \Generator
*
* @since 1.0
*/
public function seedTestToDashSeparated(): \Generator
{
yield ['Foo-Bar', 'Foo Bar'];
yield ['Foo-Bar', 'Foo-Bar'];
yield ['Foo-Bar', 'Foo_Bar'];
yield ['foo-bar', 'foo bar'];
yield ['foo-bar', 'foo-bar'];
yield ['foo-bar', 'foo_bar'];
yield ['foo-bar', 'foo bar'];
yield ['foo-bar', 'foo---bar'];
yield ['foo-bar', 'foo___bar'];
}
/**
* Method to seed data to testToSpaceSeparated.
*
* @return \Generator
*
* @since 1.0
*/
public function seedTestToSpaceSeparated(): \Generator
{
yield ['Foo Bar', 'Foo Bar'];
yield ['Foo Bar', 'Foo-Bar'];
yield ['Foo Bar', 'Foo_Bar'];
yield ['foo bar', 'foo bar'];
yield ['foo bar', 'foo-bar'];
yield ['foo bar', 'foo_bar'];
yield ['foo bar', 'foo bar'];
yield ['foo bar', 'foo---bar'];
yield ['foo bar', 'foo___bar'];
}
/**
* Method to seed data to testToUnderscoreSeparated.
*
* @return \Generator
*
* @since 1.0
*/
public function seedTestToUnderscoreSeparated(): \Generator
{
yield ['Foo_Bar', 'Foo Bar'];
yield ['Foo_Bar', 'Foo-Bar'];
yield ['Foo_Bar', 'Foo_Bar'];
yield ['foo_bar', 'foo bar'];
yield ['foo_bar', 'foo-bar'];
yield ['foo_bar', 'foo_bar'];
yield ['foo_bar', 'foo bar'];
yield ['foo_bar', 'foo---bar'];
yield ['foo_bar', 'foo___bar'];
}
/**
* Method to seed data to testToVariable.
*
* @return \Generator
*
* @since 1.0
*/
public function seedTestToVariable(): \Generator
{
yield ['myFooBar', 'My Foo Bar'];
yield ['myFooBar', 'My Foo-Bar'];
yield ['myFooBar', 'My Foo_Bar'];
yield ['myFooBar', 'my foo bar'];
yield ['myFooBar', 'my foo-bar'];
yield ['myFooBar', 'my foo_bar'];
yield ['abc3def4', '1abc3def4'];
}
/**
* Method to seed data to testToKey.
*
* @return \Generator
*
* @since 1.0
*/
public function seedTestToKey(): \Generator
{
yield ['foo_bar', 'Foo Bar'];
yield ['foo_bar', 'Foo-Bar'];
yield ['foo_bar', 'Foo_Bar'];
yield ['foo_bar', 'foo bar'];
yield ['foo_bar', 'foo-bar'];
yield ['foo_bar', 'foo_bar'];
}
/**
* @testdox A non-grouped string is converted from its camel case representation
*
* @param string $expected The expected value from the method.
* @param string $input The input value for the method.
*
* @dataProvider seedTestFromCamelCase_nongrouped
*/
public function testFromCamelCase_nongrouped(string $expected, string $input)
{
$this->assertEquals($expected, Normalise::fromCamelcase($input));
}
/**
* @testdox A grouped string is converted from its camel case representation
*
* @param string $input The input value for the method.
* @param array|string $expected The expected value from the method.
*
* @dataProvider seedTestFromCamelCase
*/
public function testFromCamelCase_grouped(string $input, $expected)
{
$this->assertEquals($expected, Normalise::fromCamelcase($input, true));
}
/**
* @testdox A string is converted to its camel case representation
*
* @param string $expected The expected value from the method.
* @param string $input The input value for the method.
*
* @dataProvider seedTestToCamelCase
*/
public function testToCamelCase(string $expected, string $input)
{
$this->assertEquals($expected, Normalise::toCamelcase($input));
}
/**
* @testdox A string is converted to its dash separated representation
*
* @param string $expected The expected value from the method.
* @param string $input The input value for the method.
*
* @dataProvider seedTestToDashSeparated
*/
public function testToDashSeparated(string $expected, string $input)
{
$this->assertEquals($expected, Normalise::toDashSeparated($input));
}
/**
* @testdox A string is converted to its space separated representation
*
* @param string $expected The expected value from the method.
* @param string $input The input value for the method.
*
* @dataProvider seedTestToSpaceSeparated
*/
public function testToSpaceSeparated(string $expected, string $input)
{
$this->assertEquals($expected, Normalise::toSpaceSeparated($input));
}
/**
* @testdox A string is converted to its underscore separated representation
*
* @param string $expected The expected value from the method.
* @param string $input The input value for the method.
*
* @dataProvider seedTestToUnderscoreSeparated
*/
public function testToUnderscoreSeparated(string $expected, string $input)
{
$this->assertEquals($expected, Normalise::toUnderscoreSeparated($input));
}
/**
* @testdox A string is converted to a value suitable for use as a variable name
*
* @param string $expected The expected value from the method.
* @param string $input The input value for the method.
*
* @dataProvider seedTestToVariable
*/
public function testToVariable(string $expected, string $input)
{
$this->assertEquals($expected, Normalise::toVariable($input));
}
/**
* @testdox A string is converted to a value suitable for use as a key name
*
* @param string $expected The expected value from the method.
* @param string $input The input value for the method.
*
* @dataProvider seedTestToKey
*/
public function testToKey(string $expected, string $input)
{
$this->assertEquals($expected, Normalise::toKey($input));
}
}