2020-06-28 00:12:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
|
|
|
|
2022-02-18 18:29:02 +01:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2023-02-17 14:54:17 +01:00
|
|
|
use Zoomyboy\LaravelNami\Data\Group;
|
2022-02-18 18:29:02 +01:00
|
|
|
use Zoomyboy\LaravelNami\Tests\TestCase;
|
2020-06-28 00:12:36 +02:00
|
|
|
|
|
|
|
class GetGroupsTest extends TestCase
|
|
|
|
{
|
2022-02-18 18:29:02 +01:00
|
|
|
public string $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":100}],"responseType":"OK"}';
|
|
|
|
public string $subgroupsResponse = '{ "success": true, "data": [ { "descriptor": "Siebengebirge", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 101300 }, { "descriptor": "Sieg", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100900 }, { "descriptor": "Sieg", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100900 }, { "descriptor": "Voreifel", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 101000 } ], "responseType": "OK" }';
|
|
|
|
public string $subsubgroupsResponse = '{ "success": true, "data": [ { "descriptor": "Silva", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100105 } ], "responseType": "OK" }';
|
2020-06-28 00:12:36 +02:00
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testGetAllGroups(): void
|
2020-06-28 00:12:36 +02:00
|
|
|
{
|
|
|
|
Http::fake([
|
2020-06-28 00:25:41 +02:00
|
|
|
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
2020-06-28 00:12:36 +02:00
|
|
|
]);
|
|
|
|
|
2023-02-17 14:54:17 +01:00
|
|
|
$group = $this->login()->groups()->first();
|
2020-06-28 00:12:36 +02:00
|
|
|
|
2023-02-17 14:54:17 +01:00
|
|
|
$this->assertSame(100, $group->id);
|
|
|
|
$this->assertSame('Group', $group->name);
|
|
|
|
$this->assertNull($group->parentId);
|
2022-03-11 20:20:00 +01:00
|
|
|
Http::assertSent(function ($request) {
|
|
|
|
return 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' == $request->url();
|
2020-06-28 00:12:36 +02:00
|
|
|
});
|
2022-02-18 18:29:02 +01:00
|
|
|
Http::assertSentCount(1);
|
2020-06-28 00:12:36 +02:00
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testHasGroupAccess(): void
|
2020-06-28 00:12:36 +02:00
|
|
|
{
|
|
|
|
Http::fake([
|
2020-06-28 00:25:41 +02:00
|
|
|
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
2020-06-28 00:12:36 +02:00
|
|
|
]);
|
2022-02-18 18:29:02 +01:00
|
|
|
$api = $this->login();
|
2020-06-28 00:12:36 +02:00
|
|
|
|
2022-02-18 18:29:02 +01:00
|
|
|
$this->assertTrue($api->hasGroup(100));
|
|
|
|
$this->assertFalse($api->hasGroup(10101));
|
2020-06-28 00:12:36 +02:00
|
|
|
|
2022-02-18 18:29:02 +01:00
|
|
|
Http::assertSentCount(2);
|
2020-06-28 00:12:36 +02:00
|
|
|
}
|
2020-06-28 02:11:23 +02:00
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function testGetSubgroupsForAGroup(): void
|
2022-02-18 18:29:02 +01:00
|
|
|
{
|
2020-06-28 02:11:23 +02:00
|
|
|
Http::fake([
|
|
|
|
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
2022-03-11 20:20:00 +01:00
|
|
|
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/100' => Http::response($this->subgroupsResponse, 200),
|
2020-06-28 02:11:23 +02:00
|
|
|
]);
|
|
|
|
|
2023-02-17 14:54:17 +01:00
|
|
|
$subgroups = $this->login()->group(100)->children();
|
2020-06-28 02:11:23 +02:00
|
|
|
|
|
|
|
$this->assertEquals([
|
2023-02-17 14:54:17 +01:00
|
|
|
['id' => 101300, 'parentId' => 100, 'name' => 'Siebengebirge'],
|
|
|
|
['id' => 100900, 'parentId' => 100, 'name' => 'Sieg'],
|
|
|
|
['id' => 100900, 'parentId' => 100, 'name' => 'Sieg'],
|
|
|
|
['id' => 101000, 'parentId' => 100, 'name' => 'Voreifel'],
|
2020-06-28 02:11:23 +02:00
|
|
|
], $subgroups->toArray());
|
2022-03-11 20:20:00 +01:00
|
|
|
$subgroups->each(function ($group) {
|
2020-06-28 02:11:23 +02:00
|
|
|
$this->assertInstanceOf(Group::class, $group);
|
|
|
|
});
|
2022-03-11 20:20:00 +01:00
|
|
|
Http::assertSent(function ($request) {
|
|
|
|
return 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' == $request->url();
|
2020-06-28 02:11:23 +02:00
|
|
|
});
|
2022-03-11 20:20:00 +01:00
|
|
|
Http::assertSent(function ($request) {
|
|
|
|
return 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/100' == $request->url();
|
2020-06-28 02:11:23 +02:00
|
|
|
});
|
2022-02-18 18:29:02 +01:00
|
|
|
Http::assertSentCount(2);
|
2020-06-28 02:11:23 +02:00
|
|
|
}
|
2020-06-28 00:12:36 +02:00
|
|
|
}
|