Merge pull request #14974 from civicrm/5.16
[civicrm-core.git] / tests / phpunit / api / v3 / CampaignTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 * Class api_v3_CampaignTest
30 * @group headless
31 */
32 class api_v3_CampaignTest extends CiviUnitTestCase {
33 protected $params;
34 protected $id;
35
36 public $DBResetRequired = FALSE;
37
38 public function setUp() {
39 $this->params = [
40 'title' => "campaign title",
41 'description' => "Call people, ask for money",
42 'created_date' => 'first sat of July 2008',
43 ];
44 parent::setUp();
45 $this->useTransaction(TRUE);
46 }
47
48 /**
49 * @param int $version
50 * @dataProvider versionThreeAndFour
51 */
52 public function testCreateCampaign($version) {
53 $this->_apiversion = $version;
54 $description = "Create a campaign - Note use of relative dates here:
55 @link http://www.php.net/manual/en/datetime.formats.relative.php.";
56 $result = $this->callAPIAndDocument('campaign', 'create', $this->params, __FUNCTION__, __FILE__, $description);
57 $this->assertEquals(1, $result['count']);
58 $this->assertNotNull($result['values'][$result['id']]['id']);
59 $this->getAndCheck(array_merge($this->params, ['created_date' => '2008-07-05 00:00:00']), $result['id'], 'campaign', TRUE);
60 }
61
62 /**
63 * @param int $version
64 * @dataProvider versionThreeAndFour
65 */
66 public function testGetCampaign($version) {
67 $this->_apiversion = $version;
68 $result = $this->callAPISuccess('campaign', 'create', $this->params);
69 $result = $this->callAPIAndDocument('campaign', 'get', $this->params, __FUNCTION__, __FILE__);
70 $this->assertEquals(1, $result['count']);
71 $this->assertNotNull($result['values'][$result['id']]['id']);
72 }
73
74 /**
75 * @param int $version
76 * @dataProvider versionThreeAndFour
77 */
78 public function testDeleteCampaign($version) {
79 $this->_apiversion = $version;
80 $this->callAPISuccess('campaign', 'create', $this->params);
81 $entity = $this->callAPISuccess('campaign', 'get', ($this->params));
82 $delete = ['id' => $entity['id']];
83 $result = $this->callAPIAndDocument('campaign', 'delete', $delete, __FUNCTION__, __FILE__);
84
85 $checkDeleted = $this->callAPISuccess('campaign', 'get', []);
86 $this->assertEquals(0, $checkDeleted['count']);
87 }
88
89 }