3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test class for API functions.
15 * @package CiviCRM_APIv3
18 class api_v3_CustomApiTest
extends CiviUnitTestCase
{
20 protected $_apiversion = 3;
22 public function setUp() {
27 public function tearDown() {
29 CRM_Core_DAO
::executeQuery('DROP TABLE civicrm_mailing_provider_data');
33 * Test that a custom api, as one would add in an extension works.
35 * This api is a bit 'special' in that it has a composite primary key rather
36 * than using 'id', make sure that works too....
38 public function testCustomApi() {
40 $this->callAPISuccess('MailingProviderData', 'create', [
41 'contact_identifier' => 'xyz',
42 'mailing_identifier' => 'abx',
44 $this->callAPISuccess('Mailing', 'create', ['name' => 'CiviMail', 'hash' => 'abx']);
45 $result = $this->callAPISuccess('MailingProviderData', 'get', ['return' => ['mailing_identifier.name', 'contact_identifier', 'mailing_identifier']]);
46 $this->assertEquals(1, $result['count']);
47 $this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']);
48 $this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']);
50 'contact_identifier' => 'xyz',
51 'mailing_identifier' => 'abx',
52 'mailing_identifier.name' => 'CiviMail',
53 ], reset($result['values']));
57 * * Implements hook_civicrm_EntityTypes().
59 * @param array $entityTypes
61 public function hookEntityTypes(&$entityTypes) {
62 $entityTypes['CRM_Omnimail_DAO_MailingProviderData'] = [
63 'name' => 'MailingProviderData',
64 'class' => 'CRM_Omnimail_DAO_MailingProviderData',
65 'table' => 'civicrm_maiing_provider_data',
70 * Install the custom api.
72 public function installApi() {
73 require_once __DIR__
. '/custom_api/MailingProviderData.php';
74 $this->hookClass
->setHook('civicrm_entityTypes', [$this, 'hookEntityTypes']);
75 CRM_Core_DAO_AllCoreTables
::init(TRUE);
76 CRM_Core_DAO
::executeQuery(
77 "CREATE TABLE IF NOT EXISTS `civicrm_mailing_provider_data` (
78 `contact_identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
79 `mailing_identifier` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
80 `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
81 `event_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
82 `recipient_action_datetime` timestamp NOT NULL DEFAULT '2017-01-01 00:00:00',
83 `contact_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
84 `is_civicrm_updated` TINYINT(4) DEFAULT '0',
85 PRIMARY KEY (`contact_identifier`,`recipient_action_datetime`,`event_type`),
86 KEY `contact_identifier` (`contact_identifier`),
87 KEY `mailing_identifier` (`mailing_identifier`),
88 KEY `contact_id` (`contact_id`),
89 KEY `email` (`email`),
90 KEY `event_type` (`event_type`),
91 KEY `recipient_action_datetime` (`recipient_action_datetime`)
92 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"