Merge branch 'master' into 2.4

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
This commit is contained in:
mark_story 2013-03-30 22:12:27 -04:00
commit 3fc627c5f8
13 changed files with 98 additions and 49 deletions

View file

@ -384,7 +384,7 @@ class AuthComponent extends Component {
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));
}
}
@ -700,9 +700,17 @@ class AuthComponent extends Component {
/**
* 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
@ -718,8 +726,10 @@ class AuthComponent extends Component {
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
$redir = $this->loginRedirect;
}
} else {
} elseif ($this->loginRedirect) {
$redir = $this->loginRedirect;
} else {
$redir = '/';
}
return Router::normalize($redir);
}

View file

@ -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.

View file

@ -112,7 +112,7 @@ class ErrorHandler {
$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');

View file

@ -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.
*

View file

@ -323,6 +323,8 @@ class HttpSocket extends CakeSocket {
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;

View file

@ -418,30 +418,6 @@ class AuthComponentTest extends CakeTestCase {
$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
*

View file

@ -394,9 +394,9 @@ class PaginatorComponentTest extends CakeTestCase {
$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'

View file

@ -1065,6 +1065,19 @@ class HttpSocketTest extends CakeTestCase {
$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);
}
/**

View file

@ -647,6 +647,22 @@ class HtmlHelperTest extends CakeTestCase {
$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
*
@ -1019,6 +1035,30 @@ class HtmlHelperTest extends CakeTestCase {
$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.
*

View file

@ -109,7 +109,7 @@ class ClassRegistry {
$defaults = $_this->_config['Model'];
}
$count = count($objects);
$availableDs = array_keys(ConnectionManager::enumConnectionObjects());
$availableDs = null;
foreach ($objects as $settings) {
if (is_numeric($settings)) {
@ -153,6 +153,9 @@ class ClassRegistry {
$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;
}

View file

@ -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

View file

@ -1421,7 +1421,7 @@ class FormHelper extends AppHelper {
}
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)));
}
/**
@ -1527,7 +1527,7 @@ class FormHelper extends AppHelper {
}
$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
);
}
@ -1584,7 +1584,7 @@ class FormHelper extends AppHelper {
$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)));
}
/**
@ -1610,7 +1610,7 @@ class FormHelper extends AppHelper {
}
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);
}
/**
@ -1636,7 +1636,7 @@ class FormHelper extends AppHelper {
$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)));
}
/**
@ -1659,7 +1659,7 @@ class FormHelper extends AppHelper {
$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));
}
@ -2020,7 +2020,7 @@ class FormHelper extends AppHelper {
) {
$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 && !(

View file

@ -399,6 +399,7 @@ class HtmlHelper extends AppHelper {
* 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
@ -441,6 +442,7 @@ class HtmlHelper extends AppHelper {
$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);
@ -506,6 +508,7 @@ class HtmlHelper extends AppHelper {
* - `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
@ -541,6 +544,7 @@ class HtmlHelper extends AppHelper {
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);
@ -799,7 +803,7 @@ class HtmlHelper extends AppHelper {
*/
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'] = '';
@ -1103,10 +1107,10 @@ class HtmlHelper extends AppHelper {
$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);
}