| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the symfony package.
|
|
|
5 |
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
include(dirname(__FILE__).'/../bootstrap/unit.php');
|
|
|
12 |
|
|
|
13 |
$t = new lime_test(23);
|
|
|
14 |
|
|
|
15 |
$conn = Doctrine_Manager::connection(new Doctrine_Adapter_Mock('mysql'));
|
|
|
16 |
|
|
|
17 |
class Test extends sfDoctrineRecord
|
|
|
18 |
{
|
|
|
19 |
public function setTableDefinition()
|
|
|
20 |
{
|
|
|
21 |
$this->hasColumn('name', 'string', 255, array('notblank' => true));
|
|
|
22 |
$this->hasColumn('test as TEST', 'string', 255);
|
|
|
23 |
$this->hasColumn('email', 'string', 255, array('email' => true, 'notnull' => true));
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public function setUp()
|
|
|
27 |
{
|
|
|
28 |
$this->hasMany('TestRelation as TestRelations', array('local' => 'id', 'foreign' => 'test_id'));
|
|
|
29 |
}
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
class TestRelation extends sfDoctrineRecord
|
|
|
33 |
{
|
|
|
34 |
public function setTableDefinition()
|
|
|
35 |
{
|
|
|
36 |
$this->hasColumn('name', 'string', 255);
|
|
|
37 |
$this->hasColumn('test_id', 'integer');
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function setUp()
|
|
|
41 |
{
|
|
|
42 |
$this->hasOne('Test', array('local' => 'test_id', 'foreign' => 'id'));
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
$column = new sfDoctrineColumn('name', Doctrine_Core::getTable('Test'));
|
|
|
47 |
$t->is($column->getName(), 'name');
|
|
|
48 |
$t->is($column->getFieldName(), 'name');
|
|
|
49 |
$t->is($column->getPhpName(), 'name');
|
|
|
50 |
$t->is($column->isNotNull(), true);
|
|
|
51 |
|
|
|
52 |
$column = new sfDoctrineColumn('test', Doctrine_Core::getTable('Test'));
|
|
|
53 |
$t->is($column->getName(), 'test');
|
|
|
54 |
$t->is($column->getFieldName(), 'TEST');
|
|
|
55 |
$t->is($column->getPhpName(), 'TEST');
|
|
|
56 |
|
|
|
57 |
$t->is($column->getDoctrineType(), 'string');
|
|
|
58 |
$t->is($column->getType(), 'VARCHAR');
|
|
|
59 |
$t->is($column->getLength(), 255);
|
|
|
60 |
$t->is($column->getSize(), 255);
|
|
|
61 |
$t->is($column->hasDefinitionKey('length'), true);
|
|
|
62 |
$t->is($column->getDefinitionKey('type'), 'string');
|
|
|
63 |
$t->is($column->isNotNull(), false);
|
|
|
64 |
|
|
|
65 |
// Is not null and has definition key
|
|
|
66 |
$column = new sfDoctrineColumn('email', Doctrine_Core::getTable('Test'));
|
|
|
67 |
$t->is($column->isNotNull(), true);
|
|
|
68 |
$t->is($column->hasDefinitionKey('email'), true);
|
|
|
69 |
$t->is($column->getDefinitionKey('email'), true);
|
|
|
70 |
|
|
|
71 |
// Is primary key
|
|
|
72 |
$column = new sfDoctrineColumn('id', Doctrine_Core::getTable('Test'));
|
|
|
73 |
$t->is($column->isPrimaryKey(), true);
|
|
|
74 |
|
|
|
75 |
// Relation/foreign key functions
|
|
|
76 |
$column = new sfDoctrineColumn('test_id', Doctrine_Core::getTable('TestRelation'));
|
|
|
77 |
$t->is($column->isForeignKey(), true);
|
|
|
78 |
$t->is($column->getForeignClassName(), 'Test');
|
|
|
79 |
$t->is($column->getForeignTable()->getOption('name'), 'Test');
|
|
|
80 |
$t->is($column->getTable()->getOption('name'), 'TestRelation');
|
|
|
81 |
|
|
|
82 |
// Array access
|
|
|
83 |
$t->is($column['type'], 'integer');
|