fix membershiptypetest
[civicrm-core.git] / tests / phpunit / api / v3 / MailSettingsTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
39de6fd5 4| CiviCRM version 4.6 |
b6708aeb 5+--------------------------------------------------------------------+
e7112fa7 6| Copyright CiviCRM LLC (c) 2004-2015 |
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
TO
27
28require_once 'CiviTest/CiviUnitTestCase.php';
e9479dcf
EM
29
30/**
31 * Class api_v3_MailSettingsTest
32 */
6a488035 33class api_v3_MailSettingsTest extends CiviUnitTestCase {
50debe3c 34 protected $_apiversion = 3;
6a488035
TO
35 protected $params;
36 protected $id;
430ae6dd
TO
37 public $DBResetRequired = FALSE;
38
00be9182 39 public function setUp() {
6a488035
TO
40 $this->params = array(
41 'domain_id' => 1,
42 'name' => "my mail setting",
43 'domain' => 'setting.com',
44 'local_part' => 'civicrm+',
45 'server' => "localhost",
46 'username' => 'sue',
47 'password' => 'pass',
694d926e 48 'is_default' => 1,
6a488035
TO
49 );
50 parent::setUp();
943e3538 51 $this->useTransaction(TRUE);
6a488035
TO
52 }
53
694d926e 54 /**
eceb18cc 55 * Test creation.
694d926e 56 */
6a488035 57 public function testCreateMailSettings() {
694d926e 58 $this->callAPISuccessGetCount('mail_settings', array(), 1);
50debe3c 59 $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
694d926e
EM
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);
6a488035
TO
64 }
65
694d926e 66 /**
eceb18cc 67 * Test caches cleared adequately.
694d926e
EM
68 */
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);
76 }
6a488035 77
694d926e 78 /**
eceb18cc 79 * Test get method.
694d926e
EM
80 */
81 public function testGetMailSettings() {
82 $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
50debe3c 83 $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params, __FUNCTION__, __FILE__);
694d926e
EM
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);
6a488035
TO
88 }
89
90 public function testDeleteMailSettings() {
694d926e 91 $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__);
50debe3c 92 $entity = $this->callAPISuccess('MailSettings', 'get', $this->params);
694d926e
EM
93 $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']);
94 $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
50debe3c 95 $checkDeleted = $this->callAPISuccess('MailSettings', 'get', array());
694d926e 96 $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']);
6a488035
TO
97 }
98
694d926e 99 /**
eceb18cc 100 * Test chained delete.
694d926e 101 */
6a488035 102 public function testGetMailSettingsChainDelete() {
5c49fee0 103 $description = "Demonstrates get + delete in the same call.";
92915c55
TO
104 $subFile = 'ChainedGetDelete';
105 $params = array(
6a488035
TO
106 'title' => "MailSettings title",
107 'api.MailSettings.delete' => 1,
108 );
694d926e
EM
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()));
6a488035 112 }
96025800 113
6a488035 114}