3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviUnitTestCase.php';
30 * Class CRM_Extension_Manager_PaymentTest
32 class CRM_Extension_Manager_PaymentTest
extends CiviUnitTestCase
{
34 public function setUp() {
36 if (class_exists('test_extension_manager_paymenttest')) {
37 test_extension_manager_paymenttest
::$counts = array();
39 $this->system
= new CRM_Extension_System(array(
40 'extensionsDir' => '',
41 'extensionsURL' => '',
43 $this->quickCleanup(array('civicrm_payment_processor'));
46 public function tearDown() {
49 $this->quickCleanup(array('civicrm_payment_processor'));
50 CRM_Core_DAO
::executeQuery('DELETE FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
54 * Install an extension with a valid type name.
56 public function testInstallDisableUninstall() {
57 $manager = $this->system
->getManager();
58 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
59 $manager->install(array('test.extension.manager.paymenttest'));
60 $this->assertEquals(1, test_extension_manager_paymenttest
::$counts['install']);
61 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
63 $manager->disable(array('test.extension.manager.paymenttest'));
64 $this->assertEquals(1, test_extension_manager_paymenttest
::$counts['disable']);
65 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
66 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
68 $manager->uninstall(array('test.extension.manager.paymenttest'));
69 $this->assertEquals(1, test_extension_manager_paymenttest
::$counts['uninstall']);
70 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
74 * Install an extension with a valid type name.
76 public function testInstallDisableEnable() {
77 $manager = $this->system
->getManager();
78 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
80 $manager->install(array('test.extension.manager.paymenttest'));
81 $this->assertEquals(1, test_extension_manager_paymenttest
::$counts['install']);
82 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
84 $manager->disable(array('test.extension.manager.paymenttest'));
85 $this->assertEquals(1, test_extension_manager_paymenttest
::$counts['disable']);
86 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
87 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
89 $manager->enable(array('test.extension.manager.paymenttest'));
90 $this->assertEquals(1, test_extension_manager_paymenttest
::$counts['enable']);
91 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
92 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
96 * Install an extension and create a payment processor which uses it.
97 * Attempts to uninstall fail
99 public function testInstall_Add_FailUninstall() {
100 $manager = $this->system
->getManager();
101 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
103 $manager->install(array('test.extension.manager.paymenttest'));
104 $this->assertEquals(1, test_extension_manager_paymenttest
::$counts['install']);
105 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
106 $payment_processor_type_id = CRM_Core_DAO
::singleValueQuery('SELECT id FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
108 $ppDAO = CRM_Financial_BAO_PaymentProcessor
::create(array(
109 'payment_processor_type_id' => $payment_processor_type_id,
110 'domain_id' => CRM_Core_Config
::domainID(),
113 $manager->disable(array('test.extension.manager.paymenttest'));
114 $this->assertEquals(1, test_extension_manager_paymenttest
::$counts['disable']);
115 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
116 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
118 // first attempt to uninstall -- fail
120 $manager->uninstall(array('test.extension.manager.paymenttest'));
121 $this->fail('Failed to catch expected exception');
123 catch (CRM_Extension_Exception_DependencyException
$e) {
125 $this->assertEquals(0, test_extension_manager_paymenttest
::getCount('uninstall'));
126 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
130 // second attempt to uninstall -- ok
131 $manager->uninstall(array('test.extension.manager.paymenttest'));
132 $this->assertEquals(1, test_extension_manager_paymenttest
::getCount('uninstall'));
133 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');