3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Test class for API functions.
31 * @package CiviCRM_APIv3
34 class api_v3_CustomApiTest
extends CiviUnitTestCase
{
36 protected $_apiversion = 3;
38 public function setUp() {
43 public function tearDown() {
45 CRM_Core_DAO
::executeQuery('DROP TABLE civicrm_mailing_provider_data');
49 * Test that a custom api, as one would add in an extension works.
51 * This api is a bit 'special' in that it has a composite primary key rather
52 * than using 'id', make sure that works too....
54 public function testCustomApi() {
56 $this->callAPISuccess('MailingProviderData', 'create', array(
57 'contact_identifier' => 'xyz',
58 'mailing_identifier' => 'abx',
60 $this->callAPISuccess('Mailing', 'create', array('name' => 'CiviMail', 'hash' => 'abx'));
61 $result = $this->callAPISuccess('MailingProviderData', 'get', array('return' => array('mailing_identifier.name', 'contact_identifier', 'mailing_identifier')));
62 $this->assertEquals(1, $result['count']);
63 $this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']);
64 $this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']);
65 $this->assertEquals(array(
66 'contact_identifier' => 'xyz',
67 'mailing_identifier' => 'abx',
68 'mailing_identifier.name' => 'CiviMail',
70 reset($result['values'])
75 * * Implements hook_civicrm_EntityTypes().
77 * @param array $entityTypes
79 public function hookEntityTypes(&$entityTypes) {
80 $entityTypes['CRM_Omnimail_DAO_MailingProviderData'] = array(
81 'name' => 'MailingProviderData',
82 'class' => 'CRM_Omnimail_DAO_MailingProviderData',
83 'table' => 'civicrm_maiing_provider_data',
88 * Install the custom api.
90 public function installApi() {
91 require_once __DIR__
. '/custom_api/MailingProviderData.php';
92 $this->hookClass
->setHook('civicrm_entityTypes', array($this, 'hookEntityTypes'));
93 CRM_Core_DAO_AllCoreTables
::init(TRUE);
94 CRM_Core_DAO
::executeQuery(
95 "CREATE TABLE IF NOT EXISTS `civicrm_mailing_provider_data` (
96 `contact_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
97 `mailing_identifier` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
98 `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
99 `event_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
100 `recipient_action_datetime` timestamp NOT NULL DEFAULT '2017-01-01 00:00:00',
101 `contact_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
102 `is_civicrm_updated` TINYINT(4) DEFAULT '0',
103 PRIMARY KEY (`contact_identifier`,`recipient_action_datetime`,`event_type`),
104 KEY `contact_identifier` (`contact_identifier`),
105 KEY `mailing_identifier` (`mailing_identifier`),
106 KEY `contact_id` (`contact_id`),
107 KEY `email` (`email`),
108 KEY `event_type` (`event_type`),
109 KEY `recipient_action_datetime` (`recipient_action_datetime`)
110 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"