Skip to content

Commit

Permalink
Change _setHost() on CakeSession to accept parameter to ease testing,…
Browse files Browse the repository at this point in the history
… add test cases for host setting, and port stripping.
  • Loading branch information
predominant authored and markstory committed Jul 28, 2010
1 parent a63474a commit ca65689
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cake/libs/cake_session.php
Expand Up @@ -143,7 +143,7 @@ public static function init($base = null, $start = true) {
self::_setupDatabase();
if ($start === true) {
self::_setPath($base);
self::_setHost();
self::_setHost(env('HTTP_HOST'));
self::start();
}
if (isset($_SESSION) || $start === true) {
Expand Down Expand Up @@ -173,13 +173,13 @@ protected static function _setPath($base = null) {
}

/**
* Set the host
* Set the host name
*
* @param string $host Hostname
* @return void
*/
protected static function _setHost() {
self::$host = env('HTTP_HOST');

protected static function _setHost($host) {
self::$host = $host;
if (strpos(self::$host, ':') !== false) {
self::$host = substr(self::$host, 0, strpos(self::$host, ':'));
}
Expand Down
28 changes: 28 additions & 0 deletions cake/tests/cases/libs/cake_session.test.php
Expand Up @@ -25,6 +25,10 @@ class TestCakeSession extends CakeSession {
public static function setUserAgent($value) {
self::$_userAgent = $value;
}

public static function setHost($host) {
self::_setHost($host);
}
}

/**
Expand Down Expand Up @@ -125,6 +129,30 @@ function testCakeSessionPathContainsQuestion() {
$this->assertEqual('/', TestCakeSession::$path);
}

/**
* testSetHost
*
* @access public
* @return void
*/
function testSetHost() {
TestCakeSession::init();
TestCakeSession::setHost('cakephp.org');
$this->assertEqual('cakephp.org', TestCakeSession::$host);
}

/**
* testSetHostWithPort
*
* @access public
* @return void
*/
function testSetHostWithPort() {
TestCakeSession::init();
TestCakeSession::setHost('cakephp.org:443');
$this->assertEqual('cakephp.org', TestCakeSession::$host);
}

/**
* testCheck method
*
Expand Down

0 comments on commit ca65689

Please sign in to comment.