| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Regression test for the {@link Inflector} class |
|---|
| 4 | * |
|---|
| 5 | * (PHP 5) |
|---|
| 6 | * |
|---|
| 7 | * @package PHPonTraxTest |
|---|
| 8 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|---|
| 9 | * @copyright (c) Walter O. Haas 2006 |
|---|
| 10 | * @version $Id$ |
|---|
| 11 | * @author Walt Haas <haas@xmission.com> |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | echo "testing Inflector\n"; |
|---|
| 15 | require_once 'testenv.php'; |
|---|
| 16 | |
|---|
| 17 | // Call InflectorTest::main() if this source file is executed directly. |
|---|
| 18 | if (!defined("PHPUnit2_MAIN_METHOD")) { |
|---|
| 19 | define("PHPUnit2_MAIN_METHOD", "InflectorTest::main"); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | require_once "PHPUnit2/Framework/TestCase.php"; |
|---|
| 23 | require_once "PHPUnit2/Framework/TestSuite.php"; |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | * Require class to be tested |
|---|
| 27 | */ |
|---|
| 28 | require_once "inflector.php"; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * Test class for Inflector. |
|---|
| 32 | * Generated by PHPUnit2_Util_Skeleton on 2006-02-11 at 13:41:16. |
|---|
| 33 | */ |
|---|
| 34 | class InflectorTest extends PHPUnit2_Framework_TestCase { |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * Runs the test methods of this class. |
|---|
| 38 | * |
|---|
| 39 | * @access public |
|---|
| 40 | * @static |
|---|
| 41 | */ |
|---|
| 42 | public static function main() { |
|---|
| 43 | require_once "PHPUnit2/TextUI/TestRunner.php"; |
|---|
| 44 | |
|---|
| 45 | $suite = new PHPUnit2_Framework_TestSuite("InflectorTest"); |
|---|
| 46 | $result = PHPUnit2_TextUI_TestRunner::run($suite); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /** |
|---|
| 50 | * Sets up the fixture, for example, open a network connection. |
|---|
| 51 | * This method is called before a test is executed. |
|---|
| 52 | * |
|---|
| 53 | * @access protected |
|---|
| 54 | */ |
|---|
| 55 | protected function setUp() { |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * Tears down the fixture, for example, close a network connection. |
|---|
| 60 | * This method is called after a test is executed. |
|---|
| 61 | * |
|---|
| 62 | * @access protected |
|---|
| 63 | */ |
|---|
| 64 | protected function tearDown() { |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * Test {@link Inflector::pluralize()} |
|---|
| 69 | */ |
|---|
| 70 | public function testPluralize() { |
|---|
| 71 | $this->assertEquals(Inflector::pluralize('order'), 'orders'); |
|---|
| 72 | $this->assertEquals(Inflector::pluralize('person'), 'people'); |
|---|
| 73 | $this->assertEquals(Inflector::pluralize('query'), 'queries'); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /** |
|---|
| 77 | * Test {@link Inflector::singularize()} |
|---|
| 78 | */ |
|---|
| 79 | public function testSingularize() { |
|---|
| 80 | $this->assertEquals(Inflector::singularize('orders'), 'order'); |
|---|
| 81 | $this->assertEquals(Inflector::singularize('people'), 'person'); |
|---|
| 82 | $this->assertEquals(Inflector::singularize('processes'), 'process'); |
|---|
| 83 | $this->assertEquals(Inflector::singularize('queries'), 'query'); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * Test {@link Inflector::camelize()} |
|---|
| 88 | */ |
|---|
| 89 | public function testCamelize() { |
|---|
| 90 | $this->assertEquals(Inflector::camelize('order'), 'Order'); |
|---|
| 91 | $this->assertEquals(Inflector::camelize('order_details'), |
|---|
| 92 | 'OrderDetails'); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | /** |
|---|
| 96 | * Test {@link Inflector::underscore()} |
|---|
| 97 | */ |
|---|
| 98 | public function testUnderscore() { |
|---|
| 99 | $this->assertEquals(Inflector::underscore('OrderDetails'), |
|---|
| 100 | 'order_details'); |
|---|
| 101 | $this->assertEquals(Inflector::underscore('Person'),'person'); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | /** |
|---|
| 105 | * Test {@link Inflector::humanize()} |
|---|
| 106 | */ |
|---|
| 107 | public function testHumanize() { |
|---|
| 108 | $this->assertEquals(Inflector::humanize('order_details'), |
|---|
| 109 | 'Order Details'); |
|---|
| 110 | $this->assertEquals(Inflector::humanize('people'), 'People'); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | /** |
|---|
| 114 | * Test {@link Inflector::tableize()} |
|---|
| 115 | */ |
|---|
| 116 | public function testTableize() { |
|---|
| 117 | $this->assertEquals(Inflector::tableize('Person'), 'people'); |
|---|
| 118 | $this->assertEquals(Inflector::tableize('Query'), 'queries'); |
|---|
| 119 | $this->assertEquals(Inflector::tableize('OrderDetail'), |
|---|
| 120 | 'order_details'); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | * Test {@link Inflector::classify()} |
|---|
| 125 | */ |
|---|
| 126 | public function testClassify() { |
|---|
| 127 | $this->assertEquals(Inflector::classify('people'), 'Person'); |
|---|
| 128 | $this->assertEquals(Inflector::classify('queries'), 'Query'); |
|---|
| 129 | $this->assertEquals(Inflector::classify('accesses'), 'Access'); |
|---|
| 130 | echo Inflector::classify('Access')."\n"; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | /** |
|---|
| 134 | * Test {@link Inflector::foreign_key()} |
|---|
| 135 | */ |
|---|
| 136 | public function testForeign_key() { |
|---|
| 137 | $this->assertEquals(Inflector::foreign_key('people'), 'people_id'); |
|---|
| 138 | $this->assertEquals(Inflector::foreign_key('queries'), 'queries_id'); |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | // Call InflectorTest::main() if this source file is executed directly. |
|---|
| 143 | if (PHPUnit2_MAIN_METHOD == "InflectorTest::main") { |
|---|
| 144 | InflectorTest::main(); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | // -- set Emacs parameters -- |
|---|
| 148 | // Local variables: |
|---|
| 149 | // tab-width: 4 |
|---|
| 150 | // c-basic-offset: 4 |
|---|
| 151 | // c-hanging-comment-ender-p: nil |
|---|
| 152 | // indent-tabs-mode: nil |
|---|
| 153 | // End: |
|---|
| 154 | ?> |
|---|