tests/phpunit - Declare `@group headless`
[civicrm-core.git] / tests / phpunit / CRM / Pledge / BAO / PledgeTest.php
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
28 /**
29 * Test class for CRM_Pledge_BAO_Pledge BAO
30 *
31 * @package CiviCRM
32 * @group headless
33 */
34 class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase {
35
36 /**
37 * Sets up the fixture, for example, opens a network connection.
38 * This method is called before a test is executed.
39 */
40 protected function setUp() {
41 parent::setUp();
42 $this->_contactId = Contact::createIndividual();
43 }
44
45 /**
46 * Tears down the fixture, for example, closes a network connection.
47 * This method is called after a test is executed.
48 */
49 protected function tearDown() {
50 }
51
52 /**
53 * Test for Add/Update Pledge.
54 */
55 public function testAdd() {
56 $params = array(
57 'contact_id' => $this->_contactId,
58 'frequency_unit' => 'month',
59 'original_installment_amount' => 25.00,
60 'frequency_interval' => 1,
61 'frequency_day' => 1,
62 'installments' => 12,
63 'financial_type_id' => 1,
64 'create_date' => '20100513000000',
65 'acknowledge_date' => '20100513000000',
66 'start_date' => '20100513000000',
67 'status_id' => 2,
68 'currency' => 'USD',
69 'amount' => 300,
70 );
71
72 //do test for normal add.
73 $pledge = CRM_Pledge_BAO_Pledge::add($params);
74
75 foreach ($params as $param => $value) {
76 $this->assertEquals($value, $pledge->$param);
77 }
78 }
79
80 /**
81 * Retrieve a pledge based on a pledge id = 0
82 */
83 public function testRetrieveZeroPledeID() {
84 $defaults = array();
85 $params = array('pledge_id' => 0);
86 $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults);
87
88 $this->assertEquals(count($pledgeId), 0, "Pledge Id must be greater than 0");
89 }
90
91 /**
92 * Retrieve a payment based on a Null pledge id random string.
93 */
94 public function testRetrieveStringPledgeID() {
95 $defaults = array();
96 $params = array('pledge_id' => 'random text');
97 $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults);
98
99 $this->assertEquals(count($pledgeId), 0, "Pledge Id must be a string");
100 }
101
102 /**
103 * Test that payment retrieve wrks based on known pledge id.
104 */
105 public function testRetrieveKnownPledgeID() {
106 $params = array(
107 'contact_id' => $this->_contactId,
108 'frequency_unit' => 'month',
109 'frequency_interval' => 1,
110 'frequency_day' => 1,
111 'original_installment_amount' => 25.00,
112 'installments' => 12,
113 'financial_type_id' => 1,
114 'create_date' => '20100513000000',
115 'acknowledge_date' => '20100513000000',
116 'start_date' => '20100513000000',
117 'status_id' => 2,
118 'currency' => 'USD',
119 'amount' => 300,
120 );
121
122 $pledge = CRM_Pledge_BAO_Pledge::add($params);
123
124 $defaults = array();
125 $pledgeParams = array('pledge_id' => $pledge->id);
126
127 $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($pledgeParams, $defaults);
128
129 $this->assertEquals(count($pledgeId), 1, "Pledge was retrieved");
130 }
131
132 }