Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.4' into 3.0
Browse files Browse the repository at this point in the history
Conflicts:
	lib/Cake/Model/Datasource/Session.php
  • Loading branch information
markstory committed Jun 22, 2013
2 parents ad3a379 + dcf7df3 commit 804d99b
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 19 deletions.
9 changes: 6 additions & 3 deletions lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -217,7 +217,7 @@ class AuthComponent extends Component {
* Error to display when user attempts to access an object or action to which they do not have
* access.
*
* @var string
* @var string|bool Error message or boolean false to suppress flash message
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#AuthComponent::$authError
*/
public $authError = null;
Expand Down Expand Up @@ -437,7 +437,7 @@ protected function _setDefaults() {
'authError' => __d('cake', 'You are not authorized to access that location.')
);
foreach ($defaults as $key => $value) {
if (empty($this->{$key})) {
if (!isset($this->{$key}) || $this->{$key} === true) {
$this->{$key} = $value;
}
}
Expand Down Expand Up @@ -703,7 +703,7 @@ public function redirect($url = null) {
}

/**
* Get the URL a use should be redirected to upon login.
* Get the URL a user should be redirected to upon login.
*
* Pass an URL in to set the destination a user should be redirected to upon
* logging in.
Expand Down Expand Up @@ -821,6 +821,9 @@ public function loggedIn() {
* @return void
*/
public function flash($message) {
if ($message === false) {
return;
}
$this->Session->setFlash($message, $this->flash['element'], $this->flash['params'], $this->flash['key']);
}

Expand Down
32 changes: 19 additions & 13 deletions lib/Cake/Model/Datasource/Session.php
Expand Up @@ -208,7 +208,7 @@ public static function started() {
* @return boolean True if variable is there
*/
public static function check($name = null) {
if (!static::started() && !static::start()) {
if (!static::start()) {
return false;
}
if (empty($name)) {
Expand All @@ -218,9 +218,17 @@ public static function check($name = null) {
}

/**
* Returns the Session id
* Returns the session id.
* Calling this method will not auto start the session. You might have to manually
* assert a started session.
*
* @param string $id
* Passing an id into it, you can also replace the session id if the session
* has not already been started.
* Note that depending on the session handler, not all characters are allowed
* within the session id. For example, the file session handler only allows
* characters in the range a-z A-Z 0-9 , (comma) and - (minus).
*
* @param string $id Id to replace the current session id
* @return string Session id
*/
public static function id($id = null) {
Expand Down Expand Up @@ -249,7 +257,7 @@ public static function delete($name) {
}

/**
* Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself
* Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself.
*
* @param array $old Set of old variables => values
* @param array $new New set of variable => value
Expand Down Expand Up @@ -328,10 +336,10 @@ protected static function _validAgentAndTime() {
}

/**
* Get / Set the userAgent
* Get / Set the user agent
*
* @param string $userAgent Set the userAgent
* @return void
* @param string $userAgent Set the user agent
* @return string Current user agent
*/
public static function userAgent($userAgent = null) {
if ($userAgent) {
Expand All @@ -350,7 +358,7 @@ public static function userAgent($userAgent = null) {
* @return mixed The value of the session variable
*/
public static function read($name = null) {
if (!static::started() && !static::start()) {
if (!static::start()) {
return false;
}
if (is_null($name)) {
Expand Down Expand Up @@ -388,7 +396,7 @@ protected static function _returnSessionVars() {
* @return boolean True if the write was successful, false if the write failed
*/
public static function write($name, $value = null) {
if (!static::started() && !static::start()) {
if (!static::start()) {
return false;
}
if (empty($name)) {
Expand All @@ -413,9 +421,7 @@ public static function write($name, $value = null) {
* @return void
*/
public static function destroy() {
if (!self::started()) {
self::start();
}
self::start();
session_destroy();
self::clear();
}
Expand Down Expand Up @@ -618,7 +624,7 @@ protected static function _startSession() {
* @return void
*/
protected static function _checkValid() {
if (!static::started() && !static::start()) {
if (!static::start()) {
static::$valid = false;
return false;
}
Expand Down
46 changes: 46 additions & 0 deletions lib/Cake/Test/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -689,13 +689,59 @@ public function testRedirectToUnauthorizedRedirect() {
array('on', 'redirect'),
array($request, $response)
);
$this->Auth->Session = $this->getMock(
'SessionComponent',
array('setFlash'),
array($Controller->Components)
);

$expected = array(
'controller' => 'no_can_do', 'action' => 'jack'
);
$Controller->expects($this->once())
->method('redirect')
->with($this->equalTo($expected));
$this->Auth->Session->expects($this->once())
->method('setFlash');
$this->Auth->startup($Controller);
}

/**
* testRedirectToUnauthorizedRedirectSuppressedAuthError
*
* @return void
*/
public function testRedirectToUnauthorizedRedirectSuppressedAuthError() {
$url = '/party/on';
$this->Auth->request = $CakeRequest = new CakeRequest($url);
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->authorize = array('Controller');
$this->Auth->login(array('username' => 'admad', 'password' => 'cake'));
$this->Auth->unauthorizedRedirect = array(
'controller' => 'no_can_do', 'action' => 'jack'
);
$this->Auth->authError = false;

$CakeResponse = new CakeResponse();
$Controller = $this->getMock(
'Controller',
array('on', 'redirect'),
array($CakeRequest, $CakeResponse)
);
$this->Auth->Session = $this->getMock(
'SessionComponent',
array('setFlash'),
array($Controller->Components)
);

$expected = array(
'controller' => 'no_can_do', 'action' => 'jack'
);
$Controller->expects($this->once())
->method('redirect')
->with($this->equalTo($expected));
$this->Auth->Session->expects($this->never())
->method('setFlash');
$this->Auth->startup($Controller);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Cake/Test/TestCase/Model/ModelWriteTest.php
Expand Up @@ -6549,7 +6549,9 @@ public function testSaveAllFieldListValidateBelongsTo() {
));
$TestModel->saveAll($data, array('fieldList' => $fieldList));

$result = $TestModel->find('all');
$result = $TestModel->find('all', array(
'order' => 'Post.id ASC',
));
$expected = array(
'Post' => array (
'id' => '4',
Expand Down
24 changes: 24 additions & 0 deletions lib/Cake/Test/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -6697,6 +6697,30 @@ public function testYearAutoExpandRange() {
$this->assertEquals($result, $expected);
}

/**
* testInputDateMaxYear method
*
* Let's say we want to only allow users born from 2006 to 2008 to register
* This being the first singup page, we still don't have any data
*
* @return void
*/
public function testInputDateMaxYear() {
$this->Form->request->data = array();
$this->Form->create('User');
$result = $this->Form->input('birthday',
array(
'label' => false,
'div' => false,
'type' => 'date',
'dateFormat' => 'DMY',
'minYear' => 2006,
'maxYear' => 2008
)
);
$this->assertContains('value="2008" selected="selected"', $result);
}

/**
* testTextArea method
*
Expand Down
7 changes: 5 additions & 2 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -2284,8 +2284,8 @@ public function minute($fieldName, $attributes = array()) {
*/
protected function _dateTimeSelected($select, $fieldName, $attributes) {
if ((empty($attributes['value']) || $attributes['value'] === true) && $value = $this->value($fieldName)) {
if (is_array($value) && isset($value[$select])) {
$attributes['value'] = $value[$select];
if (is_array($value)) {
$attributes['value'] = isset($value[$select]) ? $value[$select] : null;
} else {
if (empty($value)) {
if (!$attributes['empty']) {
Expand Down Expand Up @@ -2372,6 +2372,9 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a

if ($attributes['value'] === null && $attributes['empty'] != true) {
$attributes['value'] = time();
if (!empty($attributes['maxYear']) && $attributes['maxYear'] < date('Y')) {
$attributes['value'] = strtotime(date($attributes['maxYear'] . '-m-d'));
}
}

if (!empty($attributes['value'])) {
Expand Down

0 comments on commit 804d99b

Please sign in to comment.