Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.6' into 3.0
Browse files Browse the repository at this point in the history
Conflicts:
	lib/Cake/Cache/Engine/RedisEngine.php
	lib/Cake/Console/Command/UpgradeShell.php
	lib/Cake/Console/Templates/default/views/form.ctp
	lib/Cake/Console/Templates/default/views/view.ctp
	lib/Cake/Controller/Component/PaginatorComponent.php
	lib/Cake/Controller/Controller.php
	lib/Cake/Model/Behavior/AclBehavior.php
	lib/Cake/Model/Datasource/Database/Sqlserver.php
	lib/Cake/Model/Datasource/DboSource.php
	lib/Cake/Model/Model.php
	lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php
	lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php
	lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
	lib/Cake/Test/Case/View/Helper/FormHelperTest.php
	lib/Cake/TestSuite/CakeTestSuiteDispatcher.php
	lib/Cake/View/Errors/missing_component.ctp
	lib/Cake/View/Helper/FormHelper.php
	src/Controller/Component/AuthComponent.php
	src/Core/Configure.php
	src/Utility/Debugger.php
	src/View/View.php
	tests/TestCase/Controller/Component/AuthComponentTest.php
	tests/TestCase/Validation/ValidationTest.php
  • Loading branch information
markstory committed May 17, 2014
2 parents ad7d27f + 2e4d6eb commit 3bba1eb
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 20 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 5.4
- 5.5
- 5.6

env:
- DB=mysql db_class='Cake\Database\Driver\Mysql' db_dsn='mysql:host=0.0.0.0;dbname=cakephp_test' db_database='cakephp_test' db_login='travis' db_password=''
Expand Down
10 changes: 6 additions & 4 deletions src/Cache/Engine/RedisEngine.php
@@ -1,7 +1,5 @@
<?php
/**
* Redis storage engine for cache
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -48,6 +46,7 @@ class RedisEngine extends CacheEngine {
* cache::gc from ever being called automatically.
* - `server` URL or ip to the Redis server host.
* - `timeout` timeout in seconds (float).
* - `unix_socket` Path to the unix socket file (default: false)
*
* @var array
*/
Expand All @@ -61,7 +60,8 @@ class RedisEngine extends CacheEngine {
'prefix' => null,
'probability' => 100,
'server' => '127.0.0.1',
'timeout' => 0
'timeout' => 0,
'unix_socket' => false,
];

