From 694d926e7178fb1d994d10c79aae4597dea40a60 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 4 Jun 2014 08:33:03 +1200 Subject: [PATCH] Fix & test mail setting caching to fix test --- tests/phpunit/api/v3/MailSettingsTest.php | 53 +++++++++++++++++------ 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/api/v3/MailSettingsTest.php b/tests/phpunit/api/v3/MailSettingsTest.php index 04ccef0ff1..117d08dcdc 100644 --- a/tests/phpunit/api/v3/MailSettingsTest.php +++ b/tests/phpunit/api/v3/MailSettingsTest.php @@ -46,44 +46,71 @@ class api_v3_MailSettingsTest extends CiviUnitTestCase { 'server' => "localhost", 'username' => 'sue', 'password' => 'pass', + 'is_default' => 1, ); parent::setUp(); } function tearDown() {} + /** + * 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'], 'In line ' . __LINE__); - $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); + $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 testGetMailSettings() { + /** + * 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'], 'In line ' . __LINE__); - $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); + $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'], 'In line ' . __LINE__); - - $result = $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); + $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'], 'In line ' . __LINE__); + $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'; + $subFile = 'ChainedGetDelete'; $params = array( 'title' => "MailSettings title", 'api.MailSettings.delete' => 1, ); - $result = $this->callAPISuccess('MailSettings', 'create', $this->params); - $result = $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); - $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array()), 'In line ' . __LINE__); + $this->callAPISuccess('MailSettings', 'create', $this->params); + $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile); + $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', array())); } } -- 2.25.1