Skip to content

Commit

Permalink
Merge branch '2.4' into 3.0
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	lib/Cake/Console/Command/Task/ProjectTask.php
	lib/Cake/Routing/Filter/AssetDispatcher.php
	lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
	lib/Cake/Test/Case/Routing/Filter/AssetDispatcherTest.php
	lib/Cake/Test/TestCase/Controller/ControllerTest.php
	lib/Cake/Test/TestCase/View/Helper/FormHelperTest.php
  • Loading branch information
ADmad committed May 19, 2013
2 parents 4b2ecb9 + fb86859 commit d73ea88
Show file tree
Hide file tree
Showing 20 changed files with 535 additions and 40 deletions.
12 changes: 8 additions & 4 deletions lib/Cake/Console/Command/Task/ProjectTask.php
Expand Up @@ -430,15 +430,19 @@ public function getPrefix() {
}
if ($this->interactive) {
$this->hr();
$this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/routes.php to use prefix routing.'));
$this->out(__d('cake_console', 'You need to enable %s in %s to use prefix routing.',
'Configure::write(\'Routing.prefixes\', array(\'admin\'))',
'/app/Config/core.php'));
$this->out(__d('cake_console', 'What would you like the prefix route to be?'));
$this->out(__d('cake_console', 'Example: www.example.com/admin/controller'));
$this->out(__d('cake_console', 'Example: %s', 'www.example.com/admin/controller'));
while (!$admin) {
$admin = $this->in(__d('cake_console', 'Enter a routing prefix:'), null, 'admin');
}
if ($this->cakeAdmin($admin) !== true) {
$this->out(__d('cake_console', '<error>Unable to write to</error> /app/Config/routes.php.'));
$this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/routes.php to use prefix routing.'));
$this->out(__d('cake_console', '<error>Unable to write to</error> %s.', '/app/Config/core.php'));
$this->out(__d('cake_console', 'You need to enable %s in %s to use prefix routing.',
'Configure::write(\'Routing.prefixes\', array(\'admin\'))',
'/app/Config/core.php'));
$this->_stop();
}
return $admin . '_';
Expand Down
3 changes: 3 additions & 0 deletions lib/Cake/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -251,6 +251,9 @@ public function beforeRedirect(Controller $controller, $url, $status = null, $ex
if (!$this->request->is('ajax')) {
return;
}
if (empty($url)) {
return;
}
$_SERVER['REQUEST_METHOD'] = 'GET';
foreach ($_POST as $key => $val) {
unset($_POST[$key]);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Controller.php
Expand Up @@ -582,11 +582,11 @@ public function implementedEvents() {
*/
public function constructClasses() {
$this->_mergeControllerVars();
$this->Components->init($this);
if ($this->uses) {
$this->uses = (array)$this->uses;
list(, $this->modelClass) = pluginSplit(current($this->uses));
}
$this->Components->init($this);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/I18n/I18n.php
Expand Up @@ -596,7 +596,7 @@ protected function _parseLiteralValue($string) {
$string = $string[1];
if (substr($string, 0, 2) === $this->_escape . 'x') {
$delimiter = $this->_escape . 'x';
return implode('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string)))));
return implode('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
}
if (substr($string, 0, 2) === $this->_escape . 'd') {
$delimiter = $this->_escape . 'd';
Expand Down
164 changes: 164 additions & 0 deletions lib/Cake/Log/Engine/SyslogLog.php
@@ -0,0 +1,164 @@
<?php
/**
* Syslog logger engine for CakePHP
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package Cake.Log.Engine
* @since CakePHP(tm) v 2.4
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('BaseLog', 'Log/Engine');

/**
* Syslog stream for Logging. Writes logs to the system logger
*
* @package Cake.Log.Engine
*/
class SyslogLog extends BaseLog {

/**
*
* By default messages are formatted as:
* type: message
*
* To override the log format (e.g. to add your own info) define the format key when configuring
* this logger
*
* If you wish to include a prefix to all messages, for instance to identify the
* application or the web server, then use the prefix option. Please keep in mind
* the prefix is shared by all streams using syslog, as it is dependent of
* the running process. For a local prefix, to be used only by one stream, you
* can use the format key.
*
* ## Example:
*
* {{{
* CakeLog::config('error', array(
* 'engine' => 'SyslogLog',
* 'types' => array('emergency', 'alert', 'critical', 'error'),
* 'format' => "%s: My-App - %s",
* 'prefix' => 'Web Server 01'
* ));
* }}}
*
* @var array
*/
protected $_defaults = array(
'format' => '%s: %s',
'flag' => LOG_ODELAY,
'prefix' => '',
'facility' => LOG_USER
);

/**
*
* Used to map the string names back to their LOG_* constants
*
* @var array
*/
protected $_priorityMap = array(
'emergency' => LOG_EMERG,
'alert' => LOG_ALERT,
'critical' => LOG_CRIT,
'error' => LOG_ERR,
'warning' => LOG_WARNING,
'notice' => LOG_NOTICE,
'info' => LOG_INFO,
'debug' => LOG_DEBUG
);

/**
* Whether the logger connection is open or not
*
* @var boolean
*/
protected $_open = false;

/**
* Make sure the configuration contains the format parameter, by default it uses
* the error number and the type as a prefix to the message
*
* @param array $config
*/
public function __construct($config = array()) {
$config += $this->_defaults;
parent::__construct($config);
}

/**
* Writes a message to syslog
*
* Map the $type back to a LOG_ constant value, split multi-line messages into multiple
* log messages, pass all messages through the format defined in the configuration
*
* @param string $type The type of log you are making.
* @param string $message The message you want to log.
* @return boolean success of write.
*/
public function write($type, $message) {
if (!$this->_open) {
$config = $this->_config;
$this->_open($config['prefix'], $config['flag'], $config['facility']);
$this->_open = true;
}

$priority = LOG_DEBUG;
if (isset($this->_priorityMap[$type])) {
$priority = $this->_priorityMap[$type];
}

$messages = explode("\n", $message);
foreach ($messages as $message) {
$message = sprintf($this->_config['format'], $type, $message);
$this->_write($priority, $message);
}

return true;
}

/**
* Extracts the call to openlog() in order to run unit tests on it. This function
* will initialize the connection to the system logger
*
* @param string $ident the prefix to add to all messages logged
* @param int $options the options flags to be used for logged messages
* @param int $facility the stream or facility to log to
* @return void
*/
protected function _open($ident, $options, $facility) {
openlog($ident, $options, $facility);
}

/**
* Extracts the call to syslog() in order to run unit tests on it. This function
* will perform the actual write in the system logger
*
* @param int $priority
* @param string $message
* @return bool
*/
protected function _write($priority, $message) {
return syslog($priority, $message);
}

/**
* Closes the logger connection
*
* @return void
**/
public function __destruct() {
closelog();
}

}
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -1079,7 +1079,7 @@ protected function _generateAssociation($type, $assocKey) {

case 'joinTable':
$tables = array($this->table, $this->{$class}->table);
sort ($tables);
sort($tables);
$data = $tables[0] . '_' . $tables[1];
break;

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/Email/Email.php
Expand Up @@ -1257,7 +1257,7 @@ protected function _wrap($message, $wrapLength = Email::LINE_LENGTH_MUST) {
$formatted[] = '';
continue;
}
if (!preg_match('/\<[a-z]/i', $line)) {
if (!preg_match('/<[a-z]+.+>/i', $line)) {
$formatted = array_merge(
$formatted,
explode("\n", wordwrap($line, $wrapLength, "\n"))
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Filter/AssetDispatcher.php
Expand Up @@ -86,7 +86,7 @@ protected function _getAssetFile($url) {
}

$plugin = Inflector::camelize($parts[0]);
if (Plugin::loaded($plugin)) {
if ($plugin && Plugin::loaded($plugin)) {
unset($parts[0]);
$fileFragment = urldecode(implode(DS, $parts));
$pluginWebroot = Plugin::path($plugin) . 'webroot' . DS;
Expand Down
94 changes: 94 additions & 0 deletions lib/Cake/Test/Case/Log/Engine/SyslogLogTest.php
@@ -0,0 +1,94 @@
<?php
/**
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Log.Engine
* @since CakePHP(tm) v 2.4
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('SyslogLog', 'Log/Engine');

/**
* SyslogLogTest class
*
* @package Cake.Test.Case.Log.Engine
*/
class SyslogLogTest extends CakeTestCase {

/**
* Tests that the connection to the logger is open with the right arguments
*
* @return void
*/
public function testOpenLog() {
$log = $this->getMock('SyslogLog', array('_open', '_write'));
$log->expects($this->once())->method('_open')->with('', LOG_ODELAY, LOG_USER);
$log->write('debug', 'message');

$log = $this->getMock('SyslogLog', array('_open', '_write'));
$log->config(array(
'prefix' => 'thing',
'flag' => LOG_NDELAY,
'facility' => LOG_MAIL,
'format' => '%s: %s'
));
$log->expects($this->once())->method('_open')
->with('thing', LOG_NDELAY, LOG_MAIL);
$log->write('debug', 'message');
}

/**
* Tests that single lines are written to syslog
*
* @dataProvider typesProvider
* @return void
*/
public function testWriteOneLine($type, $expected) {
$log = $this->getMock('SyslogLog', array('_open', '_write'));
$log->expects($this->once())->method('_write')->with($expected, $type . ': Foo');
$log->write($type, 'Foo');
}

/**
* Tests that multiple lines are split and logged separately
*
* @return void
*/
public function testWriteMultiLine() {
$log = $this->getMock('SyslogLog', array('_open', '_write'));
$log->expects($this->at(1))->method('_write')->with(LOG_DEBUG, 'debug: Foo');
$log->expects($this->at(2))->method('_write')->with(LOG_DEBUG, 'debug: Bar');
$log->expects($this->exactly(2))->method('_write');
$log->write('debug', "Foo\nBar");
}

/**
* Data provider for the write function test
*
* @return array
*/
public function typesProvider() {
return array(
array('emergency', LOG_EMERG),
array('alert', LOG_ALERT),
array('critical', LOG_CRIT),
array('error', LOG_ERR),
array('warning', LOG_WARNING),
array('notice', LOG_NOTICE),
array('info', LOG_INFO),
array('debug', LOG_DEBUG)
);
}

}

Expand Up @@ -536,7 +536,7 @@ protected function _debug($printTreesToo = false) {
foreach ($permissions as $key => $values) {
array_unshift($values, $key);
$values = array_map(array(&$this, '_pad'), $values);
$permissions[$key] = implode (' ', $values);
$permissions[$key] = implode(' ', $values);
}
$permissions = array_map(array(&$this, '_pad'), $permissions);
array_unshift($permissions, 'Current Permissions :');
Expand Down
Expand Up @@ -361,6 +361,23 @@ public function testNonAjaxRedirect() {
$this->assertNull($this->RequestHandler->beforeRedirect($this->Controller, '/'));
}

/**
* test that redirects with ajax and no url don't do anything.
*
* @return void
*/
public function testAjaxRedirectWithNoUrl() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->Controller->response = $this->getMock('CakeResponse');

$this->Controller->response->expects($this->never())
->method('body');

$this->RequestHandler->initialize($this->Controller);
$this->RequestHandler->startup($this->Controller);
$this->assertNull($this->RequestHandler->beforeRedirect($this->Controller, null));
}

/**
* testRenderAs method
*
Expand Down

0 comments on commit d73ea88

Please sign in to comment.