test nested transactions
authorAlexander Stintzing <a.stintzing@metaways.de>
Fri, 30 May 2014 10:34:06 +0000 (12:34 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 30 May 2014 14:02:08 +0000 (16:02 +0200)
 - test: will inner transactions be rolled back if the outer fails?

Change-Id: Ibb526919e454455692e57eeadc29ac6352fea562
Reviewed-on: http://gerrit.tine20.com/customers/705
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Tinebase/TransactionManagerTest.php

index 7387b76..82f22de 100644 (file)
@@ -153,4 +153,32 @@ class Tinebase_TransactionManagerTest extends PHPUnit_Framework_TestCase
             $this->assertNotEquals($transactionId, $column['Column1'], 'RollBack failed, data was inserted anyway');
         }
     }
+    
+    /**
+     * tests if nested transactions will be rolled back, if the outer fails
+     */
+    public function testNestedTransactions()
+    {
+        $c1 = Sales_Controller_Contract::getInstance();
+        $c2 = Sales_Controller_CostCenter::getInstance();
+        $tm = Tinebase_TransactionManager::getInstance();
+        
+        $tm->startTransaction(Tinebase_Core::getDb());
+
+        try {
+            // create cost center
+            $costCenter = $c2->create(new Sales_Model_CostCenter(array('number' => 123, 'remark' => 'unittest123')));
+            
+            // exception should be thrown (title needed)
+            $c1->create(new Sales_Model_Contract(array()));
+            
+        } catch (Exception $e) {
+            $tm->rollBack();
+        }
+        
+        $this->setExpectedException('Tinebase_Exception_NotFound');
+        
+        // try to get the created cost center
+        $c2->get($costCenter->getId());
+    }
 }