3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Class api_v3_MailSettingsTest
33 class api_v3_MailSettingsTest
extends CiviUnitTestCase
{
34 protected $_apiversion = 3;
37 public $DBResetRequired = FALSE;
39 public function setUp() {
40 $this->params
= array(
42 'name' => "my mail setting",
43 'domain' => 'setting.com',
44 'local_part' => 'civicrm+',
45 'server' => "localhost",
51 $this->useTransaction(TRUE);
57 public function testCreateMailSettings() {
58 $this->callAPISuccessGetCount('mail_settings', array(), 1);
59 $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params
, __FUNCTION__
, __FILE__
);
60 $this->assertEquals(1, $result['count']);
61 $this->assertNotNull($result['values'][$result['id']]['id']);
62 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
63 $this->callAPISuccessGetCount('mail_settings', array(), 1);
67 * Test caches cleared adequately.
69 public function testCreateUpdateMailSettings() {
70 $result = $this->callAPISuccess('MailSettings', 'create', $this->params
);
71 $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings
::defaultDomain());
72 $this->callAPISuccess('mail_settings', 'create', array('id' => $result['id'], 'domain' => 'updated.com'));
73 $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings
::defaultDomain());
74 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
75 $this->callAPISuccessGetCount('mail_settings', array(), 1);
81 public function testGetMailSettings() {
82 $this->callAPIAndDocument('MailSettings', 'create', $this->params
, __FUNCTION__
, __FILE__
);
83 $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params
, __FUNCTION__
, __FILE__
);
84 $this->assertEquals(1, $result['count']);
85 $this->assertNotNull($result['values'][$result['id']]['id']);
86 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
87 $this->callAPISuccessGetCount('mail_settings', array(), 1);
90 public function testDeleteMailSettings() {
91 $this->callAPIAndDocument('MailSettings', 'create', $this->params
, __FUNCTION__
, __FILE__
);
92 $entity = $this->callAPISuccess('MailSettings', 'get', $this->params
);
93 $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']);
94 $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__
, __FILE__
);
95 $checkDeleted = $this->callAPISuccess('MailSettings', 'get', array());
96 $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']);
100 * Test chained delete.
102 public function testGetMailSettingsChainDelete() {
103 $description = "Demonstrates get + delete in the same call.";
104 $subFile = 'ChainedGetDelete';
106 'title' => "MailSettings title",
107 'api.MailSettings.delete' => 1,
109 $this->callAPISuccess('MailSettings', 'create', $this->params
);
110 $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subFile);
111 $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array()));