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_1296_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_1296_TestCase extends Doctrine_UnitTestCase 33{ 34 public function prepareData() { 35 $org = new NewTicket_Organization(); 36 $org->name = 'Inc.'; 37 $org->save(); 38 } 39 40 public function prepareTables() 41 { 42 $this->tables = array( 43 'NewTicket_Organization', 44 'NewTicket_Role' 45 ); 46 parent::prepareTables(); 47 } 48 49 public function testAddDuplicateOrganisation () 50 { 51 $this->assertEqual(0, $this->conn->transaction->getTransactionLevel()); 52 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 53 try { 54 $this->conn->beginTransaction(); 55 } catch (Exception $e) { 56 $this->fail("Transaction failed to start."); 57 } 58 59 $this->assertEqual(1, $this->conn->transaction->getTransactionLevel()); 60 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 61 62 $org = new NewTicket_Organization(); 63 $org->name = 'Inc.'; 64 try { 65 $org->save(); 66 $this->fail("Unique violation not reported."); 67 } catch (Exception $e) { 68 $this->assertEqual(1, $this->conn->transaction->getTransactionLevel()); 69 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 70 $this->conn->rollback(); 71 } 72 73 $this->assertEqual(0, $this->conn->transaction->getTransactionLevel()); 74 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 75 76 try { 77 $this->assertEqual(0, $this->conn->transaction->getTransactionLevel()); 78 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 79 $this->conn->commit(); 80 $this->fail(); 81 } catch (Exception $e) { 82 // Commit failed, there is no active transaction! 83 $this->pass(); 84 } 85 $this->assertEqual(0, $this->conn->transaction->getTransactionLevel()); 86 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 87 } 88 89 public function testAddRole () 90 { 91 $this->assertEqual(0, $this->conn->transaction->getTransactionLevel()); 92 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 93 94 try { 95 $this->conn->beginTransaction(); 96 } catch (Exception $e) { 97 $this->fail("Transaction failed to start."); 98 } 99 100 $this->assertEqual(1, $this->conn->transaction->getTransactionLevel()); 101 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 102 103 $r = new NewTicket_Role(); 104 $r->name = 'foo'; 105 try { 106 $r->save(); 107 $this->assertEqual(1, $this->conn->transaction->getTransactionLevel()); 108 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 109 $this->assertTrue(is_numeric($r->id)); 110 } catch (Exception $e) { 111 $this->fail(); 112 $this->conn->rollback(); 113 } 114 try { 115 $this->assertEqual(1, $this->conn->transaction->getTransactionLevel()); 116 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 117 $this->conn->commit(); 118 $this->assertEqual(0, $this->conn->transaction->getTransactionLevel()); 119 $this->assertEqual(0, $this->conn->transaction->getInternalTransactionLevel()); 120 } catch (Exception $e) { 121 $this->fail(); 122 $this->conn->rollback(); 123 } 124 } 125} 126 127class NewTicket_Organization extends Doctrine_Record { 128 public function setTableDefinition() { 129 $this->hasColumn('id', 'integer', 4, array( 130 'autoincrement' => true, 131 'notnull' => true, 132 'primary' => true 133 )); 134 $this->hasColumn('name', 'string', 255, array( 135 'notnull' => true, 136 'unique' => true 137 )); 138 } 139} 140 141class NewTicket_Role extends Doctrine_Record { 142 public function setTableDefinition() { 143 $this->hasColumn('id', 'integer', 4, array( 144 'autoincrement' => true, 145 'notnull' => true, 146 'primary' => true 147 )); 148 $this->hasColumn('name', 'string', 30, array( 149 'notnull' => true, 150 'unique' => true 151 )); 152 } 153} 154 155class NewTicket_User { 156 public function addOrganization ($name) 157 { 158 159 } 160} 161 162