summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/Web/THttpRequestTest.php218
1 files changed, 147 insertions, 71 deletions
diff --git a/tests/unit/Web/THttpRequestTest.php b/tests/unit/Web/THttpRequestTest.php
index 0933fb05..e69503b1 100644
--- a/tests/unit/Web/THttpRequestTest.php
+++ b/tests/unit/Web/THttpRequestTest.php
@@ -8,77 +8,153 @@ Prado::using('System.Web.THttpRequest');
*/
class THttpRequestTest extends PHPUnit_Framework_TestCase {
- public function testInit() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testStripSlashes() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testSetUrlFormat() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetUrl() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetRequestMethod() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetIsSecureConnection() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetPathInfo() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetQueryString() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetRequestUri() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetApplicationUrl() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetApplicationFilePath() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetServerName() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetServerPort() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetUrlReferrer() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetBrowser() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetUserAgent() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetUserHostAddress() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
-
- public function testGetUserHost() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public static $app = null;
+
+ public function setUp() {
+
+ // Fake environment variables
+ $_SERVER['HTTP_HOST'] = 'localhost';
+ $_SERVER['SERVER_NAME'] = 'localhost';
+ $_SERVER['SERVER_PORT'] = '80';
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $_SERVER['REQUEST_URI'] = '/demos/personal/index.php?page=Links';
+ $_SERVER['SCRIPT_NAME'] = '/demos/personal/index.php';
+ $_SERVER['PHP_SELF'] = '/demos/personal/index.php';
+ $_SERVER['QUERY_STRING'] = 'page=Links';
+ $_SERVER['SCRIPT_FILENAME'] = __FILE__;
+ $_SERVER['PATH_INFO'] = __FILE__;
+ $_SERVER['HTTP_REFERER'] = 'http://www.pradosoft.com';
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+ $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3';
+ $_SERVER['REMOTE_HOST'] = 'localhost';
+
+ if(self::$app === null) {
+ self::$app = new TApplication('app');
+ }
+ }
+
+ public function testInit() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('', $request->getUrlManager());
+ }
+
+ public function testStripSlashes() {
+ $request = new THttpRequest();
+ $data = 'some\\text\\with\\slashes';
+ self::assertEquals('sometextwithslashes', $request->stripSlashes($data));
+ }
+
+ public function testGetUrl() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertType('TUri', $request->getUrl());
+ }
+
+ public function testGetUrlManager() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals(null, $request->getUrlManager());
+ }
+
+ public function testSetUrlManager() {
+ throw new PHPUnit_Framework_IncompleteTestError();
+ }
+
+ public function testSetUrlFormat() {
+ throw new PHPUnit_Framework_IncompleteTestError();
+ }
+
+ public function testGetRequestType() {
+ $request = new THttpRequest();
+ self::assertEquals('GET', $request->getRequestType());
+ }
+
+ public function testGetIsSecureConnection() {
+ $request = new THttpRequest();
+ self::assertEquals(false, $request->getIsSecureConnection());
+ }
+
+ public function testGetPathInfo() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals(__FILE__, $request->getPathInfo());
+ }
+
+ public function testGetQueryString() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('page=Links', $request->getQueryString());
+ }
+
+ public function testGetRequestUri() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('/demos/personal/index.php?page=Links', $request->getRequestUri());
+ }
+
+ public function testGetBaseUrl() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('http://localhost', $request->getBaseUrl());
+ }
+
+ public function testGetApplicationUrl() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('/demos/personal/index.php', $request->getApplicationUrl());
+ }
+
+ public function testGetAbsoluteApplicationUrl() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('http://localhost/demos/personal/index.php', $request->getAbsoluteApplicationUrl());
+ }
+
+ public function testGetApplicationFilePath() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals(__FILE__, $request->getApplicationFilePath());
+ }
+
+ public function testGetServerName() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('localhost', $request->getServerName());
+ }
+
+ public function testGetServerPort() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('80', $request->getServerPort());
+ }
+
+ public function testGetUrlReferrer() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('http://www.pradosoft.com', $request->getUrlReferrer());
+ }
+
+ public function testGetBrowser() {
+ throw new PHPUnit_Framework_IncompleteTestError();
+ }
+
+ public function testGetUserAgent() {
+ $request = new THttpRequest();
+ self::assertEquals('Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3', $request->getUserAgent());
+ }
+
+ public function testGetUserHostAddress() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('127.0.0.1', $request->getUserHostAddress());
+ }
+
+ public function testGetUserHost() {
+ $request = new THttpRequest();
+ $request->init(null);
+ self::assertEquals('localhost', $request->getUserHost());
+ }
public function testGetAcceptTypes() {
throw new PHPUnit_Framework_IncompleteTestError();