3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class api_v3_MailSettingsTest
33 class api_v3_MailSettingsTest
extends CiviUnitTestCase
{
35 protected $_apiversion = 3;
41 public $DBResetRequired = FALSE;
43 public function setUp() {
46 'name' => "my mail setting",
47 'domain' => 'setting.com',
48 'localpart' => 'civicrm+',
49 'server' => "localhost",
55 $this->useTransaction(TRUE);
63 * @dataProvider versionThreeAndFour
65 public function testCreateMailSettings($version) {
66 $this->_apiversion
= $version;
67 $this->callAPISuccessGetCount('mail_settings', [], 1);
68 $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params
, __FUNCTION__
, __FILE__
);
69 $this->assertEquals(1, $result['count']);
70 $this->assertNotNull($result['values'][$result['id']]['id']);
71 $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]);
72 $this->callAPISuccessGetCount('mail_settings', [], 1);
76 * Test caches cleared adequately.
80 * @dataProvider versionThreeAndFour
82 public function testCreateUpdateMailSettings($version) {
83 $this->_apiversion
= $version;
84 $result = $this->callAPISuccess('MailSettings', 'create', $this->params
);
85 $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings
::defaultDomain());
86 $this->callAPISuccess('mail_settings', 'create', ['id' => $result['id'], 'domain' => 'updated.com']);
87 $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings
::defaultDomain());
88 $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]);
89 $this->callAPISuccessGetCount('mail_settings', [], 1);
97 * @dataProvider versionThreeAndFour
99 public function testGetMailSettings($version) {
100 $this->_apiversion
= $version;
101 $this->callAPIAndDocument('MailSettings', 'create', $this->params
, __FUNCTION__
, __FILE__
);
102 $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params
, __FUNCTION__
, __FILE__
);
103 $this->assertEquals(1, $result['count']);
104 $this->assertNotNull($result['values'][$result['id']]['id']);
105 $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]);
106 $this->callAPISuccessGetCount('mail_settings', [], 1);
110 * @param int $version
112 * @dataProvider versionThreeAndFour
114 public function testDeleteMailSettings($version) {
115 $this->_apiversion
= $version;
116 $this->callAPIAndDocument('MailSettings', 'create', $this->params
, __FUNCTION__
, __FILE__
);
117 $entity = $this->callAPISuccess('MailSettings', 'get', $this->params
);
118 $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']);
119 $this->callAPIAndDocument('MailSettings', 'delete', ['id' => $entity['id']], __FUNCTION__
, __FILE__
);
120 $checkDeleted = $this->callAPISuccess('MailSettings', 'get', []);
121 $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']);
125 * Test chained delete.
127 * @param int $version
129 * @dataProvider versionThreeAndFour
131 public function testGetMailSettingsChainDelete($version) {
132 $this->_apiversion
= $version;
133 $description = "Demonstrates get + delete in the same call.";
134 $subFile = 'ChainedGetDelete';
136 'name' => "delete this setting",
137 'api.MailSettings.delete' => 1,
139 $this->callAPISuccess('MailSettings', 'create', ['name' => "delete this setting"] +
$this->params
);
140 $result = $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subFile);
141 $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', ['name' => "delete this setting"]));