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