1<?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run'); 2 3/** 4 * Tests Kohana inflector class 5 * 6 * @group kohana 7 * @group kohana.core 8 * @group kohana.core.inflector 9 * 10 * @package Kohana 11 * @category Tests 12 * @author Kohana Team 13 * @author Jeremy Bush <contractfrombelow@gmail.com> 14 * @copyright (c) 2008-2012 Kohana Team 15 * @license http://kohanaframework.org/license 16 */ 17class Kohana_InflectorTest extends Unittest_TestCase 18{ 19 /** 20 * Provides test data for test_lang() 21 * 22 * @return array 23 */ 24 public function provider_uncountable() 25 { 26 return array( 27 // $value, $result 28 array('fish', TRUE), 29 array('cat', FALSE), 30 array('deer', TRUE), 31 array('bison', TRUE), 32 array('friend', FALSE), 33 ); 34 } 35 36 /** 37 * Tests Inflector::uncountable 38 * 39 * @test 40 * @dataProvider provider_uncountable 41 * @param boolean $input Input for File::mime 42 * @param boolean $expected Output for File::mime 43 */ 44 public function test_uncountable($input, $expected) 45 { 46 $this->assertSame($expected, Inflector::uncountable($input)); 47 } 48 49 /** 50 * Provides test data for test_lang() 51 * 52 * @return array 53 */ 54 public function provider_singular() 55 { 56 return array( 57 // $value, $result 58 array('fish', NULL, 'fish'), 59 array('cats', NULL, 'cat'), 60 array('cats', 2, 'cats'), 61 array('cats', '2', 'cats'), 62 array('children', NULL, 'child'), 63 array('meters', 0.6, 'meters'), 64 array('meters', 1.6, 'meters'), 65 array('meters', 1.0, 'meter'), 66 array('status', NULL, 'status'), 67 array('statuses', NULL, 'status'), 68 array('heroes', NULL, 'hero'), 69 ); 70 } 71 72 /** 73 * Tests Inflector::singular 74 * 75 * @test 76 * @dataProvider provider_singular 77 * @param boolean $input Input for File::mime 78 * @param boolean $expected Output for File::mime 79 */ 80 public function test_singular($input, $count, $expected) 81 { 82 $this->assertSame($expected, Inflector::singular($input, $count)); 83 } 84 85 /** 86 * Provides test data for test_lang() 87 * 88 * @return array 89 */ 90 public function provider_plural() 91 { 92 return array( 93 // $value, $result 94 array('fish', NULL, 'fish'), 95 array('cat', NULL, 'cats'), 96 array('cats', 1, 'cats'), 97 array('cats', '1', 'cats'), 98 array('movie', NULL, 'movies'), 99 array('meter', 0.6, 'meters'), 100 array('meter', 1.6, 'meters'), 101 array('meter', 1.0, 'meter'), 102 array('hero', NULL, 'heroes'), 103 array('Dog', NULL, 'Dogs'), // Titlecase 104 array('DOG', NULL, 'DOGS'), // Uppercase 105 ); 106 } 107 108 /** 109 * Tests Inflector::plural 110 * 111 * @test 112 * @dataProvider provider_plural 113 * @param boolean $input Input for File::mime 114 * @param boolean $expected Output for File::mime 115 */ 116 public function test_plural($input, $count, $expected) 117 { 118 $this->assertSame($expected, Inflector::plural($input, $count)); 119 } 120 121 /** 122 * Provides test data for test_camelize() 123 * 124 * @return array 125 */ 126 public function provider_camelize() 127 { 128 return array( 129 // $value, $result 130 array('mother cat', 'camelize', 'motherCat'), 131 array('kittens in bed', 'camelize', 'kittensInBed'), 132 array('mother cat', 'underscore', 'mother_cat'), 133 array('kittens in bed', 'underscore', 'kittens_in_bed'), 134 array('kittens-are-cats', 'humanize', 'kittens are cats'), 135 array('dogs_as_well', 'humanize', 'dogs as well'), 136 ); 137 } 138 139 /** 140 * Tests Inflector::camelize 141 * 142 * @test 143 * @dataProvider provider_camelize 144 * @param boolean $input Input for File::mime 145 * @param boolean $expected Output for File::mime 146 */ 147 public function test_camelize($input, $method, $expected) 148 { 149 $this->assertSame($expected, Inflector::$method($input)); 150 } 151 152 /** 153 * Provides data for test_decamelize() 154 * 155 * @return array 156 */ 157 public function provider_decamelize() 158 { 159 return array( 160 array('getText', '_', 'get_text'), 161 array('getJSON', '_', 'get_json'), 162 array('getLongText', '_', 'get_long_text'), 163 array('getI18N', '_', 'get_i18n'), 164 array('getL10n', '_', 'get_l10n'), 165 array('getTe5t1ng', '_', 'get_te5t1ng'), 166 array('OpenFile', '_', 'open_file'), 167 array('CloseIoSocket', '_', 'close_io_socket'), 168 array('fooBar', ' ', 'foo bar'), 169 array('camelCase', '+', 'camel+case'), 170 ); 171 } 172 173 /** 174 * Tests Inflector::decamelize() 175 * 176 * @test 177 * @dataProvider provider_decamelize 178 * @param string $input Camelized string 179 * @param string $glue Glue 180 * @param string $expected Expected string 181 */ 182 public function test_decamelize($input, $glue, $expected) 183 { 184 $this->assertSame($expected, Inflector::decamelize($input, $glue)); 185 } 186} 187