public function createSession()
 {
     $req = $this->newRequest('GET', new URL('http://localhost/'));
     $res = new HttpScriptletResponse();
     $s = newinstance('scriptlet.HttpScriptlet', [], ['needsSession' => function ($request) {
         return true;
     }]);
     $s->service($req, $res);
     $this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new URL(substr($res->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals('/', $redirect->getPath());
     $this->assertEquals(session_id(), $redirect->getParam('psessionid', ''), $redirect->getURL());
 }
Пример #2
0
 public function setArrayParam()
 {
     $u = new URL('http://localhost/');
     $u->setParam('x', ['y', 'z']);
     $this->assertEquals('http://localhost/?x[]=y&x[]=z', $u->getURL());
 }
 public function doCreate()
 {
     $req = $this->newRequest('GET', new URL('http://localhost/'));
     $res = new \scriptlet\HttpScriptletResponse();
     $s = newinstance('scriptlet.xml.XMLScriptlet', [], '{
   public function needsSession($request) { return true; }
 }');
     $s->service($req, $res);
     $this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new URL(substr($res->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals(sprintf('/xml/psessionid=%s/static', session_id()), $redirect->getPath());
     $this->assertEquals([], $redirect->getParams(), $redirect->getURL());
 }
 /**
  * Returns string representation for the URL
  *
  * The URL is build by using sprintf() and the following
  * parameters:
  * <pre>
  * Ord Fill            Example
  * --- --------------- --------------------
  *   1 scheme          http
  *   2 host            host.foo.bar
  *   3 path            /foo/bar/index.html
  *   4 dirname(path)   /foo/bar/
  *   5 basename(path)  index.html
  *   6 query           a=b&b=c
  *   7 session id      cb7978876218bb7
  *   8 fraction        #test
  * </pre>
  *
  * @return string
  */
 public function getURL()
 {
     $sessionId = $this->getSessionId();
     if ($sessionId) {
         $cloned = clone $this;
         $cloned->setParam('psessionid', $sessionId);
         $cloned->setSessionId(null);
         return $cloned->getURL();
     }
     return parent::getURL();
 }