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",
16 "process" => "processes",
17 "address" => "addresses",
23 "category" => "categories",
25 "ability" => "abilities",
26 "agency" => "agencies",
29 "archive" => "archives",
39 "salesperson" => "salespeople",
42 "spokesman" => "spokesmen",
47 "diagnosis" => "diagnoses",
51 "analysis" => "analyses",
53 "node_child" => "node_children",
54 "child" => "children",
56 "database" => "databases",
58 "experience" => "experiences",
61 "comment" => "comments",
62 "foobar" => "foobars",
63 "newsletter" => "newsletters",
65 "old_news" => "old_news",
69 "species" => "species",
73 "perspective" => "perspectives",
77 "buffalo" => "buffaloes",
78 "tomato" => "tomatoes",
81 "information" => "information",
82 "equipment" => "equipment",
84 "status" => "statuses",
90 "octopus" => "octopi",
93 "portfolio" => "portfolios",
95 "vertex" => "vertices",
96 "matrix" => "matrices",
100 "crisis" => "crises",
110 var $CamelToUnderscore = array(
111 "Product" => "product",
112 "SpecialGuest" => "special_guest",
113 "ApplicationController" => "application_controller",
114 "Area51Controller" => "area51_controller",
117 var $CamelToUnderscoreWithoutReverse = array(
118 "HTMLTidy" => "html_tidy",
119 "HTMLTidyGenerator" => "html_tidy_generator",
120 "FreeBSD" => "free_bsd",
124 var $ClassNameToForeignKeyWithUnderscore = array(
125 "Person" => "person_id",
128 var $ClassNameToForeignKeyWithoutUnderscore = array(
129 "Person" => "personid",
132 var $ClassNameToTableName = array(
133 "PrimarySpokesman" => "primary_spokesmen",
134 "NodeChild" => "node_children"
137 var $UnderscoreToHuman = array(
138 "employee_salary" => "Employee salary",
139 "employee_id" => "Employee",
140 "underground" => "Underground"
143 var $MixtureToTitleCase = array(
144 'active_record' => 'Active Record',
145 'ActiveRecord' => 'Active Record',
146 'action web service' => 'Action Web Service',
147 'Action Web Service' => 'Action Web Service',
148 'Action web service' => 'Action Web Service',
149 'actionwebservice' => 'Actionwebservice',
150 'Actionwebservice' => 'Actionwebservice'
153 var $OrdinalNumbers = array(
184 function Test_of_pluralize_plurals()
186 $this->assertEqual('plurals', AkInflector
::pluralize("plurals"));
187 $this->assertEqual('Plurals', AkInflector
::pluralize("Plurals"));
190 function Test_of_pluralize_singular()
192 foreach ($this->SingularToPlural
as $singular=>$plural){
193 $this->assertEqual($plural, AkInflector
::pluralize($singular));
194 $this->assertEqual(ucfirst($plural), AkInflector
::pluralize(ucfirst($singular)));
198 function Test_of_singularize_plural()
200 foreach ($this->SingularToPlural
as $singular=>$plural){
201 $this->assertEqual($singular, AkInflector
::singularize($plural));
202 $this->assertEqual(ucfirst($singular), AkInflector
::singularize(ucfirst($plural)));
206 function Test_of_titleize()
208 foreach ($this->MixtureToTitleCase
as $source=>$expected){
209 $this->assertEqual($expected, AkInflector
::titleize($source));
213 function Test_of_camelize()
215 foreach ($this->CamelToUnderscore
as $camel=>$underscore){
216 $this->assertEqual($camel, AkInflector
::camelize($underscore));
220 function Test_of_underscore()
222 foreach ($this->CamelToUnderscore
as $camel=>$underscore){
223 $this->assertEqual($underscore, AkInflector
::underscore($camel));
226 foreach ($this->CamelToUnderscoreWithoutReverse
as $camel=>$underscore){
227 $this->assertEqual($underscore, AkInflector
::underscore($camel));
231 function Test_of_foreignKey()
233 foreach ($this->ClassNameToForeignKeyWithUnderscore
as $class=>$foreign_key){
234 $this->assertEqual($foreign_key, AkInflector
::foreignKey($class));
236 foreach ($this->ClassNameToForeignKeyWithoutUnderscore
as $class=>$foreign_key){
237 $this->assertEqual($foreign_key, AkInflector
::foreignKey($class, false));
242 function Test_of_tableize()
244 foreach ($this->ClassNameToTableName
as $class_name=>$table_name){
245 $this->assertEqual($table_name, AkInflector
::tableize($class_name));
249 function Test_of_classify()
251 foreach ($this->ClassNameToTableName
as $class_name=>$table_name){
252 $this->assertEqual($class_name, AkInflector
::classify($table_name));
256 function Test_of_humanize()
258 foreach ($this->UnderscoreToHuman
as $underscore=>$human){
259 $this->assertEqual($human, AkInflector
::humanize($underscore));
263 function Test_of_ordinalize()
265 foreach ($this->OrdinalNumbers
as $number=>$ordinalized){
266 $this->assertEqual($ordinalized, AkInflector
::ordinalize($number));
270 function Test_of_unnaccent()
272 $this->assertEqual( 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYTsaaaaaaaceeeeiiiienoooooouuuuyty',
273 AkInflector
::unaccent('ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ'));
276 function Test_for_setting_custom_plurals()
278 AkInflector
::pluralize('camión', 'camiones');
279 $this->assertEqual(AkInflector
::pluralize('camión'), 'camiones');
282 function Test_for_setting_custom_singulars()
284 AkInflector
::singularize('camiones', 'camión');
285 $this->assertEqual(AkInflector
::singularize('camiones'), 'camión');
288 function test_should_detect_singulars()
290 foreach (array_keys($this->SingularToPlural
) as $singular){
291 $this->assertTrue(AkInflector
::is_singular($singular), $singular.' is not detected as singular');
295 function test_should_detect_plurals()
297 foreach (array_values($this->SingularToPlural
) as $plural){
298 $this->assertTrue(AkInflector
::is_plural($plural), $plural.' is not detected as plural');
302 function test_should_demodulize()
304 $this->assertEqual(AkInflector
::demodulize('admin/dashboard_controller'), 'dashboard_controller');
305 $this->assertEqual(AkInflector
::demodulize('Admin_DashboardController'), 'DashboardController');
306 $this->assertEqual(AkInflector
::demodulize('Admin::Dashboard'), 'Dashboard');
307 $this->assertEqual(AkInflector
::demodulize('User'), 'User');
310 function test_should_get_controller_file_name()
312 $this->assertEqual(AkInflector
::toControllerFilename('admin'), AK_CONTROLLERS_DIR
.DS
.'admin_controller.php');
313 $this->assertEqual(AkInflector
::toControllerFilename('user_authentication'), AK_CONTROLLERS_DIR
.DS
.'user_authentication_controller.php');
314 $this->assertEqual(AkInflector
::toControllerFilename('admin/users'), AK_CONTROLLERS_DIR
.DS
.'admin'.DS
.'users_controller.php');
318 ak_test('Test_of_AkInflector');