1<?php
2/*
3 *  $Id$
4 *
5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 *
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the LGPL. For more information, see
19 * <http://www.doctrine-project.org>.
20 */
21
22class DC521TestModel extends Doctrine_Record
23{
24    public function setTableDefinition()
25    {
26        $this->setTableName('dc521_test_model');
27        $this->hasColumn('id', 'integer', null, array(
28             'type' => 'integer',
29             'primary' => true,
30             'autoincrement' => true,
31             ));
32        $this->hasColumn('data', 'string', null, array(
33             'type' => 'string',
34             ));
35    }
36
37    public function setUp()
38    {
39        parent::setUp();
40
41    }
42}
43
44class DC521IdOnlyTestModel extends Doctrine_Record
45{
46    public function setTableDefinition()
47    {
48        $this->setTableName('dc521_idonly_test_model');
49        $this->hasColumn('id', 'integer', null, array(
50             'type' => 'integer',
51             'primary' => true,
52             'autoincrement' => true,
53             ));
54    }
55
56    public function setUp()
57    {
58        parent::setUp();
59
60    }
61}
62
63/**
64 * Doctrine_Ticket_DC521_TestCase
65 *
66 * @package     Doctrine
67 * @author      Gergely Kis <gergely.kis@mattakis.com>
68 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
69 * @category    Object Relational Mapping
70 * @link        www.doctrine-project.org
71 * @since       1.2
72 * @version     $Revision$
73 */
74class Doctrine_Ticket_DC521_TestCase extends Doctrine_UnitTestCase
75{
76    public function init()
77    {
78        Doctrine_Manager::connection('pgsql://test:test@localhost/doctrine', 'Pgsql');
79    	   $this->driverName = 'Pgsql';
80    	   parent::init();
81        $this->prepareTables();
82    }
83
84    public function setUp()
85    {
86    	   $this->driverName = 'Pgsql';
87        Doctrine_Manager::connection('pgsql://test:test@localhost/doctrine', 'Pgsql');
88    	   parent::setUp();
89    }
90
91    public function testEmptyPgsqlAutoIncrementField()
92    {
93        $m = new DC521TestModel();
94        $m->save();
95        $this->assertEqual($m->id, 1);
96    }
97
98    public function testIdOnlyPgsqlAutoIncrementField()
99    {
100        $m = new DC521IdOnlyTestModel();
101        $m->save();
102        $this->assertEqual($m->id, 1);
103    }
104
105    public function testIdOnlyPgsqlAutoIncrementFieldWithDefinedValue()
106    {
107        $m = new DC521IdOnlyTestModel();
108        $m->id = 9999;
109        $m->save();
110        $this->assertEqual($m->id, 9999);
111    }
112
113    public function testPgsqlAutoIncrementFieldWithDefinedValue()
114    {
115        $m = new DC521TestModel();
116        $m->id = 9999;
117        $m->save();
118        $this->assertEqual($m->id, 9999);
119    }
120
121    public function testPgsqlAutoIncrementFieldWithDefinedValueAndData()
122    {
123        $m = new DC521TestModel();
124        $this->assertEqual($m->id, null);
125        $m->id = 111111;
126        $m->data = "testdata";
127        $m->save();
128        $this->assertEqual($m->id, 111111);
129    }
130
131    public function prepareTables()
132    {
133        $this->tables = array('DC521TestModel', 'DC521IdOnlyTestModel');
134        parent::prepareTables();
135    }
136
137    public function tearDown()
138    {
139        Doctrine_Manager::resetInstance();
140    	   $this->driverName = null;
141    	   parent::tearDown();
142    }
143