Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
7d61e75f TO |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 10 | */ |
6a488035 | 11 | |
e9479dcf EM |
12 | /** |
13 | * Class api_v3_CampaignTest | |
acb109b7 | 14 | * @group headless |
e9479dcf | 15 | */ |
6a488035 | 16 | class api_v3_CampaignTest extends CiviUnitTestCase { |
6a488035 TO |
17 | protected $params; |
18 | protected $id; | |
b7c9bc4c | 19 | |
430ae6dd TO |
20 | public $DBResetRequired = FALSE; |
21 | ||
00be9182 | 22 | public function setUp() { |
9099cab3 | 23 | $this->params = [ |
6a488035 TO |
24 | 'title' => "campaign title", |
25 | 'description' => "Call people, ask for money", | |
26 | 'created_date' => 'first sat of July 2008', | |
9099cab3 | 27 | ]; |
6a488035 | 28 | parent::setUp(); |
3b8d698e | 29 | $this->useTransaction(TRUE); |
6a488035 TO |
30 | } |
31 | ||
2d932085 CW |
32 | /** |
33 | * @param int $version | |
34 | * @dataProvider versionThreeAndFour | |
35 | */ | |
36 | public function testCreateCampaign($version) { | |
37 | $this->_apiversion = $version; | |
5c49fee0 CW |
38 | $description = "Create a campaign - Note use of relative dates here: |
39 | @link http://www.php.net/manual/en/datetime.formats.relative.php."; | |
4e420887 | 40 | $result = $this->callAPIAndDocument('campaign', 'create', $this->params, __FUNCTION__, __FILE__, $description); |
ba4a1892 TM |
41 | $this->assertEquals(1, $result['count']); |
42 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
9099cab3 | 43 | $this->getAndCheck(array_merge($this->params, ['created_date' => '2008-07-05 00:00:00']), $result['id'], 'campaign', TRUE); |
6a488035 TO |
44 | } |
45 | ||
2d932085 CW |
46 | /** |
47 | * @param int $version | |
48 | * @dataProvider versionThreeAndFour | |
49 | */ | |
50 | public function testGetCampaign($version) { | |
51 | $this->_apiversion = $version; | |
4e420887 | 52 | $result = $this->callAPISuccess('campaign', 'create', $this->params); |
53 | $result = $this->callAPIAndDocument('campaign', 'get', $this->params, __FUNCTION__, __FILE__); | |
ba4a1892 TM |
54 | $this->assertEquals(1, $result['count']); |
55 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
56 | } |
57 | ||
2d932085 CW |
58 | /** |
59 | * @param int $version | |
60 | * @dataProvider versionThreeAndFour | |
61 | */ | |
62 | public function testDeleteCampaign($version) { | |
63 | $this->_apiversion = $version; | |
3b8d698e | 64 | $this->callAPISuccess('campaign', 'create', $this->params); |
4e420887 | 65 | $entity = $this->callAPISuccess('campaign', 'get', ($this->params)); |
9099cab3 | 66 | $delete = ['id' => $entity['id']]; |
4e420887 | 67 | $result = $this->callAPIAndDocument('campaign', 'delete', $delete, __FUNCTION__, __FILE__); |
6a488035 | 68 | |
9099cab3 | 69 | $checkDeleted = $this->callAPISuccess('campaign', 'get', []); |
ba4a1892 | 70 | $this->assertEquals(0, $checkDeleted['count']); |
6a488035 | 71 | } |
96025800 | 72 | |
6a488035 | 73 | } |