Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
b6708aeb | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
b6708aeb | 7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
6a488035 TO |
27 | require_once 'CiviTest/CiviUnitTestCase.php'; |
28 | ||
e9479dcf EM |
29 | /** |
30 | * Class CRM_Extension_Manager_PaymentTest | |
31 | */ | |
6a488035 | 32 | class CRM_Extension_Manager_PaymentTest extends CiviUnitTestCase { |
92915c55 | 33 | |
00be9182 | 34 | public function setUp() { |
6a488035 TO |
35 | parent::setUp(); |
36 | if (class_exists('test_extension_manager_paymenttest')) { | |
37 | test_extension_manager_paymenttest::$counts = array(); | |
38 | } | |
39 | $this->system = new CRM_Extension_System(array( | |
40 | 'extensionsDir' => '', | |
41 | 'extensionsURL' => '', | |
42 | )); | |
43 | $this->quickCleanup(array('civicrm_payment_processor')); | |
44 | } | |
45 | ||
00be9182 | 46 | public function tearDown() { |
6a488035 TO |
47 | parent::tearDown(); |
48 | $this->system = NULL; | |
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"'); | |
51 | } | |
52 | ||
53 | /** | |
eceb18cc | 54 | * Install an extension with a valid type name. |
6a488035 | 55 | */ |
00be9182 | 56 | public function testInstallDisableUninstall() { |
6a488035 TO |
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'); | |
62 | ||
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'); | |
67 | ||
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"'); | |
71 | } | |
72 | ||
73 | /** | |
eceb18cc | 74 | * Install an extension with a valid type name. |
6a488035 | 75 | */ |
00be9182 | 76 | public function testInstallDisableEnable() { |
6a488035 TO |
77 | $manager = $this->system->getManager(); |
78 | $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); | |
b6708aeb | 79 | |
6a488035 TO |
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'); | |
83 | ||
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'); | |
88 | ||
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'); | |
93 | } | |
92915c55 | 94 | |
6a488035 TO |
95 | /** |
96 | * Install an extension and create a payment processor which uses it. | |
97 | * Attempts to uninstall fail | |
98 | */ | |
00be9182 | 99 | public function testInstall_Add_FailUninstall() { |
6a488035 TO |
100 | $manager = $this->system->getManager(); |
101 | $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); | |
102 | ||
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"'); | |
107 | ||
108 | $ppDAO = CRM_Financial_BAO_PaymentProcessor::create(array( | |
109 | 'payment_processor_type_id' => $payment_processor_type_id, | |
110 | 'domain_id' => CRM_Core_Config::domainID(), | |
111 | )); | |
112 | ||
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'); | |
117 | ||
118 | // first attempt to uninstall -- fail | |
119 | try { | |
120 | $manager->uninstall(array('test.extension.manager.paymenttest')); | |
121 | $this->fail('Failed to catch expected exception'); | |
0db6c3e1 TO |
122 | } |
123 | catch (CRM_Extension_Exception_DependencyException $e) { | |
6a488035 | 124 | } |
6b812400 | 125 | $this->assertEquals(0, test_extension_manager_paymenttest::getCount('uninstall')); |
6a488035 TO |
126 | $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); |
127 | ||
128 | $ppDAO->delete(); | |
129 | ||
130 | // second attempt to uninstall -- ok | |
131 | $manager->uninstall(array('test.extension.manager.paymenttest')); | |
6b812400 | 132 | $this->assertEquals(1, test_extension_manager_paymenttest::getCount('uninstall')); |
6a488035 TO |
133 | $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"'); |
134 | } | |
96025800 | 135 | |
6a488035 | 136 | } |