Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | /** |
29 | * Test APIv3 civicrm_survey_* functions | |
30 | * | |
92915c55 TO |
31 | * @package CiviCRM_APIv3 |
32 | * @subpackage API_Campaign | |
6a488035 TO |
33 | */ |
34 | ||
fbda92d3 | 35 | /** |
36 | * All API should contain at minimum a success test for each | |
37 | * function - in this case - create, get & delete | |
38 | * In addition any extra functionality should be tested & documented | |
39 | * | |
40 | * Failure tests should be added for specific api behaviours but note that | |
41 | * many generic patterns are tested in the syntax conformance test | |
42 | * | |
43 | * @author eileen | |
44 | * | |
acb109b7 | 45 | * @group headless |
fbda92d3 | 46 | */ |
6a488035 | 47 | class api_v3_SurveyTest extends CiviUnitTestCase { |
6a488035 | 48 | protected $params; |
fbda92d3 | 49 | protected $entity = 'survey'; |
430ae6dd | 50 | public $DBResetRequired = FALSE; |
b7c9bc4c | 51 | |
430ae6dd | 52 | |
00be9182 | 53 | public function setUp() { |
92915c55 TO |
54 | $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', array( |
55 | 'label' => 'PhoneBank', | |
acb1052e | 56 | 'return' => 'value', |
92915c55 | 57 | ), 'integer'); |
0c250cae | 58 | $this->useTransaction(); |
9ce17194 | 59 | $this->enableCiviCampaign(); |
6a488035 | 60 | $this->params = array( |
6a488035 TO |
61 | 'title' => "survey title", |
62 | 'activity_type_id' => $phoneBankActivityTypeID, | |
63 | 'max_number_of_contacts' => 12, | |
64 | 'instructions' => "Call people, ask for money", | |
65 | ); | |
66 | parent::setUp(); | |
67 | } | |
68 | ||
fbda92d3 | 69 | /** |
eceb18cc | 70 | * Test create function succeeds. |
fbda92d3 | 71 | */ |
6a488035 | 72 | public function testCreateSurvey() { |
fbda92d3 | 73 | $result = $this->callAPIAndDocument('survey', 'create', $this->params, __FUNCTION__, __FILE__); |
74 | $this->getAndCheck($this->params, $result['id'], $this->entity); | |
6a488035 TO |
75 | } |
76 | ||
fbda92d3 | 77 | /** |
fe482240 EM |
78 | * Test get function succeeds. |
79 | * | |
80 | * This is actually largely tested in the get | |
fbda92d3 | 81 | * action on create. Add extra checks for any 'special' return values or |
82 | * behaviours | |
fbda92d3 | 83 | */ |
6a488035 | 84 | public function testGetSurvey() { |
fbda92d3 | 85 | $this->createTestEntity(); |
86 | $result = $this->callAPIAndDocument('survey', 'get', $this->params, __FUNCTION__, __FILE__); | |
ba4a1892 TM |
87 | $this->assertEquals(1, $result['count']); |
88 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
89 | } |
90 | ||
6c6e6187 | 91 | /** |
eceb18cc | 92 | * Check the delete function succeeds. |
6c6e6187 | 93 | */ |
6a488035 | 94 | public function testDeleteSurvey() { |
fbda92d3 | 95 | $entity = $this->createTestEntity(); |
96 | $result = $this->callAPIAndDocument('survey', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); | |
6c6e6187 | 97 | $checkDeleted = $this->callAPISuccess($this->entity, 'get', array()); |
ba4a1892 | 98 | $this->assertEquals(0, $checkDeleted['count']); |
6a488035 TO |
99 | } |
100 | ||
fbda92d3 | 101 | /** |
fe482240 EM |
102 | * Test & document chained delete pattern. |
103 | * | |
104 | * Note that explanation of the pattern | |
fbda92d3 | 105 | * is best put in the $description variable as it will then be displayed in the |
fe482240 | 106 | * test generated examples. (these are to be found in the api/examples folder). |
fbda92d3 | 107 | */ |
6a488035 | 108 | public function testGetSurveyChainDelete() { |
5c49fee0 | 109 | $description = "Demonstrates get + delete in the same call."; |
92915c55 TO |
110 | $subfile = 'ChainedGetDelete'; |
111 | $params = array( | |
6a488035 TO |
112 | 'title' => "survey title", |
113 | 'api.survey.delete' => 1, | |
114 | ); | |
fbda92d3 | 115 | $result = $this->callAPISuccess('survey', 'create', $this->params); |
116 | $result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); | |
ba4a1892 | 117 | $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', array())); |
6a488035 | 118 | } |
fbda92d3 | 119 | |
6a488035 | 120 | } |