/usr/share/php/tests/Horde_Support/Horde/Support/InflectorTest.php is in php-horde-support 2.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | <?php
/**
* Copyright 2007-2013 Horde LLC (http://www.horde.org/)
*
* @category Horde
* @package Support
* @subpackage UnitTests
* @license http://www.horde.org/licenses/bsd
*/
/**
* @category Horde
* @package Support
* @subpackage UnitTests
* @license http://www.horde.org/licenses/bsd
*/
class Horde_Support_InflectorTest extends PHPUnit_Framework_TestCase
{
/**
* Words to test
*
* @var array $words
*/
public $words = array(
'sheep' => 'sheep',
'man' => 'men',
'woman' => 'women',
'user' => 'users',
'foot' => 'feet',
'hive' => 'hives',
'chive' => 'chives',
'event' => 'events',
'task' => 'tasks',
'preference' => 'preferences',
'child' => 'children',
'moose' => 'moose',
'mouse' => 'mice',
);
public function setUp()
{
$this->inflector = new Horde_Support_Inflector;
}
public function testSingularizeAndPluralize()
{
foreach ($this->words as $singular => $plural) {
$this->assertEquals($plural, $this->inflector->pluralize($singular));
$this->assertEquals($singular, $this->inflector->singularize($plural));
}
}
public function testCamelize()
{
// underscore => camelize
$this->assertEquals('Test', $this->inflector->camelize('test'));
$this->assertEquals('TestCase', $this->inflector->camelize('test_case'));
$this->assertEquals('Test/Case', $this->inflector->camelize('test/case'));
$this->assertEquals('TestCase/Name', $this->inflector->camelize('test_case/name'));
// already camelized
$this->assertEquals('Test', $this->inflector->camelize('Test'));
$this->assertEquals('TestCase', $this->inflector->camelize('testCase'));
$this->assertEquals('TestCase', $this->inflector->camelize('TestCase'));
$this->assertEquals('Test/Case', $this->inflector->camelize('Test_Case'));
}
public function testCamelizeLower()
{
// underscore => camelize
$this->assertEquals('test', $this->inflector->camelize('test', 'lower'));
$this->assertEquals('testCase', $this->inflector->camelize('test_case', 'lower'));
$this->assertEquals('test/case', $this->inflector->camelize('test/case', 'lower'));
$this->assertEquals('testCase/name', $this->inflector->camelize('test_case/name', 'lower'));
// already camelized
$this->assertEquals('test', $this->inflector->camelize('Test', 'lower'));
$this->assertEquals('testCase', $this->inflector->camelize('testCase', 'lower'));
$this->assertEquals('testCase', $this->inflector->camelize('TestCase', 'lower'));
$this->assertEquals('test/case', $this->inflector->camelize('Test_Case', 'lower'));
}
public function testTitleize()
{
$this->markTestIncomplete();
}
/**
* data given to underscore() MUST be camelized already
*/
public function testUnderscore()
{
// most common scenarios (camelize => underscore)
$this->assertEquals('derek', $this->inflector->underscore('Derek'));
$this->assertEquals('dereks_test', $this->inflector->underscore('dereksTest'));
$this->assertEquals('dereks_test', $this->inflector->underscore('DereksTest'));
$this->assertEquals('dereks_test', $this->inflector->underscore('Dereks_Test'));
$this->assertEquals('dereks_name_test', $this->inflector->underscore('DereksName_Test'));
// not as common (already underscore)
$this->assertEquals('derek', $this->inflector->underscore('derek'));
$this->assertEquals('dereks_test', $this->inflector->underscore('dereks_test'));
}
public function testDasherize()
{
$this->assertEquals('derek', $this->inflector->dasherize('Derek'));
$this->assertEquals('dereks-test', $this->inflector->dasherize('dereksTest'));
$this->assertEquals('dereks-test', $this->inflector->dasherize('DereksTest'));
$this->assertEquals('dereks-test', $this->inflector->dasherize('Dereks_Test'));
$this->assertEquals('dereks-name-test', $this->inflector->dasherize('DereksName_Test'));
$this->assertEquals('derek', $this->inflector->dasherize('derek'));
$this->assertEquals('dereks-test', $this->inflector->dasherize('dereks_test'));
}
public function testHumanize()
{
// most common scenarios (column name => human)
$this->assertEquals('Derek', $this->inflector->humanize('derek'));
$this->assertEquals('Dereks test', $this->inflector->humanize('dereks_test'));
$this->assertEquals('Dereks test', $this->inflector->humanize('dereks_test_id'));
// not as common (columns are usually underscored)
$this->assertEquals('Derek', $this->inflector->humanize('Derek'));
$this->assertEquals('Dereks', $this->inflector->humanize('Dereks'));
$this->assertEquals('Dereks test', $this->inflector->humanize('dereksTest'));
$this->assertEquals('Dereks test', $this->inflector->humanize('dereksTestId'));
$this->assertEquals('Dereks test', $this->inflector->humanize('DereksTest'));
$this->assertEquals('Dereks test', $this->inflector->humanize('Dereks_Test'));
}
public function testDemodularize()
{
$this->assertEquals('Stuff', $this->inflector->demodulize('Fax_Job_Stuff'));
$this->assertEquals('Job', $this->inflector->demodulize('Fax_Job'));
$this->assertEquals('Fax', $this->inflector->demodulize('Fax'));
}
/**
* to table formatted string
*/
public function testTableize()
{
// most common scenarios (class => table)
$this->assertEquals('dereks', $this->inflector->tableize('Derek'));
$this->assertEquals('dereks', $this->inflector->tableize('Dereks'));
$this->assertEquals('dereks_tests', $this->inflector->tableize('dereksTest'));
$this->assertEquals('dereks_tests', $this->inflector->tableize('DereksTest'));
$this->assertEquals('dereks_tests', $this->inflector->tableize('Dereks_Test'));
$this->assertEquals('dereks_tests', $this->inflector->tableize('Dereks/Test'));
// not as common (already underscore)
$this->assertEquals('dereks', $this->inflector->tableize('derek'));
$this->assertEquals('dereks_tests', $this->inflector->tableize('dereks_test'));
$this->assertEquals('dereks_tests', $this->inflector->tableize('dereks/test'));
}
/**
* to class formatted string
*/
public function testClassify()
{
$this->assertEquals('Derek', $this->inflector->classify('derek'));
$this->assertEquals('DereksTest', $this->inflector->classify('dereks_test'));
// not as common
$this->assertEquals('Derek', $this->inflector->classify('Derek'));
$this->assertEquals('Derek', $this->inflector->classify('Dereks'));
$this->assertEquals('DereksTest', $this->inflector->classify('dereksTest'));
$this->assertEquals('DereksTest', $this->inflector->classify('DereksTest'));
$this->assertEquals('Dereks_Test', $this->inflector->classify('Dereks_Test'));
}
public function testForeignKey()
{
$this->markTestIncomplete();
}
public function testOrdinalize()
{
$this->markTestIncomplete();
}
/*##########################################################################
# Inflection Cache
##########################################################################*/
// test setting inflection
public function testSetCache()
{
$this->inflector->setCache('documents', 'singularize', 'document');
$this->assertEquals('document', $this->inflector->getCache('documents', 'singularize'));
}
// test setting inflection
public function testClearCache()
{
$this->inflector->setCache('documents', 'singularize', 'document');
$this->inflector->clearCache();
$this->assertEquals(false, $this->inflector->getCache('documents', 'singularize'));
}
}
|