1<?php
2
3class Doctrine_Ticket_1124_TestCase extends Doctrine_UnitTestCase
4{
5	const NO_ALIAS			= 5;
6	const SOMETHING_ELSE	= 8;
7	const TABLEIZED_ALIAS	= 27;
8	const CLASSIFIED_ALIAS  = 29;
9	const ANOTHER_ALIAS     = 30;
10
11    public function prepareTables()
12    {
13        $this->tables = array();
14        $this->tables[] = 'Ticket_1124_Record';
15
16        parent::prepareTables();
17    }
18
19    public function prepareData()
20    {
21        $record = new Ticket_1124_Record();
22        $record->no_alias		 = self::NO_ALIAS;
23        $record->somethingElse	 = self::SOMETHING_ELSE;
24        $record->tableizedAlias	 = self::TABLEIZED_ALIAS;
25        $record->ClassifiedAlias = self::CLASSIFIED_ALIAS;
26        $record->another_Alias   = self::ANOTHER_ALIAS;
27        $record->save();
28    }
29
30	private function assertIsSampleRecord($record)
31	{
32    	$this->assertNotNull($record);
33    	$this->assertEqual($record->no_alias, self::NO_ALIAS);
34    	$this->assertEqual($record->somethingElse, self::SOMETHING_ELSE);
35    	$this->assertEqual($record->tableizedAlias, self::TABLEIZED_ALIAS);
36    	$this->assertEqual($record->ClassifiedAlias, self::CLASSIFIED_ALIAS);
37	}
38
39    public function testFindByUnaliasedColumnWorks()
40    {
41        try {
42    	    $r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneByNoAlias(self::NO_ALIAS);
43    	    $this->assertIsSampleRecord($r);
44    	    $this->pass();
45        } catch (Exception $e) {
46            $this->fail($e->getMessage());
47        }
48    }
49
50    public function testFindByDisjointlyAliasedColumnWorks()
51    {
52        try {
53        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneBysomethingElse(self::SOMETHING_ELSE);	// test currently fails
54
55        	$this->assertIsSampleRecord($r);
56    	    $this->pass();
57        } catch (Exception $e) {
58            $this->fail($e->getMessage());
59        }
60    }
61
62    public function testFindByDisjointlyAliasedColumnWorks2()
63    {
64        try {
65        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneBydisjoint_alias(self::SOMETHING_ELSE);	// test currently fails
66
67        	$this->assertIsSampleRecord($r);
68    	    $this->pass();
69        } catch (Exception $e) {
70            $this->fail($e->getMessage());
71        }
72    }
73
74    public function testFindByDisjointlyAliasedColumnWorks3()
75    {
76        try {
77        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneByDisjointAlias(self::SOMETHING_ELSE);	// test currently fails
78
79        	$this->assertIsSampleRecord($r);
80    	    $this->pass();
81        } catch (Exception $e) {
82            $this->fail($e->getMessage());
83        }
84    }
85
86    public function testFindByTableizedAliasedColumnWorks()
87    {
88        try {
89        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneBytableizedAlias(self::TABLEIZED_ALIAS);	// test currently fails
90
91        	$this->assertIsSampleRecord($r);
92    	    $this->pass();
93        } catch (Exception $e) {
94            $this->fail($e->getMessage());
95        }
96    }
97
98    public function testFindByTableizedAliasedColumnWorks2()
99    {
100        try {
101        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneBytableized_alias(self::TABLEIZED_ALIAS);	// test currently fails
102
103        	$this->assertIsSampleRecord($r);
104    	    $this->pass();
105        } catch (Exception $e) {
106            $this->fail($e->getMessage());
107        }
108    }
109
110    public function testFindByClassifiedAliasedColumnWorks()
111    {
112        try {
113        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneByClassifiedAlias(self::CLASSIFIED_ALIAS);	// test currently fails
114
115        	$this->assertIsSampleRecord($r);
116    	    $this->pass();
117        } catch (Exception $e) {
118            $this->fail($e->getMessage());
119        }
120    }
121
122    public function testFindByAnotherAliasedColumnWorks()
123    {
124        try {
125        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneByTest(self::ANOTHER_ALIAS);	// test currently fails
126
127        	$this->assertIsSampleRecord($r);
128    	    $this->pass();
129        } catch (Exception $e) {
130            $this->fail($e->getMessage());
131        }
132    }
133
134    public function testFindByAnotherAliasedColumnWorks2()
135    {
136        try {
137        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneBytest(self::ANOTHER_ALIAS);	// test currently fails
138
139        	$this->assertIsSampleRecord($r);
140    	    $this->pass();
141        } catch (Exception $e) {
142            $this->fail($e->getMessage());
143        }
144    }
145
146    public function testFindByAnotherAliasedColumnWorks3()
147    {
148        try {
149        	$r = Doctrine_Core::getTable('Ticket_1124_Record')->findOneByanother_Alias(self::ANOTHER_ALIAS);	// test currently fails
150
151        	$this->assertIsSampleRecord($r);
152    	    $this->pass();
153        } catch (Exception $e) {
154            $this->fail($e->getMessage());
155        }
156    }
157}
158
159class Ticket_1124_Record extends Doctrine_Record
160{
161    public function setTableDefinition()
162    {
163        $this->setTableName('emb1_record');
164        $this->hasColumn('id', 'integer', 15, array('autoincrement' => true, 'unsigned' => true, 'primary' => true, 'notnull' => true));
165        $this->hasColumn('no_alias', 'integer', 4);	// column with no aliasing
166        $this->hasColumn('disjoint_alias as somethingElse', 'integer', 4);	// column whose alias has no relation to the column itself
167        $this->hasColumn('tableized_alias as tableizedAlias', 'integer', 4);	// column whose alias' tableized form is equivalent to the column name itself
168        $this->hasColumn('w00t as ClassifiedAlias', 'integer', 4);
169        $this->hasColumn('test as another_Alias', 'integer', 4);
170    }
171}