-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
242 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
namespace tests; | ||
|
||
use PHPUnit\Framework\MockObject\Exception; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
use GlpiPlugin\Ticketfilter\TicketHandler; | ||
use GlpiPlugin\Ticketfilter\FilterPattern; | ||
|
||
// Needs more work. | ||
// We need to work around the fact that the GLPI objects | ||
// are not available in the plugin repository. | ||
// Maybe create MOC objects instead. | ||
/* | ||
class UserValidationTest extends Testcase { | ||
public function testUserValidation() | ||
{ | ||
$ticket = new TestTicket(); | ||
$ticket->addToFields('status', 1); | ||
$ticketHandler = new TicketHandler($ticket, FilterPattern::getDummyPattern()); | ||
//if(!$this->assertTrue() | ||
} | ||
} | ||
class Ticket { | ||
// Do stuff to represent a real ticket class. | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
// User Params | ||
$glpiUrl = 'https://your.glpi.url'; // Do not include closing slash '/' | ||
$appToken = 'FOUND-IN-SETUP-GENERAL-API-ADD-API-CLIENT'; | ||
$userToken = 'REMOTE-ACCESS-KEY-GENERATED-IN-GLPI-USERTAB'; | ||
$ticketBody = json_encode([ | ||
"input" => [ | ||
"name" => "[TEST TICKET] CREATE TEST TICKET!", // Title | ||
"content" => "Awsom ticket content!", // Content body | ||
"_users_id_requester" => 523, // Match your user | ||
"urgency" => 3, | ||
"itilcategories_id" => 1, // Match your category | ||
"type" => 2, // Request | ||
"status" => 1 // Open. | ||
], | ||
]); | ||
|
||
// Init Curl library; | ||
// I just assume its present, else an fatal error will occur. | ||
$ch = curl_init(); | ||
|
||
// Define HTTP headers to be send by Curl. | ||
$initHeaders = ['Content-Type: application/json', | ||
"Authorization: user_token $userToken", | ||
"App-Token: $appToken", | ||
]; | ||
|
||
// Initialize CURL params. | ||
// See: https://www.php.net/manual/en/function.curl-setopt-array.php | ||
$options = [ | ||
CURLOPT_URL => $glpiUrl.'/apirest.php/initSession', // What URL to open | ||
CURLOPT_HEADER => false, // Do not return header information in response | ||
CURLOPT_POST => true, // Use HTTP POST in the request | ||
CURLOPT_TIMEOUT => 4, // Timeout after 4 attempts | ||
CURLOPT_HTTPHEADER => $initHeaders, // Include de Init headers | ||
CURLOPT_RETURNTRANSFER => true, // Put response in the returnvalue of curl_exec() for further processing | ||
]; | ||
|
||
// perform Curl to receive valid session Token. | ||
try { | ||
curl_setopt_array($ch, $options); | ||
if( ! $result = curl_exec($ch)) { | ||
trigger_error(curl_error($ch)); | ||
} | ||
}catch(Exception $e){ // Might also be ValueError :S | ||
echo 'Caught exception: ', $e->getMessage(), "\n"; | ||
exit; | ||
} | ||
|
||
var_dump($result); | ||
|
||
// A nice thing to do would be to catch the HTTP 200 (OK) here and validate the response. | ||
// I assume the request is succesfull, else an error will be shown by var_dump; | ||
// But im lazy in debugging scripts. | ||
|
||
// Lets create our ticket; | ||
$ticketHeaders = ['Content-Type: application/json', | ||
'App-Token: $appToken', | ||
"Session-Token: ".json_decode($result)->session_token, | ||
]; | ||
|
||
// ReInitialize CURL params. | ||
$options = [ | ||
CURLOPT_URL => $glpiUrl.'/apirest.php/Ticket', | ||
CURLOPT_HEADER => false, | ||
CURLOPT_POST => true, | ||
CURLOPT_TIMEOUT => 4, | ||
CURLOPT_HTTPHEADER => $ticketHeaders, | ||
CURLOPT_POSTFIELDS => $ticketBody, | ||
CURLOPT_RETURNTRANSFER => true, | ||
]; | ||
|
||
// perform Curl to receive valid session Token. | ||
try { | ||
curl_setopt_array($ch, $options); | ||
if( ! $result = curl_exec($ch)) { | ||
trigger_error(curl_error($ch)); | ||
} | ||
}catch(ValueError $e){ | ||
echo 'Caught exception: ', $e->getMessage(), "\n"; | ||
} | ||
|
||
var_dump($result); | ||
|
||
curl_close($ch); | ||
|