diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index 0b5c33ac82..e477b179e0 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -391,10 +391,10 @@ public function setSchema(array $schema): void { * Get the schema for this table. * * @return array - * A schema array. + * A Drupal Schema API array, or an empty array if none found. */ public function getSchema(): array { - return $this->schema; + return $this->schema ?? []; } /** diff --git a/modules/datastore/tests/src/Functional/Api1/DatastoreQueryApiTest.php b/modules/datastore/tests/src/Functional/Api1/DatastoreQueryApiTest.php new file mode 100644 index 0000000000..a0668dca60 --- /dev/null +++ b/modules/datastore/tests/src/Functional/Api1/DatastoreQueryApiTest.php @@ -0,0 +1,65 @@ +getSampleDataset(); + $this->post($dataset, FALSE); + $dataset_id = $dataset->identifier; + + $response = $this->httpClient->get("api/1/datastore/query/$dataset_id/0", [ + RequestOptions::HTTP_ERRORS => FALSE, + ]); + $this->assertEquals(400, $response->getStatusCode()); + $this->validator->validate($response, "/api/1/datastore/query/{datasetId}/{index}", 'get'); + + // Confirm a 200 response after the datastore_import has run. + $dataset_info = \Drupal::service('dkan.common.dataset_info')->gather($dataset_id); + $resource_id = $dataset_info['latest_revision']['distributions'][0]['resource_id']; + \Drupal::service('dkan.datastore.service')->import($resource_id, FALSE); + $response = $this->httpClient->get("api/1/datastore/query/$dataset_id/0", [ + RequestOptions::HTTP_ERRORS => FALSE, + ]); + $this->assertEquals(200, $response->getStatusCode()); + $this->validator->validate($response, "/api/1/datastore/query/{datasetId}/{index}", 'get'); + } + + /** + * Query on in progress datastore updates. + * + * Confirm a 400 response after a resource is updated, localize_import + * has run, but the datastore_import queue has not yet run. + */ + public function testBasicQueryAfterTableDrop() { + $dataset = $this->getSampleDataset(); + $this->post($dataset, FALSE); + $dataset_id = $dataset->identifier; + + $dataset_info = \Drupal::service('dkan.common.dataset_info')->gather($dataset_id); + $resource_id = $dataset_info['latest_revision']['distributions'][0]['resource_id']; + \Drupal::service('dkan.datastore.service')->import($resource_id, FALSE); + + $dataset_info = \Drupal::service('dkan.common.dataset_info')->gather($dataset_id); + $datastore_table = $dataset_info['latest_revision']['distributions'][0]['table_name']; + \Drupal::database()->schema()->dropTable($datastore_table); + + $response = $this->httpClient->get("api/1/datastore/query/$dataset_id/0", [ + RequestOptions::HTTP_ERRORS => FALSE, + ]); + $this->assertEquals(400, $response->getStatusCode()); + $this->validator->validate($response, "/api/1/datastore/query/{datasetId}/{index}", 'get'); + } + +}