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
22/**
23 * Doctrine_Ticket_1325_TestCase
24 *
25 * @package     Doctrine
26 * @author      Andrea Baron <andrea@bhweb.it>
27 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28 * @category    Object Relational Mapping
29 * @link        www.doctrine-project.org
30 * @since       1.0
31 * @version     $Revision$
32 */
33class Doctrine_Ticket_1325_TestCase extends Doctrine_UnitTestCase
34{
35    public function prepareTables()
36    {
37        $this->tables[] = 'Ticket_1325_TableName_NoAlias';
38        $this->tables[] = 'Ticket_1325_TableName_Aliased';
39        parent::prepareTables();
40    }
41
42    public function testShouldInsertWithoutAlias()
43    {
44        $elem = new Ticket_1325_TableName_NoAlias();
45        $elem->id = 1;
46        $elem->save();
47
48        $res = Doctrine_Query::create()
49            ->from('Ticket_1325_TableName_NoAlias')
50            ->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
51
52        $now = time();
53        $time = strtotime($res['event_date']);
54        $this->assertTrue(($now + 5 >= $time) && ($time >= $now));
55    }
56
57    public function testShouldInsertWithAlias()
58    {
59        $elem = new Ticket_1325_TableName_Aliased();
60        $elem->id = 1;
61        $elem->save();
62
63        $res = Doctrine_Query::create()
64            ->from('Ticket_1325_TableName_Aliased')
65            ->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
66
67        $now = time();
68        $time = strtotime($res['eventDate']);
69        $this->assertTrue(strtotime($res['eventDate']) > 0);
70    }
71}
72
73class Ticket_1325_TableName_NoAlias extends Doctrine_Record
74{
75    public function setTableDefinition()
76    {
77        $this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
78    }
79
80    public function setUp()
81    {
82        $this->actAs(new Doctrine_Template_Timestampable(array('created' => array('name' => 'event_date', 'type' => 'timestamp'), 'updated' => array('disabled' => true))));
83    }
84}
85
86class Ticket_1325_TableName_Aliased extends Doctrine_Record
87{
88    public function setTableDefinition()
89    {
90        $this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
91    }
92
93    public function setUp()
94    {
95        $this->actAs(new Doctrine_Template_Timestampable(array('created' => array('name' => 'event_date', 'alias' => 'eventDate', 'type' => 'timestamp'), 'updated' => array('disabled' => true))));
96    }
97}