1<?php 2 3 4class Doctrine_Ticket_1830_TestCase extends Doctrine_UnitTestCase 5{ 6 public function init() 7 { 8 Doctrine_Manager::connection('mysql://root:password@localhost/doctrine', 'Mysql'); 9 $this->driverName = 'Mysql'; 10 parent::init(); 11 Doctrine_Manager::connection('mysql://root:password@localhost/doctrine', 'Mysql'); 12 $this->prepareTables(); 13 $this->prepareData(); 14 } 15 16 public function run(DoctrineTest_Reporter $reporter = null, $filter = null) 17 { 18 parent::run($reporter, $filter); 19 $this->manager->closeConnection($this->connection); 20 } 21 22 public function prepareData() 23 { 24 } 25 26 public function prepareTables() 27 { 28 try { 29 $this->conn->exec('DROP TABLE ticket_1830__article_translation'); 30 } catch(Doctrine_Connection_Exception $e) { 31 } 32 $this->tables = array('Ticket_1830_Article'); 33 parent::prepareTables(); 34 } 35 36 public function testDuplicatedParamsInSubQuery() 37 { 38 $this->connection->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true); 39 40 $article = new Ticket_1830_Article(); 41 $article->Translation['en']->title = 'Node1'; 42 $article->save($this->connection); 43 $article = new Ticket_1830_Article(); 44 $article->Translation['en']->title = 'Node2'; 45 $article->save($this->connection); 46 $article = new Ticket_1830_Article(); 47 $article->Translation['en']->title = 'Node3'; 48 $article->save($this->connection); 49 $article = new Ticket_1830_Article(); 50 $article->Translation['en']->title = 'Node4'; 51 $article->save($this->connection); 52 $article = new Ticket_1830_Article(); 53 $article->Translation['en']->title = 'Node5'; 54 $article->save($this->connection); 55 56 try 57 { 58 $q = Doctrine_Core::getTable('Ticket_1830_Article') 59 ->createQuery('a') 60 ->select('a.*, t.*') 61 ->leftJoin('a.Translation t') 62 ->addWhere('a.id = ? OR a.id = ?', array(2, 3)) 63 ->orderBy('a.id DESC') 64 ->limit(1); 65 $results = $q->execute(); 66 $this->assertEqual(count($results), 1); 67 $this->assertEqual($results[0]->id, 3); 68 } 69 catch (Exception $e) 70 { 71 $this->fail($e->getMessage()); 72 } 73 74 $this->connection->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, false); 75 } 76} 77 78class Ticket_1830_Article extends Doctrine_Record 79{ 80 public function setTableDefinition() 81 { 82 $this->setTableName('ticket_1830_article'); 83 $this->hasColumn('title', 'string', 255, array('type' => 'string', 'length' => '255')); 84 85 $this->option('type', 'InnoDB'); 86 $this->option('collate', 'utf8_unicode_ci'); 87 $this->option('charset', 'utf8'); 88 } 89 90 public function setUp() 91 { 92 $i18n0 = new Doctrine_Template_I18n(array('fields' => array(0 => 'title'))); 93 $this->actAs($i18n0); 94 } 95}