Permalink
Browse files

Merge branch '2.0' of github.com:cakephp/cakephp into 2.0

  • Loading branch information...
2 parents df2ef0e + aa6d6a9 commit 6b7c752478ec9c3545bbdc31231d29bed20770ee @lorenzo lorenzo committed Sep 29, 2011
Showing with 259 additions and 49 deletions.
  1. +4 −1 lib/Cake/Cache/Engine/FileEngine.php
  2. +1 −1 lib/Cake/Console/Command/AclShell.php
  3. +36 −2 lib/Cake/Console/Command/UpgradeShell.php
  4. +13 −0 lib/Cake/Console/Templates/default/views/home.ctp
  5. +2 −1 lib/Cake/Controller/Component/Auth/CrudAuthorize.php
  6. +6 −2 lib/Cake/Controller/Component/AuthComponent.php
  7. +1 −1 lib/Cake/Controller/Scaffold.php
  8. +2 −2 lib/Cake/Core/App.php
  9. +1 −1 lib/Cake/Error/ExceptionRenderer.php
  10. +0 −1 lib/Cake/Model/CakeSchema.php
  11. +1 −1 lib/Cake/Model/Datasource/Database/Postgres.php
  12. +3 −3 lib/Cake/Model/Model.php
  13. +5 −5 lib/Cake/Network/CakeRequest.php
  14. +1 −1 lib/Cake/Test/Case/Cache/CacheTest.php
  15. +2 −2 lib/Cake/Test/Case/Controller/Component/Auth/CrudAuthorizeTest.php
  16. +5 −0 lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
  17. +4 −4 lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php
  18. +1 −1 lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
  19. +3 −1 lib/Cake/Test/Case/Model/ModelReadTest.php
  20. +42 −0 lib/Cake/Test/Case/Model/ModelValidationTest.php
  21. +6 −6 lib/Cake/Test/Case/Network/CakeRequestTest.php
  22. +1 −0 lib/Cake/Test/Case/Routing/RouterTest.php
  23. +1 −1 lib/Cake/Test/Case/Utility/DebuggerTest.php
  24. +40 −1 lib/Cake/Test/Case/Utility/FolderTest.php
  25. +39 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  26. +1 −1 lib/Cake/TestSuite/CakeTestSuite.php
  27. +1 −1 lib/Cake/Utility/Folder.php
  28. +1 −1 lib/Cake/View/Errors/missing_action.ctp
  29. +22 −7 lib/Cake/View/Helper/FormHelper.php
  30. +1 −1 lib/Cake/View/Helper/PaginatorHelper.php
  31. +13 −0 lib/Cake/View/Pages/home.ctp
