fetch() public method

Dispatches the content to the route's socket.
public fetch ( integer $timeout ) : SimpleHttpResponse
$timeout integer Connection timeout.
return SimpleHttpResponse A response which may only have an error, but hopefully has a complete web page.
コード例 #1
0
ファイル: live_test.php プロジェクト: adamfranco/harmoni
 function testHttp()
 {
     $http = new SimpleHttpRequest("www.lastcraft.com/test/network_confirm.php?gkey=gvalue");
     $http->setCookie(new SimpleCookie("ckey", "cvalue"));
     $this->assertIsA($reponse = $http->fetch(), "SimpleHttpResponse");
     $this->assertEqual($reponse->getResponseCode(), 200);
     $this->assertEqual($reponse->getMimeType(), "text/html");
     $this->assertWantedPattern('/A target for the SimpleTest test suite/', $reponse->getContent());
     $this->assertWantedPattern('/gkey=gvalue/', $reponse->getContent());
     $this->assertWantedPattern('/ckey=cvalue/', $reponse->getContent());
 }
コード例 #2
0
ファイル: http_test.php プロジェクト: VasuLief/simpletest
 public function testContentHeadersCalculatedWithXmlEntityBody()
 {
     $socket = new MockSimpleSocket();
     $socket->expectAt(0, 'write', array("Content-Length: 27\r\n"));
     $socket->expectAt(1, 'write', array("Content-Type: text/xml\r\n"));
     $socket->expectAt(2, 'write', array("\r\n"));
     $socket->expectAt(3, 'write', array("<a><b>one</b><c>two</c></a>"));
     $route = new MockSimpleRoute();
     $route->setReturnReference('createConnection', $socket);
     $route->expect('createConnection', array('POST', 15));
     $request = new SimpleHttpRequest($route, new SimplePostEncoding('<a><b>one</b><c>two</c></a>', 'text/xml'));
     $this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
 }
コード例 #3
0
ファイル: http_test.php プロジェクト: Hassanj343/candidats
 function testContentHeadersCalculated()
 {
     $socket = new MockSimpleSocket();
     $socket->expectArgumentsAt(0, 'write', array("Content-Length: 3\r\n"));
     $socket->expectArgumentsAt(1, 'write', array("Content-Type: application/x-www-form-urlencoded\r\n"));
     $socket->expectArgumentsAt(2, 'write', array("\r\n"));
     $socket->expectArgumentsAt(3, 'write', array("a=A"));
     $route = new MockSimpleRoute();
     $route->setReturnReference('createConnection', $socket);
     $route->expectArguments('createConnection', array('POST', 15));
     $request = new SimpleHttpRequest($route, new SimplePostEncoding(array('a' => 'A')));
     $this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
 }
コード例 #4
0
ファイル: browser.php プロジェクト: adamfranco/harmoni
 /**
  *    Fetches a URL performing the standard tests.
  *    @param $url        Target to fetch as string.
  *    @param $request    Test version of SimpleHttpRequest.
  *    @return            Content of page.
  *    @access public
  */
 function fetchUrl($url, $request = false)
 {
     if (!is_object($request)) {
         $request = new SimpleHttpRequest($url);
     }
     foreach ($this->_cookie_jar->getValidCookies() as $cookie) {
         $request->setCookie($cookie);
     }
     $this->_response = $request->fetch();
     $this->_checkExpectations($url, $this->_response);
     foreach ($this->_response->getNewCookies() as $cookie) {
         $parsed_url = new SimpleUrl($url);
         if ($parsed_url->getHost()) {
             $cookie->setHost($parsed_url->getHost());
         }
         $this->_cookie_jar->setCookie($cookie);
     }
     return $this->_response->getContent();
 }
コード例 #5
0
ファイル: http_test.php プロジェクト: adamfranco/harmoni
 function testMultipleCookieWriting()
 {
     $request = new SimpleHttpRequest("a.valid.host/and/path");
     $request->setCookie(new SimpleCookie("a", "A"));
     $request->setCookie(new SimpleCookie("b", "B"));
     $socket =& new MockSimpleSocket($this);
     $socket->setReturnValue("isError", false);
     $socket->expectArgumentsSequence(2, "write", array("Cookie: a=A;b=B\r\n"));
     $request->fetch($socket);
     $socket->tally();
 }