tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Contribute / Form / Contribution / MainTest.php
CommitLineData
8cb12ff1 1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
8cb12ff1 28/**
29 * Test APIv3 civicrm_contribute_* functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
33 */
34class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase {
35
36 /**
37 * Clean up DB.
38 */
39 public function tearDown() {
40 $this->quickCleanUpFinancialEntities();
41 }
42
43 /**
44 * Test that the membership is set to recurring if the membership type is always autorenew.
45 */
46 public function testSetRecurFunction() {
47 $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 2, 'minimum_fee' => 80));
48 $form = $this->getContributionForm();
49 $form->testSubmit(array(
50 'selectMembership' => $membershipTypeID,
51 ));
52 $this->assertEquals(1, $form->_params['is_recur']);
53 }
54
55 /**
56 * Test that the membership is set to recurring if the membership type is always autorenew.
57 */
58 public function testSetRecurFunctionOptionalYes() {
59 $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 1, 'minimum_fee' => 80));
60 $form = $this->getContributionForm();
61 $form->testSubmit(array(
62 'selectMembership' => $membershipTypeID,
63 'is_recur' => 1,
64 ));
65 $this->assertEquals(1, $form->_params['is_recur']);
66 }
67
68 /**
69 * Test that the membership is set to recurring if the membership type is always autorenew.
70 */
71 public function testSetRecurFunctionOptionalNo() {
72 $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 1, 'minimum_fee' => 80));
73 $form = $this->getContributionForm();
74 $form->testSubmit(array(
75 'selectMembership' => $membershipTypeID,
76 'is_recur' => 0,
77 ));
78 $this->assertEquals(0, $form->_params['is_recur']);
79 }
80
81 /**
82 * Test that the membership is set to recurring if the membership type is always autorenew.
83 */
84 public function testSetRecurFunctionNotAvailable() {
85 $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 0, 'minimum_fee' => 80));
86 $form = $this->getContributionForm();
87 $form->testSubmit(array(
88 'selectMembership' => $membershipTypeID,
89 ));
90 $this->assertArrayNotHasKey('is_recur', $form->_params);
91 }
92
93 /**
94 * Get a contribution form object for testing.
95 *
96 * @return \CRM_Contribute_Form_Contribution_Main
97 */
98 protected function getContributionForm() {
99 $form = new CRM_Contribute_Form_Contribution_Main();
100 $form->_values['is_monetary'] = 1;
101 $form->_values['is_pay_later'] = 0;
102 $form->_priceSetId = $this->callAPISuccessGetValue('PriceSet', array(
103 'name' => 'default_membership_type_amount',
104 'return' => 'id',
105 ));
106 $priceFields = $this->callAPISuccess('PriceField', 'get', array('id' => $form->_priceSetId));
107 $form->_priceSet['fields'] = $priceFields['values'];
108 $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy'));
109 $form->_paymentProcessor = array(
110 'billing_mode' => CRM_Core_Payment::BILLING_MODE_FORM,
111 'object' => Civi\Payment\System::singleton()->getById($paymentProcessorID),
112 'is_recur' => TRUE,
113 );
114 $form->_values = array(
115 'title' => "Test Contribution Page",
116 'financial_type_id' => 1,
117 'currency' => 'NZD',
118 'goal_amount' => 6000,
119 'is_pay_later' => 1,
120 'is_monetary' => TRUE,
121 'pay_later_text' => 'Front up',
122 'pay_later_receipt' => 'Ta',
123 );
124 return $form;
125 }
126
127}