$t->diag('Initialization'); $b = new sfWebBrowser(array(), $adapter); $t->is($b->getUserAgent(), '', 'a new browser has an empty user agent'); $t->is($b->getResponseText(), '', 'a new browser has an empty response'); $t->is($b->getResponseCode(), '', 'a new browser has an empty response code'); $t->is($b->getResponseHeaders(), array(), 'a new browser has empty reponse headers'); /*******************/ /* Utility methods */ /*******************/ $t->diag('Utility methods'); $b = new sfWebBrowser(array(), $adapter); $t->is($b->setUserAgent('foo bar')->getUserAgent(), 'foo bar', 'setUserAgent() sets the user agent'); $t->is($b->setResponseText('foo bar')->getResponseText(), 'foo bar', 'setResponseText() extracts the response'); $t->is($b->setResponseCode('foo 123 bar')->getResponseCode(), '123', 'setResponseCode() extracts the three-digits code'); $t->is($b->setResponseCode('foo 12 bar')->getResponseCode(), '', 'setResponseCode() fails silently when response status is incorrect'); $t->is_deeply($b->setResponseHeaders(array('HTTP1.1 200 OK', 'foo: bar', 'bar: baz'))->getResponseHeaders(), array('Foo' => 'bar', 'Bar' => 'baz'), 'setResponseHeaders() extracts the headers array'); $t->is_deeply($b->setResponseHeaders(array('ETag: "535a8-9fb-44ff4a13"', 'WWW-Authenticate: Basic realm="Myself"'))->getResponseHeaders(), array('ETag' => '"535a8-9fb-44ff4a13"', 'WWW-Authenticate' => 'Basic realm="Myself"'), 'setResponseHeaders() extracts the headers array and accepts response headers with several uppercase characters'); $t->is_deeply($b->setResponseHeaders(array('HTTP1.1 200 OK', 'foo: bar', 'bar:baz', 'baz:bar'))->getResponseHeaders(), array('Foo' => 'bar'), 'setResponseHeaders() ignores malformed headers'); /**************/ /* Exceptions */ /**************/ $t->diag('Exceptions'); $b = new sfWebBrowser(array(), $adapter); try { $b->get('htp://askeet'); $t->fail('get() throws an exception when passed an uri which is neither http nor https'); } catch (Exception $e) { $t->pass('get() throws an exception when passed an uri which is neither http nor https'); } /**********************/ /* Simple GET request */