Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function plugin_evidence_initialize_database() {
$data = [];
$data['columns'][] = ['name' => 'id', 'type' => 'int(11)', 'NULL' => false];
$data['columns'][] = ['name' => 'organization', 'type' => 'varchar(200)', 'NULL' => false];
$data['primary'] = ['id'];
$data['primary'] = 'id';
$data['type'] = 'InnoDB';
$data['comment'] = 'evidence organizations';
api_plugin_db_table_create('evidence', 'plugin_evidence_organization', $data);
Expand All @@ -65,7 +65,7 @@ function plugin_evidence_initialize_database() {
$data['columns'][] = ['name' => 'method', 'type' => 'enum("get", "walk", "info", "table")', 'default' => 'get', 'NULL' => false];
$data['columns'][] = ['name' => 'table_items', 'type' => 'varchar(100)', 'default' => null, 'NULL' => true];
$data['columns'][] = ['name' => 'mandatory', 'type' => 'enum("yes","no")', 'default' => 'yes', 'NULL' => false];
$data['primary'] = ['id'];
$data['primary'] = 'id';
$data['type'] = 'InnoDB';
$data['comment'] = 'evidence specific';
api_plugin_db_table_create('evidence', 'plugin_evidence_specific_query', $data);
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/EvidenceDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@
));
});

it('declares scalar primary keys for api_plugin_db_table_create', function () {
// api_plugin_db_table_create() interpolates data['primary'] straight into
// PRIMARY KEY (`...`) down to the 1.2.29 compat floor, so an array would
// render as PRIMARY KEY (`Array`) and fail the create on a fresh install.
plugin_evidence_setup_database();

$withPrimary = array_filter($GLOBALS['__test_db_calls'], function ($call) {
return $call['fn'] === 'api_plugin_db_table_create' && isset($call['params']['primary']);
});

expect($withPrimary)->not->toBeEmpty();

foreach ($withPrimary as $call) {
expect($call['params']['primary'])->toBeString();
}
});

it('seeds the vendor-specific query catalog', function () {
plugin_evidence_setup_database();

Expand Down
Loading