Skip to content

Commit

Permalink
Merge branch 'master' into 2.4
Browse files Browse the repository at this point in the history
Conflicts:
	lib/Cake/Controller/Component/AuthComponent.php
	lib/Cake/Error/ErrorHandler.php
	lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
	lib/Cake/View/Helper/HtmlHelper.php
  • Loading branch information
markstory committed Mar 31, 2013
2 parents 42ea689 + 7b90542 commit 3fc627c
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 49 deletions.
20 changes: 15 additions & 5 deletions lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -384,7 +384,7 @@ protected function _isLoginAction(Controller $controller) {

if ($loginAction == $url) {
if (empty($controller->request->data)) {
if (!$this->Session->check('Auth.redirect') && !$this->loginRedirect && env('HTTP_REFERER')) {
if (!$this->Session->check('Auth.redirect') && env('HTTP_REFERER')) {
$this->Session->write('Auth.redirect', $controller->referer(null, true));
}
}
Expand Down Expand Up @@ -700,9 +700,17 @@ public function redirect($url = null) {
/**
* Get the URL a use should be redirected to upon login.
*
* If no parameter is passed, gets the authentication redirect URL. Pass a url in to
* set the destination a user should be redirected to upon logging in. Will fallback to
* AuthComponent::$loginRedirect if there is no stored redirect value.
* Pass a url in to set the destination a user should be redirected to upon
* logging in.
*
* If no parameter is passed, gets the authentication redirect URL. The url
* returned is as per following rules:
*
* - Returns the session Auth.redirect value if it is present and for the same
* domain the current app is running on.
* - If there is no session value and there is a $loginRedirect, the $loginRedirect
* value is returned.
* - If there is no session and no $loginRedirect, / is returned.
*
* @param string|array $url Optional URL to write as the login redirect URL.
* @return string Redirect URL
Expand All @@ -718,8 +726,10 @@ public function redirectUrl($url = null) {
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
$redir = $this->loginRedirect;
}
} else {
} elseif ($this->loginRedirect) {
$redir = $this->loginRedirect;
} else {
$redir = '/';
}
return Router::normalize($redir);
}
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Core/App.php
Expand Up @@ -17,6 +17,7 @@
* @since CakePHP(tm) v 1.2.0.6001
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Inflector', 'Utility');

/**
* App is responsible for path management, class location and class loading.
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Error/ErrorHandler.php
Expand Up @@ -112,7 +112,7 @@ public static function handleException(Exception $exception) {
$config = Configure::read('Exception');
self::_log($exception, $config);

$renderer = $config['renderer'];
$renderer = isset($config['renderer']) ? $config['renderer'] : 'ExceptionRenderer';
if ($renderer !== 'ExceptionRenderer') {
list($plugin, $renderer) = pluginSplit($renderer, true);
App::uses($renderer, $plugin . 'Error');
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Event/CakeEvent.php
Expand Up @@ -18,7 +18,7 @@
*/

/**
* Represents the transport class of events across the system, it receives a name, and subject and an optional
* Represents the transport class of events across the system. It receives a name, subject and an optional
* payload. The name can be any string that uniquely identifies the event across the application, while the subject
* represents the object that the event applies to.
*
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/Network/Http/HttpSocket.php
Expand Up @@ -323,6 +323,8 @@ public function request($request = array()) {

if (isset($this->request['uri']['user'], $this->request['uri']['pass'])) {
$this->configAuth('Basic', $this->request['uri']['user'], $this->request['uri']['pass']);
} elseif (isset($this->request['auth'], $this->request['auth']['method'], $this->request['auth']['user'], $this->request['auth']['pass'])) {
$this->configAuth($this->request['auth']['method'], $this->request['auth']['user'], $this->request['auth']['pass']);
}
$this->_setAuth();
$this->request['auth'] = $this->_auth;
Expand Down
24 changes: 0 additions & 24 deletions lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
Expand Up @@ -418,30 +418,6 @@ public function testLogin() {
$this->assertEquals($user, $this->Auth->user());
}

/**
* test that being redirected to the login page, with no post data does
* not set the session value. Saving the session value in this circumstance
* can cause the user to be redirected to an already public page.
*
* @return void
*/
public function testLoginActionNotSettingAuthRedirect() {
$_SERVER['HTTP_REFERER'] = '/pages/display/about';

$this->Controller->data = array();
$this->Controller->request->addParams(Router::parse('auth_test/login'));
$this->Controller->request->url = 'auth_test/login';
$this->Auth->Session->delete('Auth');

$this->Auth->loginRedirect = '/users/dashboard';
$this->Auth->loginAction = 'auth_test/login';
$this->Auth->userModel = 'AuthUser';

$this->Auth->startup($this->Controller);
$redirect = $this->Auth->Session->read('Auth.redirect');
$this->assertNull($redirect);
}

/**
* testRedirectVarClearing method
*
Expand Down
Expand Up @@ -394,9 +394,9 @@ public function testPaginate() {
$this->assertEquals(array(3, 2, 1), $results);

$Controller->request->params['named'] = array('sort' => 'NotExisting.field', 'direction' => 'desc');
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id');
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page'], 'Invalid field in query %s');
$this->assertEquals(array(1, 2, 3), $results);
$Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
$this->assertEquals(array(), $Controller->PaginatorControllerPost->lastQueries[1]['order'][0], 'no order should be set.');

$Controller->request->params['named'] = array(
'sort' => 'PaginatorControllerPost.author_id', 'direction' => 'allYourBase'
Expand Down
13 changes: 13 additions & 0 deletions lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
Expand Up @@ -1065,6 +1065,19 @@ public function testAuth() {
$socket->configAuth('Test', 'mark', 'passwd');
$socket->get('http://example.com/test');
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Test mark.passwd') !== false);

$socket->configAuth(false);
$socket->request(array(
'method' => 'GET',
'uri' => 'http://example.com/test',
'auth' => array(
'method' => 'Basic',
'user' => 'joel',
'pass' => 'hunter2'
)
));
$this->assertEquals($socket->request['auth'],array('Basic' => array('user' => 'joel', 'pass' => 'hunter2')));
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic am9lbDpodW50ZXIy') !== false);
}

/**
Expand Down
40 changes: 40 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -647,6 +647,22 @@ public function testCssLinkBC() {
$this->assertNull($result);
}

/**
* testCssWithFullBase method
*
* @return void
*/
public function testCssWithFullBase() {
Configure::write('Asset.filter.css', false);
$here = $this->Html->url('/', true);

$result = $this->Html->css('screen', null, array('fullBase' => true));
$expected = array(
'link' => array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $here . 'css/screen.css')
);
$this->assertTags($result, $expected);
}

/**
* testPluginCssLink method
*
Expand Down Expand Up @@ -1019,6 +1035,30 @@ public function testScriptAssetFilter() {
$this->assertTags($result, $expected);
}

/**
* testScriptWithFullBase method
*
* @return void
*/
public function testScriptWithFullBase() {
$here = $this->Html->url('/', true);

$result = $this->Html->script('foo', array('fullBase' => true));
$expected = array(
'script' => array('type' => 'text/javascript', 'src' => $here . 'js/foo.js')
);
$this->assertTags($result, $expected);

$result = $this->Html->script(array('foobar', 'bar'), array('fullBase' => true));
$expected = array(
array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/foobar.js')),
'/script',
array('script' => array('type' => 'text/javascript', 'src' => $here . 'js/bar.js')),
'/script',
);
$this->assertTags($result, $expected);
}

/**
* test a script file in the webroot/theme dir.
*
Expand Down
5 changes: 4 additions & 1 deletion lib/Cake/Utility/ClassRegistry.php
Expand Up @@ -109,7 +109,7 @@ public static function init($class, $strict = false) {
$defaults = $_this->_config['Model'];
}
$count = count($objects);
$availableDs = array_keys(ConnectionManager::enumConnectionObjects());
$availableDs = null;

foreach ($objects as $settings) {
if (is_numeric($settings)) {
Expand Down Expand Up @@ -153,6 +153,9 @@ public static function init($class, $strict = false) {
$defaultProperties = $reflection->getDefaultProperties();
if (isset($defaultProperties['useDbConfig'])) {
$useDbConfig = $defaultProperties['useDbConfig'];
if ($availableDs === null) {
$availableDs = array_keys(ConnectionManager::enumConnectionObjects());
}
if (in_array('test_' . $useDbConfig, $availableDs)) {
$useDbConfig = 'test_' . $useDbConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Utility/ObjectCollection.php
Expand Up @@ -18,8 +18,8 @@
* to implement its own load() functionality.
*
* All core subclasses of ObjectCollection by convention loaded objects are stored
* in `$this->_loaded`. Enabled objects are stored in `$this->_enabled`. In addition
* the all support an `enabled` option that controls the enabled/disabled state of the object
* in `$this->_loaded`. Enabled objects are stored in `$this->_enabled`. In addition,
* they all support an `enabled` option that controls the enabled/disabled state of the object
* when loaded.
*
* @package Cake.Utility
Expand Down
14 changes: 7 additions & 7 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -1421,7 +1421,7 @@ public function checkbox($fieldName, $options = array()) {
}
unset($options['hiddenField']);

return $output . $this->Html->useTag('checkbox', $options['name'], array_diff_key($options, array('name' => '')));
return $output . $this->Html->useTag('checkbox', $options['name'], array_diff_key($options, array('name' => null)));
}

/**
Expand Down Expand Up @@ -1527,7 +1527,7 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
}
$allOptions = array_merge($attributes, $optionsHere);
$out[] = $this->Html->useTag('radio', $attributes['name'], $tagName,
array_diff_key($allOptions, array('name' => '', 'type' => '', 'id' => '')),
array_diff_key($allOptions, array('name' => null, 'type' => null, 'id' => null)),
$optTitle
);
}
Expand Down Expand Up @@ -1584,7 +1584,7 @@ public function __call($method, $params) {
$options['type'] = $method;
}
$options = $this->_initInputField($params[0], $options);
return $this->Html->useTag('input', $options['name'], array_diff_key($options, array('name' => '')));
return $this->Html->useTag('input', $options['name'], array_diff_key($options, array('name' => null)));
}

/**
Expand All @@ -1610,7 +1610,7 @@ public function textarea($fieldName, $options = array()) {
}
unset($options['value']);
}
return $this->Html->useTag('textarea', $options['name'], array_diff_key($options, array('type' => '', 'name' => '')), $value);
return $this->Html->useTag('textarea', $options['name'], array_diff_key($options, array('type' => null, 'name' => null)), $value);
}

/**
Expand All @@ -1636,7 +1636,7 @@ public function hidden($fieldName, $options = array()) {
$this->_secure(true, null, '' . $options['value']);
}

return $this->Html->useTag('hidden', $options['name'], array_diff_key($options, array('name' => '')));
return $this->Html->useTag('hidden', $options['name'], array_diff_key($options, array('name' => null)));
}

/**
Expand All @@ -1659,7 +1659,7 @@ public function file($fieldName, $options = array()) {
$this->_secure($secure, array_merge($field, array($suffix)));
}

$exclude = array('name' => '', 'value' => '');
$exclude = array('name' => null, 'value' => null);
return $this->Html->useTag('file', $options['name'], array_diff_key($options, $exclude));
}

Expand Down Expand Up @@ -2020,7 +2020,7 @@ public function select($fieldName, $options = array(), $attributes = array()) {
) {
$this->_secure(true);
}
$select[] = $this->Html->useTag($tag, $attributes['name'], array_diff_key($attributes, array('name' => '', 'value' => '')));
$select[] = $this->Html->useTag($tag, $attributes['name'], array_diff_key($attributes, array('name' => null, 'value' => null)));
}
$emptyMulti = (
$showEmpty !== null && $showEmpty !== false && !(
Expand Down
14 changes: 9 additions & 5 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -399,6 +399,7 @@ public function link($title, $url = null, $options = array(), $confirmMessage =
* This overrides the `inline` option.
* - `plugin` False value will prevent parsing path as a plugin
* - `rel` Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be imported.
* - `fullBase` If true the url will get a full address for the css file.
*
* @param string|array $path The name of a CSS style sheet or an array containing names of
* CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
Expand Down Expand Up @@ -441,6 +442,7 @@ public function css($path, $options = array()) {
$url = $path;
} else {
$url = $this->assetUrl($path, $options + array('pathPrefix' => CSS_URL, 'ext' => '.css'));
$options = array_diff_key($options, array('fullBase' => null));

if (Configure::read('Asset.filter.css')) {
$pos = strpos($url, CSS_URL);
Expand Down Expand Up @@ -506,6 +508,7 @@ public function css($path, $options = array()) {
* - `once` Whether or not the script should be checked for uniqueness. If true scripts will only be
* included once, use false to allow the same script to be included more than once per request.
* - `plugin` False value will prevent parsing path as a plugin
* - `fullBase` If true the url will get a full address for the script file.
*
* @param string|array $url String or array of javascript files to include
* @param array|boolean $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
Expand Down Expand Up @@ -541,6 +544,7 @@ public function script($url, $options = array()) {

if (strpos($url, '//') === false) {
$url = $this->assetUrl($url, $options + array('pathPrefix' => JS_URL, 'ext' => '.js'));
$options = array_diff_key($options, array('fullBase' => null));

if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
Expand Down Expand Up @@ -799,7 +803,7 @@ protected function _prepareCrumbs($startText) {
*/
public function image($path, $options = array()) {
$path = $this->assetUrl($path, $options + array('pathPrefix' => IMAGES_URL));
$options = array_diff_key($options, array('fullBase' => '', 'pathPrefix' => ''));
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));

if (!isset($options['alt'])) {
$options['alt'] = '';
Expand Down Expand Up @@ -1103,10 +1107,10 @@ public function media($path, $options = array()) {
$text = $options['text'];

$options = array_diff_key($options, array(
'tag' => '',
'fullBase' => '',
'pathPrefix' => '',
'text' => ''
'tag' => null,
'fullBase' => null,
'pathPrefix' => null,
'text' => null
));
return $this->tag($tag, $text, $options);
}
Expand Down

0 comments on commit 3fc627c

Please sign in to comment.