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_MailSettingsTest | |
f78dbf0b | 14 | * |
acb109b7 | 15 | * @group headless |
e9479dcf | 16 | */ |
6a488035 | 17 | class api_v3_MailSettingsTest extends CiviUnitTestCase { |
f78dbf0b | 18 | |
50debe3c | 19 | protected $_apiversion = 3; |
f78dbf0b | 20 | |
6a488035 | 21 | protected $params; |
f78dbf0b | 22 | |
6a488035 | 23 | protected $id; |
f78dbf0b | 24 | |
430ae6dd TO |
25 | public $DBResetRequired = FALSE; |
26 | ||
00be9182 | 27 | public function setUp() { |
f78dbf0b | 28 | $this->params = [ |
6a488035 TO |
29 | 'domain_id' => 1, |
30 | 'name' => "my mail setting", | |
31 | 'domain' => 'setting.com', | |
2d932085 | 32 | 'localpart' => 'civicrm+', |
6a488035 TO |
33 | 'server' => "localhost", |
34 | 'username' => 'sue', | |
35 | 'password' => 'pass', | |
694d926e | 36 | 'is_default' => 1, |
f78dbf0b | 37 | ]; |
6a488035 | 38 | parent::setUp(); |
943e3538 | 39 | $this->useTransaction(TRUE); |
6a488035 TO |
40 | } |
41 | ||
694d926e | 42 | /** |
eceb18cc | 43 | * Test creation. |
f78dbf0b | 44 | * |
2d932085 | 45 | * @param int $version |
f78dbf0b | 46 | * |
2d932085 | 47 | * @dataProvider versionThreeAndFour |
694d926e | 48 | */ |
2d932085 CW |
49 | public function testCreateMailSettings($version) { |
50 | $this->_apiversion = $version; | |
f78dbf0b | 51 | $this->callAPISuccessGetCount('mail_settings', [], 1); |
50debe3c | 52 | $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__); |
694d926e EM |
53 | $this->assertEquals(1, $result['count']); |
54 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
f78dbf0b | 55 | $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]); |
56 | $this->callAPISuccessGetCount('mail_settings', [], 1); | |
6a488035 TO |
57 | } |
58 | ||
694d926e | 59 | /** |
eceb18cc | 60 | * Test caches cleared adequately. |
f78dbf0b | 61 | * |
2d932085 | 62 | * @param int $version |
f78dbf0b | 63 | * |
2d932085 | 64 | * @dataProvider versionThreeAndFour |
694d926e | 65 | */ |
2d932085 CW |
66 | public function testCreateUpdateMailSettings($version) { |
67 | $this->_apiversion = $version; | |
694d926e EM |
68 | $result = $this->callAPISuccess('MailSettings', 'create', $this->params); |
69 | $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings::defaultDomain()); | |
f78dbf0b | 70 | $this->callAPISuccess('mail_settings', 'create', ['id' => $result['id'], 'domain' => 'updated.com']); |
694d926e | 71 | $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings::defaultDomain()); |
f78dbf0b | 72 | $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]); |
73 | $this->callAPISuccessGetCount('mail_settings', [], 1); | |
694d926e | 74 | } |
6a488035 | 75 | |
694d926e | 76 | /** |
eceb18cc | 77 | * Test get method. |
f78dbf0b | 78 | * |
2d932085 | 79 | * @param int $version |
f78dbf0b | 80 | * |
2d932085 | 81 | * @dataProvider versionThreeAndFour |
694d926e | 82 | */ |
2d932085 CW |
83 | public function testGetMailSettings($version) { |
84 | $this->_apiversion = $version; | |
694d926e | 85 | $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__); |
50debe3c | 86 | $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params, __FUNCTION__, __FILE__); |
694d926e EM |
87 | $this->assertEquals(1, $result['count']); |
88 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
f78dbf0b | 89 | $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]); |
90 | $this->callAPISuccessGetCount('mail_settings', [], 1); | |
6a488035 TO |
91 | } |
92 | ||
2d932085 CW |
93 | /** |
94 | * @param int $version | |
f78dbf0b | 95 | * |
2d932085 CW |
96 | * @dataProvider versionThreeAndFour |
97 | */ | |
98 | public function testDeleteMailSettings($version) { | |
99 | $this->_apiversion = $version; | |
694d926e | 100 | $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__); |
50debe3c | 101 | $entity = $this->callAPISuccess('MailSettings', 'get', $this->params); |
694d926e | 102 | $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']); |
f78dbf0b | 103 | $this->callAPIAndDocument('MailSettings', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__); |
104 | $checkDeleted = $this->callAPISuccess('MailSettings', 'get', []); | |
694d926e | 105 | $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']); |
6a488035 TO |
106 | } |
107 | ||
694d926e | 108 | /** |
eceb18cc | 109 | * Test chained delete. |
f78dbf0b | 110 | * |
2d932085 | 111 | * @param int $version |
f78dbf0b | 112 | * |
2d932085 | 113 | * @dataProvider versionThreeAndFour |
694d926e | 114 | */ |
2d932085 CW |
115 | public function testGetMailSettingsChainDelete($version) { |
116 | $this->_apiversion = $version; | |
5c49fee0 | 117 | $description = "Demonstrates get + delete in the same call."; |
92915c55 | 118 | $subFile = 'ChainedGetDelete'; |
f78dbf0b | 119 | $params = [ |
2d932085 | 120 | 'name' => "delete this setting", |
6a488035 | 121 | 'api.MailSettings.delete' => 1, |
f78dbf0b | 122 | ]; |
2d932085 CW |
123 | $this->callAPISuccess('MailSettings', 'create', ['name' => "delete this setting"] + $this->params); |
124 | $result = $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile); | |
125 | $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', ['name' => "delete this setting"])); | |
6a488035 | 126 | } |
96025800 | 127 | |
6a488035 | 128 | } |