tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Extension / Manager / PaymentTest.php
CommitLineData
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 27
e9479dcf
EM
28/**
29 * Class CRM_Extension_Manager_PaymentTest
30 */
6a488035 31class CRM_Extension_Manager_PaymentTest extends CiviUnitTestCase {
92915c55 32
00be9182 33 public function setUp() {
6a488035
TO
34 parent::setUp();
35 if (class_exists('test_extension_manager_paymenttest')) {
36 test_extension_manager_paymenttest::$counts = array();
37 }
38 $this->system = new CRM_Extension_System(array(
39 'extensionsDir' => '',
40 'extensionsURL' => '',
41 ));
42 $this->quickCleanup(array('civicrm_payment_processor'));
43 }
44
00be9182 45 public function tearDown() {
6a488035
TO
46 parent::tearDown();
47 $this->system = NULL;
48 $this->quickCleanup(array('civicrm_payment_processor'));
49 CRM_Core_DAO::executeQuery('DELETE FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
50 }
51
52 /**
eceb18cc 53 * Install an extension with a valid type name.
6a488035 54 */
00be9182 55 public function testInstallDisableUninstall() {
6a488035
TO
56 $manager = $this->system->getManager();
57 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
58 $manager->install(array('test.extension.manager.paymenttest'));
59 $this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']);
60 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
61
62 $manager->disable(array('test.extension.manager.paymenttest'));
63 $this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']);
64 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
65 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
66
67 $manager->uninstall(array('test.extension.manager.paymenttest'));
68 $this->assertEquals(1, test_extension_manager_paymenttest::$counts['uninstall']);
69 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
70 }
71
72 /**
eceb18cc 73 * Install an extension with a valid type name.
6a488035 74 */
00be9182 75 public function testInstallDisableEnable() {
6a488035
TO
76 $manager = $this->system->getManager();
77 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
b6708aeb 78
6a488035
TO
79 $manager->install(array('test.extension.manager.paymenttest'));
80 $this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']);
81 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
82
83 $manager->disable(array('test.extension.manager.paymenttest'));
84 $this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']);
85 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
86 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
87
88 $manager->enable(array('test.extension.manager.paymenttest'));
89 $this->assertEquals(1, test_extension_manager_paymenttest::$counts['enable']);
90 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
91 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
92 }
92915c55 93
6a488035
TO
94 /**
95 * Install an extension and create a payment processor which uses it.
96 * Attempts to uninstall fail
97 */
00be9182 98 public function testInstall_Add_FailUninstall() {
6a488035
TO
99 $manager = $this->system->getManager();
100 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
101
102 $manager->install(array('test.extension.manager.paymenttest'));
103 $this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']);
104 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
105 $payment_processor_type_id = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
106
107 $ppDAO = CRM_Financial_BAO_PaymentProcessor::create(array(
108 'payment_processor_type_id' => $payment_processor_type_id,
109 'domain_id' => CRM_Core_Config::domainID(),
110 ));
111
112 $manager->disable(array('test.extension.manager.paymenttest'));
113 $this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']);
114 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
115 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
116
117 // first attempt to uninstall -- fail
118 try {
119 $manager->uninstall(array('test.extension.manager.paymenttest'));
120 $this->fail('Failed to catch expected exception');
0db6c3e1
TO
121 }
122 catch (CRM_Extension_Exception_DependencyException $e) {
6a488035 123 }
6b812400 124 $this->assertEquals(0, test_extension_manager_paymenttest::getCount('uninstall'));
6a488035
TO
125 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
126
127 $ppDAO->delete();
128
129 // second attempt to uninstall -- ok
130 $manager->uninstall(array('test.extension.manager.paymenttest'));
6b812400 131 $this->assertEquals(1, test_extension_manager_paymenttest::getCount('uninstall'));
6a488035
TO
132 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
133 }
96025800 134
6a488035 135}