Skip to content

Commit dd033e2

Browse files
committed
Lib: Enhanced DoQuery and GetSchema, and tests
- Added support for normalizing variables and chdbids in DoQuery and GetSchema responses. This is a breaking change. - Enhanced tests to test expected and actual data structures
1 parent 6e86f9e commit dd033e2

9 files changed

+623
-13
lines changed

quickbase.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,33 @@ final public static function API_DoQuery(&$query, &$results){
542542
$results['table']['records'][$i] = $newRecord;
543543
}
544544
}
545+
546+
if(isset($results['table']['variables']) && isset($results['table']['variables']['var'])){
547+
if(isset($results['table']['variables']['var']['_'])){
548+
$results['table']['variables']['var'] = array( $results['table']['variables']['var'] );
549+
}
550+
551+
$vars = array();
552+
553+
foreach($results['table']['variables']['var'] as $key => $value){
554+
$vars[$value['name']] = $value['_'];
555+
}
556+
557+
$results['table']['variables'] = $vars;
558+
}
559+
560+
if(isset($results['table']['chdbids'])){
561+
if(isset($results['table']['chdbids']['_'])){
562+
$results['table']['chdbids'] = array( $results['table']['chdbids'] );
563+
}
564+
565+
for($i = 0, $l = count($results['table']['chdbids']); $i < $l; ++$i){
566+
$results['table']['chdbids'][$i] = array(
567+
'name' => $results['table']['chdbids'][$i]['name'],
568+
'dbid' => $results['table']['chdbids'][$i]['_']
569+
);
570+
}
571+
}
545572
}else{
546573
if(isset($results['record'])){
547574
$results['records'] = $results['record'];
@@ -585,13 +612,31 @@ final public static function API_DoQuery(&$query, &$results){
585612

586613
final public static function API_GetSchema(&$query, &$results){
587614
if(isset($results['table']['chdbids'])){
615+
if(isset($results['table']['chdbids']['_'])){
616+
$results['table']['chdbids'] = array( $results['table']['chdbids'] );
617+
}
618+
588619
for($i = 0, $l = count($results['table']['chdbids']); $i < $l; ++$i){
589620
$results['table']['chdbids'][$i] = array(
590621
'name' => $results['table']['chdbids'][$i]['name'],
591622
'dbid' => $results['table']['chdbids'][$i]['_']
592623
);
593624
}
594625
}
626+
627+
if(isset($results['table']['variables']) && isset($results['table']['variables']['var'])){
628+
if(isset($results['table']['variables']['var']['_'])){
629+
$results['table']['variables']['var'] = array( $results['table']['variables']['var'] );
630+
}
631+
632+
$vars = array();
633+
634+
foreach($results['table']['variables']['var'] as $key => $value){
635+
$vars[$value['name']] = $value['_'];
636+
}
637+
638+
$results['table']['variables'] = $vars;
639+
}
595640
}
596641

597642
// final public static function API_GetRecordAsHTML(&$query, &$results){ }

tests/API_AddField.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,37 @@
1515
* limitations under the License.
1616
*/
1717

18-
$response = $qb->api('API_AddField', array(
18+
$expected = array(
19+
'action' => 'API_AddField',
20+
'errcode' => 0,
21+
'errtext' => 'No error',
22+
'fid' => 0,
23+
'label' => 'Test Field'
24+
);
25+
26+
$actual = $qb->api('API_AddField', array(
1927
'dbid' => getenv('dbid'),
2028
'label' => 'Test Field',
2129
'type' => 'text'
2230
));
2331

24-
$qb->api('API_DeleteField', array(
32+
if(!objStrctMatch($actual, $expected)){
33+
throw new Exception('Mismatched API_AddField Data Structure');
34+
}
35+
36+
$expected = array(
37+
'action' => 'API_DeleteField',
38+
'errcode' => 0,
39+
'errtext' => 'No error'
40+
);
41+
42+
$actual = $qb->api('API_DeleteField', array(
2543
'dbid' => getenv('dbid'),
26-
'fid' => $response['fid']
44+
'fid' => $actual['fid']
2745
));
2846

47+
if(!objStrctMatch($actual, $expected)){
48+
throw new Exception('Mismatched API_DeleteField Data Structure');
49+
}
50+
2951
?>

tests/API_AddRecord.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,36 @@
1515
* limitations under the License.
1616
*/
1717

18-
$response = $qb->api('API_AddRecord', array(
18+
$expected = array(
19+
'action' => 'API_AddRecord',
20+
'errcode' => 0,
21+
'errtext' => 'No error',
22+
'rid' => 0,
23+
'update_id' => 0
24+
);
25+
26+
$actual = $qb->api('API_AddRecord', array(
1927
'dbid' => getenv('dbid')
2028
));
2129

22-
$qb->api('API_DeleteRecord', array(
30+
if(!objStrctMatch($actual, $expected)){
31+
throw new Exception('Mismatched API_AddRecord Data Structure');
32+
}
33+
34+
$expected = array(
35+
'action' => 'API_DeleteRecord',
36+
'errcode' => 0,
37+
'errtext' => 'No error',
38+
'rid' => 0
39+
);
40+
41+
$actual = $qb->api('API_DeleteRecord', array(
2342
'dbid' => getenv('dbid'),
24-
'rid' => $response['rid']
43+
'rid' => $actual['rid']
2544
));
2645

46+
if(!objStrctMatch($actual, $expected)){
47+
throw new Exception('Mismatched API_DeleteRecord Data Structure');
48+
}
49+
2750
?>

tests/API_Authenticate.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@
1515
* limitations under the License.
1616
*/
1717

18-
$qb->api('API_Authenticate', array(
18+
$expected = array(
19+
'action' => 'API_Authenticate',
20+
'errcode' => 0,
21+
'errtext' => 'No error',
22+
'ticket' => '',
23+
'userid' => ''
24+
);
25+
26+
$actual = $qb->api('API_Authenticate', array(
1927
'username' => getenv('username'),
2028
'password' => getenv('password')
2129
));
2230

31+
if(!objStrctMatch($actual, $expected)){
32+
throw new Exception('Mismatched API_Authenticate Data Structure');
33+
}
34+
2335
?>

0 commit comments

Comments
 (0)