Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 90ac326

Browse files
DIOHz0rajsb85
authored andcommitted
test(item): added new tests for client class
1 parent 200a7eb commit 90ac326

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

tests/unit/Client.php

+39-11
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,65 @@
3737
*/
3838
class Client extends BaseTestCase {
3939

40+
/**
41+
* @tags testInitSession
42+
*/
4043
public function testInitSession() {
4144
$client = $this->newTestedInstance(GLPI_URL);
4245

4346
// Test invalid credentials
4447
$this->exception(function () use ($client) {
4548
$client->initSessionByCredentials('glpi', 'bad password');
46-
})->isIdenticalTo($this->exception);
49+
})->hasMessage('Cannot connect to api');
4750

4851
// Test valid credentials
4952
$success = $client->initSessionByCredentials('glpi', 'glpi');
5053
$this->boolean($success)->isTrue();
5154

5255
// Test invalid credentials for user token
53-
$this->exception(function () use ($client){
56+
$this->exception(function () use ($client) {
5457
$client->initSessionByUserToken('loremIpsum');
55-
})->isIdenticalTo($this->exception);
56-
}
57-
58-
/*public function testComputer() {
59-
$client = $this->newTestedInstance(GLPI_URL);
60-
$this->boolean($client->initSessionByCredentials('glpi', 'glpi'))->isTrue();
58+
})->hasMessage('Cannot connect to api');
6159

62-
$response = $client->computer('post', ['name' => 'computer 0001']);
63-
$this->object($response)->isInstanceOf(\Psr\Http\Message\ResponseInterface::class);
64-
}*/
60+
// TODO: Test valid credentials for user token
61+
/*$response = $client->initSessionByUserToken('loremIpsum');
62+
$this->boolean($success)->isTrue();*/
63+
}
6564

65+
/**
66+
* @tags testGetFullSession
67+
*/
6668
public function testGetFullSession() {
6769
$this->loginSuperAdmin();
6870
$response = $this->client->getFullSession();
6971
$this->assertJsonResponse($response);
72+
}
73+
74+
/**
75+
* @tags testKillSession
76+
*/
77+
public function testKillSession() {
78+
$this->loginSuperAdmin();
79+
$client = $this->client;
80+
$response = $client->killSession();
81+
$this->boolean($response)->isTrue();
82+
83+
// Test invalid kill session
84+
$this->exception(function () use ($client) {
85+
$client->killSession();
86+
})->hasMessage('session_token seems invalid');
87+
}
7088

89+
90+
/**
91+
* @tags testGetGlpiConfig
92+
*/
93+
public function testGetGlpiConfig() {
94+
$this->loginSuperAdmin();
95+
$response = $this->client->getGlpiConfig();
96+
$this->assertJsonResponse($response);
97+
$arrayOfStdClass = json_decode($response['body']);
98+
$this->boolean(property_exists($arrayOfStdClass, 'cfg_glpi'))->isTrue();
7199
}
72100

73101
}

0 commit comments

Comments
 (0)