/** * @covers ::createHeaders */ public function test_createHeaders() { $Called = 0; $this->Browser->_on('Headers', function () use(&$Called) { $Called++; }); $Headers = $this->Browser->createHeaders(); $this->assertArrayHasKey('User-Agent', $Headers, 'Nexus::getHeaders() Failed to set UserAgent'); $this->assertContainsOnlyInstancesOf('\\BLW\\Type\\MIME\\IHeader', $Headers, 'Nexus::getHeaders() Returned an invalid value'); $this->assertSame(1, $Called, 'Nexus::getHeaders() Failed to trigger Headers event'); }
/** * @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'); }