Permalink
Browse files

Merge branch '2.3' of https://github.com/cakephp/cakephp into feature…

…/smtp-tls
  • Loading branch information...
2 parents f1250a3 + 2359fb7 commit 17db6f9d23ad2aeb16e90aa6a90d52da91553341 @steinkel steinkel committed Jul 23, 2012
@@ -18,6 +18,7 @@
* @since CakePHP(tm) v 0.2.9
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('AppController', 'Controller');
/**
* Static content controller
@@ -18,6 +18,7 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('AppController', 'Controller');
/**
* Error Handling Controller
@@ -16,6 +16,7 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('Component', 'Controller');
App::uses('Hash', 'Utility');
/**
@@ -50,6 +51,20 @@
*
* This would allow you to have different pagination settings for `Comment` and `Post` models.
*
+ * #### Paginating with custom finders
+ *
+ * You can paginate with any find type defined on your model using the `findType` option.
+ *
+ * {{{
+ * $this->Paginator->settings = array(
+ * 'Post' => array(
+ * 'findType' => 'popular'
+ * )
+ * );
+ * }}}
+ *
+ * Would paginate using the `find('popular')` method.
+ *
* @package Cake.Controller.Component
* @link http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html
*/
@@ -19,6 +19,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('Component', 'Controller');
App::uses('Xml', 'Utility');
/**
@@ -23,6 +23,7 @@
App::uses('Sanitize', 'Utility');
App::uses('Router', 'Routing');
App::uses('CakeResponse', 'Network');
+App::uses('Controller', 'Controller');
/**
* Exception Renderer.
View
@@ -88,14 +88,14 @@ class CakeLog {
* @var array
*/
protected static $_defaultLevels = array(
- LOG_EMERG => 'emergency',
- LOG_ALERT => 'alert',
- LOG_CRIT => 'critical',
- LOG_ERR => 'error',
- LOG_WARNING => 'warning',
- LOG_NOTICE => 'notice',
- LOG_INFO => 'info',
- LOG_DEBUG => 'debug',
+ 'emergency' => LOG_EMERG,
+ 'alert' => LOG_ALERT,
+ 'critical' => LOG_CRIT,
+ 'error' => LOG_ERR,
+ 'warning' => LOG_WARNING,
+ 'notice' => LOG_NOTICE,
+ 'info' => LOG_INFO,
+ 'debug' => LOG_DEBUG,
);
/**
@@ -276,8 +276,8 @@ public static function levels($levels = array(), $append = true) {
* @return array default log levels
*/
public static function defaultLevels() {
- self::$_levels = self::$_defaultLevels;
- self::$_levelMap = array_flip(self::$_levels);
+ self::$_levelMap = self::$_defaultLevels;
+ self::$_levels = array_flip(self::$_levelMap);
return self::$_levels;
}
@@ -18,6 +18,7 @@
* @since CakePHP v 1.2.0.4487
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('ModelBehavior', 'Model');
App::uses('AclNode', 'Model');
App::uses('Hash', 'Utility');
@@ -18,6 +18,7 @@
* @since CakePHP(tm) v 1.2.0.5669
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('ModelBehavior', 'Model');
/**
* Behavior to allow for dynamic and atomic manipulation of a Model's associations
@@ -13,6 +13,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('ModelBehavior', 'Model');
App::uses('I18n', 'I18n');
App::uses('I18nModel', 'Model');
@@ -395,9 +396,12 @@ public function afterSave(Model $model, $created) {
$fields = array_merge($this->settings[$model->alias], $this->runtime[$model->alias]['fields']);
if ($created) {
- foreach ($fields as $field) {
+ // set each field value to an empty string
+ foreach ($fields as $key => $field) {
+ if (!is_numeric($key)) {
+ $field = $key;
+ }
if (!isset($tempData[$field])) {
- //set the field value to an empty string
$tempData[$field] = '';
}
}
@@ -18,6 +18,7 @@
* @since CakePHP v 1.2.0.4487
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('ModelBehavior', 'Model');
/**
* Tree Behavior.
@@ -12,6 +12,7 @@
* @since CakePHP(tm) v 1.2.0.4525
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('AppModel', 'Model');
/**
* A model used by TranslateBehavior to access the translation tables.
@@ -946,13 +946,17 @@ public function domain($domain = null) {
* $email->attachments(array('custom_name.png' => array(
* 'file' => 'path/to/file',
* 'mimetype' => 'image/png',
- * 'contentId' => 'abc123'
+ * 'contentId' => 'abc123',
+ * 'contentDisposition' => false
* ));
* }}}
*
* The `contentId` key allows you to specify an inline attachment. In your email text, you
* can use `<img src="cid:abc123" />` to display the image inline.
*
+ * The `contentDisposition` key allows you to disable the `Content-Disposition` header, this can improve
+ * attachment compatibility with outlook email clients.
+ *
* @param string|array $attachments String with the filename or array with filenames
* @return array|CakeEmail Either the array of attachments when getting or $this when setting.
* @throws SocketException
@@ -991,6 +995,7 @@ public function attachments($attachments = null) {
* @param string|array $attachments String with the filename or array with filenames
* @return CakeEmail $this
* @throws SocketException
+ * @see CakeEmail::attachments()
*/
public function addAttachments($attachments) {
$current = $this->_attachments;
@@ -1355,7 +1360,12 @@ protected function _attachFiles($boundary = null) {
$msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64';
- $msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
+ if (
+ !isset($fileInfo['contentDisposition']) ||
+ $fileInfo['contentDisposition']
+ ) {
+ $msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
+ }
$msg[] = '';
$msg[] = $data;
$msg[] = '';
@@ -214,12 +214,12 @@ public function testSelectiveLoggingByLevel() {
}
CakeLog::config('spam', array(
'engine' => 'FileLog',
- 'types' => 'info',
+ 'types' => 'debug',
'file' => 'spam',
));
CakeLog::config('eggs', array(
'engine' => 'FileLog',
- 'types' => array('eggs', 'info', 'error', 'warning'),
+ 'types' => array('eggs', 'debug', 'error', 'warning'),
'file' => 'eggs',
));
@@ -229,13 +229,13 @@ public function testSelectiveLoggingByLevel() {
$this->assertTrue(file_exists(LOGS . 'eggs.log'));
$this->assertFalse(file_exists(LOGS . 'spam.log'));
- CakeLog::write(LOG_INFO, $testMessage);
+ CakeLog::write(LOG_DEBUG, $testMessage);
$this->assertTrue(file_exists(LOGS . 'spam.log'));
$contents = file_get_contents(LOGS . 'spam.log');
- $this->assertContains('Info: ' . $testMessage, $contents);
+ $this->assertContains('Debug: ' . $testMessage, $contents);
$contents = file_get_contents(LOGS . 'eggs.log');
- $this->assertContains('Info: ' . $testMessage, $contents);
+ $this->assertContains('Debug: ' . $testMessage, $contents);
if (file_exists(LOGS . 'spam.log')) {
unlink(LOGS . 'spam.log');
@@ -491,10 +491,10 @@ public function testConvenienceScopedLogging() {
$this->_resetLogConfig();
CakeLog::config('shops', array(
'engine' => 'FileLog',
- 'types' => array('info', 'notice', 'warning'),
+ 'types' => array('info', 'debug', 'notice', 'warning'),
'scopes' => array('transactions', 'orders'),
'file' => 'shops',
- ));
+ ));
CakeLog::info('info message', 'transactions');
$this->assertFalse(file_exists(LOGS . 'error.log'));
@@ -540,14 +540,14 @@ public function testConvenienceMethods() {
$testMessage = 'emergency message';
CakeLog::emergency($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
- $this->assertContains('Emergency: ' . $testMessage, $contents);
+ $this->assertRegExp('/(Emergency|Critical): ' . $testMessage . '/', $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->_deleteLogs();
$testMessage = 'alert message';
CakeLog::alert($testMessage);
$contents = file_get_contents(LOGS . 'error.log');
- $this->assertContains('Alert: ' . $testMessage, $contents);
+ $this->assertRegExp('/(Alert|Critical): ' . $testMessage . '/', $contents);
$this->assertFalse(file_exists(LOGS . 'debug.log'));
$this->_deleteLogs();
@@ -575,14 +575,14 @@ public function testConvenienceMethods() {
$testMessage = 'notice message';
CakeLog::notice($testMessage);
$contents = file_get_contents(LOGS . 'debug.log');
- $this->assertContains('Notice: ' . $testMessage, $contents);
+ $this->assertRegExp('/(Notice|Debug): ' . $testMessage . '/', $contents);
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->_deleteLogs();
$testMessage = 'info message';
CakeLog::info($testMessage);
$contents = file_get_contents(LOGS . 'debug.log');
- $this->assertContains('Info: ' . $testMessage, $contents);
+ $this->assertRegExp('/(Info|Debug): ' . $testMessage . '/', $contents);
$this->assertFalse(file_exists(LOGS . 'error.log'));
$this->_deleteLogs();
@@ -1,9 +1,5 @@
<?php
/**
- * TranslateBehaviorTest file
- *
- * PHP 5
- *
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -12,7 +8,6 @@
*
* @copyright Copyright 2005-2012, 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.Model.Behavior
* @since CakePHP(tm) v 1.2.0.5669
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
@@ -1058,4 +1053,36 @@ public function testUnbindTranslation() {
$this->assertNotContains('slug', $result);
}
+/**
+ * Test that additional records are not inserted for associated translations.
+ *
+ * @return void
+ */
+ public function testNoExtraRowsForAssociatedTranslations() {
+ $this->loadFixtures('Translate', 'TranslatedItem');
+ $TestModel = new TranslatedItem();
+ $TestModel->locale = 'spa';
+ $TestModel->unbindTranslation();
+ $TestModel->bindTranslation(array('name' => 'nameTranslate'));
+
+ $data = array(
+ 'TranslatedItem' => array(
+ 'slug' => 'spanish-name',
+ 'name' => 'Spanish name',
+ ),
+ );
+ $TestModel->create($data);
+ $TestModel->save();
+
+ $Translate = $TestModel->translateModel();
+ $results = $Translate->find('all', array(
+ 'conditions' => array(
+ 'locale' => $TestModel->locale,
+ 'foreign_key' => $TestModel->id
+ )
+ ));
+ $this->assertCount(1, $results, 'Only one field should be saved');
+ $this->assertEquals('name', $results[0]['TranslateTestModel']['field']);
+ }
+
}
@@ -640,13 +640,20 @@ public function testViewVars() {
*/
public function testAttachments() {
$this->CakeEmail->attachments(CAKE . 'basics.php');
- $expected = array('basics.php' => array('file' => CAKE . 'basics.php', 'mimetype' => 'application/octet-stream'));
+ $expected = array(
+ 'basics.php' => array(
+ 'file' => CAKE . 'basics.php',
+ 'mimetype' => 'application/octet-stream'
+ )
+ );
$this->assertSame($this->CakeEmail->attachments(), $expected);
$this->CakeEmail->attachments(array());
$this->assertSame($this->CakeEmail->attachments(), array());
- $this->CakeEmail->attachments(array(array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain')));
+ $this->CakeEmail->attachments(array(
+ array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain')
+ ));
$this->CakeEmail->addAttachments(CAKE . 'bootstrap.php');
$this->CakeEmail->addAttachments(array(CAKE . 'bootstrap.php'));
$this->CakeEmail->addAttachments(array('other.txt' => CAKE . 'bootstrap.php', 'license' => CAKE . 'LICENSE.txt'));
@@ -938,6 +945,43 @@ public function testSendWithInlineAttachments() {
}
/**
+ * Test disabling content-disposition.
+ *
+ * @return void
+ */
+ public function testSendWithNoContentDispositionAttachments() {
+ $this->CakeEmail->transport('debug');
+ $this->CakeEmail->from('cake@cakephp.org');
+ $this->CakeEmail->to('cake@cakephp.org');
+ $this->CakeEmail->subject('My title');
+ $this->CakeEmail->emailFormat('text');
+ $this->CakeEmail->attachments(array(
+ 'cake.png' => array(
+ 'file' => CAKE . 'VERSION.txt',
+ 'contentDisposition' => false
+ )
+ ));
+ $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: text/plain; charset=UTF-8\r\n" .
+ "Content-Transfer-Encoding: 8bit\r\n" .
+ "\r\n" .
+ "Hello" .
+ "\r\n" .
+ "\r\n" .
+ "\r\n" .
+ "--{$boundary}\r\n" .
+ "Content-Type: application/octet-stream\r\n" .
+ "Content-Transfer-Encoding: base64\r\n" .
+ "\r\n";
+
+ $this->assertContains($expected, $result['message']);
+ $this->assertContains('--' . $boundary . '--', $result['message']);
+ }
+/**
* testSendWithLog method
*
* @return void
Oops, something went wrong.

0 comments on commit 17db6f9

Please sign in to comment.