public function testMalformedContentType() { $httpRequest = $this->getMockBuilder(Client::class)->setMethods(['post'])->getMock(); $httpResponse = $this->getMock(MessageInterface::class); $httpRequest->expects($this->once())->method('post')->with('https://www.url.com/', ['form_params' => ['token' => 'token', 'part' => 'unknown', 'command' => 'unknown']])->willReturn($httpResponse); $httpResponse->expects($this->once())->method('getHeader')->with('content-type')->willReturn(['application/unknown; UTF-8']); $this->setExpectedException(ResponseException::class, 'Wrong content type, malformed charset: UTF-8'); $connection = new Connection($httpRequest, 'https://www.url.com/', 'token'); $response = $connection->command('unknown', 'unknown'); $response->getBody(); }
public function testText() { $httpRequest = $this->getMockBuilder(Client::class)->setMethods(['post'])->getMock(); $httpResponse = $this->getMock(MessageInterface::class); $httpRequest->expects($this->once())->method('post')->with('https://www.url.com/', ['form_params' => ['token' => 'token', 'part' => 'organization', 'command' => 'login', 'uid' => 'username', 'password' => 'password']])->willReturn($httpResponse); $httpResponse->expects($this->once())->method('getBody')->willReturn('true'); $httpResponse->expects($this->once())->method('getHeader')->with('content-type')->willReturn(['text/txt']); $connection = new Connection($httpRequest, 'https://www.url.com/', 'token'); $response = $connection->command('organization', 'login', ['uid' => 'username', 'password' => 'password']); $this->assertInstanceOf(Response::class, $response); $this->assertEquals('true', $response->getBody()); }
public function testJsonWithCharset() { $httpRequest = $this->getMockBuilder(Client::class)->setMethods(['post'])->getMock(); $httpResponse = $this->getMock(MessageInterface::class); $httpRequest->expects($this->once())->method('post')->willReturn($httpResponse); $httpResponse->expects($this->once())->method('getBody')->willReturn(json_encode([['id' => 1, 'name' => 'Top Element']])); $httpResponse->expects($this->once())->method('getHeader')->with('content-type')->willReturn(['application/json; charset=UTF-8']); $connection = new Connection($httpRequest, 'https://www.url.com/', 'token'); $response = $connection->command('organization', 'tree'); $this->assertEquals('application/json', $response->getContentType()); $this->assertEquals('UTF-8', $response->getCharset()); $this->assertContainsOnlyInstancesOf(StdClass::class, $response->getBody()); $this->assertEquals('Top Element', $response->getBody()[0]->name); }
<?php require_once '../vendor/autoload.php'; use Genkgo\Api\Connection; use GuzzleHttp\Client; $config = (require_once 'config.php'); $connection = new Connection(new Client(), $config['url'], $config['token']); $result = $connection->command('organization', 'login', ['uid' => 'test', 'password' => 'test']); var_dump($result);
<?php require_once '../vendor/autoload.php'; use Genkgo\Api\Connection; use GuzzleHttp\Client; $config = (require_once 'config.php'); $connection = new Connection(new Client(), $config['url'], $config['token']); $folder = $connection->command('organization', 'find', ['name' => 'Aanmeldingen'])->getBody(); $newEntry = $connection->command('organization', 'create', ['id' => $folder->id, 'name' => 'Weergave Naam', 'objectclass' => 'associationMember'])->getBody(); $result = $connection->command('organization', 'modify', ['id' => $newEntry->id, 'properties' => ['givenname' => 'Voornaam', 'middlename' => 'Tussenvoegsel', 'surname' => 'Achternaam', 'gender' => 'male', 'birthdate' => '2000-01-01', 'initials' => 'V.', 'title_pre' => 'drs.', 'title_post' => 'MSc', 'mail' => '*****@*****.**', 'secondarymail' => '*****@*****.**', 'telephonenumber' => '+31 6 1000 1000', 'homephone' => '+31 6 1000 1000', 'mobile' => '+31 6 1000 1000', 'url' => 'https://www.genkgo.com', 'htmlmail' => true, 'smsmail' => true, 'street' => 'Straat', 'postalcode' => '1000AA', 'city' => 'Amsterdam', 'country' => 'Nederland', 'state' => 'Noord-Holland', 'billingaccount' => 'NL91ABNA0417164300']]); var_dump($result); exit;