123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <?php
- /**
- * Part of the Fuel framework.
- *
- * @package Fuel
- * @version 1.5
- * @author Fuel Development Team
- * @license MIT License
- * @copyright 2010 - 2013 Fuel Development Team
- * @link http://fuelphp.com
- */
- namespace Fuel\Core;
- /**
- * Inflector class tests
- *
- * @group Core
- * @group Inflector
- */
- class Test_Inflector extends TestCase
- {
- public function ordinalize_provider()
- {
- return array(
- array(1, 'st'),
- array(21, 'st'),
- array(2, 'nd'),
- array(22, 'nd'),
- array(3, 'rd'),
- array(23, 'rd'),
- array(4, 'th'),
- array(24, 'th'),
- array(111, 'th'),
- array(112, 'th'),
- array(113, 'th'),
- );
- }
- /**
- * Test for Inflector::ordinalize()
- *
- * @test
- * @dataProvider ordinalize_provider
- */
- public function test_ordinalize($number, $ending)
- {
- $this->assertEquals($number.$ending, Inflector::ordinalize($number));
- }
- /**
- * Test for Inflector::ordinalize()
- *
- * @test
- */
- public function test_ordinalize_of_string()
- {
- $this->assertEquals('Foo', Inflector::ordinalize('Foo'));
- }
- /**
- * Test for Inflector::ascii()
- *
- * @test
- */
- public function test_ascii()
- {
- $output = Inflector::ascii('Inglés');
- $expected = "Ingles";
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::camelize()
- *
- * @test
- */
- public function test_camelize()
- {
- $output = Inflector::camelize('apples_and_oranges');
- $expected = 'ApplesAndOranges';
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::classify()
- *
- * @test
- */
- public function test_classify()
- {
- $output = Inflector::classify('fuel_users');
- $expected = 'Fuel_User';
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::demodulize()
- *
- * @test
- */
- public function test_demodulize()
- {
- $output = Inflector::demodulize('Uri::main()');
- $expected = 'main()';
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::denamespace()
- *
- * @test
- */
- public function test_denamespace()
- {
- $this->assertEquals(Inflector::denamespace('Fuel\\SomeClass'), 'SomeClass');
- $this->assertEquals(Inflector::denamespace('\\SomeClass'), 'SomeClass');
- $this->assertEquals(Inflector::denamespace('SomeClass'), 'SomeClass');
- $this->assertEquals(Inflector::denamespace('SomeClass\\'), 'SomeClass');
- }
- /**
- * Test for Inflector::foreign_key()
- *
- * @test
- */
- public function test_foreign_key()
- {
- $output = Inflector::foreign_key('Inflector');
- $expected = 'inflector_id';
- $this->assertEquals($expected, $output);
- $output = Inflector::foreign_key('Inflector', false);
- $expected = 'inflectorid';
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::foreign_key()
- *
- * @test
- */
- public function test_foreign_key_with_model_prefx()
- {
- $this->assertEquals('inflector_id', Inflector::foreign_key('Model_Inflector'));
- }
- /**
- * Test for Inflector::friendly_title()
- *
- * @test
- */
- public function test_friendly_title()
- {
- $output = Inflector::friendly_title('Fuel is a community driven PHP 5 web framework.');
- $expected = 'Fuel-is-a-community-driven-PHP-5-web-framework';
- $this->assertEquals($expected, $output);
- }
- public function test_friendly_title_sep()
- {
- $output = Inflector::friendly_title('Fuel is a community driven PHP 5 web framework.', '_');
- $expected = 'Fuel_is_a_community_driven_PHP_5_web_framework';
- $this->assertEquals($expected, $output);
- }
- public function test_friendly_title_lowercase()
- {
- $output = Inflector::friendly_title('Fuel is a community driven PHP 5 web framework.', '-', true);
- $expected = 'fuel-is-a-community-driven-php-5-web-framework';
- $this->assertEquals($expected, $output);
- }
- public function test_friendly_title_non_ascii()
- {
- $output = Inflector::friendly_title('وقود هو مجتمع مدفوعة إطار شبكة الإنترنت');
- $expected = '';
- $this->assertEquals($expected, $output);
- }
- public function test_friendly_title_allow_non_ascii()
- {
- $output = Inflector::friendly_title('وقود هو مجتمع مدفوعة إطار شبكة الإنترنت', '-', false, true);
- $expected = 'وقود-هو-مجتمع-مدفوعة-إطار-شبكة-الإنترنت';
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::humanize()
- *
- * @test
- */
- public function test_humanize()
- {
- $output = Inflector::humanize('apples_and_oranges');
- $expected = 'Apples and oranges';
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::is_countable()
- *
- * @test
- */
- public function test_is_countable()
- {
- $output = Inflector::is_countable('fish');
- $this->assertFalse($output);
- $output = Inflector::is_countable('apple');
- $this->assertTrue($output);
- }
- /**
- * Test for Inflector::pluralize()
- *
- * @test
- */
- public function test_pluralize()
- {
- $output = Inflector::pluralize('apple');
- $expected = "apples";
- $this->assertEquals($expected, $output);
- $output = Inflector::pluralize('apple', 1);
- $expected = "apple";
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::pluralize()
- *
- * @test
- */
- public function test_pluralize_uncountable()
- {
- $this->assertEquals('equipment', Inflector::pluralize('equipment'));
- }
- /**
- * Test for Inflector::singularize()
- *
- * @test
- */
- public function test_singularize()
- {
- $output = Inflector::singularize('apples');
- $expected = "apple";
- $this->assertEquals($expected, $output);
- }
- /**
- * Test for Inflector::singularize()
- *
- * @test
- */
- public function test_singularize_uncountable()
- {
- $this->assertEquals('equipment', Inflector::singularize('equipment'));
- }
- public function tableize_provider()
- {
- return array(
- array('\\Model\\User', 'users'),
- array('\\Model\\Person', 'people'),
- array('\\Model\\Mouse', 'mice'),
- array('\\Model\\Ox', 'oxen'),
- array('\\Model\\Matrix', 'matrices'),
- array('Model_User', 'users'),
- );
- }
- /**
- * Test for Inflector::tableize()
- *
- * @test
- * @dataProvider tableize_provider
- */
- public function test_tableize($class, $table)
- {
- $this->assertEquals(Inflector::tableize($class), $table);
- }
- public function get_namespace_provider()
- {
- return array(
- array('\\Model\\User', 'Model\\'),
- array('\\Fuel\\Core\\Inflector', 'Fuel\\Core\\'),
- array('Model_User', ''),
- );
- }
- /**
- * Test for Inflector::get_namespace()
- *
- * @test
- * @dataProvider get_namespace_provider
- */
- public function test_get_namespace($class, $namespace)
- {
- $this->assertEquals(Inflector::get_namespace($class), $namespace);
- }
- /**
- * Test for Inflector::underscore()
- *
- * @test
- */
- public function test_underscore()
- {
- $output = Inflector::underscore('ApplesAndOranges');
- $expected = "apples_and_oranges";
- $this->assertEquals($expected, $output);
- }
- }
|