From 397e0e51f19ea8fe3265db59e9e669e7690d64e5 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Thu, 15 Aug 2013 14:48:22 +0100 Subject: [PATCH] CRM-12826 - Implement MessageTemplatesTest for testing MessageTemplates APIs --- api/v3/examples/MessageTemplatesCreate.php | 82 ++++++++++++++++ api/v3/examples/MessageTemplatesDelete.php | 61 ++++++++++++ api/v3/examples/MessageTemplatesGet.php | 82 ++++++++++++++++ tests/phpunit/api/v3/MessageTemplatesTest.php | 96 +++++++++++++++++++ 4 files changed, 321 insertions(+) create mode 100644 api/v3/examples/MessageTemplatesCreate.php create mode 100644 api/v3/examples/MessageTemplatesDelete.php create mode 100644 api/v3/examples/MessageTemplatesGet.php create mode 100644 tests/phpunit/api/v3/MessageTemplatesTest.php diff --git a/api/v3/examples/MessageTemplatesCreate.php b/api/v3/examples/MessageTemplatesCreate.php new file mode 100644 index 0000000000..55ac4025b9 --- /dev/null +++ b/api/v3/examples/MessageTemplatesCreate.php @@ -0,0 +1,82 @@ + 'msg_title_1', + 'msg_subject' => 'msg_subject_1', + 'msg_text' => 'msg_text_1', + 'msg_html' => 'msg_html_1', + 'workflow_id' => 1, + 'is_default' => '', + 'is_reserved' => 1, + 'pdf_format_id' => '1', +); + +try{ + $result = civicrm_api3('message_templates', 'create', $params); +} +catch (CiviCRM_API3_Exception $e) { + // handle error here + $errorMessage = $e->getMessage(); + $errorCode = $e->getErrorCode(); + $errorData = $e->getExtraParams(); + return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); +} + +return $result; +} + +/** + * Function returns array of result expected from previous function + */ +function message_templates_create_expectedresult(){ + + $expectedResult = array( + 'is_error' => 0, + 'version' => 3, + 'count' => 1, + 'id' => 2, + 'values' => array( + '2' => array( + 'id' => '2', + 'msg_title' => 'msg_title_1', + 'msg_subject' => 'msg_subject_1', + 'msg_text' => 'msg_text_1', + 'msg_html' => 'msg_html_1', + 'is_active' => '1', + 'workflow_id' => '1', + 'is_default' => '', + 'is_reserved' => '1', + 'pdf_format_id' => '1', + ), + ), +); + + return $expectedResult; +} + + +/* +* This example has been generated from the API test suite. The test that created it is called +* +* testCreate and can be found in +* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/MessageTemplatesTest.php +* +* You can see the outcome of the API tests at +* http://tests.dev.civicrm.org/trunk/results-api_v3 +* +* To Learn about the API read +* http://book.civicrm.org/developer/current/techniques/api/ +* +* and review the wiki at +* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs +* +* Read more about testing here +* http://wiki.civicrm.org/confluence/display/CRM/Testing +* +* API Standards documentation: +* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards +*/ \ No newline at end of file diff --git a/api/v3/examples/MessageTemplatesDelete.php b/api/v3/examples/MessageTemplatesDelete.php new file mode 100644 index 0000000000..2bfe00470c --- /dev/null +++ b/api/v3/examples/MessageTemplatesDelete.php @@ -0,0 +1,61 @@ + 2, +); + +try{ + $result = civicrm_api3('message_templates', 'delete', $params); +} +catch (CiviCRM_API3_Exception $e) { + // handle error here + $errorMessage = $e->getMessage(); + $errorCode = $e->getErrorCode(); + $errorData = $e->getExtraParams(); + return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); +} + +return $result; +} + +/** + * Function returns array of result expected from previous function + */ +function message_templates_delete_expectedresult(){ + + $expectedResult = array( + 'is_error' => 0, + 'version' => 3, + 'count' => 1, + 'values' => true, +); + + return $expectedResult; +} + + +/* +* This example has been generated from the API test suite. The test that created it is called +* +* testDelete and can be found in +* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/MessageTemplatesTest.php +* +* You can see the outcome of the API tests at +* http://tests.dev.civicrm.org/trunk/results-api_v3 +* +* To Learn about the API read +* http://book.civicrm.org/developer/current/techniques/api/ +* +* and review the wiki at +* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs +* +* Read more about testing here +* http://wiki.civicrm.org/confluence/display/CRM/Testing +* +* API Standards documentation: +* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards +*/ \ No newline at end of file diff --git a/api/v3/examples/MessageTemplatesGet.php b/api/v3/examples/MessageTemplatesGet.php new file mode 100644 index 0000000000..dcaa796afe --- /dev/null +++ b/api/v3/examples/MessageTemplatesGet.php @@ -0,0 +1,82 @@ + 'msg_title_2', + 'msg_subject' => 'msg_subject_2', + 'msg_text' => 'msg_text_2', + 'msg_html' => 'msg_html_2', + 'workflow_id' => 2, + 'is_default' => '', + 'is_reserved' => 1, + 'pdf_format_id' => '1', +); + +try{ + $result = civicrm_api3('message_templates', 'get', $params); +} +catch (CiviCRM_API3_Exception $e) { + // handle error here + $errorMessage = $e->getMessage(); + $errorCode = $e->getErrorCode(); + $errorData = $e->getExtraParams(); + return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); +} + +return $result; +} + +/** + * Function returns array of result expected from previous function + */ +function message_templates_get_expectedresult(){ + + $expectedResult = array( + 'is_error' => 0, + 'version' => 3, + 'count' => 1, + 'id' => 1, + 'values' => array( + '1' => array( + 'id' => '1', + 'msg_title' => 'msg_title_2', + 'msg_subject' => 'msg_subject_2', + 'msg_text' => 'msg_text_2', + 'msg_html' => 'msg_html_2', + 'is_active' => 0, + 'workflow_id' => '2', + 'is_default' => 0, + 'is_reserved' => '1', + 'pdf_format_id' => '1', + ), + ), +); + + return $expectedResult; +} + + +/* +* This example has been generated from the API test suite. The test that created it is called +* +* testGet and can be found in +* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/MessageTemplatesTest.php +* +* You can see the outcome of the API tests at +* http://tests.dev.civicrm.org/trunk/results-api_v3 +* +* To Learn about the API read +* http://book.civicrm.org/developer/current/techniques/api/ +* +* and review the wiki at +* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs +* +* Read more about testing here +* http://wiki.civicrm.org/confluence/display/CRM/Testing +* +* API Standards documentation: +* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards +*/ \ No newline at end of file diff --git a/tests/phpunit/api/v3/MessageTemplatesTest.php b/tests/phpunit/api/v3/MessageTemplatesTest.php new file mode 100644 index 0000000000..87059607d1 --- /dev/null +++ b/tests/phpunit/api/v3/MessageTemplatesTest.php @@ -0,0 +1,96 @@ +_apiversion = 3; + parent::setUp(); + $this->quickCleanup(array('civicrm_msg_template')); + $template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplates')->toArray(); + $this->params = array( + 'msg_title' => $template['msg_title'], + 'msg_subject' => $template['msg_subject'], + 'msg_text' => $template['msg_text'], + 'msg_html' => $template['msg_html'], + 'workflow_id' => $template['workflow_id'], + 'is_default' => $template['is_default'], + 'is_reserved' => $template['is_reserved'], + 'pdf_format_id' => $template['pdf_format_id'], + ); + } + function tearDown() {} + + /** + * test create function succeeds + */ + public function testCreate() { + $result = $this->callAPIAndDocument('MessageTemplates', 'create', $this->params, __FUNCTION__, __FILE__); + var_dump($result); + $this->getAndCheck($this->params, $result['id'], $this->entity); + } + + /** + * Test get function succeeds (this is actually largely tested in the get + * action on create. Add extra checks for any 'special' return values or + * behaviours + * + */ + public function testGet() { + $this->createTestEntity(); + $result = $this->callAPIAndDocument('MessageTemplates', 'get', $this->params, __FUNCTION__, __FILE__); + $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); + $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); + } + +/** + * Check the delete function succeeds + */ + public function testDelete() { + $entity = $this->createTestEntity(); + $result = $this->callAPIAndDocument('MessageTemplates', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); + $checkDeleted = $this->callAPISuccess($this->entity, 'get', array( + 'id' => $entity['id'] + )); + $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__); + } + +} + -- 2.25.1