--- /dev/null
+<?php
+/**
+ * Test Generated example of using message_templates create API
+ * *
+ */
+function message_templates_create_example(){
+$params = array(
+ 'msg_title' => '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
--- /dev/null
+<?php
+/**
+ * Test Generated example of using message_templates delete API
+ * *
+ */
+function message_templates_delete_example(){
+$params = array(
+ 'id' => 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
--- /dev/null
+<?php
+/**
+ * Test Generated example of using message_templates get API
+ * *
+ */
+function message_templates_get_example(){
+$params = array(
+ 'msg_title' => '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
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+*/
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+/**
+ * Test class for Template API - civicrm_msg_template*
+ *
+ * @package CiviCRM_APIv3
+ */
+class api_v3_MessageTemplatesTest extends CiviUnitTestCase {
+ /**
+ * Assume empty database with just civicrm_data
+ */
+ protected $entity = 'MessageTemplates';
+ protected $params;
+
+
+ function setUp() {
+ $this->_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__);
+ }
+
+}
+