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_1304_TestCase
24 *
25 * @package     Doctrine
26 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
27 * @category    Object Relational Mapping
28 * @link        www.doctrine-project.org
29 * @since       1.0
30 * @version     $Revision$
31 */
32class Doctrine_Ticket_1304_TestCase extends Doctrine_UnitTestCase {
33  public function prepareTables() {
34    $this->tables[] = 'Doctrine_Ticket_1304_Slug';
35    parent::prepareTables();
36  }
37
38  public function testTicket()
39  {
40	// run 1
41     try {
42        $r = new Doctrine_Ticket_1304_Slug();
43        $r->Translation['en']->title	= 'Title';
44        $r->Translation['en']->content	= 'Content';
45        $r->save();
46      } catch (Exception $e) {
47          $this->fail($e->getMessage());
48      }
49      $this->assertEqual('title', $r->Translation['en']->slug);
50
51	// run 2
52     try {
53        $r = new Doctrine_Ticket_1304_Slug();
54        $r->Translation['en']->title	= 'Title';
55        $r->Translation['en']->content	= 'Content';
56        $r->save();
57      } catch (Exception $e) {
58          $this->fail($e->getMessage());
59      }
60      $this->assertEqual('title-1', $r->Translation['en']->slug);
61
62	// run 3
63     try {
64        $r = new Doctrine_Ticket_1304_Slug();
65        $r->Translation['en']->title	= 'Title';
66        $r->Translation['en']->content	= 'Content';
67        $r->save();
68      } catch (Exception $e) {
69          $this->fail($e->getMessage());
70      }
71      $this->assertEqual('title-2', $r->Translation['en']->slug);
72  }
73}
74
75class Doctrine_Ticket_1304_Slug extends Doctrine_Record
76{
77  public function setTableDefinition()
78  {
79    $this->hasColumn('title', 'string', 255, array('type' => 'string', 'length' => '255'));
80    $this->hasColumn('content', 'string', null, array('type' => 'string'));
81  }
82
83  public function setUp()
84  {
85    $i18n0 = new Doctrine_Template_I18n(array('fields' => array(0 => 'title', 1 => 'content')));
86    $sluggable1 = new Doctrine_Template_Sluggable(array('fields' => array(0 => 'title'), 'indexName' => 'i18n_sluggable_test'));
87    $i18n0->addChild($sluggable1);
88    $this->actAs($i18n0);
89  }
90}