@@ -22,7 +22,17 @@ public function setUpHeadless(): CiviEnvBuilder {
22
22
->apply ();
23
23
}
24
24
25
- public function testEntityDisplay () {
25
+ public static function getDataModes (): array {
26
+ return [
27
+ ['table ' ],
28
+ ['view ' ],
29
+ ];
30
+ }
31
+
32
+ /**
33
+ * @dataProvider getDataModes
34
+ */
35
+ public function testEntityDisplay (string $ dataMode ) {
26
36
$ lastName = uniqid (__FUNCTION__ );
27
37
28
38
$ this ->saveTestRecords ('Contact ' , [
@@ -51,6 +61,7 @@ public function testEntityDisplay() {
51
61
->addValue ('label ' , 'MyNewEntity ' )
52
62
->addValue ('name ' , 'MyNewEntity ' )
53
63
->addValue ('settings ' , [
64
+ 'data_mode ' => $ dataMode ,
54
65
'columns ' => [
55
66
[
56
67
'key ' => 'id ' ,
@@ -90,22 +101,33 @@ public function testEntityDisplay() {
90
101
])
91
102
->execute ()->first ();
92
103
104
+ $ expectTypes = ['table ' => 'BASE TABLE ' , 'view ' => 'VIEW ' ];
105
+ $ this ->assertEquals ($ expectTypes [$ dataMode ], \CRM_Core_BAO_SchemaHandler::getTableType ('civicrm_sk_my_new_entity ' ));
106
+
93
107
$ schema = \CRM_Core_DAO::executeQuery ('DESCRIBE civicrm_sk_my_new_entity ' )->fetchAll ();
94
108
$ this ->assertCount (7 , $ schema );
95
109
$ this ->assertEquals ('_row ' , $ schema [0 ]['Field ' ]);
96
- $ this ->assertStringStartsWith ('int ' , $ schema [0 ]['Type ' ]);
97
- $ this ->assertEquals ('PRI ' , $ schema [0 ]['Key ' ]);
110
+ // $this->assertStringStartsWith('int', $schema[0]['Type']);
111
+ $ this ->assertMatchesRegularExpression ('/^(int|bigint)/ ' , $ schema [0 ]['Type ' ]);
112
+ if ($ dataMode === 'table ' ) {
113
+ $ this ->assertEquals ('PRI ' , $ schema [0 ]['Key ' ]);
114
+ }
98
115
99
- // created_date and modified_date should be NULLable and have no default/extra
100
- $ this ->assertEmpty ($ schema [5 ]['Default ' ]);
101
- $ this ->assertEmpty ($ schema [5 ]['Extra ' ]);
102
- $ this ->assertEquals ('YES ' , $ schema [5 ]['Null ' ]);
103
- $ this ->assertEmpty ($ schema [6 ]['Default ' ]);
104
- $ this ->assertEmpty ($ schema [6 ]['Extra ' ]);
105
- $ this ->assertEquals ('YES ' , $ schema [5 ]['Null ' ]);
116
+ if ($ dataMode === 'table ' ) {
117
+ // created_date and modified_date should be NULLable and have no default/extra
118
+ $ this ->assertEmpty ($ schema [5 ]['Default ' ]);
119
+ $ this ->assertEmpty ($ schema [5 ]['Extra ' ]);
120
+ $ this ->assertEquals ('YES ' , $ schema [5 ]['Null ' ]);
121
+ $ this ->assertEmpty ($ schema [6 ]['Default ' ]);
122
+ $ this ->assertEmpty ($ schema [6 ]['Extra ' ]);
123
+ $ this ->assertEquals ('YES ' , $ schema [5 ]['Null ' ]);
124
+ }
106
125
107
- $ rows = \CRM_Core_DAO::executeQuery ('SELECT * FROM civicrm_sk_my_new_entity ' )->fetchAll ();
108
- $ this ->assertCount (0 , $ rows );
126
+ if ($ dataMode === 'table ' ) {
127
+ // SQL table is not yet hydrated.
128
+ $ rows = \CRM_Core_DAO::executeQuery ('SELECT * FROM civicrm_sk_my_new_entity ' )->fetchAll ();
129
+ $ this ->assertCount (0 , $ rows );
130
+ }
109
131
110
132
$ getFields = civicrm_api4 ('SK_MyNewEntity ' , 'getFields ' , ['loadOptions ' => TRUE ])->indexBy ('name ' );
111
133
$ this ->assertNotEmpty ($ getFields ['prefix_id ' ]['options ' ][1 ]);
@@ -160,7 +182,10 @@ public function testEntityDisplay() {
160
182
$ this ->assertStringContainsString ('SK_MyNewEntity ' , $ e ->getMessage ());
161
183
}
162
184
163
- public function testEntityDisplayWithJoin () {
185
+ /**
186
+ * @dataProvider getDataModes
187
+ */
188
+ public function testEntityDisplayWithJoin (string $ dataMode ) {
164
189
165
190
$ lastName = uniqid (__FUNCTION__ );
166
191
$ contacts = (array ) $ this ->saveTestRecords ('Individual ' , [
@@ -198,6 +223,7 @@ public function testEntityDisplayWithJoin() {
198
223
->addValue ('label ' , 'MyNewEntityWithJoin ' )
199
224
->addValue ('name ' , 'MyNewEntityWithJoin ' )
200
225
->addValue ('settings ' , [
226
+ 'data_mode ' => $ dataMode ,
201
227
// Additional column data will be filled in automatically
202
228
// @see SKEntitySubscriber::formatFieldSpec
203
229
'columns ' => [
@@ -271,7 +297,10 @@ public function testEntityDisplayWithJoin() {
271
297
$ this ->assertSame ('Event_SK_MyNewEntityWithJoin_Contact_Participant_contact_id_01_event_id ' , $ eventJoin [0 ]['alias ' ]);
272
298
}
273
299
274
- public function testEntityWithSqlFunctions (): void {
300
+ /**
301
+ * @dataProvider getDataModes
302
+ */
303
+ public function testEntityWithSqlFunctions (string $ dataMode ): void {
275
304
$ cids = $ this ->saveTestRecords ('Individual ' , [
276
305
'records ' => [
277
306
['first_name ' => 'A ' , 'last_name ' => 'A ' ],
@@ -324,6 +353,7 @@ public function testEntityWithSqlFunctions(): void {
324
353
'saved_search_id.name ' => 'Major_Donors_entity_test ' ,
325
354
'type ' => 'entity ' ,
326
355
'settings ' => [
356
+ 'data_mode ' => $ dataMode ,
327
357
'sort ' => [
328
358
['YEAR_receive_date ' , 'ASC ' ],
329
359
],
@@ -361,9 +391,9 @@ public function testEntityWithSqlFunctions(): void {
361
391
$ schema = \CRM_Core_DAO::executeQuery ('DESCRIBE civicrm_sk_major_donors_entity_test_db_entity1 ' )->fetchAll ();
362
392
$ this ->assertCount (6 , $ schema );
363
393
$ this ->assertEquals ('_row ' , $ schema [0 ]['Field ' ]);
364
- $ this ->assertStringStartsWith ( ' int ' , $ schema [0 ]['Type ' ]);
365
- $ this ->assertStringStartsWith ( ' int ' , $ schema [1 ]['Type ' ]);
366
- $ this ->assertStringStartsWith ( ' int ' , $ schema [2 ]['Type ' ]);
394
+ $ this ->assertMatchesRegularExpression ( ' /^( int|bigint)/ ' , $ schema [0 ]['Type ' ]);
395
+ $ this ->assertMatchesRegularExpression ( ' /^( int|bigint)/ ' , $ schema [1 ]['Type ' ]);
396
+ $ this ->assertMatchesRegularExpression ( ' /^( int|bigint)/ ' , $ schema [2 ]['Type ' ]);
367
397
$ this ->assertStringStartsWith ('text ' , $ schema [3 ]['Type ' ]);
368
398
$ this ->assertStringStartsWith ('decimal ' , $ schema [4 ]['Type ' ]);
369
399
$ this ->assertStringStartsWith ('text ' , $ schema [3 ]['Type ' ]);
0 commit comments