Skip to content

Commit

Permalink
Merge branch '1.3' into merger
Browse files Browse the repository at this point in the history
Conflicts:
	cake/libs/configure.php
	cake/libs/controller/components/email.php
	cake/libs/model/datasources/dbo/dbo_mysqli.php
	cake/libs/view/pages/home.ctp
	cake/tests/cases/libs/controller/components/email.test.php
	cake/tests/cases/libs/model/datasources/dbo_source.test.php
	lib/Cake/Config/config.php
	lib/Cake/Console/Command/Task/ViewTask.php
	lib/Cake/Model/Datasource/DboSource.php
	lib/Cake/Model/Model.php
	lib/Cake/Test/Case/Model/ModelReadTest.php
	lib/Cake/Test/Case/Model/ModelValidationTest.php
	lib/Cake/Test/Case/Utility/InflectorTest.php
	lib/Cake/Test/Case/View/Helper/FormHelperTest.php
	lib/Cake/Utility/Inflector.php
	lib/Cake/Utility/Validation.php
	lib/Cake/VERSION.txt
	lib/Cake/View/Helper.php
	lib/Cake/View/Helper/FormHelper.php
  • Loading branch information
markstory committed Oct 2, 2011
2 parents ff570d9 + 534291a commit c9bd973
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/Task/ViewTask.php
Expand Up @@ -327,7 +327,7 @@ public function customAction() {
$this->hr();
$this->out(__d('cake_console', 'Controller Name: %s', $this->controllerName));
$this->out(__d('cake_console', 'Action Name: %s', $action));
$this->out(__d('cake_console', 'Path: %s', $this->params['app'] . DS . $this->controllerName . DS . Inflector::underscore($action) . ".ctp"));
$this->out(__d('cake_console', 'Path: %s', $this->params['app'] . DS . 'View' . DS . $this->controllerName . DS . Inflector::underscore($action) . ".ctp"));
$this->hr();
$looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y','n'), 'y');
if (strtolower($looksGood) == 'y') {
Expand Down
13 changes: 8 additions & 5 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -1488,7 +1488,7 @@ public function generateAssociationQuery($model, $linkModel, $type, $association
$query += array('order' => $assocData['order'], 'limit' => $assocData['limit']);
} else {
$join = array(
'table' => $this->fullTableName($linkModel),
'table' => $linkModel,
'alias' => $association,
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
'conditions' => trim($this->conditions($conditions, true, false, $model))
Expand Down Expand Up @@ -1527,7 +1527,7 @@ public function generateAssociationQuery($model, $linkModel, $type, $association
$joinKeys = array($assocData['foreignKey'], $assocData['associationForeignKey']);
list($with, $joinFields) = $model->joinModel($assocData['with'], $joinKeys);

$joinTbl = $this->fullTableName($model->{$with});
$joinTbl = $model->{$with};
$joinAlias = $joinTbl;

if (is_array($joinFields) && !empty($joinFields)) {
Expand All @@ -1537,8 +1537,8 @@ public function generateAssociationQuery($model, $linkModel, $type, $association
$joinFields = array();
}
} else {
$joinTbl = $this->fullTableName($assocData['joinTable']);
$joinAlias = $joinTbl;
$joinTbl = $assocData['joinTable'];
$joinAlias = $this->fullTableName($assocData['joinTable']);
}
$query = array(
'conditions' => $assocData['conditions'],
Expand Down Expand Up @@ -1622,6 +1622,9 @@ public function buildJoinStatement($join) {
if (!empty($data['conditions'])) {
$data['conditions'] = trim($this->conditions($data['conditions'], true, false));
}
if (!empty($data['table'])) {
$data['table'] = $this->fullTableName($data['table']);
}
return $this->renderJoinStatement($data);
}

Expand Down Expand Up @@ -1904,7 +1907,7 @@ protected function _getJoins($model) {
if (isset($model->{$assoc}) && $model->useDbConfig == $model->{$assoc}->useDbConfig && $model->{$assoc}->getDataSource()) {
$assocData = $model->getAssociated($assoc);
$join[] = $this->buildJoinStatement(array(
'table' => $this->fullTableName($model->{$assoc}),
'table' => $model->{$assoc},
'alias' => $assoc,
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
'conditions' => trim($this->conditions(
Expand Down
5 changes: 1 addition & 4 deletions lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -626,7 +626,7 @@ public function getHeaders($include = array()) {
}
if ($this->_messageId !== false) {
if ($this->_messageId === true) {
$headers['Message-ID'] = '<' . String::UUID() . '@' . env('HTTP_HOST') . '>';
$headers['Message-ID'] = '<' . str_replace('-', '', String::UUID()) . '@' . env('HTTP_HOST') . '>';
} else {
$headers['Message-ID'] = $this->_messageId;
}
Expand All @@ -639,9 +639,6 @@ public function getHeaders($include = array()) {
$headers['MIME-Version'] = '1.0';
if (!empty($this->_attachments)) {
$headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->_boundary . '"';
$headers[] = 'This part of the E-mail should never be seen. If';
$headers[] = 'you are reading this, consider upgrading your e-mail';
$headers[] = 'client to a MIME-compatible client.';
} elseif ($this->_emailFormat === 'text') {
$headers['Content-Type'] = 'text/plain; charset=' . $this->charset;
} elseif ($this->_emailFormat === 'html') {
Expand Down
Expand Up @@ -852,7 +852,7 @@ public function testMessageId() {
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
$result = DebugCompTransport::$lastEmail;

$this->assertPattern('/Message-ID: \<[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}@' . env('HTTP_HOST') . '\>\n/', $result);
$this->assertPattern('/Message-ID: \<[a-f0-9]{8}[a-f0-9]{4}[a-f0-9]{4}[a-f0-9]{4}[a-f0-9]{12}@' . env('HTTP_HOST') . '\>\n/', $result);

$this->Controller->EmailTest->messageId = '<22091985.998877@example.com>';

Expand Down
35 changes: 35 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
Expand Up @@ -3503,6 +3503,41 @@ public function testResetMultipleHabtmAssociations() {
$this->assertEqual($expected, $this->Article->hasAndBelongsToMany);
}

/**
* test that bindModel and unbindModel work with find() calls in between.
*/
function testBindMultipleTimesWithFind() {
$binding = array(
'hasOne' => array(
'ArticlesTag' => array(
'foreignKey' => false,
'type' => 'INNER',
'conditions' => array(
'ArticlesTag.article_id = Article.id'
)
),
'Tag' => array(
'type' => 'INNER',
'foreignKey' => false,
'conditions' => array(
'ArticlesTag.tag_id = Tag.id'
)
)
)
);
$this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
$this->Article->bindModel($binding);
$result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag')));

$this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
$this->Article->bindModel($binding);
$result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag')));

$associated = $this->Article->getAssociated();
$this->assertEqual('hasAndBelongsToMany', $associated['Tag']);
$this->assertFalse(isset($associated['ArticleTag']));
}

/**
* test that autoFields doesn't splice in fields from other databases.
*
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -978,6 +978,7 @@ public function testGenerateAssociationQuerySelfJoin() {
'offset' => array(),
'group' => array()
);
$queryData['joins'][0]['table'] = $this->Dbo->fullTableName($queryData['joins'][0]['table']);
$this->assertEqual($queryData, $expected);
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
Expand Down
38 changes: 38 additions & 0 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -237,6 +237,44 @@ public function testDynamicBehaviorAttachment() {
$this->assertFalse(isset($TestModel->Behaviors->Tree));
}

/**
* testFindWithJoinsOption method
*
* @access public
* @return void
*/
function testFindWithJoinsOption() {
$this->loadFixtures('Article', 'User');
$TestUser =& new User();

$options = array (
'fields' => array(
'user',
'Article.published',
),
'joins' => array (
array (
'table' => 'articles',
'alias' => 'Article',
'type' => 'LEFT',
'conditions' => array(
'User.id = Article.user_id',
),
),
),
'group' => array('User.user'),
'recursive' => -1,
);
$result = $TestUser->find('all', $options);
$expected = array(
array('User' => array('user' => 'garrett'), 'Article' => array('published' => '')),
array('User' => array('user' => 'larry'), 'Article' => array('published' => 'Y')),
array('User' => array('user' => 'mariano'), 'Article' => array('published' => 'Y')),
array('User' => array('user' => 'nate'), 'Article' => array('published' => ''))
);
$this->assertEqual($result, $expected);
}

/**
* Tests cross database joins. Requires $test and $test2 to both be set in DATABASE_CONFIG
* NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections,
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Model/ModelReadTest.php
Expand Up @@ -4750,7 +4750,7 @@ public function testBindMultipleTimesWithDifferentResetSettings() {
*
* @return void
*/
public function bindWithCustomPrimaryKey() {
public function testBindWithCustomPrimaryKey() {
$this->loadFixtures('Story', 'StoriesTag', 'Tag');
$Model = ClassRegistry::init('StoriesTag');
$Model->bindModel(array(
Expand Down Expand Up @@ -5234,7 +5234,7 @@ public function testHabtmFinderQuery() {
'group' => null,
'joins' => array(array(
'alias' => 'ArticlesTag',
'table' => $this->db->fullTableName('articles_tags'),
'table' => 'articles_tags',
'conditions' => array(
array("ArticlesTag.article_id" => '{$__cakeID__$}'),
array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id'))
Expand Down
6 changes: 4 additions & 2 deletions lib/Cake/Test/Case/Utility/InflectorTest.php
Expand Up @@ -399,9 +399,11 @@ public function testRulesClearsCaches() {
$this->assertEquals('Banazzz', Inflector::singularize('Bananas'), 'Was inflected with old rules.');

Inflector::rules('plural', array(
'rules' => array('/(.*)na$/i' => '\1zzz')
'rules' => array('/(.*)na$/i' => '\1zzz'),
'irregular' => array('corpus' => 'corpora')
));
$this->assertEqual('Banazzz', Inflector::pluralize('Banana'), 'Was inflected with old rules.');
$this->assertEqual(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules.');
$this->assertEqual(Inflector::pluralize('corpus'), 'corpora', 'Was inflected with old irregular form.');
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/Test/Case/Utility/ValidationTest.php
Expand Up @@ -1424,6 +1424,8 @@ public function testTime() {
$this->assertTrue(Validation::time('12:01am'));
$this->assertTrue(Validation::time('12:01pm'));
$this->assertTrue(Validation::time('1pm'));
$this->assertTrue(Validation::time('1 pm'));
$this->assertTrue(Validation::time('1 PM'));
$this->assertTrue(Validation::time('01:00'));
$this->assertFalse(Validation::time('1:00'));
$this->assertTrue(Validation::time('1:00pm'));
Expand Down
72 changes: 71 additions & 1 deletion lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -1048,6 +1048,20 @@ public function testFormSecurityMultipleInputFields() {
$this->assertTags($result, $expected);
}

/**
* Test form security with Model.field.0 style inputs
*
* @return void
*/
function testFormSecurityArrayFields() {
$key = 'testKey';

$this->Form->request->params['_Token']['key'] = $key;
$this->Form->create('Address');
$this->Form->input('Address.primary.1');
$this->assertEqual('Address.primary', $this->Form->fields[0]);
}

/**
* testFormSecurityMultipleInputDisabledFields method
*
Expand Down Expand Up @@ -1416,6 +1430,62 @@ public function testPasswordValidation() {
$this->assertTags($result, $expected);
}

/**
* testEmptyErrorValidation method
*
* test validation error div when validation message is an empty string
*
* @access public
* @return void
*/
function testEmptyErrorValidation() {
$this->Form->validationErrors['Contact']['password'] = '';
$result = $this->Form->input('Contact.password');
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
array(),
'/div',
'/div'
);
$this->assertTags($result, $expected);
}

/**
* testEmptyInputErrorValidation method
*
* test validation error div when validation message is overriden by an empty string when calling input()
*
* @access public
* @return void
*/
function testEmptyInputErrorValidation() {
$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
$result = $this->Form->input('Contact.password', array('error' => ''));
$expected = array(
'div' => array('class' => 'input password error'),
'label' => array('for' => 'ContactPassword'),
'Password',
'/label',
'input' => array(
'type' => 'password', 'name' => 'data[Contact][password]',
'id' => 'ContactPassword', 'class' => 'form-error'
),
array('div' => array('class' => 'error-message')),
array(),
'/div',
'/div'
);
$this->assertTags($result, $expected);
}

/**
* testFormValidationAssociated method
*
Expand Down Expand Up @@ -6147,7 +6217,7 @@ public function testCreateOnSubmit() {

$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post',
'id' => 'ContactAddForm', 'method' => 'post',
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
'action' => '/contacts/index/param',
'accept-charset' => 'utf-8'
Expand Down
8 changes: 6 additions & 2 deletions lib/Cake/Utility/Inflector.php
Expand Up @@ -319,7 +319,11 @@ public static function rules($type, $rules, $reset = false) {
if ($reset) {
self::${$var}[$rule] = $pattern;
} else {
self::${$var}[$rule] = array_merge($pattern, self::${$var}[$rule]);
if ($rule === 'uninflected') {
self::${$var}[$rule] = array_merge($pattern, self::${$var}[$rule]);
} else {
self::${$var}[$rule] = $pattern + self::${$var}[$rule];
}
}
unset($rules[$rule], self::${$var}['cache' . ucfirst($rule)]);
if (isset(self::${$var}['merged'][$rule])) {
Expand All @@ -332,7 +336,7 @@ public static function rules($type, $rules, $reset = false) {
}
}
}
self::${$var}['rules'] = array_merge($rules, self::${$var}['rules']);
self::${$var}['rules'] = $rules + self::${$var}['rules'];
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Validation.php
Expand Up @@ -356,7 +356,7 @@ public function datetime($check, $dateFormat = 'ymd', $regex = null) {
* @return boolean Success
*/
public static function time($check) {
return self::_check($check, '%^((0?[1-9]|1[012])(:[0-5]\d){0,2}([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%');
return self::_check($check, '%^((0?[1-9]|1[012])(:[0-5]\d){0,2} ?([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%');
}

/**
Expand Down
1 change: 0 additions & 1 deletion lib/Cake/VERSION.txt
Expand Up @@ -18,4 +18,3 @@
// +--------------------------------------------------------------------------------------------+ //
////////////////////////////////////////////////////////////////////////////////////////////////////
2.0.0-RC2

4 changes: 2 additions & 2 deletions lib/Cake/View/Helper.php
Expand Up @@ -621,7 +621,7 @@ public function value($options = array(), $field = null, $key = 'value') {

$entity = $this->entity();
if (!empty($data) && !empty($entity)) {
$result = Set::extract($data, implode('.', $entity));
$result = Set::extract(implode('.', $entity), $data);
}

$habtmKey = $this->field();
Expand Down Expand Up @@ -666,7 +666,7 @@ protected function _initInputField($field, $options = array()) {
$options = $this->_name($options);
$options = $this->value($options);
$options = $this->domId($options);
if ($this->tagIsInvalid()) {
if ($this->tagIsInvalid() !== false) {
$options = $this->addClass($options, 'form-error');
}
return $options;
Expand Down

0 comments on commit c9bd973

Please sign in to comment.