|
|
@ -8,35 +8,35 @@ use yiiunit\TestCase; |
|
|
|
|
|
|
|
|
|
|
|
class InflectorTest extends TestCase |
|
|
|
class InflectorTest extends TestCase |
|
|
|
{ |
|
|
|
{ |
|
|
|
public function testPluralize() |
|
|
|
public function testPluralize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$testData = array( |
|
|
|
$testData = array( |
|
|
|
'move' => 'moves', |
|
|
|
'move' => 'moves', |
|
|
|
'foot' => 'feet', |
|
|
|
'foot' => 'feet', |
|
|
|
'child' => 'children', |
|
|
|
'child' => 'children', |
|
|
|
'human' => 'humans', |
|
|
|
'human' => 'humans', |
|
|
|
'man' => 'men', |
|
|
|
'man' => 'men', |
|
|
|
'staff' => 'staff', |
|
|
|
'staff' => 'staff', |
|
|
|
'tooth' => 'teeth', |
|
|
|
'tooth' => 'teeth', |
|
|
|
'person' => 'people', |
|
|
|
'person' => 'people', |
|
|
|
'mouse' => 'mice', |
|
|
|
'mouse' => 'mice', |
|
|
|
'touch' => 'touches', |
|
|
|
'touch' => 'touches', |
|
|
|
'hash' => 'hashes', |
|
|
|
'hash' => 'hashes', |
|
|
|
'shelf' => 'shelves', |
|
|
|
'shelf' => 'shelves', |
|
|
|
'potato' => 'potatoes', |
|
|
|
'potato' => 'potatoes', |
|
|
|
'bus' => 'buses', |
|
|
|
'bus' => 'buses', |
|
|
|
'test' => 'tests', |
|
|
|
'test' => 'tests', |
|
|
|
'car' => 'cars', |
|
|
|
'car' => 'cars', |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($testData as $testIn => $testOut) { |
|
|
|
foreach ($testData as $testIn => $testOut) { |
|
|
|
$this->assertEquals($testOut, Inflector::pluralize($testIn)); |
|
|
|
$this->assertEquals($testOut, Inflector::pluralize($testIn)); |
|
|
|
$this->assertEquals(ucfirst($testOut), ucfirst(Inflector::pluralize($testIn))); |
|
|
|
$this->assertEquals(ucfirst($testOut), ucfirst(Inflector::pluralize($testIn))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testSingularize() |
|
|
|
public function testSingularize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$testData = array( |
|
|
|
$testData = array( |
|
|
|
'moves' => 'move', |
|
|
|
'moves' => 'move', |
|
|
|
'feet' => 'foot', |
|
|
|
'feet' => 'foot', |
|
|
@ -59,77 +59,77 @@ class InflectorTest extends TestCase |
|
|
|
$this->assertEquals($testOut, Inflector::singularize($testIn)); |
|
|
|
$this->assertEquals($testOut, Inflector::singularize($testIn)); |
|
|
|
$this->assertEquals(ucfirst($testOut), ucfirst(Inflector::singularize($testIn))); |
|
|
|
$this->assertEquals(ucfirst($testOut), ucfirst(Inflector::singularize($testIn))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testTitleize() |
|
|
|
public function testTitleize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals("Me my self and i", Inflector::titleize('MeMySelfAndI')); |
|
|
|
$this->assertEquals("Me my self and i", Inflector::titleize('MeMySelfAndI')); |
|
|
|
$this->assertEquals("Me My Self And I", Inflector::titleize('MeMySelfAndI', true)); |
|
|
|
$this->assertEquals("Me My Self And I", Inflector::titleize('MeMySelfAndI', true)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testCamelize() |
|
|
|
public function testCamelize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals("MeMySelfAndI", Inflector::camelize('me my_self-andI')); |
|
|
|
$this->assertEquals("MeMySelfAndI", Inflector::camelize('me my_self-andI')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testUnderscore() |
|
|
|
public function testUnderscore() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals("me_my_self_and_i", Inflector::underscore('MeMySelfAndI')); |
|
|
|
$this->assertEquals("me_my_self_and_i", Inflector::underscore('MeMySelfAndI')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testCamel2words() |
|
|
|
public function testCamel2words() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals('Camel Case', Inflector::camel2words('camelCase')); |
|
|
|
$this->assertEquals('Camel Case', Inflector::camel2words('camelCase')); |
|
|
|
$this->assertEquals('Lower Case', Inflector::camel2words('lower_case')); |
|
|
|
$this->assertEquals('Lower Case', Inflector::camel2words('lower_case')); |
|
|
|
$this->assertEquals('Tricky Stuff It Is Testing', Inflector::camel2words(' tricky_stuff.it-is testing... ')); |
|
|
|
$this->assertEquals('Tricky Stuff It Is Testing', Inflector::camel2words(' tricky_stuff.it-is testing... ')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testCamel2id() |
|
|
|
public function testCamel2id() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals('post-tag', Inflector::camel2id('PostTag')); |
|
|
|
$this->assertEquals('post-tag', Inflector::camel2id('PostTag')); |
|
|
|
$this->assertEquals('post_tag', Inflector::camel2id('PostTag', '_')); |
|
|
|
$this->assertEquals('post_tag', Inflector::camel2id('PostTag', '_')); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('post-tag', Inflector::camel2id('postTag')); |
|
|
|
$this->assertEquals('post-tag', Inflector::camel2id('postTag')); |
|
|
|
$this->assertEquals('post_tag', Inflector::camel2id('postTag', '_')); |
|
|
|
$this->assertEquals('post_tag', Inflector::camel2id('postTag', '_')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testId2camel() |
|
|
|
public function testId2camel() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals('PostTag', Inflector::id2camel('post-tag')); |
|
|
|
$this->assertEquals('PostTag', Inflector::id2camel('post-tag')); |
|
|
|
$this->assertEquals('PostTag', Inflector::id2camel('post_tag', '_')); |
|
|
|
$this->assertEquals('PostTag', Inflector::id2camel('post_tag', '_')); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('PostTag', Inflector::id2camel('post-tag')); |
|
|
|
$this->assertEquals('PostTag', Inflector::id2camel('post-tag')); |
|
|
|
$this->assertEquals('PostTag', Inflector::id2camel('post_tag', '_')); |
|
|
|
$this->assertEquals('PostTag', Inflector::id2camel('post_tag', '_')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testHumanize() |
|
|
|
public function testHumanize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals("Me my self and i", Inflector::humanize('me_my_self_and_i')); |
|
|
|
$this->assertEquals("Me my self and i", Inflector::humanize('me_my_self_and_i')); |
|
|
|
$this->assertEquals("Me My Self And I", Inflector::humanize('me_my_self_and_i', true)); |
|
|
|
$this->assertEquals("Me My Self And I", Inflector::humanize('me_my_self_and_i', true)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testVariablize() |
|
|
|
public function testVariablize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals("customerTable", Inflector::variablize('customer_table')); |
|
|
|
$this->assertEquals("customerTable", Inflector::variablize('customer_table')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testTableize() |
|
|
|
public function testTableize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals("customer_tables", Inflector::tableize('customerTable')); |
|
|
|
$this->assertEquals("customer_tables", Inflector::tableize('customerTable')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testSlug() |
|
|
|
public function testSlug() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals("this-is-a-title", Inflector::slug('this is a title')); |
|
|
|
$this->assertEquals("this-is-a-title", Inflector::slug('this is a title')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testClassify() |
|
|
|
public function testClassify() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals("CustomerTable", Inflector::classify('customer_tables')); |
|
|
|
$this->assertEquals("CustomerTable", Inflector::classify('customer_tables')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testOrdinalize() |
|
|
|
public function testOrdinalize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertEquals('21st', Inflector::ordinalize('21')); |
|
|
|
$this->assertEquals('21st', Inflector::ordinalize('21')); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|