aedb9de5 |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
4 | | Copyright CiviCRM LLC. All rights reserved. | |
5 | | | |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | |
8 | | and copyright information, see https://civicrm.org/licensing | |
9 | +--------------------------------------------------------------------+ |
10 | */ |
11 | |
12 | /** |
13 | * @group headless |
14 | */ |
15 | class CRM_Contribute_Form_ContributionViewTest extends CiviUnitTestCase { |
16 | |
17 | /** |
18 | * Test that can still view a contribution without full permissions. |
19 | */ |
20 | public function testContributionViewLimitedPermissions() { |
21 | CRM_Core_Config::singleton()->userPermissionClass->permissions = [ |
22 | 'access CiviCRM', |
23 | 'access all custom data', |
24 | 'edit all contacts', |
25 | 'access CiviContribute', |
26 | 'edit contributions', |
27 | 'delete in CiviContribute', |
28 | ]; |
29 | $contact_id = $this->individualCreate(); |
30 | $contribution = $this->callAPISuccess('Contribution', 'create', [ |
31 | 'contact_id' => $contact_id, |
32 | 'financial_type_id' => 'Donation', |
33 | 'total_amount' => '10', |
34 | ]); |
35 | |
36 | $_SERVER['REQUEST_URI'] = "civicrm/contact/view/contribution?reset=1&action=view&id={$contribution['id']}&cid={$contact_id}"; |
37 | $_GET['q'] = $_REQUEST['q'] = 'civicrm/contact/view/contribution'; |
38 | $_GET['reset'] = $_REQUEST['reset'] = 1; |
39 | $_GET['action'] = $_REQUEST['action'] = 'view'; |
40 | $_GET['id'] = $_REQUEST['id'] = $contribution['id']; |
41 | $_GET['cid'] = $_REQUEST['cid'] = $contact_id; |
42 | |
43 | $item = CRM_Core_Invoke::getItem(['civicrm/contact/view/contribution']); |
44 | ob_start(); |
45 | CRM_Core_Invoke::runItem($item); |
46 | $contents = ob_get_clean(); |
47 | |
48 | unset($_GET['q'], $_REQUEST['q']); |
49 | unset($_GET['reset'], $_REQUEST['reset']); |
50 | unset($_GET['action'], $_REQUEST['action']); |
51 | unset($_GET['id'], $_REQUEST['id']); |
52 | unset($_GET['cid'], $_REQUEST['cid']); |
53 | |
54 | $this->assertRegExp('/Contribution Total:\s+\$10\.00/', $contents); |
55 | $this->assertStringContainsString('Mr. Anthony Anderson II', $contents); |
56 | } |
57 | |
58 | } |