Commit | Line | Data |
---|---|---|
523c222f | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
523c222f | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
523c222f | 7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * Test class for API functions. | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | * @group headless | |
33 | */ | |
34 | class api_v3_CustomApiTest extends CiviUnitTestCase { | |
35 | ||
36 | protected $_apiversion = 3; | |
37 | ||
38 | public function setUp() { | |
39 | parent::setUp(); | |
40 | $this->installApi(); | |
41 | } | |
42 | ||
43 | public function tearDown() { | |
44 | parent::tearDown(); | |
45 | CRM_Core_DAO::executeQuery('DROP TABLE civicrm_mailing_provider_data'); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Test that a custom api, as one would add in an extension works. | |
50 | * | |
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.... | |
53 | */ | |
54 | public function testCustomApi() { | |
55 | $this->installApi(); | |
56 | $this->callAPISuccess('MailingProviderData', 'create', array( | |
57 | 'contact_identifier' => 'xyz', | |
58 | 'mailing_identifier' => 'abx', | |
59 | )); | |
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']); | |
7d3b1a9d SL |
63 | $this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']); |
64 | $this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']); | |
523c222f | 65 | $this->assertEquals(array( |
66 | 'contact_identifier' => 'xyz', | |
67 | 'mailing_identifier' => 'abx', | |
68 | 'mailing_identifier.name' => 'CiviMail', | |
69 | ), | |
70 | reset($result['values']) | |
71 | ); | |
72 | } | |
73 | ||
74 | /** | |
75 | * * Implements hook_civicrm_EntityTypes(). | |
76 | * | |
77 | * @param array $entityTypes | |
78 | */ | |
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', | |
84 | ); | |
85 | } | |
86 | ||
87 | /** | |
88 | * Install the custom api. | |
89 | */ | |
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 '', | |
7d3b1a9d | 100 | `recipient_action_datetime` timestamp NOT NULL DEFAULT '2017-01-01 00:00:00', |
523c222f | 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" | |
111 | ); | |
112 | } | |
113 | ||
114 | } |