2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-05-01 17:03:30 +00:00
|
|
|
* InflectorTest
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 17:03:30 +00:00
|
|
|
* InflectorTest is used to test cases on the Inflector class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 17:03:30 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 17:03:30 +00:00
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
|
|
|
* @package Cake.Test.Case.Utility
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-01-26 22:54:34 +00:00
|
|
|
* @license Open Group Test Suite License (http://www.opensource.org/licenses/opengroup.php)
|
2009-05-01 17:03:30 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-01 17:03:30 +00:00
|
|
|
/**
|
|
|
|
* Included libraries.
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Inflector', 'Utility');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Short description for class.
|
|
|
|
*
|
2009-11-02 18:51:46 +00:00
|
|
|
* @package cake.tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-12 00:22:09 +00:00
|
|
|
class InflectorTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2010-09-26 03:04:49 +00:00
|
|
|
* teardown
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2010-09-26 03:04:49 +00:00
|
|
|
* @return void
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-09-26 03:04:49 +00:00
|
|
|
parent::tearDown();
|
|
|
|
Inflector::reset();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInflectingSingulars method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInflectingSingulars() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('categorias'), 'categoria');
|
|
|
|
$this->assertEqual(Inflector::singularize('menus'), 'menu');
|
|
|
|
$this->assertEqual(Inflector::singularize('news'), 'news');
|
|
|
|
$this->assertEqual(Inflector::singularize('food_menus'), 'food_menu');
|
|
|
|
$this->assertEqual(Inflector::singularize('Menus'), 'Menu');
|
|
|
|
$this->assertEqual(Inflector::singularize('FoodMenus'), 'FoodMenu');
|
|
|
|
$this->assertEqual(Inflector::singularize('houses'), 'house');
|
|
|
|
$this->assertEqual(Inflector::singularize('powerhouses'), 'powerhouse');
|
|
|
|
$this->assertEqual(Inflector::singularize('quizzes'), 'quiz');
|
|
|
|
$this->assertEqual(Inflector::singularize('Buses'), 'Bus');
|
|
|
|
$this->assertEqual(Inflector::singularize('buses'), 'bus');
|
|
|
|
$this->assertEqual(Inflector::singularize('matrix_rows'), 'matrix_row');
|
|
|
|
$this->assertEqual(Inflector::singularize('matrices'), 'matrix');
|
|
|
|
$this->assertEqual(Inflector::singularize('vertices'), 'vertex');
|
|
|
|
$this->assertEqual(Inflector::singularize('indices'), 'index');
|
|
|
|
$this->assertEqual(Inflector::singularize('Aliases'), 'Alias');
|
|
|
|
$this->assertEqual(Inflector::singularize('Alias'), 'Alias');
|
|
|
|
$this->assertEqual(Inflector::singularize('Media'), 'Media');
|
|
|
|
$this->assertEqual(Inflector::singularize('alumni'), 'alumnus');
|
|
|
|
$this->assertEqual(Inflector::singularize('bacilli'), 'bacillus');
|
|
|
|
$this->assertEqual(Inflector::singularize('cacti'), 'cactus');
|
|
|
|
$this->assertEqual(Inflector::singularize('foci'), 'focus');
|
|
|
|
$this->assertEqual(Inflector::singularize('fungi'), 'fungus');
|
|
|
|
$this->assertEqual(Inflector::singularize('nuclei'), 'nucleus');
|
|
|
|
$this->assertEqual(Inflector::singularize('octopuses'), 'octopus');
|
|
|
|
$this->assertEqual(Inflector::singularize('radii'), 'radius');
|
|
|
|
$this->assertEqual(Inflector::singularize('stimuli'), 'stimulus');
|
|
|
|
$this->assertEqual(Inflector::singularize('syllabi'), 'syllabus');
|
|
|
|
$this->assertEqual(Inflector::singularize('termini'), 'terminus');
|
|
|
|
$this->assertEqual(Inflector::singularize('viri'), 'virus');
|
|
|
|
$this->assertEqual(Inflector::singularize('people'), 'person');
|
2008-07-12 00:22:09 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('gloves'), 'glove');
|
|
|
|
$this->assertEqual(Inflector::singularize('doves'), 'dove');
|
|
|
|
$this->assertEqual(Inflector::singularize('lives'), 'life');
|
|
|
|
$this->assertEqual(Inflector::singularize('knives'), 'knife');
|
|
|
|
$this->assertEqual(Inflector::singularize('wolves'), 'wolf');
|
2009-07-30 19:29:16 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('slaves'), 'slave');
|
2008-07-12 00:22:09 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('shelves'), 'shelf');
|
2009-02-22 04:09:39 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('taxis'), 'taxi');
|
|
|
|
$this->assertEqual(Inflector::singularize('taxes'), 'tax');
|
2009-08-11 01:29:01 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('Taxes'), 'Tax');
|
2010-03-13 05:26:23 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('AwesomeTaxes'), 'AwesomeTax');
|
2009-02-22 04:09:39 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('faxes'), 'fax');
|
|
|
|
$this->assertEqual(Inflector::singularize('waxes'), 'wax');
|
2009-11-02 18:51:46 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('niches'), 'niche');
|
2009-08-23 00:26:27 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('waves'), 'wave');
|
2009-11-13 13:23:33 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('bureaus'), 'bureau');
|
2010-04-28 03:03:19 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('genetic_analyses'), 'genetic_analysis');
|
|
|
|
$this->assertEqual(Inflector::singularize('doctor_diagnoses'), 'doctor_diagnosis');
|
|
|
|
$this->assertEqual(Inflector::singularize('parantheses'), 'paranthesis');
|
2010-05-22 03:49:49 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('Causes'), 'Cause');
|
|
|
|
$this->assertEqual(Inflector::singularize('colossuses'), 'colossus');
|
2010-08-13 00:26:11 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('diagnoses'), 'diagnosis');
|
|
|
|
$this->assertEqual(Inflector::singularize('bases'), 'basis');
|
|
|
|
$this->assertEqual(Inflector::singularize('analyses'), 'analysis');
|
2011-07-07 17:38:03 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('curves'), 'curve');
|
2010-04-28 03:03:19 +00:00
|
|
|
|
2008-08-26 18:30:54 +00:00
|
|
|
$this->assertEqual(Inflector::singularize(''), '');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInflectingPlurals method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInflectingPlurals() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual(Inflector::pluralize('categoria'), 'categorias');
|
|
|
|
$this->assertEqual(Inflector::pluralize('house'), 'houses');
|
|
|
|
$this->assertEqual(Inflector::pluralize('powerhouse'), 'powerhouses');
|
|
|
|
$this->assertEqual(Inflector::pluralize('Bus'), 'Buses');
|
|
|
|
$this->assertEqual(Inflector::pluralize('bus'), 'buses');
|
|
|
|
$this->assertEqual(Inflector::pluralize('menu'), 'menus');
|
|
|
|
$this->assertEqual(Inflector::pluralize('news'), 'news');
|
|
|
|
$this->assertEqual(Inflector::pluralize('food_menu'), 'food_menus');
|
|
|
|
$this->assertEqual(Inflector::pluralize('Menu'), 'Menus');
|
|
|
|
$this->assertEqual(Inflector::pluralize('FoodMenu'), 'FoodMenus');
|
|
|
|
$this->assertEqual(Inflector::pluralize('quiz'), 'quizzes');
|
|
|
|
$this->assertEqual(Inflector::pluralize('matrix_row'), 'matrix_rows');
|
|
|
|
$this->assertEqual(Inflector::pluralize('matrix'), 'matrices');
|
|
|
|
$this->assertEqual(Inflector::pluralize('vertex'), 'vertices');
|
|
|
|
$this->assertEqual(Inflector::pluralize('index'), 'indices');
|
|
|
|
$this->assertEqual(Inflector::pluralize('Alias'), 'Aliases');
|
|
|
|
$this->assertEqual(Inflector::pluralize('Aliases'), 'Aliases');
|
|
|
|
$this->assertEqual(Inflector::pluralize('Media'), 'Media');
|
|
|
|
$this->assertEqual(Inflector::pluralize('alumnus'), 'alumni');
|
|
|
|
$this->assertEqual(Inflector::pluralize('bacillus'), 'bacilli');
|
|
|
|
$this->assertEqual(Inflector::pluralize('cactus'), 'cacti');
|
|
|
|
$this->assertEqual(Inflector::pluralize('focus'), 'foci');
|
|
|
|
$this->assertEqual(Inflector::pluralize('fungus'), 'fungi');
|
|
|
|
$this->assertEqual(Inflector::pluralize('nucleus'), 'nuclei');
|
|
|
|
$this->assertEqual(Inflector::pluralize('octopus'), 'octopuses');
|
|
|
|
$this->assertEqual(Inflector::pluralize('radius'), 'radii');
|
|
|
|
$this->assertEqual(Inflector::pluralize('stimulus'), 'stimuli');
|
|
|
|
$this->assertEqual(Inflector::pluralize('syllabus'), 'syllabi');
|
|
|
|
$this->assertEqual(Inflector::pluralize('terminus'), 'termini');
|
|
|
|
$this->assertEqual(Inflector::pluralize('virus'), 'viri');
|
|
|
|
$this->assertEqual(Inflector::pluralize('person'), 'people');
|
|
|
|
$this->assertEqual(Inflector::pluralize('people'), 'people');
|
2008-07-12 00:22:09 +00:00
|
|
|
$this->assertEqual(Inflector::pluralize('glove'), 'gloves');
|
2009-02-22 04:09:39 +00:00
|
|
|
$this->assertEqual(Inflector::pluralize('crisis'), 'crises');
|
2009-08-11 01:29:01 +00:00
|
|
|
$this->assertEqual(Inflector::pluralize('tax'), 'taxes');
|
2009-08-23 00:26:27 +00:00
|
|
|
$this->assertEqual(Inflector::pluralize('wave'), 'waves');
|
2009-11-13 13:23:33 +00:00
|
|
|
$this->assertEqual(Inflector::pluralize('bureau'), 'bureaus');
|
2008-11-08 02:58:37 +00:00
|
|
|
$this->assertEqual(Inflector::pluralize(''), '');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInflectorSlug method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInflectorSlug() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more');
|
|
|
|
$expected = 'Foo_Bar_Not_just_for_breakfast_any_more';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('this/is/a/path');
|
|
|
|
$expected = 'this_is_a_path';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "-");
|
|
|
|
$expected = 'Foo-Bar-Not-just-for-breakfast-any-more';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "+");
|
|
|
|
$expected = 'Foo+Bar+Not+just+for+breakfast+any+more';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Inflector::slug('Äpfel Über Öl grün ärgert groß öko', '-');
|
|
|
|
$expected = 'Aepfel-Ueber-Oel-gruen-aergert-gross-oeko';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('The truth - and- more- news', '-');
|
|
|
|
$expected = 'The-truth-and-more-news';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('The truth: and more news', '-');
|
|
|
|
$expected = 'The-truth-and-more-news';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Inflector::slug('La langue française est un attribut de souveraineté en France', '-');
|
|
|
|
$expected = 'La-langue-francaise-est-un-attribut-de-souverainete-en-France';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('!@$#exciting stuff! - what !@-# was that?', '-');
|
|
|
|
$expected = 'exciting-stuff-what-was-that';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('20% of profits went to me!', '-');
|
|
|
|
$expected = '20-of-profits-went-to-me';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('#this melts your face1#2#3', '-');
|
|
|
|
$expected = 'this-melts-your-face1-2-3';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-07-25 18:21:34 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('controller/action/りんご/1');
|
|
|
|
$expected = 'controller_action_りんご_1';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-07-25 19:10:21 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('の話が出たので大丈夫かなあと');
|
|
|
|
$expected = 'の話が出たので大丈夫かなあと';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-07-25 19:10:21 +00:00
|
|
|
|
|
|
|
$result = Inflector::slug('posts/view/한국어/page:1/sort:asc');
|
|
|
|
$expected = 'posts_view_한국어_page_1_sort_asc';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-01 17:34:19 +00:00
|
|
|
/**
|
|
|
|
* testInflectorSlugWithMap method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInflectorSlugWithMap() {
|
2011-03-24 02:31:27 +00:00
|
|
|
Inflector::rules('transliteration', array('/r/' => '1'));
|
|
|
|
$result = Inflector::slug('replace every r');
|
2010-01-14 22:47:22 +00:00
|
|
|
$expected = '1eplace_eve1y_1';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-05-01 17:34:19 +00:00
|
|
|
|
2011-03-24 02:31:27 +00:00
|
|
|
$result = Inflector::slug('replace every r', '_');
|
2010-01-14 22:47:22 +00:00
|
|
|
$expected = '1eplace_eve1y_1';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2010-01-14 22:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testInflectorSlugWithMapOverridingDefault method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInflectorSlugWithMapOverridingDefault() {
|
2011-03-24 02:31:27 +00:00
|
|
|
Inflector::rules('transliteration', array('/å/' => 'aa', '/ø/' => 'oe'));
|
|
|
|
$result = Inflector::slug('Testing æ ø å', '-');
|
2010-01-14 22:47:22 +00:00
|
|
|
$expected = 'Testing-ae-oe-aa';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-05-01 17:34:19 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-01-10 09:52:49 +00:00
|
|
|
/**
|
|
|
|
* testInflectorUnderscore method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testInflectorUnderscore() {
|
2010-01-10 09:52:49 +00:00
|
|
|
$this->assertIdentical(Inflector::underscore('TestThing'), 'test_thing');
|
|
|
|
$this->assertIdentical(Inflector::underscore('testThing'), 'test_thing');
|
|
|
|
$this->assertIdentical(Inflector::underscore('TestThingExtra'), 'test_thing_extra');
|
|
|
|
$this->assertIdentical(Inflector::underscore('testThingExtra'), 'test_thing_extra');
|
2010-01-10 09:54:20 +00:00
|
|
|
|
|
|
|
// Identical checks test the cache code path.
|
|
|
|
$this->assertIdentical(Inflector::underscore('TestThing'), 'test_thing');
|
|
|
|
$this->assertIdentical(Inflector::underscore('testThing'), 'test_thing');
|
|
|
|
$this->assertIdentical(Inflector::underscore('TestThingExtra'), 'test_thing_extra');
|
|
|
|
$this->assertIdentical(Inflector::underscore('testThingExtra'), 'test_thing_extra');
|
|
|
|
|
|
|
|
// Test stupid values
|
|
|
|
$this->assertIdentical(Inflector::underscore(''), '');
|
|
|
|
$this->assertIdentical(Inflector::underscore(0), '0');
|
|
|
|
$this->assertIdentical(Inflector::underscore(false), '');
|
2010-01-10 09:52:49 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testVariableNaming method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testVariableNaming() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual(Inflector::variable('test_field'), 'testField');
|
|
|
|
$this->assertEqual(Inflector::variable('test_fieLd'), 'testFieLd');
|
|
|
|
$this->assertEqual(Inflector::variable('test field'), 'testField');
|
|
|
|
$this->assertEqual(Inflector::variable('Test_field'), 'testField');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testClassNaming method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testClassNaming() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual(Inflector::classify('artists_genres'), 'ArtistsGenre');
|
|
|
|
$this->assertEqual(Inflector::classify('file_systems'), 'FileSystem');
|
|
|
|
$this->assertEqual(Inflector::classify('news'), 'News');
|
2009-11-13 13:23:33 +00:00
|
|
|
$this->assertEqual(Inflector::classify('bureaus'), 'Bureau');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testTableNaming method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTableNaming() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual(Inflector::tableize('ArtistsGenre'), 'artists_genres');
|
|
|
|
$this->assertEqual(Inflector::tableize('FileSystem'), 'file_systems');
|
|
|
|
$this->assertEqual(Inflector::tableize('News'), 'news');
|
2009-11-13 13:23:33 +00:00
|
|
|
$this->assertEqual(Inflector::tableize('Bureau'), 'bureaus');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testHumanization method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testHumanization() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual(Inflector::humanize('posts'), 'Posts');
|
|
|
|
$this->assertEqual(Inflector::humanize('posts_tags'), 'Posts Tags');
|
|
|
|
$this->assertEqual(Inflector::humanize('file_systems'), 'File Systems');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 05:43:53 +00:00
|
|
|
/**
|
|
|
|
* testCustomPluralRule method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCustomPluralRule() {
|
2009-03-18 05:43:53 +00:00
|
|
|
Inflector::rules('plural', array('/^(custom)$/i' => '\1izables'));
|
|
|
|
$this->assertEqual(Inflector::pluralize('custom'), 'customizables');
|
|
|
|
|
2009-11-02 18:51:46 +00:00
|
|
|
Inflector::rules('plural', array('uninflected' => array('uninflectable')));
|
|
|
|
$this->assertEqual(Inflector::pluralize('uninflectable'), 'uninflectable');
|
|
|
|
|
|
|
|
Inflector::rules('plural', array(
|
|
|
|
'rules' => array('/^(alert)$/i' => '\1ables'),
|
|
|
|
'uninflected' => array('noflect', 'abtuse'),
|
|
|
|
'irregular' => array('amaze' => 'amazable', 'phone' => 'phonezes')
|
|
|
|
));
|
|
|
|
$this->assertEqual(Inflector::pluralize('noflect'), 'noflect');
|
|
|
|
$this->assertEqual(Inflector::pluralize('abtuse'), 'abtuse');
|
|
|
|
$this->assertEqual(Inflector::pluralize('alert'), 'alertables');
|
|
|
|
$this->assertEqual(Inflector::pluralize('amaze'), 'amazable');
|
|
|
|
$this->assertEqual(Inflector::pluralize('phone'), 'phonezes');
|
2009-03-18 05:43:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-22 00:08:21 +00:00
|
|
|
/**
|
|
|
|
* testCustomSingularRule method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCustomSingularRule() {
|
2009-11-02 18:51:46 +00:00
|
|
|
Inflector::rules('singular', array('/(eple)r$/i' => '\1', '/(jente)r$/i' => '\1'));
|
|
|
|
|
|
|
|
$this->assertEqual(Inflector::singularize('epler'), 'eple');
|
|
|
|
$this->assertEqual(Inflector::singularize('jenter'), 'jente');
|
|
|
|
|
|
|
|
Inflector::rules('singular', array(
|
|
|
|
'rules' => array('/^(bil)er$/i' => '\1', '/^(inflec|contribu)tors$/i' => '\1ta'),
|
|
|
|
'uninflected' => array('singulars'),
|
|
|
|
'irregular' => array('spins' => 'spinor')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEqual(Inflector::singularize('inflectors'), 'inflecta');
|
|
|
|
$this->assertEqual(Inflector::singularize('contributors'), 'contributa');
|
|
|
|
$this->assertEqual(Inflector::singularize('spins'), 'spinor');
|
|
|
|
$this->assertEqual(Inflector::singularize('singulars'), 'singulars');
|
|
|
|
}
|
2009-03-22 00:08:21 +00:00
|
|
|
|
2010-03-13 20:20:13 +00:00
|
|
|
/**
|
|
|
|
* testCustomTransliterationRule method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCustomTransliterationRule() {
|
2010-03-13 20:20:13 +00:00
|
|
|
$this->assertEqual(Inflector::slug('Testing æ ø å'), 'Testing_ae_o_a');
|
|
|
|
|
|
|
|
Inflector::rules('transliteration', array('/å/' => 'aa', '/ø/' => 'oe'));
|
|
|
|
$this->assertEqual(Inflector::slug('Testing æ ø å'), 'Testing_ae_oe_aa');
|
|
|
|
|
|
|
|
Inflector::rules('transliteration', array('/ä|æ/' => 'ae', '/å/' => 'aa'), true);
|
|
|
|
$this->assertEqual(Inflector::slug('Testing æ ø å'), 'Testing_ae_ø_aa');
|
|
|
|
}
|
|
|
|
|
2010-04-22 02:49:48 +00:00
|
|
|
/**
|
|
|
|
* test that setting new rules clears the inflector caches.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRulesClearsCaches() {
|
2010-04-22 02:49:48 +00:00
|
|
|
$this->assertEqual(Inflector::singularize('Bananas'), 'Banana');
|
|
|
|
$this->assertEqual(Inflector::tableize('Banana'), 'bananas');
|
|
|
|
$this->assertEqual(Inflector::pluralize('Banana'), 'Bananas');
|
|
|
|
|
|
|
|
Inflector::rules('singular', array(
|
|
|
|
'rules' => array('/(.*)nas$/i' => '\1zzz')
|
|
|
|
));
|
2010-07-05 01:46:48 +00:00
|
|
|
$this->assertEquals('Banazzz', Inflector::singularize('Bananas'), 'Was inflected with old rules.');
|
2010-04-22 02:49:48 +00:00
|
|
|
|
|
|
|
Inflector::rules('plural', array(
|
|
|
|
'rules' => array('/(.*)na$/i' => '\1zzz')
|
|
|
|
));
|
2010-07-05 01:46:48 +00:00
|
|
|
$this->assertEqual('Banazzz', Inflector::pluralize('Banana'), 'Was inflected with old rules.');
|
2010-04-22 02:49:48 +00:00
|
|
|
}
|
|
|
|
|
2010-01-17 00:19:12 +00:00
|
|
|
/**
|
|
|
|
* Test resetting inflection rules.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCustomRuleWithReset() {
|
2010-01-14 23:14:20 +00:00
|
|
|
$uninflected = array('atlas', 'lapis', 'onibus', 'pires', 'virus', '.*x');
|
|
|
|
$pluralIrregular = array('as' => 'ases');
|
|
|
|
|
|
|
|
Inflector::rules('singular', array(
|
|
|
|
'rules' => array('/^(.*)(a|e|o|u)is$/i' => '\1\2l'),
|
|
|
|
'uninflected' => $uninflected,
|
|
|
|
), true);
|
|
|
|
|
|
|
|
Inflector::rules('plural', array(
|
|
|
|
'rules' => array(
|
|
|
|
'/^(.*)(a|e|o|u)l$/i' => '\1\2is',
|
|
|
|
),
|
|
|
|
'uninflected' => $uninflected,
|
|
|
|
'irregular' => $pluralIrregular
|
|
|
|
), true);
|
|
|
|
|
|
|
|
$this->assertEqual(Inflector::pluralize('Alcool'), 'Alcoois');
|
|
|
|
$this->assertEqual(Inflector::pluralize('Atlas'), 'Atlas');
|
|
|
|
$this->assertEqual(Inflector::singularize('Alcoois'), 'Alcool');
|
|
|
|
$this->assertEqual(Inflector::singularize('Atlas'), 'Atlas');
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|