Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
05523640
Commit
05523640
authored
May 22, 2013
by
Antonio Ramirez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed pluralize + singularize rules for tests
parent
7b98b424
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
Inflector.php
framework/yii/helpers/base/Inflector.php
+8
-1
InflectorTest.php
tests/unit/framework/helpers/InflectorTest.php
+22
-4
No files found.
framework/yii/helpers/base/Inflector.php
View file @
05523640
...
...
@@ -23,7 +23,12 @@ class Inflector
*/
protected
static
$plural
=
array
(
'rules'
=>
array
(
'/(m)ove$/i'
=>
'\1oves'
,
'/(f)oot$/i'
=>
'\1eet'
,
'/(h)uman$/i'
=>
'\1umans'
,
'/(s)tatus$/i'
=>
'\1\2tatuses'
,
'/(s)taff$/i'
=>
'\1taff'
,
'/(t)ooth$/i'
=>
'\1eeth'
,
'/(quiz)$/i'
=>
'\1zes'
,
'/^(ox)$/i'
=>
'\1\2en'
,
'/([m|l])ouse$/i'
=>
'\1ice'
,
...
...
@@ -37,7 +42,7 @@ class Inflector
'/(p)erson$/i'
=>
'\1eople'
,
'/(m)an$/i'
=>
'\1en'
,
'/(c)hild$/i'
=>
'\1hildren'
,
'/(buffal|tomat
)o$/i'
=>
'\1\2
oes'
,
'/(buffal|tomat
|potat|ech|her|vet)o$/i'
=>
'\1
oes'
,
'/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i'
=>
'\1i'
,
'/us$/i'
=>
'uses'
,
'/(alias)$/i'
=>
'\1es'
,
...
...
@@ -97,6 +102,8 @@ class Inflector
protected
static
$singular
=
array
(
'rules'
=>
array
(
'/(s)tatuses$/i'
=>
'\1\2tatus'
,
'/(f)eet$/i'
=>
'\1oot'
,
'/(t)eeth$/i'
=>
'\1ooth'
,
'/^(.*)(menu)s$/i'
=>
'\1\2'
,
'/(quiz)zes$/i'
=>
'\\1'
,
'/(matr)ices$/i'
=>
'\1ix'
,
...
...
tests/unit/framework/helpers/InflectorTest.php
View file @
05523640
...
...
@@ -39,10 +39,28 @@ class InflectorTest extends TestCase
public
function
testSingularize
()
{
$this
->
assertEquals
(
"person"
,
Inflector
::
singularize
(
'people'
));
$this
->
assertEquals
(
"fish"
,
Inflector
::
singularize
(
'fish'
));
$this
->
assertEquals
(
"man"
,
Inflector
::
singularize
(
'men'
));
$this
->
assertEquals
(
"table"
,
Inflector
::
singularize
(
'tables'
));
$testData
=
array
(
'moves'
=>
'move'
,
'feet'
=>
'foot'
,
'children'
=>
'child'
,
'humans'
=>
'human'
,
'men'
=>
'man'
,
'staff'
=>
'staff'
,
'teeth'
=>
'tooth'
,
'people'
=>
'person'
,
'mice'
=>
'mouse'
,
'touches'
=>
'touch'
,
'hashes'
=>
'hash'
,
'shelves'
=>
'shelf'
,
'potatoes'
=>
'potato'
,
'buses'
=>
'bus'
,
'tests'
=>
'test'
,
'cars'
=>
'car'
,
);
foreach
(
$testData
as
$testIn
=>
$testOut
)
{
$this
->
assertEquals
(
$testOut
,
Inflector
::
pluralize
(
$testIn
));
$this
->
assertEquals
(
ucfirst
(
$testOut
),
ucfirst
(
Inflector
::
pluralize
(
$testIn
)));
}
}
public
function
testTitleize
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment