2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* InflectorTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2008-10-30 17:30:26 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
App::import('Core', 'Inflector');
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* InflectorTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-12 00:22:09 +00:00
|
|
|
class InflectorTest extends CakeTestCase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setUp() {
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* tearDown method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-03-18 17:55:58 +00:00
|
|
|
function tearDown() {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
|
|
|
unset($this->Inflector);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInstantiation method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testInstantiation() {
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->skipUnless(strpos(Debugger::trace(), 'GroupTest') === false, '%s Cannot be run from within a group test');
|
|
|
|
|
|
|
|
$Instance = Inflector::getInstance();
|
|
|
|
$this->assertEqual(new Inflector(), $Instance);
|
2008-05-30 11:40:08 +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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testInflectingSingulars() {
|
|
|
|
$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');
|
|
|
|
$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');
|
|
|
|
$this->assertEqual(Inflector::singularize('faxes'), 'fax');
|
|
|
|
$this->assertEqual(Inflector::singularize('waxes'), 'wax');
|
2008-08-26 18:30:54 +00:00
|
|
|
$this->assertEqual(Inflector::singularize(''), '');
|
2008-05-30 11:40:08 +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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testInflectingPlurals() {
|
|
|
|
$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');
|
2008-11-08 02:58:37 +00:00
|
|
|
$this->assertEqual(Inflector::pluralize(''), '');
|
2008-05-30 11:40:08 +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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testInflectorSlug() {
|
|
|
|
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more');
|
|
|
|
$expected = 'Foo_Bar_Not_just_for_breakfast_any_more';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Inflector::slug('this/is/a/path');
|
|
|
|
$expected = 'this_is_a_path';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "-");
|
|
|
|
$expected = 'Foo-Bar-Not-just-for-breakfast-any-more';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Inflector::slug('Foo Bar: Not just for breakfast any-more', "+");
|
|
|
|
$expected = 'Foo+Bar+Not+just+for+breakfast+any+more';
|
|
|
|
$this->assertEqual($result, $expected);
|
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';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Inflector::slug('The truth - and- more- news', '-');
|
|
|
|
$expected = 'The-truth-and-more-news';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Inflector::slug('The truth: and more news', '-');
|
|
|
|
$expected = 'The-truth-and-more-news';
|
|
|
|
$this->assertEqual($result, $expected);
|
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';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Inflector::slug('!@$#exciting stuff! - what !@-# was that?', '-');
|
|
|
|
$expected = 'exciting-stuff-what-was-that';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Inflector::slug('20% of profits went to me!', '-');
|
|
|
|
$expected = '20-of-profits-went-to-me';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Inflector::slug('#this melts your face1#2#3', '-');
|
|
|
|
$expected = 'this-melts-your-face1-2-3';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testVariableNaming() {
|
|
|
|
$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');
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testClassNaming() {
|
|
|
|
$this->assertEqual(Inflector::classify('artists_genres'), 'ArtistsGenre');
|
|
|
|
$this->assertEqual(Inflector::classify('file_systems'), 'FileSystem');
|
|
|
|
$this->assertEqual(Inflector::classify('news'), 'News');
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testTableNaming() {
|
|
|
|
$this->assertEqual(Inflector::tableize('ArtistsGenre'), 'artists_genres');
|
|
|
|
$this->assertEqual(Inflector::tableize('FileSystem'), 'file_systems');
|
|
|
|
$this->assertEqual(Inflector::tableize('News'), 'news');
|
|
|
|
}
|
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
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testHumanization() {
|
|
|
|
$this->assertEqual(Inflector::humanize('posts'), 'Posts');
|
|
|
|
$this->assertEqual(Inflector::humanize('posts_tags'), 'Posts Tags');
|
|
|
|
$this->assertEqual(Inflector::humanize('file_systems'), 'File Systems');
|
|
|
|
}
|
|
|
|
}
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|