@@ -66,7 +66,7 @@ class FileEngine extends CacheEngine {
public function init($settings = array()) {
parent::init(array_merge(
array(
- 'engine' => 'File', 'path' => CACHE, 'prefix'=> 'cake_', 'lock'=> false,
+ 'engine' => 'File', 'path' => CACHE, 'prefix'=> 'cake_', 'lock'=> true,
'serialize'=> true, 'isWindows' => false
),
$settings
@@ -162,6 +162,9 @@ public function read($key) {
$cachetime = intval($this->_File->current());
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
+ if ($this->settings['lock']) {
+ $this->_File->flock(LOCK_UN);
+ }
return false;
}
@@ -427,7 +427,7 @@ public function getOptionParser() {
'help' => __d('cake_console', 'Check the permissions between an ACO and ARO.'),
'parser' => array(
'description' => array(
- __d('cake_console', 'Use this command to grant ACL permissions. Once executed, the ARO specified (and its children, if any) will have ALLOW access to the specified ACO action (and the ACO\'s children, if any).')
+ __d('cake_console', 'Use this command to check ACL permissions.')
),
'arguments' => array(
'aro' => array('help' => __d('cake_console', 'ARO to check.'), 'required' => true),
@@ -132,7 +132,6 @@ public function locations() {
}
if (is_dir('plugins')) {
-
$Folder = new Folder('plugins');
list($plugins) = $Folder->read();
foreach($plugins as $plugin) {
@@ -143,6 +142,8 @@ public function locations() {
chdir($cwd);
}
+ $this->_moveViewFiles();
+
$moves = array(
'libs' => 'Lib',
'tests' => 'Test',
@@ -181,7 +182,7 @@ public function locations() {
$defaultOptions = array(
'recursive' => true,
'checkFolder' => true,
- 'regex' => '@class (\S*) .*{@'
+ 'regex' => '@class (\S*) .*{@i'
);
foreach($sourceDirs as $dir => $options) {
if (is_numeric($dir)) {
@@ -507,6 +508,39 @@ public function components() {
}
/**
+ * Move application views files to where they now should be
+ *
+ * Find all view files in the folder and determine where cake expects the file to be
+ *
+ * @return void
+ */
+ protected function _moveViewFiles() {
+ if (!is_dir('views')) {
+ return;
+ }
+
+ $dirs = scandir('views');
+ foreach ($dirs as $old) {
+ if (!is_dir('views' . DS . $old) || $old === '.' || $old === '..') {
+ continue;
+ }
+
+ $new = 'View' . DS . Inflector::camelize($old);
+ $old = 'views' . DS . $old;
+
+ $this->out(__d('cake_console', 'Moving %s to %s', $old, $new));
+ if (!$this->params['dry-run']) {
+ if ($this->params['git']) {
+ exec('git mv -f ' . escapeshellarg($old) . ' ' . escapeshellarg($new));
+ } else {
+ $Folder = new Folder($old);
+ $Folder->move($new);
+ }
+ }
+ }
+ }
+
+/**
* Move application php files to where they now should be
*
* Find all php files in the folder (honoring recursive) and determine where cake expects the file to be
@@ -12,6 +12,19 @@ if (Configure::read() > 0):
endif;
?>
<p>
+<?php
+ if (version_compare(PHP_VERSION, '5.2.6', '>=')):
+ echo '<span class=\"notice success\">';
+ echo __d('cake_dev', 'Your version of PHP is 5.2.6 or higher.');
+ echo '</span>';
+ else:
+ echo '<span class=\"notice\">';
+ echo __d('cake_dev', 'Your version of PHP is too low. You need PHP 5.2.6 or higher to use CakePHP.');
+ echo '</span>';
+ endif;
+?>
+</p>
+<p>
<?php
if (is_writable(TMP)):
echo '<span class=\"notice success\">';
@@ -90,11 +90,12 @@ public function authorize($user, CakeRequest $request) {
);
return false;
}
+ $user = array($this->settings['userModel'] => $user);
$Acl = $this->_Collection->load('Acl');
return $Acl->check(
$user,
$this->action($request, ':controller'),
$this->settings['actionMap'][$request->params['action']]
);
}
-}
+}
@@ -491,7 +491,8 @@ public function mapActions($map = array()) {
/**
* Log a user in. If a $user is provided that data will be stored as the logged in user. If `$user` is empty or not
* specified, the request will be used to identify a user. If the identification was successful,
- * the user record is written to the session key specified in AuthComponent::$sessionKey.
+ * the user record is written to the session key specified in AuthComponent::$sessionKey. Logging in
+ * will also change the session id in order to help mitigate session replays.
*
* @param mixed $user Either an array of user data, or null to identify a user using the current request.
* @return boolean True on login success, false on failure
@@ -504,6 +505,7 @@ public function login($user = null) {
$user = $this->identify($this->request, $this->response);
}
if ($user) {
+ $this->Session->renew();
$this->Session->write(self::$sessionKey, $user);
}
return $this->loggedIn();
@@ -513,7 +515,8 @@ public function login($user = null) {
* Logs a user out, and returns the login action to redirect to.
* Triggers the logout() method of all the authenticate objects, so they can perform
* custom logout logic. AuthComponent will remove the session data, so
- * there is no need to do that in an authentication object.
+ * there is no need to do that in an authentication object. Logging out
+ * will also renew the session id. This helps mitigate issues with session replays.
*
* @return string AuthComponent::$logoutRedirect
* @see AuthComponent::$logoutRedirect
@@ -530,6 +533,7 @@ public function logout() {
}
$this->Session->delete(self::$sessionKey);
$this->Session->delete('Auth.redirect');
+ $this->Session->renew();
return Router::normalize($this->logoutRedirect);
}
@@ -75,7 +75,7 @@ class Scaffold {
public $request;
/**
- * valid session.
+ * Valid session.
*
* @var boolean
*/
@@ -43,7 +43,7 @@
* You can inspect the currently loaded paths using `App::path('Controller')` for example to see loaded
* controller paths.
*
- * It is also possible to inspect paths for plugin classes, for instance, to see a plugin's helpers you would call
+ * It is also possible to inspect paths for plugin classes, for instance, to see a plugin's helpers you would call
* `App::path('View/Helper', 'MyPlugin')`
*
* ### Locating plugins and themes
@@ -251,7 +251,7 @@ public static function paths() {
*
* `App::build(array('Model' => array('/path/to/models/')), App::RESET); will setup the path as the only valid path for searching models`
*
- * `App::build(array('View/Helper' => array('/path/to/helpers/', '/another/path/))); will setup multiple search paths for helpers`
+ * `App::build(array('View/Helper' => array('/path/to/helpers/', '/another/path/'))); will setup multiple search paths for helpers`
*
* If reset is set to true, all loaded plugins will be forgotten and they will be needed to be loaded again.
*
@@ -179,7 +179,7 @@ public function render() {
*/
protected function _cakeError(CakeException $error) {
$url = $this->controller->request->here();
- $code = $error->getCode();
+ $code = ($error->getCode() >= 400 && $error->getCode() < 506) ? $error->getCode() : 500;
$this->controller->response->statusCode($code);
$this->controller->set(array(
'code' => $code,
@@ -412,7 +412,6 @@ public function generateTable($table, $fields) {
}
$col .= join(', ', $props);
} elseif ($field == 'tableParameters') {
- //@todo add charset, collate and engine here
$col = "\t\t'tableParameters' => array(";
$props = array();
foreach ((array)$value as $key => $param) {
@@ -769,7 +769,7 @@ public function boolean($data, $quote = false) {
* @return boolean True on success, false on failure
*/
public function setEncoding($enc) {
- if ($this->_execute('SET NAMES ?', array($enc))) {
+ if ($this->_execute("SET NAMES '?'", array($enc))) {
return true;
}
return false;
@@ -2433,7 +2433,7 @@ public function hasAny($conditions = null) {
* - If three fields are specified, they are used (in order) for key, value and group.
* - Otherwise, first and second fields are used for key and value.
*
- * Note: find(list) + database views have issues with MySQL 5.0. Try upgrading to MySQL 5.1 if you
+ * Note: find(list) + database views have issues with MySQL 5.0. Try upgrading to MySQL 5.1 if you
* have issues with database views.
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
@@ -2570,8 +2570,8 @@ protected function _findCount($state, $query, $results = array()) {
} elseif ($state === 'after') {
foreach (array(0, $this->alias) as $key) {
if (isset($results[0][$key]['count'])) {
- if (count($results) > 1) {
- return intval(array_sum(Set::extract('/' . $key . '/count', $results)));
+ if (($count = count($results)) > 1) {
+ return $count;
} else {
return intval($results[0][$key]['count']);
}
@@ -714,7 +714,7 @@ public function data($name) {
}
/**
- * Read data from `php://stdin`. Useful when interacting with XML or JSON
+ * Read data from `php://input`. Useful when interacting with XML or JSON
* request body content.
*
* Getting input with a decoding function:
@@ -733,7 +733,7 @@ public function data($name) {
* @return The decoded/processed request data.
*/
public function input($callback = null) {
- $input = $this->_readStdin();
+ $input = $this->_readInput();
$args = func_get_args();
if (!empty($args)) {
$callback = array_shift($args);
@@ -744,11 +744,11 @@ public function input($callback = null) {
}
/**
- * Read data from php://stdin, mocked in tests.
+ * Read data from php://input, mocked in tests.
*
- * @return string contents of stdin
+ * @return string contents of php://input
*/
- protected function _readStdin() {
+ protected function _readInput() {
if (empty($this->_input)) {
$fh = fopen('php://input', 'r');
$content = stream_get_contents($fh);
@@ -197,7 +197,7 @@ public function testWritingWithConfig() {
$expected = array(
'path' => TMP . 'sessions' . DS,
'prefix' => 'cake_',
- 'lock' => false,
+ 'lock' => true,
'serialize' => true,
'duration' => 3600,
'probability' => 100,
@@ -86,7 +86,7 @@ public function testAuthorizeCheckSuccess() {
->with($user, 'Posts', 'read')
->will($this->returnValue(true));
- $this->assertTrue($this->auth->authorize($user, $request));
+ $this->assertTrue($this->auth->authorize($user['User'], $request));
}
/**
@@ -108,7 +108,7 @@ public function testAuthorizeCheckFailure() {
->with($user, 'Posts', 'read')
->will($this->returnValue(false));
- $this->assertFalse($this->auth->authorize($user, $request));
+ $this->assertFalse($this->auth->authorize($user['User'], $request));
}
@@ -385,6 +385,8 @@ public function testLogin() {
'userModel' => 'AuthUser'
)
);
+ $this->Auth->Session = $this->getMock('SessionComponent', array('renew'), array(), '', false);
+
$mocks = $this->Auth->constructAuthenticate();
$this->mockObjects[] = $mocks[0];
@@ -405,6 +407,9 @@ public function testLogin() {
->with($this->Auth->request)
->will($this->returnValue($user));
+ $this->Auth->Session->expects($this->once())
+ ->method('renew');
+
$result = $this->Auth->login();
$this->assertTrue($result);
@@ -256,7 +256,7 @@ public function testAutoAjaxLayout() {
public function testStartupCallback() {
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/xml';
- $this->Controller->request = $this->getMock('CakeRequest', array('_readStdin'));
+ $this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
$this->RequestHandler->startup($this->Controller);
$this->assertTrue(is_array($this->Controller->data));
$this->assertFalse(is_object($this->Controller->data));
@@ -270,7 +270,7 @@ public function testStartupCallback() {
public function testStartupCallbackCharset() {
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8';
- $this->Controller->request = $this->getMock('CakeRequest', array('_readStdin'));
+ $this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
$this->RequestHandler->startup($this->Controller);
$this->assertTrue(is_array($this->Controller->data));
$this->assertFalse(is_object($this->Controller->data));
@@ -287,9 +287,9 @@ public function testStartupCustomTypeProcess() {
}
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'text/csv';
- $this->Controller->request = $this->getMock('CakeRequest', array('_readStdin'));
+ $this->Controller->request = $this->getMock('CakeRequest', array('_readInput'));
$this->Controller->request->expects($this->once())
- ->method('_readStdin')
+ ->method('_readInput')
->will($this->returnValue('"A","csv","string"'));
$this->RequestHandler->addInputType('csv', array('str_getcsv'));
$this->RequestHandler->startup($this->Controller);
@@ -347,7 +347,7 @@ public function testLocalizedFloats() {
setlocale(LC_ALL, 'de_DE');
$result = $this->db->value(3.141593, 'float');
- $this->assertEqual((string)$result, "3.141593");
+ $this->assertEqual((string)$result, "3.14159");
$result = $this->db->value(3.14);
$this->assertEqual((string)$result, "3.140000");
@@ -6591,8 +6591,10 @@ public function testFindCount() {
$this->assertNoPattern('/ORDER\s+BY/', $log['log'][0]['query']);
$Article = new Article();
+ $Article->recursive = -1;
+ $expected = count($Article->find('all', array('group' => 'Article.user_id')));
$result = $Article->find('count', array('group' => 'Article.user_id'));
- $this->assertEqual($result, 3);
+ $this->assertEquals($expected, $result);
}
/**
Oops, something went wrong.

0 comments on commit 6b7c752

Please sign in to comment.