diff --git a/src/Species.php b/src/Species.php
index d0ce03dd8ed8e4a8f629bde35cc28587c2fb9e55..0e03a87736d889339ada40df3204a35a97740419 100644
--- a/src/Species.php
+++ b/src/Species.php
@@ -128,7 +128,7 @@ class Species extends Gbif {
if (!$uuid && !$short_name) {
throw new GbifException('`uuid` and `short_name` cannot be both NULL if `data` equals "root"');
}
- $uri = $uuid ? 'species/' . $uuid : 'species/' . $short_name;
+ $uri = $uuid ? 'species/root/' . $uuid : 'species/root/' . $short_name;
}
else {
$uri = 'species/' . $key . '/' . $data;
diff --git a/tests/Unit/SpeciesTest.php b/tests/Unit/SpeciesTest.php
index 0c2a7e54dd3c1bf016cc01a4db784a52a4e947aa..ef197474ccf008772dfbf2016b00114a98390627 100644
--- a/tests/Unit/SpeciesTest.php
+++ b/tests/Unit/SpeciesTest.php
@@ -39,16 +39,36 @@ final class SpeciesTest extends TestCase
$this->species->nameUsage([], 'root', '123');
}
- public function testShouldGetValidResponseWithValidArguments()
+ public function providerNameUsageList(): iterable
{
- $response = $this->species->nameUsage([]);
+ yield 'Empty args' => [[], 'all', null, null, null, ['offset' => 0, 'limit' => 100, 'endOfRecords' => false]];
+ yield 'Root with UUID args' => [[], 'root', 63306619, 'd7dddbf4-2cf0-4f39-9b2a-bb099caae36c', null, ['offset' => 0, 'limit' => 100, 'endOfRecords' => true]];
+ }
- $this->assertEquals(0, $response['offset']);
- $this->assertEquals(100, $response['limit']);
- $this->assertFalse($response['endOfRecords']);
+ /** @dataProvider providerNameUsageList */
+ public function testShouldGetValidListResponseWithValidArguments(array $args, ?string $data, ?int $key, ?string $uuid, ?string $short_name, array $expected): void
+ {
+ $response = $this->species->nameUsage($args, $data, $key, $uuid, $short_name);
+
+ $this->assertEquals($expected['offset'], $response['offset']);
+ $this->assertEquals($expected['limit'], $response['limit']);
+ $this->assertSame($expected['endOfRecords'], $response['endOfRecords']);
$this->assertIsArray($response['results']);
}
+ public function providerNameUsageRecord(): iterable
+ {
+ yield '' => [[], 'name', 2435098, null, null, ['canonicalName' => 'Puma']];
+ }
+
+ /** @dataProvider providerNameUsageRecord */
+ public function testShouldGetValidRecordResponseWithValidArguments(array $args, ?string $data, ?int $key, ?string $uuid, ?string $short_name, array $expected): void
+ {
+ $response = $this->species->nameUsage($args, $data, $key, $uuid, $short_name);
+
+ $this->assertSame($expected['canonicalName'], $response['canonicalName']);
+ }
+
public function testShouldGetValidResponseFromNameUsageByKey()
{
$response = $this->species->nameUsageByKey(5231190);