params = array( 'domain_id' => 1, 'name' => "my mail setting", 'domain' => 'setting.com', 'local_part' => 'civicrm+', 'server' => "localhost", 'username' => 'sue', 'password' => 'pass', 'is_default' => 1, ); parent::setUp(); $this->useTransaction(TRUE); } /** * Test creation. */ public function testCreateMailSettings() { $this->callAPISuccessGetCount('mail_settings', array(), 1); $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id'])); $this->callAPISuccessGetCount('mail_settings', array(), 1); } /** * Test caches cleared adequately. */ public function testCreateUpdateMailSettings() { $result = $this->callAPISuccess('MailSettings', 'create', $this->params); $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings::defaultDomain()); $this->callAPISuccess('mail_settings', 'create', array('id' => $result['id'], 'domain' => 'updated.com')); $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings::defaultDomain()); $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id'])); $this->callAPISuccessGetCount('mail_settings', array(), 1); } /** * Test get method. */ public function testGetMailSettings() { $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__); $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id'])); $this->callAPISuccessGetCount('mail_settings', array(), 1); } public function testDeleteMailSettings() { $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__); $entity = $this->callAPISuccess('MailSettings', 'get', $this->params); $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']); $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); $checkDeleted = $this->callAPISuccess('MailSettings', 'get', array()); $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']); } /** * Test chained delete. */ public function testGetMailSettingsChainDelete() { $description = "Demonstrates get + delete in the same call."; $subFile = 'ChainedGetDelete'; $params = array( 'title' => "MailSettings title", 'api.MailSettings.delete' => 1, ); $this->callAPISuccess('MailSettings', 'create', $this->params); $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile); $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array())); } }