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_2355_TestCase
24 *
25 * @package     Doctrine
26 * @author      Jacek Dębowczyk <j.debowczyk@diface.com>
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.1
31 * @version     $Revision$
32 */
33class Doctrine_Ticket_2377_TestCase extends Doctrine_UnitTestCase
34{
35    public function prepareTables()
36    {
37        $this->tables[] = 'Ticket_2377_Author';
38        $this->tables[] = 'Ticket_2377_Article';
39        parent::prepareTables();
40    }
41
42    public function testSynchronize()
43    {
44        try {
45			$author = new Ticket_2377_Author();
46			$article = new Ticket_2377_Article();
47			$article->Author = $author;
48
49			$array = $article->toArray(true);
50
51			$article2 = new Ticket_2377_Article();
52			$article2->synchronizeWithArray($array);
53
54			$this->assertTrue($article2->Author instanceof Ticket_2377_Author);
55
56            $this->pass();
57        } catch (Exception $e) {
58			$this->fail();
59        }
60    }
61}
62
63class Ticket_2377_Author extends Doctrine_Record
64{
65    public function setTableDefinition()
66    {
67        $this->setTableName('author');
68        $this->hasColumn('id', 'integer', 2,
69          array('type' => 'integer', 'primary' => true, 'autoincrement' => true, 'length' => '2'));
70        $this->hasColumn('name', 'string', 2,
71          array('type' => 'string', 'length' => '100'));
72    }
73
74    public function setUp()
75    {
76        $this->hasMany('Ticket_2377_Article as Article', array('local' => 'id', 'foreign' => 'author_id'));
77    }
78}
79
80class Ticket_2377_Article extends Doctrine_Record
81{
82    public function setTableDefinition()
83    {
84        $this->setTableName('article');
85        $this->hasColumn('id', 'integer', 2,
86          array('type' => 'integer', 'primary' => true, 'autoincrement' => true, 'length' => '2'));
87        $this->hasColumn('author_id', 'integer', 2,
88          array('type' => 'integer', 'unsigned' => true, 'length' => '2'));
89        $this->hasColumn('content', 'string', 100,
90          array('type' => 'string', 'length' => '100'));
91    }
92
93    public function setUp()
94    {
95        $this->hasOne('Ticket_2377_Author as Author', array('local' => 'author_id', 'foreign' => 'id'));
96    }
97}