public function testAttachBlob() { $client = new NuxeoPhpAutomationClient($this->server->getUrl()); $session = $client->getSession(self::LOGIN, self::PASSWORD); $this->server->enqueue(array(new Response(200))); $session->newRequest("Blob.Attach")->set('params', 'document', array("entity-type" => "string", "value" => self::MYFILE_DOCPATH))->loadBlob(self::NEWFILE_PATH, self::NEWFILE_TYPE)->sendRequest(); $requests = $this->server->getReceivedRequests(true); $this->assertEquals(1, count($requests)); /** @var EntityEnclosingRequest $request */ $request = $requests[0]; $this->assertArrayHasKey('content-type', $request->getHeaders()); $this->assertStringMatchesFormat('multipart/related;boundary="%s";type="application/json+nxrequest";start="request"', $request->getHeader('content-type')->__toString()); $this->assertArrayHasKey('x-nxvoidoperation', $request->getHeaders()); $this->assertEquals('true', $request->getHeader('x-nxvoidoperation')->__toString()); $this->assertArrayHasKey('accept', $request->getHeaders()); $this->assertEquals('application/json+nxentity, */*', $request->getHeader('accept')->__toString()); $this->assertContains($this->readPartFromFile('_files/setblob-part1.txt'), $request->getBody()->__toString()); $this->assertContains($this->readPartFromFile('_files/setblob-part2.txt'), $request->getBody()->__toString()); }
public function tearDown() { $this->server->stop(); parent::tearDown(); }
public function testCanHandleStaleIfErrorWhenRevalidating() { $server = new Server(8000); $server->start(); $server->flush(); $lm = gmdate('c', time() - 60); $server->enqueue(array("HTTP/1.1 200 OK\r\n" . "Date: {$lm}\r\n" . "Cache-Control: must-revalidate, max-age=0, stale-if-error=1200\r\n" . "Last-Modified: {$lm}\r\n" . "Content-Length: 2\r\n\r\nhi")); $cache = new CachePlugin(); $client = new Client($server->getUrl()); $client->addSubscriber($cache); $this->assertEquals(200, $client->get()->send()->getStatusCode()); $this->assertEquals(1, count($server->getReceivedRequests())); // wait for the server to actually stop $server->stop(); while ($server->isRunning()) { sleep(1); } $this->assertEquals(200, $client->get()->send()->getStatusCode()); }
public function testCanHandleStaleIfError() { $server = new Server(8000); $server->start(); $server->flush(); $lm = gmdate('c', time() - 60); $server->enqueue(array("HTTP/1.1 200 OK\r\n" . "Date: Mon, 12 Nov 2012 03:06:37 GMT\r\n" . "Cache-Control: max-age=120, stale-if-error=1200\r\n" . "Last-Modified: {$lm}\r\n" . "Content-Length: 2\r\n\r\nhi")); $cache = new CachePlugin(); $client = new Client($server->getUrl()); $client->addSubscriber($cache); $this->assertEquals(200, $client->get()->send()->getStatusCode()); $this->assertEquals(1, count($server->getReceivedRequests())); $this->assertEquals(200, $client->get()->send()->getStatusCode()); }
protected function tearDown() { $this->server->stop(); }