Fixing content type ordering when content_type is not defined.
[akelos.git] / test / unit / lib / AkInflector.php
blob172c8f41d300f1c5d9d448a14c156250ec466b0d
1 <?php
3 defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);
4 require_once(dirname(__FILE__).'/../../fixtures/config/config.php');
6 require_once(AK_LIB_DIR.DS.'AkInflector.php');
9 class Test_of_AkInflector extends UnitTestCase
11 var $SingularToPlural = array(
12 "search" => "searches",
13 "switch" => "switches",
14 "fix" => "fixes",
15 "box" => "boxes",
16 "process" => "processes",
17 "address" => "addresses",
18 "case" => "cases",
19 "stack" => "stacks",
20 "wish" => "wishes",
21 "fish" => "fish",
23 "category" => "categories",
24 "query" => "queries",
25 "ability" => "abilities",
26 "agency" => "agencies",
27 "movie" => "movies",
29 "archive" => "archives",
31 "index" => "indices",
33 "wife" => "wives",
34 "safe" => "saves",
35 "half" => "halves",
37 "move" => "moves",
39 "salesperson" => "salespeople",
40 "person" => "people",
42 "spokesman" => "spokesmen",
43 "man" => "men",
44 "woman" => "women",
46 "basis" => "bases",
47 "diagnosis" => "diagnoses",
49 "datum" => "data",
50 "medium" => "media",
51 "analysis" => "analyses",
53 "node_child" => "node_children",
54 "child" => "children",
56 "database" => "databases",
58 "experience" => "experiences",
59 "day" => "days",
61 "comment" => "comments",
62 "foobar" => "foobars",
63 "newsletter" => "newsletters",
65 "old_news" => "old_news",
66 "news" => "news",
68 "series" => "series",
69 "species" => "species",
71 "quiz" => "quizzes",
73 "perspective" => "perspectives",
75 "ox" => "oxen",
76 "photo" => "photos",
77 "buffalo" => "buffaloes",
78 "tomato" => "tomatoes",
79 "dwarf" => "dwarves",
80 "elf" => "elves",
81 "information" => "information",
82 "equipment" => "equipment",
83 "bus" => "buses",
84 "status" => "statuses",
85 "wax" => "waxes",
86 "mouse" => "mice",
88 "louse" => "lice",
89 "house" => "houses",
90 "octopus" => "octopi",
91 "virus" => "viri",
92 "alias" => "aliases",
93 "portfolio" => "portfolios",
95 "vertex" => "vertices",
96 "matrix" => "matrices",
98 "axis" => "axes",
99 "testis" => "testes",
100 "crisis" => "crises",
102 "rice" => "rice",
103 "shoe" => "shoes",
105 "horse" => "horses",
106 "prize" => "prizes",
107 "price" => "prices",
108 "edge" => "edges"
111 var $CamelToUnderscore = array(
112 "Product" => "product",
113 "SpecialGuest" => "special_guest",
114 "ApplicationController" => "application_controller",
115 "Area51Controller" => "area51_controller",
118 var $CamelToUnderscoreWithoutReverse = array(
119 "HTMLTidy" => "html_tidy",
120 "HTMLTidyGenerator" => "html_tidy_generator",
121 "FreeBSD" => "free_bsd",
122 "HTML" => "html",
125 var $ClassNameToForeignKeyWithUnderscore = array(
126 "Person" => "person_id",
129 var $ClassNameToForeignKeyWithoutUnderscore = array(
130 "Person" => "personid",
133 var $ClassNameToTableName = array(
134 "PrimarySpokesman" => "primary_spokesmen",
135 "NodeChild" => "node_children"
138 var $UnderscoreToHuman = array(
139 "employee_salary" => "Employee salary",
140 "employee_id" => "Employee",
141 "underground" => "Underground"
144 var $MixtureToTitleCase = array(
145 'active_record' => 'Active Record',
146 'ActiveRecord' => 'Active Record',
147 'action web service' => 'Action Web Service',
148 'Action Web Service' => 'Action Web Service',
149 'Action web service' => 'Action Web Service',
150 'actionwebservice' => 'Actionwebservice',
151 'Actionwebservice' => 'Actionwebservice'
154 var $OrdinalNumbers = array(
155 "0" => "0th",
156 "1" => "1st",
157 "2" => "2nd",
158 "3" => "3rd",
159 "4" => "4th",
160 "5" => "5th",
161 "6" => "6th",
162 "7" => "7th",
163 "8" => "8th",
164 "9" => "9th",
165 "10" => "10th",
166 "11" => "11th",
167 "12" => "12th",
168 "13" => "13th",
169 "14" => "14th",
170 "20" => "20th",
171 "21" => "21st",
172 "22" => "22nd",
173 "23" => "23rd",
174 "24" => "24th",
175 "100" => "100th",
176 "101" => "101st",
177 "102" => "102nd",
178 "103" => "103rd",
179 "104" => "104th",
180 "110" => "110th",
181 "1000" => "1000th",
182 "1001" => "1001st"
185 function Test_of_pluralize_plurals()
187 $this->assertEqual('plurals', AkInflector::pluralize("plurals"));
188 $this->assertEqual('Plurals', AkInflector::pluralize("Plurals"));
191 function Test_of_pluralize_singular()
193 foreach ($this->SingularToPlural as $singular=>$plural){
194 $this->assertEqual($plural, AkInflector::pluralize($singular));
195 $this->assertEqual(ucfirst($plural), AkInflector::pluralize(ucfirst($singular)));
199 function Test_of_singularize_plural()
201 foreach ($this->SingularToPlural as $singular=>$plural){
202 $this->assertEqual($singular, AkInflector::singularize($plural));
203 $this->assertEqual(ucfirst($singular), AkInflector::singularize(ucfirst($plural)));
207 function Test_of_titleize()
209 foreach ($this->MixtureToTitleCase as $source=>$expected){
210 $this->assertEqual($expected, AkInflector::titleize($source));
214 function Test_of_camelize()
216 foreach ($this->CamelToUnderscore as $camel=>$underscore){
217 $this->assertEqual($camel, AkInflector::camelize($underscore));
221 function Test_of_underscore()
223 foreach ($this->CamelToUnderscore as $camel=>$underscore){
224 $this->assertEqual($underscore, AkInflector::underscore($camel));
227 foreach ($this->CamelToUnderscoreWithoutReverse as $camel=>$underscore){
228 $this->assertEqual($underscore, AkInflector::underscore($camel));
232 function Test_of_foreignKey()
234 foreach ($this->ClassNameToForeignKeyWithUnderscore as $class=>$foreign_key){
235 $this->assertEqual($foreign_key, AkInflector::foreignKey($class));
237 foreach ($this->ClassNameToForeignKeyWithoutUnderscore as $class=>$foreign_key){
238 $this->assertEqual($foreign_key, AkInflector::foreignKey($class, false));
243 function Test_of_tableize()
245 foreach ($this->ClassNameToTableName as $class_name=>$table_name){
246 $this->assertEqual($table_name, AkInflector::tableize($class_name));
250 function Test_of_classify()
252 foreach ($this->ClassNameToTableName as $class_name=>$table_name){
253 $this->assertEqual($class_name, AkInflector::classify($table_name));
257 function Test_of_humanize()
259 foreach ($this->UnderscoreToHuman as $underscore=>$human){
260 $this->assertEqual($human, AkInflector::humanize($underscore));
264 function Test_of_ordinalize()
266 foreach ($this->OrdinalNumbers as $number=>$ordinalized){
267 $this->assertEqual($ordinalized, AkInflector::ordinalize($number));
271 function Test_of_unnaccent()
273 $this->assertEqual( 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYTsaaaaaaaceeeeiiiienoooooouuuuyty',
274 AkInflector::unaccent('ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'));
277 function Test_for_setting_custom_plurals()
279 AkInflector::pluralize('camión', 'camiones');
280 $this->assertEqual(AkInflector::pluralize('camión'), 'camiones');
283 function Test_for_setting_custom_singulars()
285 AkInflector::singularize('camiones', 'camión');
286 $this->assertEqual(AkInflector::singularize('camiones'), 'camión');
289 function test_should_detect_singulars()
291 foreach (array_keys($this->SingularToPlural) as $singular){
292 $this->assertTrue(AkInflector::is_singular($singular), $singular.' is not detected as singular');
296 function test_should_detect_plurals()
298 foreach (array_values($this->SingularToPlural) as $plural){
299 $this->assertTrue(AkInflector::is_plural($plural), $plural.' is not detected as plural');
303 function test_should_demodulize()
305 $this->assertEqual(AkInflector::demodulize('admin/dashboard_controller'), 'dashboard_controller');
306 $this->assertEqual(AkInflector::demodulize('Admin_DashboardController'), 'DashboardController');
307 $this->assertEqual(AkInflector::demodulize('Admin::Dashboard'), 'Dashboard');
308 $this->assertEqual(AkInflector::demodulize('User'), 'User');
311 function test_should_get_controller_file_name()
313 $this->assertEqual(AkInflector::toControllerFilename('admin'), AK_CONTROLLERS_DIR.DS.'admin_controller.php');
314 $this->assertEqual(AkInflector::toControllerFilename('user_authentication'), AK_CONTROLLERS_DIR.DS.'user_authentication_controller.php');
315 $this->assertEqual(AkInflector::toControllerFilename('admin/users'), AK_CONTROLLERS_DIR.DS.'admin'.DS.'users_controller.php');
319 ak_test('Test_of_AkInflector');