/**
Expand Down Expand Up @@ -90,7 +90,9 @@ protected function _connect() {
$return = false;
try {
$this->_Redis = new \Redis();
if (empty($this->_config['persistent'])) {
if (!empty($this->settings['unix_socket'])) {
$return = $this->_Redis->connect($this->settings['unix_socket']);
} elseif (empty($this->_config['persistent'])) {
$return = $this->_Redis->connect($this->_config['server'], $this->_config['port'], $this->_config['timeout']);
} else {
$persistentId = $this->_config['port'] . $this->_config['timeout'] . $this->_config['database'];
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -739,6 +739,10 @@ public function constructAuthenticate() {
unset($authenticate[AuthComponent::ALL]);
}
foreach ($authenticate as $class => $config) {
if (!empty($config['className'])) {
$class = $config['className'];
unset($config['className']);
}
$className = App::className($class, 'Controller/Component/Auth', 'Authenticate');
if (!class_exists($className)) {
throw new Error\Exception(sprintf('Authentication adapter "%s" was not found.', $class));
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Expand Up @@ -636,7 +636,7 @@ public function referer($default = null, $local = false) {

$referer = $this->request->referer($local);
if ($referer === '/' && $default) {
return Router::url($default, true);
return Router::url($default, !$local);
}
return $referer;
}
Expand Down
15 changes: 9 additions & 6 deletions src/Network/Email/Email.php
Expand Up @@ -772,8 +772,10 @@ public function getHeaders(array $include = array()) {
}

$headers['MIME-Version'] = '1.0';
if (!empty($this->_attachments) || $this->_emailFormat === 'both') {
if (!empty($this->_attachments)) {
$headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->_boundary . '"';
} elseif ($this->_emailFormat === 'both') {
$headers['Content-Type'] = 'multipart/alternative; boundary="' . $this->_boundary . '"';
} elseif ($this->_emailFormat === 'text') {
$headers['Content-Type'] = 'text/plain; charset=' . $this->_getContentTypeCharset();
} elseif ($this->_emailFormat === 'html') {
Expand Down Expand Up @@ -1067,7 +1069,7 @@ public function attachments($attachments = null) {
$fileName = $fileInfo['file'];
$fileInfo['file'] = realpath($fileInfo['file']);
if ($fileInfo['file'] === false || !file_exists($fileInfo['file'])) {
throw new Error\SocketException('File not found: "%s"', $fileName);
throw new Error\SocketException(sprintf('File not found: "%s"', $fileName));
}
if (is_int($name)) {
$name = basename($fileInfo['file']);
Expand Down Expand Up @@ -1590,6 +1592,7 @@ protected function _render($content) {
$hasInlineAttachments = count($contentIds) > 0;
$hasAttachments = !empty($this->_attachments);
$hasMultipleTypes = count($rendered) > 1;
$multiPart = ($hasAttachments || $hasMultipleTypes);

$boundary = $relBoundary = $textBoundary = $this->_boundary;

Expand All @@ -1600,15 +1603,15 @@ protected function _render($content) {
$relBoundary = $textBoundary = 'rel-' . $boundary;
}

if ($hasMultipleTypes) {
if ($hasMultipleTypes && $hasAttachments) {
$msg[] = '--' . $relBoundary;
$msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $boundary . '"';
$msg[] = '';
$textBoundary = 'alt-' . $boundary;
}

if (isset($rendered['text'])) {
if ($textBoundary !== $boundary || $hasAttachments) {
if ($multiPart) {
$msg[] = '--' . $textBoundary;
$msg[] = 'Content-Type: text/plain; charset=' . $this->_getContentTypeCharset();
$msg[] = 'Content-Transfer-Encoding: ' . $this->_getContentTransferEncoding();
Expand All @@ -1621,7 +1624,7 @@ protected function _render($content) {
}

if (isset($rendered['html'])) {
if ($textBoundary !== $boundary || $hasAttachments) {
if ($multiPart) {
$msg[] = '--' . $textBoundary;
$msg[] = 'Content-Type: text/html; charset=' . $this->_getContentTypeCharset();
$msg[] = 'Content-Transfer-Encoding: ' . $this->_getContentTransferEncoding();
Expand All @@ -1633,7 +1636,7 @@ protected function _render($content) {
$msg[] = '';
}

if ($hasMultipleTypes) {
if ($textBoundary !== $relBoundary) {
$msg[] = '--' . $textBoundary . '--';
$msg[] = '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Debugger.php
Expand Up @@ -699,7 +699,7 @@ public static function addFormat($format, array $strings) {
* @deprecated Use Debugger::outputAs() and Debugger::addFormat(). Will be removed
* in 3.0
*/
public function output($format = null, array $strings = array()) {
public static function output($format = null, $strings = array()) {
$self = Debugger::getInstance();
$data = null;

Expand Down
2 changes: 2 additions & 0 deletions src/Utility/Hash.php
Expand Up @@ -1030,6 +1030,8 @@ public static function nest(array $data, array $options = array()) {

if ($options['root']) {
$root = $options['root'];
} elseif (!$return) {
return array();
} else {
$root = static::get($return[0], $parentKeys);
}
Expand Down
6 changes: 6 additions & 0 deletions src/View/Helper/FormHelper.php
Expand Up @@ -345,7 +345,13 @@ public function create($model = null, $options = []) {
if (!empty($append)) {
$append = $templater->format('hiddenblock', ['content' => $append]);
}

$this->_lastAction = $action;
if (strpos($action, '://')) {
$query = parse_url($action, PHP_URL_QUERY);
$query = $query ? '?' . $query : '';
$this->_lastAction = parse_url($action, PHP_URL_PATH) . $query;
}

$actionAttr = $templater->formatAttributes(['action' => $action, 'escape' => false]);
return $templater->format('formstart', [
Expand Down
14 changes: 12 additions & 2 deletions src/View/View.php
Expand Up @@ -605,8 +605,18 @@ public function getVars() {
}

/**
* Returns the contents of the given View variable or a block.
* Blocks are checked before view variables.
* Returns the contents of the given View variable(s)
*
* @param string $var The view var you want the contents of.
* @return mixed The content of the named var if its set, otherwise null.
* @deprecated Will be removed in 3.0. Use View::get() instead.
*/
public function getVar($var) {
return $this->get($var);
}

/**
* Returns the contents of the given View variable.
*
* @param string $var The view var you want the contents of.
* @param mixed $default The default/fallback content of $var.
Expand Down
23 changes: 22 additions & 1 deletion tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -369,6 +369,27 @@ public function testAllConfigWithAuthenticate() {
$this->assertEquals('AuthUsers', $result->config('userModel'));
}

/**
* test defining the same Authenticate object but with different password hashers
*
* @return void
*/
public function testSameAuthenticateWithDifferentHashers() {
$this->Controller->Auth->config('authenticate', [
'FormSimple' => ['className' => 'Form', 'passwordHasher' => 'Simple'],
'FormBlowfish' => ['className' => 'Form', 'passwordHasher' => 'Blowfish'],
]);

$objects = $this->Controller->Auth->constructAuthenticate();
$this->assertEquals(2, count($objects));

$this->assertInstanceOf('Cake\Controller\Component\Auth\FormAuthenticate', $objects[0]);
$this->assertInstanceOf('Cake\Controller\Component\Auth\FormAuthenticate', $objects[1]);

$this->assertInstanceOf('Cake\Controller\Component\Auth\SimplePasswordHasher', $objects[0]->passwordHasher());
$this->assertInstanceOf('Cake\Controller\Component\Auth\BlowfishPasswordHasher', $objects[1]->passwordHasher());
}

/**
* Tests that deny always takes precedence over allow
*
Expand Down Expand Up @@ -715,7 +736,7 @@ public function testDefaultToLoginRedirect() {
);
$event = new Event('Controller.startup', $Controller);

$expected = Router::url($this->Auth->config('loginRedirect'), true);
$expected = Router::url($this->Auth->config('loginRedirect'));
$Controller->expects($this->once())
->method('redirect')
->with($this->equalTo($expected));
Expand Down
93 changes: 90 additions & 3 deletions tests/TestCase/Network/Email/EmailTest.php
Expand Up @@ -1214,6 +1214,49 @@ public function testSendWithInlineAttachments() {
$this->assertContains('--' . $boundary . '--', $result['message']);
}

/**
* Test setting inline attachments and HTML only messages.
*
* @return void
*/
public function testSendWithInlineAttachmentsHtmlOnly() {
$this->CakeEmail->transport('debug');
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to('cake@cakephp.org');
$this->CakeEmail->subject('My title');
$this->CakeEmail->emailFormat('html');
$this->CakeEmail->attachments(array(
'cake.png' => array(
'file' => CORE_PATH . 'VERSION.txt',
'contentId' => 'abc123'
)
));
$result = $this->CakeEmail->send('Hello');

$boundary = $this->CakeEmail->getBoundary();
$this->assertContains('Content-Type: multipart/mixed; boundary="' . $boundary . '"', $result['headers']);
$expected = "--$boundary\r\n" .
"Content-Type: multipart/related; boundary=\"rel-$boundary\"\r\n" .
"\r\n" .
"--rel-$boundary\r\n" .
"Content-Type: text/html; charset=UTF-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n" .
"\r\n" .
"Hello" .
"\r\n" .
"\r\n" .
"\r\n" .
"--rel-$boundary\r\n" .
"Content-Disposition: inline; filename=\"cake.png\"\r\n";
"Content-Type: application/octet-stream\r\n" .
"Content-Transfer-Encoding: base64\r\n" .
"Content-ID: <abc123>\r\n" .
"\r\n";
$this->assertContains($expected, $result['message']);
$this->assertContains('--rel-' . $boundary . '--', $result['message']);
$this->assertContains('--' . $boundary . '--', $result['message']);
}

/**
* Test disabling content-disposition.
*
Expand Down Expand Up @@ -1353,6 +1396,52 @@ public function testSendRenderNoLayout() {
$this->assertNotContains('This email was sent using the CakePHP Framework', $result['message']);
}

/**
* testSendRender both method
*
* @return void
*/
public function testSendRenderBoth() {
$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');

$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->profile(array('empty'));
$this->CakeEmail->template('default', 'default');
$this->CakeEmail->emailFormat('both');
$result = $this->CakeEmail->send();

$this->assertContains('Message-ID: ', $result['headers']);
$this->assertContains('To: ', $result['headers']);

$boundary = $this->CakeEmail->getBoundary();
$this->assertContains('Content-Type: multipart/alternative; boundary="' . $boundary . '"', $result['headers']);

$expected = "--$boundary\r\n" .
"Content-Type: text/plain; charset=UTF-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n" .
"\r\n" .
"\r\n" .
"\r\n" .
"This email was sent using the CakePHP Framework, http://cakephp.org." .
"\r\n" .
"\r\n" .
"--$boundary\r\n" .
"Content-Type: text/html; charset=UTF-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n" .
"\r\n" .
"<!DOCTYPE html";
$this->assertStringStartsWith($expected, $result['message']);

$expected = "</html>\r\n" .
"\r\n" .
"\r\n" .
"--$boundary--\r\n";
$this->assertStringEndsWith($expected, $result['message']);
}

/**
* testSendRender method for ISO-2022-JP
*
Expand Down Expand Up @@ -1591,8 +1680,6 @@ public function testSendMultipleMIME() {
$this->assertFalse(empty($boundary));
$this->assertContains('--' . $boundary, $message);
$this->assertContains('--' . $boundary . '--', $message);
$this->assertContains('--alt-' . $boundary, $message);
$this->assertContains('--alt-' . $boundary . '--', $message);

$this->CakeEmail->attachments(array('fake.php' => __FILE__));
$this->CakeEmail->send();
Expand Down Expand Up @@ -2064,7 +2151,7 @@ public function testBodyEncodingIso2022JpMs() {
}

protected function _checkContentTransferEncoding($message, $charset) {
$boundary = '--alt-' . $this->CakeEmail->getBoundary();
$boundary = '--' . $this->CakeEmail->getBoundary();
$result['text'] = false;
$result['html'] = false;
$length = count($message);
Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase/Utility/HashTest.php
Expand Up @@ -2235,6 +2235,25 @@ public function testMissingParent() {
$this->assertEquals($input, $result);
}

/**
* Tests that nest() returns an empty array for invalid input instead of throwing notices.
*
* @return void
*/
public function testNestInvalid() {
$input = array(
array(
'ParentCategory' => array(
'id' => '1',
'name' => 'Lorem ipsum dolor sit amet',
'parent_id' => '1'
)
)
);
$result = Hash::nest($input);
$this->assertSame(array(), $result);
}

/**
* testMergeDiff method
*
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Validation/ValidationTest.php
Expand Up @@ -1674,8 +1674,7 @@ public function testDecimalCustomRegex() {
public function testDecimalLocaleSet() {
$this->skipIf(DS === '\\', 'The locale is not supported in Windows and affects other tests.');
$restore = setlocale(LC_NUMERIC, 0);
$this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available.");
$this->skipIf(strpos(',', (string)12345.67) === false, "The German locale does not include , for numbers.");
$this->skipIf(setlocale(LC_NUMERIC, 'da_DK') === false, "The Danish locale isn't available.");

$this->assertTrue(Validation::decimal(1.54), '1.54 should be considered a valid float');
$this->assertTrue(Validation::decimal('1.54'), '"1.54" should be considered a valid float');
Expand Down

0 comments on commit 3bba1eb

Please sign in to comment.