public function testDetails() { $json = '{ "account": "cperformance", "accountType": "GLOBAL", "capabilityFlags": [ "CAN_SEND", "CAN_SIGN", "CAN_REPLACE_SIGNER" ], "channel": "_default", "company": "John Law Group", "email": "*****@*****.**", "firstName": "Bill", "initials": "NJ", "lastName": "John", "passwordExpiration": "2021-11-11T08:26:30-08:00" }'; $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); $stream = Stream::factory($json); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $users = new Users('465789', $transport); $response = $users->details('123456'); $this->assertInstanceOf('Echosign\\Responses\\UserDetailsInfo', $response); $this->assertEquals('*****@*****.**', $response->getEmail()); $capabilities = $response->getCapabilityFlags(); $this->assertEquals(3, count($capabilities)); }
protected function initViews() { $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); $json = '{"viewUrl":"http://localhost"}'; $stream = Stream::factory($json); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $this->views = new Views('465789', $transport); return $this->views; }
public function testGetBaseUris() { $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); // mock the request $json = ["api_access_point" => "https://api.echosign.com", "web_access_point" => "https://secure.echosign.com"]; $stream = Stream::factory(json_encode($json)); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $baseUris = new BaseUris('12345', $transport); $baseUriInfo = $baseUris->getBaseUris(); $this->assertInstanceOf('Echosign\\Responses\\BaseUriInfo', $baseUriInfo); $this->assertEquals($json["api_access_point"], $baseUriInfo->getApiAccessPoint()); $this->assertEquals($json["web_access_point"], $baseUriInfo->getWebAccessPoint()); }
public function testCreate() { $returnJson = '{ "result": "SUCCESS", "recipientEmail": "*****@*****.**" }'; $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); $stream = Stream::factory($returnJson); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $reminder = new Reminders('123456', $transport); $creationInfo = new ReminderCreationInfo('1234', 'have a great day'); $response = $reminder->create($creationInfo); $this->assertInstanceOf('Echosign\\Responses\\ReminderCreationResult', $response); $this->assertEquals('SUCCESS', $response->getResult()); $this->assertEquals('*****@*****.**', $response->getRecipientEmail()); }
public function testHandleError() { $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); // mock the request $json = ['code' => 'INVALID_FACE', 'message' => 'failed']; $stream = Stream::factory(json_encode($json)); $mock = new Mock([new Response(401, ['Content-Type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $request = new \Echosign\Requests\GetRequest('12345'); $request->setRequestUrl('http://localhost'); try { $response = $transport->handleRequest($request); } catch (JsonApiResponseException $e) { $this->assertEquals(401, $e->getCode()); $this->assertEquals('INVALID_FACE', $e->getApiCode()); $this->assertEquals('failed', $e->getMessage()); } }
public function testCreateDocument() { $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); $docId = md5(time()); $json = ['transientDocumentId' => $docId]; $stream = Stream::factory(json_encode($json)); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $td = new TransientDocuments('12345', $transport); // create a crap sample file. $file = tempnam(sys_get_temp_dir(), 'TMP'); $fp = fopen($file, 'w+'); fwrite($fp, "hey look, I just work here okay?"); fclose($fp); $response = $td->create($file); $this->assertInstanceOf('Echosign\\Responses\\TransientDocumentResponse', $response); $this->assertEquals($docId, $response->getTransientDocumentId()); }
public function testResult() { $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); // mock the request $json = '{ "events": [ { "agreementAssetId": "2BAABLblqZhARJcIh9hAZIrdTii8G2wvQzCNPWf9x7Mb83vrC6TzIlBunHE2m9f-qenIfQ9Vl2aE*", "agreementAssetName": "grid math.pdf", "agreementAssetType": "agreement", "documentHistoryEvent": { "actingUserEmail": "*****@*****.**", "date": "2014-10-21T09:40:00-07:00", "description": "Sent out for signature to test@gmail.com", "participantEmail": "*****@*****.**", "type": "SIGNATURE_REQUESTED" } } ], "nextPageCursor": "BwELAQYAAgEAAAICABC3ZbmoWj1h0-Yh4J_rTKgWDqg3GHWhshZTliKBxcTxfLM6jDjlKoH4Kg**" }'; $jsonArray = json_decode($json, true); $stream = Stream::factory($json); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); #$log = new Monolog\Logger('test'); #$handler = new Monolog\Handler\TestHandler(); #$log->pushHandler( $handler ); $search = new Search('123465', $transport); #$search->setLogger( $log ); $response = $search->result('search_id_doesnt_matter', 'lame_page_cursor'); $this->assertInstanceOf('Echosign\\Responses\\AgreementAssetEventGetResponse', $response); $events = $response->getEvents(); $this->assertEquals(1, count($events)); $this->assertEquals($jsonArray['nextPageCursor'], $response->getNextPageCursor()); //print_r( $handler->getRecords() ); }
public function testCancel() { $returnJson = '{ "result": "CANCELLED" }'; $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); $stream = Stream::factory($returnJson); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $agreement = new Agreements('12335', $transport); $info = new \Echosign\RequestBuilders\AgreementStatusUpdateInfo(); $response = $agreement->cancel('12345', $info); $this->assertInstanceOf('Echosign\\Responses\\AgreementStatusUpdateResponse', $response); $this->assertEquals('CANCELLED', $response->getResult()); }
public function testCombinedDocument() { $documentId = substr(md5(time()), 8) . '.pdf'; $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $documentId; $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); /* HTTP/1.1 200 OK Date: Fri, 30 Jan 2015 00:59:05 GMT Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 Last-Modified: Fri, 21 Nov 2014 20:57:09 GMT ETag: "2265-50864b0336560" Accept-Ranges: bytes Content-Length: 8805 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: application/pdf */ $sampleFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files/sample.pdf'; $stream = Stream::factory(file_get_contents($sampleFile)); $mock = new Mock([new Response(200, ['Content-Type' => 'application/pdf', 'Content-Length' => filesize($sampleFile)], $stream)]); $client->getEmitter()->attach($mock); $agreement = new LibraryDocuments('12335', $transport); file_put_contents($file, $stream->__toString()); $response = $agreement->combinedDocument('123kf', $file); $this->assertTrue($response); }