Eileen has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/381162 )
Change subject: Add test for Exception Rollback
......................................................................
Add test for Exception Rollback
Bug: T171349
Change-Id: Ibd08450f1223c12b9e285da944fdfeb3cbd4683d
---
M sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php
1 file changed, 59 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/62/381162/1
diff --git a/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php
b/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php
index b01483c..d884430 100644
--- a/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php
+++ b/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php
@@ -111,6 +111,7 @@
}
function testExistsNone() {
+ civicrm_initialize();
$transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY ' .
mt_rand() );
$this->assertEquals( false, $transaction->exists() );
}
@@ -159,4 +160,62 @@
$transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY ' .
$gateway_txn_id );
$transaction->getContribution();
}
+
+ /**
+ * Test that when an exception is thrown without our wrapper no further
rollback happens.
+ *
+ * (this is really just the 'control' for the following test.
+ */
+ public function testNoRollBack() {
+ civicrm_initialize();
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET description =
'WMF'");
+
+ $this->callbackFunction(1);
+
+ $this->assertEquals('Cool planet',
CRM_Core_DAO::singleValueQuery('SELECT description FROM civicrm_domain LIMIT
1'));
+ $contact = $this->callAPISuccess('Contact', 'get',
array('external_identifier' => 'oh so strange'));
+ $this->assertEquals(1, $contact['count']);
+
+ // Cleanup
+ $this->callAPISuccess('Contact', 'delete', array('id' =>
$contact['id']));
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET description =
'WMF'");
+ }
+
+ /**
+ * Test that when an exception is thrown with our wrapper the whole lot
rolls back.
+ */
+ public function testFullRollBack() {
+ civicrm_initialize();
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET description =
'WMF'");
+
+ try {
+ WmfDatabase::transactionalCall(array($this, 'callbackFunction'),
array());
+ }
+ catch (RuntimeException $e) {
+ // We were expecting this :-)
+ }
+
+ $this->assertEquals('WMF', CRM_Core_DAO::singleValueQuery('SELECT
description FROM civicrm_domain LIMIT 1'));
+ $contact = $this->callAPISuccess('Contact', 'getcount',
array('external_identifier' => 'oh so strange'));
+ $this->assertEquals(0, $contact['count']);
+ }
+
+ public function callbackFunction() {
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET description =
'Cool planet'");
+ $contact = array(
+ 'contact_type' => 'Individual',
+ 'first_name' => 'Dr',
+ 'last_name' => 'Strange',
+ 'external_identifier' => 'oh so strange',
+ );
+ $this->callAPISuccess('Contact', 'create', $contact);
+ try {
+ civicrm_api3('Contact', 'create', $contact);
+ }
+ catch (Exception $e) {
+ // We have done nothing to roll back.
+ return;
+ }
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/381162
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd08450f1223c12b9e285da944fdfeb3cbd4683d
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits