| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* InflectorTest
|
|
|
4 |
*
|
|
|
5 |
* InflectorTest is used to test cases on the Inflector class
|
|
|
6 |
*
|
|
|
7 |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
8 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
9 |
*
|
|
|
10 |
* Licensed under The MIT License
|
|
|
11 |
* For full copyright and license information, please see the LICENSE.txt
|
|
|
12 |
* Redistributions of files must retain the above copyright notice.
|
|
|
13 |
*
|
|
|
14 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
15 |
* @link http://book.cakephp.org/2.0/en/development/testing.html
|
|
|
16 |
* @package Cake.Test.Case.Utility
|
|
|
17 |
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
18 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Included libraries.
|
|
|
23 |
*/
|
|
|
24 |
App::uses('Inflector', 'Utility');
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Short description for class.
|
|
|
28 |
*
|
|
|
29 |
* @package Cake.Test.Case.Utility
|
|
|
30 |
*/
|
|
|
31 |
class InflectorTest extends CakeTestCase {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* tearDown
|
|
|
35 |
*
|
|
|
36 |
* @return void
|
|
|
37 |
*/
|
|
|
38 |
public function tearDown() {
|
|
|
39 |
parent::tearDown();
|
|
|
40 |
Inflector::reset();
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* testInflectingSingulars method
|
|
|
45 |
*
|
|
|
46 |
* @return void
|
|
|
47 |
*/
|
|
|
48 |
public function testInflectingSingulars() {
|
|
|
49 |
$this->assertEquals(Inflector::singularize('categorias'), 'categoria');
|
|
|
50 |
$this->assertEquals(Inflector::singularize('menus'), 'menu');
|
|
|
51 |
$this->assertEquals(Inflector::singularize('news'), 'news');
|
|
|
52 |
$this->assertEquals(Inflector::singularize('food_menus'), 'food_menu');
|
|
|
53 |
$this->assertEquals(Inflector::singularize('Menus'), 'Menu');
|
|
|
54 |
$this->assertEquals(Inflector::singularize('FoodMenus'), 'FoodMenu');
|
|
|
55 |
$this->assertEquals(Inflector::singularize('houses'), 'house');
|
|
|
56 |
$this->assertEquals(Inflector::singularize('powerhouses'), 'powerhouse');
|
|
|
57 |
$this->assertEquals(Inflector::singularize('quizzes'), 'quiz');
|
|
|
58 |
$this->assertEquals(Inflector::singularize('Buses'), 'Bus');
|
|
|
59 |
$this->assertEquals(Inflector::singularize('buses'), 'bus');
|
|
|
60 |
$this->assertEquals(Inflector::singularize('matrix_rows'), 'matrix_row');
|
|
|
61 |
$this->assertEquals(Inflector::singularize('matrices'), 'matrix');
|
|
|
62 |
$this->assertEquals(Inflector::singularize('vertices'), 'vertex');
|
|
|
63 |
$this->assertEquals(Inflector::singularize('indices'), 'index');
|
|
|
64 |
$this->assertEquals(Inflector::singularize('Aliases'), 'Alias');
|
|
|
65 |
$this->assertEquals(Inflector::singularize('Alias'), 'Alias');
|
|
|
66 |
$this->assertEquals(Inflector::singularize('Media'), 'Media');
|
|
|
67 |
$this->assertEquals(Inflector::singularize('NodeMedia'), 'NodeMedia');
|
|
|
68 |
$this->assertEquals(Inflector::singularize('alumni'), 'alumnus');
|
|
|
69 |
$this->assertEquals(Inflector::singularize('bacilli'), 'bacillus');
|
|
|
70 |
$this->assertEquals(Inflector::singularize('cacti'), 'cactus');
|
|
|
71 |
$this->assertEquals(Inflector::singularize('foci'), 'focus');
|
|
|
72 |
$this->assertEquals(Inflector::singularize('fungi'), 'fungus');
|
|
|
73 |
$this->assertEquals(Inflector::singularize('nuclei'), 'nucleus');
|
|
|
74 |
$this->assertEquals(Inflector::singularize('octopuses'), 'octopus');
|
|
|
75 |
$this->assertEquals(Inflector::singularize('radii'), 'radius');
|
|
|
76 |
$this->assertEquals(Inflector::singularize('stimuli'), 'stimulus');
|
|
|
77 |
$this->assertEquals(Inflector::singularize('syllabi'), 'syllabus');
|
|
|
78 |
$this->assertEquals(Inflector::singularize('termini'), 'terminus');
|
|
|
79 |
$this->assertEquals(Inflector::singularize('viri'), 'virus');
|
|
|
80 |
$this->assertEquals(Inflector::singularize('people'), 'person');
|
|
|
81 |
$this->assertEquals(Inflector::singularize('gloves'), 'glove');
|
|
|
82 |
$this->assertEquals(Inflector::singularize('doves'), 'dove');
|
|
|
83 |
$this->assertEquals(Inflector::singularize('lives'), 'life');
|
|
|
84 |
$this->assertEquals(Inflector::singularize('knives'), 'knife');
|
|
|
85 |
$this->assertEquals(Inflector::singularize('wolves'), 'wolf');
|
|
|
86 |
$this->assertEquals(Inflector::singularize('slaves'), 'slave');
|
|
|
87 |
$this->assertEquals(Inflector::singularize('shelves'), 'shelf');
|
|
|
88 |
$this->assertEquals(Inflector::singularize('taxis'), 'taxi');
|
|
|
89 |
$this->assertEquals(Inflector::singularize('taxes'), 'tax');
|
|
|
90 |
$this->assertEquals(Inflector::singularize('Taxes'), 'Tax');
|
|
|
91 |
$this->assertEquals(Inflector::singularize('AwesomeTaxes'), 'AwesomeTax');
|
|
|
92 |
$this->assertEquals(Inflector::singularize('faxes'), 'fax');
|
|
|
93 |
$this->assertEquals(Inflector::singularize('waxes'), 'wax');
|
|
|
94 |
$this->assertEquals(Inflector::singularize('niches'), 'niche');
|
|
|
95 |
$this->assertEquals(Inflector::singularize('waves'), 'wave');
|
|
|
96 |
$this->assertEquals(Inflector::singularize('bureaus'), 'bureau');
|
|
|
97 |
$this->assertEquals(Inflector::singularize('genetic_analyses'), 'genetic_analysis');
|
|
|
98 |
$this->assertEquals(Inflector::singularize('doctor_diagnoses'), 'doctor_diagnosis');
|
|
|
99 |
$this->assertEquals(Inflector::singularize('parantheses'), 'paranthesis');
|
|
|
100 |
$this->assertEquals(Inflector::singularize('Causes'), 'Cause');
|
|
|
101 |
$this->assertEquals(Inflector::singularize('colossuses'), 'colossus');
|
|
|
102 |
$this->assertEquals(Inflector::singularize('diagnoses'), 'diagnosis');
|
|
|
103 |
$this->assertEquals(Inflector::singularize('bases'), 'basis');
|
|
|
104 |
$this->assertEquals(Inflector::singularize('analyses'), 'analysis');
|
|
|
105 |
$this->assertEquals(Inflector::singularize('curves'), 'curve');
|
|
|
106 |
$this->assertEquals(Inflector::singularize('cafes'), 'cafe');
|
|
|
107 |
$this->assertEquals(Inflector::singularize('roofs'), 'roof');
|
|
|
108 |
$this->assertEquals(Inflector::singularize('foes'), 'foe');
|
|
|
109 |
$this->assertEquals(Inflector::singularize('databases'), 'database');
|
|
|
110 |
$this->assertEquals(Inflector::singularize('cookies'), 'cookie');
|
|
|
111 |
$this->assertEquals(Inflector::singularize('thieves'), 'thief');
|
|
|
112 |
$this->assertEquals(Inflector::singularize('potatoes'), 'potato');
|
|
|
113 |
$this->assertEquals(Inflector::singularize('heroes'), 'hero');
|
|
|
114 |
$this->assertEquals(Inflector::singularize('buffalos'), 'buffalo');
|
|
|
115 |
$this->assertEquals(Inflector::singularize('babies'), 'baby');
|
|
|
116 |
$this->assertEquals(Inflector::singularize('teeth'), 'tooth');
|
|
|
117 |
$this->assertEquals(Inflector::singularize('geese'), 'goose');
|
|
|
118 |
$this->assertEquals(Inflector::singularize('feet'), 'foot');
|
|
|
119 |
$this->assertEquals(Inflector::singularize('objectives'), 'objective');
|
|
|
120 |
$this->assertEquals(Inflector::singularize('archives'), 'archive');
|
|
|
121 |
$this->assertEquals(Inflector::singularize('briefs'), 'brief');
|
|
|
122 |
$this->assertEquals(Inflector::singularize('quotas'), 'quota');
|
|
|
123 |
$this->assertEquals(Inflector::singularize('curves'), 'curve');
|
|
|
124 |
$this->assertEquals(Inflector::singularize('body_curves'), 'body_curve');
|
|
|
125 |
$this->assertEquals(Inflector::singularize('metadata'), 'metadata');
|
|
|
126 |
$this->assertEquals(Inflector::singularize(''), '');
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
* testInflectingPlurals method
|
|
|
131 |
*
|
|
|
132 |
* @return void
|
|
|
133 |
*/
|
|
|
134 |
public function testInflectingPlurals() {
|
|
|
135 |
$this->assertEquals(Inflector::pluralize('categoria'), 'categorias');
|
|
|
136 |
$this->assertEquals(Inflector::pluralize('house'), 'houses');
|
|
|
137 |
$this->assertEquals(Inflector::pluralize('powerhouse'), 'powerhouses');
|
|
|
138 |
$this->assertEquals(Inflector::pluralize('Bus'), 'Buses');
|
|
|
139 |
$this->assertEquals(Inflector::pluralize('bus'), 'buses');
|
|
|
140 |
$this->assertEquals(Inflector::pluralize('menu'), 'menus');
|
|
|
141 |
$this->assertEquals(Inflector::pluralize('news'), 'news');
|
|
|
142 |
$this->assertEquals(Inflector::pluralize('food_menu'), 'food_menus');
|
|
|
143 |
$this->assertEquals(Inflector::pluralize('Menu'), 'Menus');
|
|
|
144 |
$this->assertEquals(Inflector::pluralize('FoodMenu'), 'FoodMenus');
|
|
|
145 |
$this->assertEquals(Inflector::pluralize('quiz'), 'quizzes');
|
|
|
146 |
$this->assertEquals(Inflector::pluralize('matrix_row'), 'matrix_rows');
|
|
|
147 |
$this->assertEquals(Inflector::pluralize('matrix'), 'matrices');
|
|
|
148 |
$this->assertEquals(Inflector::pluralize('vertex'), 'vertices');
|
|
|
149 |
$this->assertEquals(Inflector::pluralize('index'), 'indices');
|
|
|
150 |
$this->assertEquals(Inflector::pluralize('Alias'), 'Aliases');
|
|
|
151 |
$this->assertEquals(Inflector::pluralize('Aliases'), 'Aliases');
|
|
|
152 |
$this->assertEquals(Inflector::pluralize('Media'), 'Media');
|
|
|
153 |
$this->assertEquals(Inflector::pluralize('NodeMedia'), 'NodeMedia');
|
|
|
154 |
$this->assertEquals(Inflector::pluralize('alumnus'), 'alumni');
|
|
|
155 |
$this->assertEquals(Inflector::pluralize('bacillus'), 'bacilli');
|
|
|
156 |
$this->assertEquals(Inflector::pluralize('cactus'), 'cacti');
|
|
|
157 |
$this->assertEquals(Inflector::pluralize('focus'), 'foci');
|
|
|
158 |
$this->assertEquals(Inflector::pluralize('fungus'), 'fungi');
|
|
|
159 |
$this->assertEquals(Inflector::pluralize('nucleus'), 'nuclei');
|
|
|
160 |
$this->assertEquals(Inflector::pluralize('octopus'), 'octopuses');
|
|
|
161 |
$this->assertEquals(Inflector::pluralize('radius'), 'radii');
|
|
|
162 |
$this->assertEquals(Inflector::pluralize('stimulus'), 'stimuli');
|
|
|
163 |
$this->assertEquals(Inflector::pluralize('syllabus'), 'syllabi');
|
|
|
164 |
$this->assertEquals(Inflector::pluralize('terminus'), 'termini');
|
|
|
165 |
$this->assertEquals(Inflector::pluralize('virus'), 'viri');
|
|
|
166 |
$this->assertEquals(Inflector::pluralize('person'), 'people');
|
|
|
167 |
$this->assertEquals(Inflector::pluralize('people'), 'people');
|
|
|
168 |
$this->assertEquals(Inflector::pluralize('glove'), 'gloves');
|
|
|
169 |
$this->assertEquals(Inflector::pluralize('crisis'), 'crises');
|
|
|
170 |
$this->assertEquals(Inflector::pluralize('tax'), 'taxes');
|
|
|
171 |
$this->assertEquals(Inflector::pluralize('wave'), 'waves');
|
|
|
172 |
$this->assertEquals(Inflector::pluralize('bureau'), 'bureaus');
|
|
|
173 |
$this->assertEquals(Inflector::pluralize('cafe'), 'cafes');
|
|
|
174 |
$this->assertEquals(Inflector::pluralize('roof'), 'roofs');
|
|
|
175 |
$this->assertEquals(Inflector::pluralize('foe'), 'foes');
|
|
|
176 |
$this->assertEquals(Inflector::pluralize('cookie'), 'cookies');
|
|
|
177 |
$this->assertEquals(Inflector::pluralize('wolf'), 'wolves');
|
|
|
178 |
$this->assertEquals(Inflector::pluralize('thief'), 'thieves');
|
|
|
179 |
$this->assertEquals(Inflector::pluralize('potato'), 'potatoes');
|
|
|
180 |
$this->assertEquals(Inflector::pluralize('hero'), 'heroes');
|
|
|
181 |
$this->assertEquals(Inflector::pluralize('buffalo'), 'buffalo');
|
|
|
182 |
$this->assertEquals(Inflector::pluralize('tooth'), 'teeth');
|
|
|
183 |
$this->assertEquals(Inflector::pluralize('goose'), 'geese');
|
|
|
184 |
$this->assertEquals(Inflector::pluralize('foot'), 'feet');
|
|
|
185 |
$this->assertEquals(Inflector::pluralize('objective'), 'objectives');
|
|
|
186 |
$this->assertEquals(Inflector::pluralize('brief'), 'briefs');
|
|
|
187 |
$this->assertEquals(Inflector::pluralize('quota'), 'quotas');
|
|
|
188 |
$this->assertEquals(Inflector::pluralize('curve'), 'curves');
|
|
|
189 |
$this->assertEquals(Inflector::pluralize('body_curve'), 'body_curves');
|
|
|
190 |
$this->assertEquals(Inflector::pluralize('metadata'), 'metadata');
|
|
|
191 |
$this->assertEquals(Inflector::pluralize(''), '');
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
/**
|
|
|
195 |
* testInflectorSlug method
|
|
|
196 |
*
|
|
|
197 |
* @return void
|
|
|
198 |
*/
|
|
|
199 |
public function testInflectorSlug() {
|
|
|
200 |
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more');
|
|
|
201 |
$expected = 'Foo_Bar_Not_just_for_breakfast_any_more';
|
|
|
202 |
$this->assertEquals($expected, $result);
|
|
|
203 |
|
|
|
204 |
$result = Inflector::slug('this/is/a/path');
|
|
|
205 |
$expected = 'this_is_a_path';
|
|
|
206 |
$this->assertEquals($expected, $result);
|
|
|
207 |
|
|
|
208 |
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "-");
|
|
|
209 |
$expected = 'Foo-Bar-Not-just-for-breakfast-any-more';
|
|
|
210 |
$this->assertEquals($expected, $result);
|
|
|
211 |
|
|
|
212 |
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "+");
|
|
|
213 |
$expected = 'Foo+Bar+Not+just+for+breakfast+any+more';
|
|
|
214 |
$this->assertEquals($expected, $result);
|
|
|
215 |
|
|
|
216 |
$result = Inflector::slug('Äpfel Über Öl grün ärgert groß öko', '-');
|
|
|
217 |
$expected = 'Aepfel-Ueber-Oel-gruen-aergert-gross-oeko';
|
|
|
218 |
$this->assertEquals($expected, $result);
|
|
|
219 |
|
|
|
220 |
$result = Inflector::slug('The truth - and- more- news', '-');
|
|
|
221 |
$expected = 'The-truth-and-more-news';
|
|
|
222 |
$this->assertEquals($expected, $result);
|
|
|
223 |
|
|
|
224 |
$result = Inflector::slug('The truth: and more news', '-');
|
|
|
225 |
$expected = 'The-truth-and-more-news';
|
|
|
226 |
$this->assertEquals($expected, $result);
|
|
|
227 |
|
|
|
228 |
$result = Inflector::slug('La langue française est un attribut de souveraineté en France', '-');
|
|
|
229 |
$expected = 'La-langue-francaise-est-un-attribut-de-souverainete-en-France';
|
|
|
230 |
$this->assertEquals($expected, $result);
|
|
|
231 |
|
|
|
232 |
$result = Inflector::slug('!@$#exciting stuff! - what !@-# was that?', '-');
|
|
|
233 |
$expected = 'exciting-stuff-what-was-that';
|
|
|
234 |
$this->assertEquals($expected, $result);
|
|
|
235 |
|
|
|
236 |
$result = Inflector::slug('20% of profits went to me!', '-');
|
|
|
237 |
$expected = '20-of-profits-went-to-me';
|
|
|
238 |
$this->assertEquals($expected, $result);
|
|
|
239 |
|
|
|
240 |
$result = Inflector::slug('#this melts your face1#2#3', '-');
|
|
|
241 |
$expected = 'this-melts-your-face1-2-3';
|
|
|
242 |
$this->assertEquals($expected, $result);
|
|
|
243 |
|
|
|
244 |
$result = Inflector::slug('controller/action/りんご/1');
|
|
|
245 |
$expected = 'controller_action_りんご_1';
|
|
|
246 |
$this->assertEquals($expected, $result);
|
|
|
247 |
|
|
|
248 |
$result = Inflector::slug('の話が出たので大丈夫かなあと');
|
|
|
249 |
$expected = 'の話が出たので大丈夫かなあと';
|
|
|
250 |
$this->assertEquals($expected, $result);
|
|
|
251 |
|
|
|
252 |
$result = Inflector::slug('posts/view/한국어/page:1/sort:asc');
|
|
|
253 |
$expected = 'posts_view_한국어_page_1_sort_asc';
|
|
|
254 |
$this->assertEquals($expected, $result);
|
|
|
255 |
|
|
|
256 |
$result = Inflector::slug("non\xc2\xa0breaking\xc2\xa0space");
|
|
|
257 |
$this->assertEquals('non_breaking_space', $result);
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
/**
|
|
|
261 |
* testInflectorSlugWithMap method
|
|
|
262 |
*
|
|
|
263 |
* @return void
|
|
|
264 |
*/
|
|
|
265 |
public function testInflectorSlugWithMap() {
|
|
|
266 |
Inflector::rules('transliteration', array('/r/' => '1'));
|
|
|
267 |
$result = Inflector::slug('replace every r');
|
|
|
268 |
$expected = '1eplace_eve1y_1';
|
|
|
269 |
$this->assertEquals($expected, $result);
|
|
|
270 |
|
|
|
271 |
$result = Inflector::slug('replace every r', '_');
|
|
|
272 |
$expected = '1eplace_eve1y_1';
|
|
|
273 |
$this->assertEquals($expected, $result);
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
/**
|
|
|
277 |
* testInflectorSlugWithMapOverridingDefault method
|
|
|
278 |
*
|
|
|
279 |
* @return void
|
|
|
280 |
*/
|
|
|
281 |
public function testInflectorSlugWithMapOverridingDefault() {
|
|
|
282 |
Inflector::rules('transliteration', array('/å/' => 'aa', '/ø/' => 'oe'));
|
|
|
283 |
$result = Inflector::slug('Testing æ ø å', '-');
|
|
|
284 |
$expected = 'Testing-ae-oe-aa';
|
|
|
285 |
$this->assertEquals($expected, $result);
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
/**
|
|
|
289 |
* testInflectorUnderscore method
|
|
|
290 |
*
|
|
|
291 |
* @return void
|
|
|
292 |
*/
|
|
|
293 |
public function testInflectorUnderscore() {
|
|
|
294 |
$this->assertSame(Inflector::underscore('TestThing'), 'test_thing');
|
|
|
295 |
$this->assertSame(Inflector::underscore('testThing'), 'test_thing');
|
|
|
296 |
$this->assertSame(Inflector::underscore('TestThingExtra'), 'test_thing_extra');
|
|
|
297 |
$this->assertSame(Inflector::underscore('testThingExtra'), 'test_thing_extra');
|
|
|
298 |
|
|
|
299 |
// Identical checks test the cache code path.
|
|
|
300 |
$this->assertSame(Inflector::underscore('TestThing'), 'test_thing');
|
|
|
301 |
$this->assertSame(Inflector::underscore('testThing'), 'test_thing');
|
|
|
302 |
$this->assertSame(Inflector::underscore('TestThingExtra'), 'test_thing_extra');
|
|
|
303 |
$this->assertSame(Inflector::underscore('testThingExtra'), 'test_thing_extra');
|
|
|
304 |
|
|
|
305 |
// Test stupid values
|
|
|
306 |
$this->assertSame(Inflector::underscore(''), '');
|
|
|
307 |
$this->assertSame(Inflector::underscore(0), '0');
|
|
|
308 |
$this->assertSame(Inflector::underscore(false), '');
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
/**
|
|
|
312 |
* testVariableNaming method
|
|
|
313 |
*
|
|
|
314 |
* @return void
|
|
|
315 |
*/
|
|
|
316 |
public function testVariableNaming() {
|
|
|
317 |
$this->assertEquals(Inflector::variable('test_field'), 'testField');
|
|
|
318 |
$this->assertEquals(Inflector::variable('test_fieLd'), 'testFieLd');
|
|
|
319 |
$this->assertEquals(Inflector::variable('test field'), 'testField');
|
|
|
320 |
$this->assertEquals(Inflector::variable('Test_field'), 'testField');
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
/**
|
|
|
324 |
* testClassNaming method
|
|
|
325 |
*
|
|
|
326 |
* @return void
|
|
|
327 |
*/
|
|
|
328 |
public function testClassNaming() {
|
|
|
329 |
$this->assertEquals(Inflector::classify('artists_genres'), 'ArtistsGenre');
|
|
|
330 |
$this->assertEquals(Inflector::classify('file_systems'), 'FileSystem');
|
|
|
331 |
$this->assertEquals(Inflector::classify('news'), 'News');
|
|
|
332 |
$this->assertEquals(Inflector::classify('bureaus'), 'Bureau');
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
/**
|
|
|
336 |
* testTableNaming method
|
|
|
337 |
*
|
|
|
338 |
* @return void
|
|
|
339 |
*/
|
|
|
340 |
public function testTableNaming() {
|
|
|
341 |
$this->assertEquals(Inflector::tableize('ArtistsGenre'), 'artists_genres');
|
|
|
342 |
$this->assertEquals(Inflector::tableize('FileSystem'), 'file_systems');
|
|
|
343 |
$this->assertEquals(Inflector::tableize('News'), 'news');
|
|
|
344 |
$this->assertEquals(Inflector::tableize('Bureau'), 'bureaus');
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
/**
|
|
|
348 |
* testHumanization method
|
|
|
349 |
*
|
|
|
350 |
* @return void
|
|
|
351 |
*/
|
|
|
352 |
public function testHumanization() {
|
|
|
353 |
$this->assertEquals(Inflector::humanize('posts'), 'Posts');
|
|
|
354 |
$this->assertEquals(Inflector::humanize('posts_tags'), 'Posts Tags');
|
|
|
355 |
$this->assertEquals(Inflector::humanize('file_systems'), 'File Systems');
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
/**
|
|
|
359 |
* testCustomPluralRule method
|
|
|
360 |
*
|
|
|
361 |
* @return void
|
|
|
362 |
*/
|
|
|
363 |
public function testCustomPluralRule() {
|
|
|
364 |
Inflector::rules('plural', array('/^(custom)$/i' => '\1izables'));
|
|
|
365 |
$this->assertEquals(Inflector::pluralize('custom'), 'customizables');
|
|
|
366 |
|
|
|
367 |
Inflector::rules('plural', array('uninflected' => array('uninflectable')));
|
|
|
368 |
$this->assertEquals(Inflector::pluralize('uninflectable'), 'uninflectable');
|
|
|
369 |
|
|
|
370 |
Inflector::rules('plural', array(
|
|
|
371 |
'rules' => array('/^(alert)$/i' => '\1ables'),
|
|
|
372 |
'uninflected' => array('noflect', 'abtuse'),
|
|
|
373 |
'irregular' => array('amaze' => 'amazable', 'phone' => 'phonezes')
|
|
|
374 |
));
|
|
|
375 |
$this->assertEquals(Inflector::pluralize('noflect'), 'noflect');
|
|
|
376 |
$this->assertEquals(Inflector::pluralize('abtuse'), 'abtuse');
|
|
|
377 |
$this->assertEquals(Inflector::pluralize('alert'), 'alertables');
|
|
|
378 |
$this->assertEquals(Inflector::pluralize('amaze'), 'amazable');
|
|
|
379 |
$this->assertEquals(Inflector::pluralize('phone'), 'phonezes');
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
/**
|
|
|
383 |
* testCustomSingularRule method
|
|
|
384 |
*
|
|
|
385 |
* @return void
|
|
|
386 |
*/
|
|
|
387 |
public function testCustomSingularRule() {
|
|
|
388 |
Inflector::rules('singular', array('/(eple)r$/i' => '\1', '/(jente)r$/i' => '\1'));
|
|
|
389 |
|
|
|
390 |
$this->assertEquals(Inflector::singularize('epler'), 'eple');
|
|
|
391 |
$this->assertEquals(Inflector::singularize('jenter'), 'jente');
|
|
|
392 |
|
|
|
393 |
Inflector::rules('singular', array(
|
|
|
394 |
'rules' => array('/^(bil)er$/i' => '\1', '/^(inflec|contribu)tors$/i' => '\1ta'),
|
|
|
395 |
'uninflected' => array('singulars'),
|
|
|
396 |
'irregular' => array('spins' => 'spinor')
|
|
|
397 |
));
|
|
|
398 |
|
|
|
399 |
$this->assertEquals(Inflector::singularize('inflectors'), 'inflecta');
|
|
|
400 |
$this->assertEquals(Inflector::singularize('contributors'), 'contributa');
|
|
|
401 |
$this->assertEquals(Inflector::singularize('spins'), 'spinor');
|
|
|
402 |
$this->assertEquals(Inflector::singularize('singulars'), 'singulars');
|
|
|
403 |
}
|
|
|
404 |
|
|
|
405 |
/**
|
|
|
406 |
* testCustomTransliterationRule method
|
|
|
407 |
*
|
|
|
408 |
* @return void
|
|
|
409 |
*/
|
|
|
410 |
public function testCustomTransliterationRule() {
|
|
|
411 |
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing_ae_o_a');
|
|
|
412 |
|
|
|
413 |
Inflector::rules('transliteration', array('/å/' => 'aa', '/ø/' => 'oe'));
|
|
|
414 |
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing_ae_oe_aa');
|
|
|
415 |
|
|
|
416 |
Inflector::rules('transliteration', array('/ä|æ/' => 'ae', '/å/' => 'aa'), true);
|
|
|
417 |
$this->assertEquals(Inflector::slug('Testing æ ø å'), 'Testing_ae_ø_aa');
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
/**
|
|
|
421 |
* test that setting new rules clears the inflector caches.
|
|
|
422 |
*
|
|
|
423 |
* @return void
|
|
|
424 |
*/
|
|
|
425 |
public function testRulesClearsCaches() {
|
|
|
426 |
$this->assertEquals(Inflector::singularize('Bananas'), 'Banana');
|
|
|
427 |
$this->assertEquals(Inflector::tableize('Banana'), 'bananas');
|
|
|
428 |
$this->assertEquals(Inflector::pluralize('Banana'), 'Bananas');
|
|
|
429 |
|
|
|
430 |
Inflector::rules('singular', array(
|
|
|
431 |
'rules' => array('/(.*)nas$/i' => '\1zzz')
|
|
|
432 |
));
|
|
|
433 |
$this->assertEquals('Banazzz', Inflector::singularize('Bananas'), 'Was inflected with old rules.');
|
|
|
434 |
|
|
|
435 |
Inflector::rules('plural', array(
|
|
|
436 |
'rules' => array('/(.*)na$/i' => '\1zzz'),
|
|
|
437 |
'irregular' => array('corpus' => 'corpora')
|
|
|
438 |
));
|
|
|
439 |
$this->assertEquals(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules.');
|
|
|
440 |
$this->assertEquals(Inflector::pluralize('corpus'), 'corpora', 'Was inflected with old irregular form.');
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
/**
|
|
|
444 |
* Test resetting inflection rules.
|
|
|
445 |
*
|
|
|
446 |
* @return void
|
|
|
447 |
*/
|
|
|
448 |
public function testCustomRuleWithReset() {
|
|
|
449 |
$uninflected = array('atlas', 'lapis', 'onibus', 'pires', 'virus', '.*x');
|
|
|
450 |
$pluralIrregular = array('as' => 'ases');
|
|
|
451 |
|
|
|
452 |
Inflector::rules('singular', array(
|
|
|
453 |
'rules' => array('/^(.*)(a|e|o|u)is$/i' => '\1\2l'),
|
|
|
454 |
'uninflected' => $uninflected,
|
|
|
455 |
), true);
|
|
|
456 |
|
|
|
457 |
Inflector::rules('plural', array(
|
|
|
458 |
'rules' => array(
|
|
|
459 |
'/^(.*)(a|e|o|u)l$/i' => '\1\2is',
|
|
|
460 |
),
|
|
|
461 |
'uninflected' => $uninflected,
|
|
|
462 |
'irregular' => $pluralIrregular
|
|
|
463 |
), true);
|
|
|
464 |
|
|
|
465 |
$this->assertEquals(Inflector::pluralize('Alcool'), 'Alcoois');
|
|
|
466 |
$this->assertEquals(Inflector::pluralize('Atlas'), 'Atlas');
|
|
|
467 |
$this->assertEquals(Inflector::singularize('Alcoois'), 'Alcool');
|
|
|
468 |
$this->assertEquals(Inflector::singularize('Atlas'), 'Atlas');
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
}
|