Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / CampaignTest.php
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 * Class api_v3_CampaignTest
14 * @group headless
15 */
16 class api_v3_CampaignTest extends CiviUnitTestCase {
17 protected $params;
18 protected $id;
19
20 public $DBResetRequired = FALSE;
21
22 public function setUp() {
23 $this->params = [
24 'title' => "campaign title",
25 'description' => "Call people, ask for money",
26 'created_date' => 'first sat of July 2008',
27 ];
28 parent::setUp();
29 $this->useTransaction(TRUE);
30 }
31
32 /**
33 * @param int $version
34 * @dataProvider versionThreeAndFour
35 */
36 public function testCreateCampaign($version) {
37 $this->_apiversion = $version;
38 $description = "Create a campaign - Note use of relative dates here:
39 @link http://www.php.net/manual/en/datetime.formats.relative.php.";
40 $result = $this->callAPIAndDocument('campaign', 'create', $this->params, __FUNCTION__, __FILE__, $description);
41 $this->assertEquals(1, $result['count']);
42 $this->assertNotNull($result['values'][$result['id']]['id']);
43 $this->getAndCheck(array_merge($this->params, ['created_date' => '2008-07-05 00:00:00']), $result['id'], 'campaign', TRUE);
44 }
45
46 /**
47 * @param int $version
48 * @dataProvider versionThreeAndFour
49 */
50 public function testGetCampaign($version) {
51 $this->_apiversion = $version;
52 $result = $this->callAPISuccess('campaign', 'create', $this->params);
53 $result = $this->callAPIAndDocument('campaign', 'get', $this->params, __FUNCTION__, __FILE__);
54 $this->assertEquals(1, $result['count']);
55 $this->assertNotNull($result['values'][$result['id']]['id']);
56 }
57
58 /**
59 * @param int $version
60 * @dataProvider versionThreeAndFour
61 */
62 public function testDeleteCampaign($version) {
63 $this->_apiversion = $version;
64 $this->callAPISuccess('campaign', 'create', $this->params);
65 $entity = $this->callAPISuccess('campaign', 'get', ($this->params));
66 $delete = ['id' => $entity['id']];
67 $result = $this->callAPIAndDocument('campaign', 'delete', $delete, __FUNCTION__, __FILE__);
68
69 $checkDeleted = $this->callAPISuccess('campaign', 'get', []);
70 $this->assertEquals(0, $checkDeleted['count']);
71 }
72
73 }