Пример #1
0
    /**
     * @covers ::createGET
     * @covers ::_addHeaders
     */
    public function test_createGet()
    {
        $Expected = <<<EOT
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
Accept-Language: en-us, en;q=0.5
Accept-Encoding: gzip, deflate
Test: foo1
Test: foo2


EOT;
        # Valid Arguments
        $URI = new GenericURI('http://example.com');
        $Request = $this->Factory->createGET($URI, $URI, $this->Headers);
        $this->assertEquals($URI, $Request->URI, 'IFactory::createGET() Failed to set request URI');
        $this->assertEquals(IRequest::GET, $Request->Type, 'IFactory::createGET() Failed to set request Type');
        $this->assertEquals($Expected, strval($Request), 'IFactory::createGET() Produced an invalid request');
        # Invalid arguments
        for ($args = $this->generateInvalidGET(); list($k, list($URI, $BaseURI, $Headers)) = each($args);) {
            try {
                $this->Factory->createGET($URI, $BaseURI, $Headers);
                $this->fail('Failed to generate exception with invalid arguments');
            } catch (InvalidArgumentException $e) {
            }
        }
    }
Пример #2
0
 /**
  * @covers ::translate
  * @covers ::_translateHeaders
  * @covers ::_translateURI
  * @covers ::_translateReferer
  */
 public function test_translate()
 {
     $Expected = array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_MAXREDIRS => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array('Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8', 'Accept-Language: en-us, en;q=0.5', 'Cache-Control: max-age=0', 'Content-Type: application/x-www-form-urlencoded'), CURLOPT_ENCODING => '', CURLOPT_AUTOREFERER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYPEER => 1, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_URL => 'http://example.com', CURLOPT_PORT => 1000, CURLOPT_USERPWD => 'user:pass', CURLOPT_REFERER => 'about:nothing', CURLOPT_USERAGENT => 'Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.72 Safari/537.36', CURLOPT_POSTFIELDS => 'foo=bar', CURLOPT_COOKIEFILE => $this->Client->createCookieFile()->getPathname(), CURLOPT_COOKIEJAR => $this->Client->createCookieFile()->getPathname());
     $Factory = new RequestFactory();
     $Browser = new Nexus($this->Client, new Config(array('MaxHistory' => 10)));
     $Request = $Factory->createPOST(new GenericURI('http://*****:*****@example.com:1000'), new GenericURI('about:nothing'), array('foo' => 'bar'), $Browser->createHeaders());
     $this->Client->send($Request);
     $this->assertEquals($Expected, $this->Client->translate($Request), 'cURL::translate() Returned an invalid value');
     unset($Request->Referer);
     $Request->getHeader()->offsetSet('Referer', new Referer(new GenericURI('about:nothing')));
     $this->assertEquals($Expected, $this->Client->translate($Request), 'cURL::translate() Returned an invalid value');
     $Request->getHeader()->offsetUnset('Referer');
     unset($Expected[CURLOPT_REFERER]);
     $this->assertEquals($Expected, $this->Client->translate($Request), 'cURL::translate() Returned an invalid value');
     # Inalid request
     $this->assertSame(array(), $this->Client->translate($Factory->createGET(new GenericURI('about:nothing'), new GenericURI('about:nothing'))), 'cURL::translate() Returned an invalid value');
 }