Merge branch '2.7' into 2.8

This commit is contained in:
mark_story 2015-11-11 22:53:45 -05:00
commit 48450e71fa
11 changed files with 57 additions and 116 deletions

View file

@ -189,7 +189,7 @@ class Controller extends Object implements CakeEventListener {
* @var array
* @link http://book.cakephp.org/2.0/en/controllers/components.html
*/
public $components = array('Session');
public $components = array('Session', 'Flash');
/**
* The name of the View class this controller sends output to.

View file

@ -145,7 +145,9 @@ class Scaffold {
$this->controller->viewClass = 'Scaffold';
}
$this->_validSession = (
isset($this->controller->Session) && $this->controller->Session->valid()
isset($this->controller->Session) &&
$this->controller->Session->valid() &&
isset($this->controller->Flash)
);
$this->_scaffold($request);
}
@ -246,12 +248,12 @@ class Scaffold {
Inflector::humanize($this->modelKey),
$success
);
return $this->_sendMessage($message);
return $this->_sendMessage($message, 'success');
}
return $this->controller->afterScaffoldSaveError($action);
}
if ($this->_validSession) {
$this->controller->Session->setFlash(__d('cake', 'Please correct errors below.'));
$this->controller->Flash->set(__d('cake', 'Please correct errors below.'));
}
}
@ -303,7 +305,7 @@ class Scaffold {
}
if ($this->ScaffoldModel->delete()) {
$message = __d('cake', 'The %1$s with id: %2$s has been deleted.', Inflector::humanize($this->modelClass), $id);
return $this->_sendMessage($message);
return $this->_sendMessage($message, 'success');
}
$message = __d('cake',
'There was an error deleting the %1$s with id: %2$s',
@ -321,11 +323,12 @@ class Scaffold {
* on the availability of a session
*
* @param string $message Message to display
* @param string $element Flash template to use
* @return void
*/
protected function _sendMessage($message) {
protected function _sendMessage($message, $element = 'default') {
if ($this->_validSession) {
$this->controller->Session->setFlash($message);
$this->controller->Flash->set($message, compact('element'));
return $this->controller->redirect($this->redirect);
}
$this->controller->flash($message, $this->redirect);

View file

@ -87,6 +87,12 @@ class Configure {
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
);
if (PHP_SAPI === 'cli') {
App::uses('ConsoleErrorHandler', 'Console');
$console = new ConsoleErrorHandler();
$exception['handler'] = array($console, 'handleException');
$error['handler'] = array($console, 'handleError');
}
static::_setErrorHandlers($error, $exception);
if (!include APP . 'Config' . DS . 'bootstrap.php') {

View file

@ -134,7 +134,12 @@ class CakeSocket {
$scheme = $this->config['protocol'] . '://';
}
$this->_setSslContext($this->config['host']);
$host = $this->config['host'];
if (isset($this->config['request']['uri']['host'])) {
$host = $this->config['request']['uri']['host'];
}
$this->_setSslContext($host);
if (!empty($this->config['context'])) {
$context = stream_context_create($this->config['context']);
} else {
@ -200,6 +205,7 @@ class CakeSocket {
* Configure the SSL context options.
*
* @param string $host The host name being connected to.
* @return void
*/
protected function _setSslContext($host) {
foreach ($this->config as $key => $value) {

View file

@ -993,6 +993,7 @@ class ControllerTest extends CakeTestCase {
$Controller->constructClasses();
$this->assertFalse(isset($Controller->Session));
$this->assertFalse(isset($Controller->Flash));
}
/**

View file

@ -183,25 +183,6 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::alphaNumeric(''));
}
/**
* testAlphaNumericPassedAsArray method
*
* @return void
*/
public function testAlphaNumericPassedAsArray() {
$this->assertTrue(Validation::alphaNumeric(array('check' => 'frferrf')));
$this->assertTrue(Validation::alphaNumeric(array('check' => '12234')));
$this->assertTrue(Validation::alphaNumeric(array('check' => '1w2e2r3t4y')));
$this->assertTrue(Validation::alphaNumeric(array('check' => '0')));
$this->assertFalse(Validation::alphaNumeric(array('check' => '12 234')));
$this->assertFalse(Validation::alphaNumeric(array('check' => 'dfd 234')));
$this->assertFalse(Validation::alphaNumeric(array('check' => "\n")));
$this->assertFalse(Validation::alphaNumeric(array('check' => "\t")));
$this->assertFalse(Validation::alphaNumeric(array('check' => "\r")));
$this->assertFalse(Validation::alphaNumeric(array('check' => ' ')));
$this->assertFalse(Validation::alphaNumeric(array('check' => '')));
}
/**
* testLengthBetween method
*
@ -231,21 +212,6 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::blank('Blank'));
}
/**
* testBlankAsArray method
*
* @return void
*/
public function testBlankAsArray() {
$this->assertTrue(Validation::blank(array('check' => '')));
$this->assertTrue(Validation::blank(array('check' => ' ')));
$this->assertTrue(Validation::blank(array('check' => "\n")));
$this->assertTrue(Validation::blank(array('check' => "\t")));
$this->assertTrue(Validation::blank(array('check' => "\r")));
$this->assertFalse(Validation::blank(array('check' => ' Blank')));
$this->assertFalse(Validation::blank(array('check' => 'Blank')));
}
/**
* testcc method
*
@ -999,17 +965,6 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::custom('missing regex'));
}
/**
* testCustomAsArray method
*
* @return void
*/
public function testCustomAsArray() {
$this->assertTrue(Validation::custom(array('check' => '12345', 'regex' => '/(?<!\\S)\\d++(?!\\S)/')));
$this->assertFalse(Validation::custom(array('check' => 'Text', 'regex' => '/(?<!\\S)\\d++(?!\\S)/')));
$this->assertFalse(Validation::custom(array('check' => '123.45', 'regex' => '/(?<!\\S)\\d++(?!\\S)/')));
}
/**
* testDateDdmmyyyy method
*

View file

@ -395,6 +395,26 @@ class ViewTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test that plugin files with absolute file paths are scoped
* to the plugin and do now allow any file path.
*
* @expectedException MissingViewException
* @return void
*/
public function testPluginGetTemplateAbsoluteFail() {
$this->Controller->viewPath = 'Pages';
$this->Controller->action = 'display';
$this->Controller->params['pass'] = array('home');
$view = new TestThemeView($this->Controller);
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'Company' . DS . 'TestPluginThree' . DS . 'View' . DS . 'Pages' . DS . 'index.ctp';
$result = $view->getViewFileName('Company/TestPluginThree./Pages/index');
$this->assertPathEquals($expected, $result);
$view->getViewFileName('Company/TestPluginThree./etc/passwd');
}
/**
* Test getLayoutFileName method on plugin
*

View file

@ -27,7 +27,7 @@ class CakeText {
* Generate a random UUID
*
* @see http://www.ietf.org/rfc/rfc4122.txt
* @return RFC 4122 UUID
* @return string RFC 4122 UUID
*/
public static function uuid() {
$node = env('SERVER_ADDR');

View file

@ -73,10 +73,9 @@ class Validation {
* @return bool Success
*/
public static function notBlank($check) {
if (is_array($check)) {
extract(static::_defaults($check));
if (!is_scalar($check)) {
return false;
}
if (empty($check) && (string)$check !== '0') {
return false;
}
@ -95,10 +94,6 @@ class Validation {
* @return bool Success
*/
public static function alphaNumeric($check) {
if (is_array($check)) {
extract(static::_defaults($check));
}
if (empty($check) && $check != '0') {
return false;
}
@ -145,9 +140,6 @@ class Validation {
* @return bool Success
*/
public static function blank($check) {
if (is_array($check)) {
extract(static::_defaults($check));
}
return !static::_check($check, '/[^\\s]/');
}
@ -166,8 +158,8 @@ class Validation {
* @see Validation::luhn()
*/
public static function cc($check, $type = 'fast', $deep = false, $regex = null) {
if (is_array($check)) {
extract(static::_defaults($check));
if (!is_scalar($check)) {
return false;
}
$check = str_replace(array('-', ' '), '', $check);
@ -300,8 +292,8 @@ class Validation {
* @return bool Success
*/
public static function custom($check, $regex = null) {
if (is_array($check)) {
extract(static::_defaults($check));
if (!is_scalar($check)) {
return false;
}
if ($regex === null) {
static::$errors[] = __d('cake_dev', 'You must define a regular expression for %s', 'Validation::custom()');
@ -480,10 +472,6 @@ class Validation {
* @return bool Success
*/
public static function email($check, $deep = false, $regex = null) {
if (is_array($check)) {
extract(static::_defaults($check));
}
if ($regex === null) {
$regex = '/^[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]+)*@' . static::$_pattern['hostname'] . '$/ui';
}
@ -670,10 +658,6 @@ class Validation {
* @return bool Success
*/
public static function phone($check, $regex = null, $country = 'all') {
if (is_array($check)) {
extract(static::_defaults($check));
}
if ($regex === null) {
switch ($country) {
case 'us':
@ -715,10 +699,6 @@ class Validation {
* @return bool Success
*/
public static function postal($check, $regex = null, $country = 'us') {
if (is_array($check)) {
extract(static::_defaults($check));
}
if ($regex === null) {
switch ($country) {
case 'uk':
@ -780,10 +760,6 @@ class Validation {
* @deprecated Deprecated 2.6. Will be removed in 3.0.
*/
public static function ssn($check, $regex = null, $country = null) {
if (is_array($check)) {
extract(static::_defaults($check));
}
if ($regex === null) {
switch ($country) {
case 'dk':
@ -905,35 +881,12 @@ class Validation {
* @return bool Success of match
*/
protected static function _check($check, $regex) {
if (is_string($regex) && preg_match($regex, $check)) {
if (is_string($regex) && is_scalar($check) && preg_match($regex, $check)) {
return true;
}
return false;
}
/**
* Get the values to use when value sent to validation method is
* an array.
*
* @param array $params Parameters sent to validation method
* @return void
*/
protected static function _defaults($params) {
static::_reset();
$defaults = array(
'check' => null,
'regex' => null,
'country' => null,
'deep' => false,
'type' => null
);
$params += $defaults;
if ($params['country'] !== null) {
$params['country'] = mb_strtolower($params['country']);
}
return $params;
}
/**
* Luhn algorithm
*
@ -943,8 +896,8 @@ class Validation {
* @see http://en.wikipedia.org/wiki/Luhn_algorithm
*/
public static function luhn($check, $deep = false) {
if (is_array($check)) {
extract(static::_defaults($check));
if (!is_scalar($check)) {
return false;
}
if ($deep !== true) {
return true;

View file

@ -34,7 +34,7 @@ class TimeHelper extends AppHelper {
/**
* CakeTime instance
*
* @var stdClass
* @var CakeTime
*/
protected $_engine = null;
@ -193,7 +193,7 @@ class TimeHelper extends AppHelper {
/**
* Returns a formatted descriptive date string for given datetime string.
*
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime objectp
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object.
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
* @return string Described, relative date string
* @see CakeTime::niceShort()
@ -465,7 +465,7 @@ class TimeHelper extends AppHelper {
* ```
* $this->Time->format('2012-02-15', '%m-%d-%Y'); // returns 02-15-2012
* $this->Time->format('2012-02-15 23:01:01', '%c'); // returns preferred date and time based on configured locale
* $this->Time->format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A becuase an invalid date was passed
* $this->Time->format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A because an invalid date was passed
* $this->Time->format('2012-02-15 23:01:01', '%c', 'N/A', 'America/New_York'); // converts passed date to timezone
* ```
*

View file

@ -1012,9 +1012,6 @@ class View extends Object {
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
} elseif (strpos($name, DS) !== false) {
if ($name[0] === DS || $name[1] === ':') {
if (is_file($name)) {
return $name;
}
$name = trim($name, DS);
} elseif ($name[0] === '.') {
$name = substr($name, 3);