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",
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",
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(
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');