Skip to content

Commit

Permalink
Merge branch 'master' into 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 20, 2012
2 parents b346227 + 08cde9f commit 554d579
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 27 deletions.
8 changes: 4 additions & 4 deletions lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -53,7 +53,7 @@ class TreeBehavior extends ModelBehavior {
*
* @var array
*/
protected $_deletedRow = null;
protected $_deletedRow = array();

/**
* Initiate Tree behavior
Expand Down Expand Up @@ -130,7 +130,7 @@ public function beforeDelete(Model $Model, $cascade = true) {
'fields' => array($Model->escapeField($left), $Model->escapeField($right)),
'recursive' => -1));
if ($data) {
$this->_deletedRow = current($data);
$this->_deletedRow[$Model->alias] = current($data);
}
return true;
}
Expand All @@ -145,8 +145,8 @@ public function beforeDelete(Model $Model, $cascade = true) {
*/
public function afterDelete(Model $Model) {
extract($this->settings[$Model->alias]);
$data = $this->_deletedRow;
$this->_deletedRow = null;
$data = $this->_deletedRow[$Model->alias];
$this->_deletedRow[$Model->alias] = null;

if (!$data[$right] || !$data[$left]) {
return true;
Expand Down
7 changes: 3 additions & 4 deletions lib/Cake/Model/Model.php
Expand Up @@ -1317,10 +1317,8 @@ public function schema($field = false) {
if ($this->useTable !== false && (!is_array($this->_schema) || $field === true)) {
$db = $this->getDataSource();
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
if (method_exists($db, 'describe') && $this->useTable !== false) {
if (method_exists($db, 'describe')) {
$this->_schema = $db->describe($this);
} elseif ($this->useTable === false) {
$this->_schema = array();
}
}
if (!is_string($field)) {
Expand Down Expand Up @@ -1484,7 +1482,8 @@ public function create($data = array(), $filterKey = false) {
$this->validationErrors = array();

if ($data !== null && $data !== false) {
foreach ($this->schema() as $field => $properties) {
$schema = (array)$this->schema();
foreach ($schema as $field => $properties) {
if ($this->primaryKey !== $field && isset($properties['default']) && $properties['default'] !== '') {
$defaults[$field] = $properties['default'];
}
Expand Down
15 changes: 9 additions & 6 deletions lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1242,7 +1242,7 @@ protected function _encodeString($text, $charset) {
* @param string $message Message to wrap
* @return array Wrapped message
*/
protected function _wrap($message) {
protected function _wrap($message, $wrapLength = CakeEmail::LINE_LENGTH_MUST) {
$message = str_replace(array("\r\n", "\r"), "\n", $message);
$lines = explode("\n", $message);
$formatted = array();
Expand All @@ -1253,7 +1253,10 @@ protected function _wrap($message) {
continue;
}
if (!preg_match('/\<[a-z]/i', $line)) {
$formatted = array_merge($formatted, explode("\n", wordwrap($line, self::LINE_LENGTH_SHOULD, "\n")));
$formatted = array_merge(
$formatted,
explode("\n", wordwrap($line, $wrapLength, "\n"))
);
continue;
}

Expand All @@ -1266,7 +1269,7 @@ protected function _wrap($message) {
$tag .= $char;
if ($char === '>') {
$tagLength = strlen($tag);
if ($tagLength + $tmpLineLength < self::LINE_LENGTH_SHOULD) {
if ($tagLength + $tmpLineLength < $wrapLength) {
$tmpLine .= $tag;
$tmpLineLength += $tagLength;
} else {
Expand All @@ -1275,7 +1278,7 @@ protected function _wrap($message) {
$tmpLine = '';
$tmpLineLength = 0;
}
if ($tagLength > self::LINE_LENGTH_SHOULD) {
if ($tagLength > $wrapLength) {
$formatted[] = $tag;
} else {
$tmpLine = $tag;
Expand All @@ -1292,14 +1295,14 @@ protected function _wrap($message) {
$tag = '<';
continue;
}
if ($char === ' ' && $tmpLineLength >= self::LINE_LENGTH_SHOULD) {
if ($char === ' ' && $tmpLineLength >= $wrapLength) {
$formatted[] = $tmpLine;
$tmpLineLength = 0;
continue;
}
$tmpLine .= $char;
$tmpLineLength++;
if ($tmpLineLength === self::LINE_LENGTH_SHOULD) {
if ($tmpLineLength === $wrapLength) {
$nextChar = $line[$i + 1];
if ($nextChar === ' ' || $nextChar === '<') {
$formatted[] = trim($tmpLine);
Expand Down
14 changes: 14 additions & 0 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -906,6 +906,20 @@ public function testSchema() {
$this->assertEquals($Post->getColumnTypes(), array_combine($columns, $types));
}

/**
* Check schema() on a model with useTable = false;
*
* @return void
*/
public function testSchemaUseTableFalse() {
$model = new TheVoid();
$result = $model->schema();
$this->assertNull($result);

$result = $model->create();
$this->assertEmpty($result);
}

/**
* data provider for time tests.
*
Expand Down
16 changes: 8 additions & 8 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -42,8 +42,8 @@ public function formatAddress($address) {
* Wrap to protected method
*
*/
public function wrap($text) {
return parent::_wrap($text);
public function wrap($text, $length = CakeEmail::LINE_LENGTH_MUST) {
return parent::_wrap($text, $length);
}

/**
Expand Down Expand Up @@ -1398,7 +1398,7 @@ public function testResetWithCharset() {
*/
public function testWrap() {
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.';
$result = $this->CakeEmail->wrap($text);
$result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac turpis orci,',
'non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.',
Expand All @@ -1407,7 +1407,7 @@ public function testWrap() {
$this->assertSame($expected, $result);

$text = 'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan amet.';
$result = $this->CakeEmail->wrap($text);
$result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum dolor sit amet, consectetur < adipiscing elit. Donec ac turpis',
'orci, non commodo odio. Morbi nibh nisi, vehicula > pellentesque accumsan',
Expand All @@ -1417,7 +1417,7 @@ public function testWrap() {
$this->assertSame($expected, $result);

$text = '<p>Lorem ipsum dolor sit amet,<br> consectetur adipiscing elit.<br> Donec ac turpis orci, non <b>commodo</b> odio. <br /> Morbi nibh nisi, vehicula pellentesque accumsan amet.<hr></p>';
$result = $this->CakeEmail->wrap($text);
$result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'<p>Lorem ipsum dolor sit amet,<br> consectetur adipiscing elit.<br> Donec ac',
'turpis orci, non <b>commodo</b> odio. <br /> Morbi nibh nisi, vehicula',
Expand All @@ -1427,7 +1427,7 @@ public function testWrap() {
$this->assertSame($expected, $result);

$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac <a href="http://cakephp.org">turpis</a> orci, non commodo odio. Morbi nibh nisi, vehicula pellentesque accumsan amet.';
$result = $this->CakeEmail->wrap($text);
$result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac',
'<a href="http://cakephp.org">turpis</a> orci, non commodo odio. Morbi nibh',
Expand All @@ -1437,7 +1437,7 @@ public function testWrap() {
$this->assertSame($expected, $result);

$text = 'Lorem ipsum <a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">ok</a>';
$result = $this->CakeEmail->wrap($text);
$result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum',
'<a href="http://www.cakephp.org/controller/action/param1/param2" class="nice cool fine amazing awesome">',
Expand All @@ -1447,7 +1447,7 @@ public function testWrap() {
$this->assertSame($expected, $result);

$text = 'Lorem ipsum withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite ok.';
$result = $this->CakeEmail->wrap($text);
$result = $this->CakeEmail->wrap($text, CakeEmail::LINE_LENGTH_SHOULD);
$expected = array(
'Lorem ipsum',
'withonewordverybigMorethanthelineshouldsizeofrfcspecificationbyieeeavailableonieeesite',
Expand Down
11 changes: 11 additions & 0 deletions lib/Cake/Utility/Hash.php
Expand Up @@ -699,6 +699,17 @@ public static function reduce(array $data, $path, $function) {
* Apply a callback to a set of extracted values using `$function`.
* The function will get the extracted values as the first argument.
*
* ### Example
*
* You can easily count the results of an extract using apply().
* For example to count the comments on an Article:
*
* `$count = Hash::apply($data, 'Article.Comment.{n}', 'count');`
*
* You could also use a function like `array_sum` to sum the results.
*
* `$total = Hash::apply($data, '{n}.Item.price', 'array_sum');`
*
* @param array $data The data to reduce.
* @param string $path The path to extract from $data.
* @param callable $function The function to call on each extracted value.
Expand Down
3 changes: 1 addition & 2 deletions lib/Cake/View/Helper.php
Expand Up @@ -751,8 +751,7 @@ public function value($options = array(), $field = null, $key = 'value') {

/**
* Sets the defaults for an input tag. Will set the
* name, value, and id attributes for an array of html attributes. Will also
* add a 'form-error' class if the field contains validation errors.
* name, value, and id attributes for an array of html attributes.
*
* @param string $field The field name to initialize.
* @param array $options Array of options to use while initializing an input field.
Expand Down
8 changes: 5 additions & 3 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -303,9 +303,10 @@ public function tagIsInvalid() {
* can be overridden when calling input()
* - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
*
* @param string|array $model The model object which the form is being defined for. Should
* include the plugin name for plugin forms. e.g. `ContactManager.Contact`.
* @param mixed $model The model name for which the form is being defined. Should
* include the plugin name for plugin models. e.g. `ContactManager.Contact`.
* If an array is passed and $options argument is empty, the array will be used as options.
* If `false` no model is used.
* @param array $options An array of html attributes and options.
* @return string An formatted opening FORM tag.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-create
Expand Down Expand Up @@ -2746,7 +2747,8 @@ protected function _generateOptions($name, $options = array()) {
}

/**
* Sets field defaults and adds field to form security input hash
* Sets field defaults and adds field to form security input hash.
* Will also add a 'form-error' class if the field contains validation errors.
*
* ### Options
*
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/View/ThemeView.php
Expand Up @@ -25,6 +25,7 @@
* Stub class for 2.1 Compatibility
*
* @package Cake.View
* @deprecated Deprecated since 2.1, use View class instead
*/
class ThemeView extends View {

Expand Down

0 comments on commit 554d579

Please sign in to comment.