Merge pull request #7764 from pradpnayak/CRM-16617-master
[civicrm-core.git] / tests / phpunit / api / v3 / MailSettingsTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
81621fee 4| CiviCRM version 4.7 |
b6708aeb 5+--------------------------------------------------------------------+
fa938177 6| Copyright CiviCRM LLC (c) 2004-2016 |
b6708aeb 7+--------------------------------------------------------------------+
8| This file is a part of CiviCRM. |
9| |
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. |
13| |
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. |
18| |
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+--------------------------------------------------------------------+
e70a7fc0 26 */
6a488035 27
e9479dcf
EM
28/**
29 * Class api_v3_MailSettingsTest
acb109b7 30 * @group headless
e9479dcf 31 */
6a488035 32class api_v3_MailSettingsTest extends CiviUnitTestCase {
50debe3c 33 protected $_apiversion = 3;
6a488035
TO
34 protected $params;
35 protected $id;
430ae6dd
TO
36 public $DBResetRequired = FALSE;
37
00be9182 38 public function setUp() {
6a488035
TO
39 $this->params = array(
40 'domain_id' => 1,
41 'name' => "my mail setting",
42 'domain' => 'setting.com',
43 'local_part' => 'civicrm+',
44 'server' => "localhost",
45 'username' => 'sue',
46 'password' => 'pass',
694d926e 47 'is_default' => 1,
6a488035
TO
48 );
49 parent::setUp();
943e3538 50 $this->useTransaction(TRUE);
6a488035
TO
51 }
52
694d926e 53 /**
eceb18cc 54 * Test creation.
694d926e 55 */
6a488035 56 public function testCreateMailSettings() {
694d926e 57 $this->callAPISuccessGetCount('mail_settings', array(), 1);
50debe3c 58 $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
694d926e
EM
59 $this->assertEquals(1, $result['count']);
60 $this->assertNotNull($result['values'][$result['id']]['id']);
61 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
62 $this->callAPISuccessGetCount('mail_settings', array(), 1);
6a488035
TO
63 }
64
694d926e 65 /**
eceb18cc 66 * Test caches cleared adequately.
694d926e
EM
67 */
68 public function testCreateUpdateMailSettings() {
69 $result = $this->callAPISuccess('MailSettings', 'create', $this->params);
70 $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings::defaultDomain());
71 $this->callAPISuccess('mail_settings', 'create', array('id' => $result['id'], 'domain' => 'updated.com'));
72 $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings::defaultDomain());
73 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
74 $this->callAPISuccessGetCount('mail_settings', array(), 1);
75 }
6a488035 76
694d926e 77 /**
eceb18cc 78 * Test get method.
694d926e
EM
79 */
80 public function testGetMailSettings() {
81 $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
50debe3c 82 $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params, __FUNCTION__, __FILE__);
694d926e
EM
83 $this->assertEquals(1, $result['count']);
84 $this->assertNotNull($result['values'][$result['id']]['id']);
85 $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id']));
86 $this->callAPISuccessGetCount('mail_settings', array(), 1);
6a488035
TO
87 }
88
89 public function testDeleteMailSettings() {
694d926e 90 $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
50debe3c 91 $entity = $this->callAPISuccess('MailSettings', 'get', $this->params);
694d926e
EM
92 $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']);
93 $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
50debe3c 94 $checkDeleted = $this->callAPISuccess('MailSettings', 'get', array());
694d926e 95 $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']);
6a488035
TO
96 }
97
694d926e 98 /**
eceb18cc 99 * Test chained delete.
694d926e 100 */
6a488035 101 public function testGetMailSettingsChainDelete() {
5c49fee0 102 $description = "Demonstrates get + delete in the same call.";
92915c55
TO
103 $subFile = 'ChainedGetDelete';
104 $params = array(
6a488035
TO
105 'title' => "MailSettings title",
106 'api.MailSettings.delete' => 1,
107 );
694d926e
EM
108 $this->callAPISuccess('MailSettings', 'create', $this->params);
109 $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile);
110 $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array()));
6a488035 111 }
96025800 112
6a488035 113}