Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for ResourceImporter and sample_content #4276

Draft
wants to merge 17 commits into
base: 2.x
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
expanded sample content test
  • Loading branch information
paul-m committed Sep 10, 2024
commit 92c2493f2030eb9f8531d2b9a00e0058dca6a91c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SampleContentCommandsTest extends BrowserTestBase {
protected $strictConfigSchema = FALSE;

protected static $modules = [
'datastore',
'node',
'sample_content',
];
Expand Down Expand Up @@ -114,6 +115,36 @@ public function test() {
$this->getSimplifiedErrorOutput()
);

// What does the RESTful API say?
$response = $this->getApiClient()->get('/api/1/metastore/schemas/dataset/items');
$this->assertEquals(200, $response->getStatusCode());
$this->assertCount(10, json_decode($response->getBody()->getContents()));

// Find the bike lanes dataset.
$identifier = 'cedcd327-4e5d-43f9-8eb1-c11850fa7c55';
$response = $this->getApiClient()->get('/api/1/metastore/schemas/dataset/items/' . $identifier);
$this->assertEquals(200, $response->getStatusCode());
$this->assertIsObject($payload = json_decode($response->getBody()->getContents()));
$this->assertEquals($identifier, $payload->identifier ?? 'nope');

// There is a download URL.
$this->assertNotEmpty(
$download_url = $payload->distribution[0]->downloadURL ?? ''
);
// Ensure the server is not 'default'.
$this->assertStringNotContainsString('default', $download_url);

// We can reach the download URL. Roll our own Guzzle client since we don't
// want a base URL option.
/** @var \GuzzleHttp\Client $client */
$client = $this->container->get('http_client_factory')->fromOptions([
RequestOptions::HTTP_ERRORS => FALSE,
]);
// HEAD request since we don't want to actually transfer the file right
// now.
$this->assertNotEmpty($response = $client->head($download_url));
$this->assertEquals(200, $response->getStatusCode());

// Run the remove command.
$this->drush('dkan:sample-content:remove');
// Logged output counts as an error, even if it's not an error.
Expand Down