Merge commit 'origin/1.3' into 1.3-form

This commit is contained in:
José Lorenzo Rodríguez 2010-02-27 23:23:43 -04:30
commit 1f1e0f4ff7
9 changed files with 104 additions and 58 deletions

View file

@ -1,5 +1,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// +--------------------------------------------------------------------------------------------+ // // CakePHP Version
// +--------------------------------------------------------------------------------------------+ //
// CakePHP Version
//
// Holds a static string representing the current version of CakePHP
//

View file

@ -264,10 +264,13 @@ class ShellDispatcher {
}
}
Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php'));
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
App::build();
}
Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php'));
return true;
}

View file

@ -289,9 +289,10 @@ class ViewTask extends Shell {
}
$controllerClassName = $this->controllerName . 'Controller';
$controllerObj =& new $controllerClassName();
$controllerObj->plugin = $this->plugin;
$controllerObj->constructClasses();
$modelClass = $controllerObj->modelClass;
$modelObj =& ClassRegistry::getObject($controllerObj->modelKey);
$modelObj =& $controllerObj->{$controllerObj->modelClass};
if ($modelObj) {
$primaryKey = $modelObj->primaryKey;
@ -302,13 +303,10 @@ class ViewTask extends Shell {
$fields = array_keys($schema);
$associations = $this->__associations($modelObj);
} else {
$primaryKey = null;
$displayField = null;
$primaryKey = $displayField = null;
$singularVar = Inflector::variable(Inflector::singularize($this->controllerName));
$singularHumanName = $this->_singularHumanName($this->controllerName);
$fields = array();
$schema = array();
$associations = array();
$fields = $schema = $associations = array();
}
$pluralVar = Inflector::variable($this->controllerName);
$pluralHumanName = $this->_pluralHumanName($this->controllerName);

View file

@ -56,9 +56,15 @@ if (!empty($validate)):
echo "\t);\n";
endif;
foreach ($associations as $assoc):
if (!empty($assoc)):
?>
//The Associations below have been created with all possible keys, those that are not needed can be removed
<?php
break;
endif;
endforeach;
foreach (array('hasOne', 'belongsTo') as $assocType):
if (!empty($associations[$assocType])):
$typeCount = count($associations[$assocType]);

View file

@ -484,26 +484,26 @@ class DboSource extends DataSource {
}
return $data;
}
$cacheKey = crc32($data);
$cacheKey = crc32($this->startQuote.$data.$this->endQuote);
if (isset($this->methodCache[__FUNCTION__][$cacheKey])) {
return $this->methodCache[__FUNCTION__][$cacheKey];
}
$data = trim($data);
if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string
if (strpos($data, '.') === false) { // string
return $this->startQuote . $data . $this->endQuote;
return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . $data . $this->endQuote;
}
$items = explode('.', $data);
return $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote;
return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote;
}
if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.*
return $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data);
return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data);
}
if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions
return $matches[1] . '(' . $this->name($matches[2]) . ')';
return $this->methodCache[__FUNCTION__][$cacheKey] = $matches[1] . '(' . $this->name($matches[2]) . ')';
}
if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/', $data, $matches)) {
return preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]));
return $this->methodCache[__FUNCTION__][$cacheKey] = preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]));
}
return $this->methodCache[__FUNCTION__][$cacheKey] = $data;
}

View file

@ -2105,9 +2105,6 @@ class Model extends Overloadable {
function _findFirst($state, $query, $results = array()) {
if ($state == 'before') {
$query['limit'] = 1;
if (empty($query['conditions']) && !empty($this->id)) {
$query['conditions'] = array($this->escapeField() => $this->id);
}
return $query;
} elseif ($state == 'after') {
if (empty($results[0])) {

View file

@ -698,8 +698,8 @@ class FormHelper extends AppHelper {
}
if (!isset($options['type'])) {
$magicType = true;
$options['type'] = 'text';
$fieldDef = array();
if (isset($options['options'])) {
$options['type'] = 'select';
} elseif (in_array($fieldKey, array('psword', 'passwd', 'password'))) {
@ -740,13 +740,19 @@ class FormHelper extends AppHelper {
}
$types = array('checkbox', 'radio', 'select');
if (!isset($options['options']) && in_array($options['type'], $types)) {
if (
(!isset($options['options']) && in_array($options['type'], $types)) ||
(isset($magicType) && $options['type'] == 'text')
) {
$view =& ClassRegistry::getObject('view');
$varName = Inflector::variable(
Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey))
);
$varOptions = $view->getVar($varName);
if (is_array($varOptions)) {
if ($options['type'] !== 'radio') {
$options['type'] = 'select';
}
$options['options'] = $varOptions;
}
}
@ -759,13 +765,9 @@ class FormHelper extends AppHelper {
$options['maxlength'] = array_sum(explode(',', $fieldDef['length']))+1;
}
$div = true;
$divOptions = array();
if (array_key_exists('div', $options)) {
$div = $options['div'];
unset($options['div']);
}
$div = $this->_extractOption('div', $options, true);
unset($options['div']);
if (!empty($div)) {
$divOptions['class'] = 'input';
@ -778,7 +780,7 @@ class FormHelper extends AppHelper {
if (
isset($this->fieldset[$modelKey]) &&
in_array($fieldKey, $this->fieldset[$modelKey]['validates'])
) {
) {
$divOptions = $this->addClass($divOptions, 'required');
}
if (!isset($divOptions['tag'])) {
@ -795,11 +797,7 @@ class FormHelper extends AppHelper {
if ($options['type'] === 'radio') {
$label = false;
if (isset($options['options'])) {
if (is_array($options['options'])) {
$radioOptions = $options['options'];
} else {
$radioOptions = array($options['options']);
}
$radioOptions = (array)$options['options'];
unset($options['options']);
}
}
@ -833,36 +831,24 @@ class FormHelper extends AppHelper {
$label = $this->label($fieldName, $labelText, $labelAttributes);
}
$error = null;
if (isset($options['error'])) {
$error = $options['error'];
unset($options['error']);
}
$error = $this->_extractOption('error', $options, null);
unset($options['error']);
$selected = $this->_extractOption('selected', $options, null);
unset($options['selected']);
$selected = null;
if (array_key_exists('selected', $options)) {
$selected = $options['selected'];
unset($options['selected']);
}
if (isset($options['rows']) || isset($options['cols'])) {
$options['type'] = 'textarea';
}
$timeFormat = 12;
if (isset($options['timeFormat'])) {
$timeFormat = $options['timeFormat'];
unset($options['timeFormat']);
}
$dateFormat = 'MDY';
if (isset($options['dateFormat'])) {
$dateFormat = $options['dateFormat'];
unset($options['dateFormat']);
}
if ($options['type'] === 'datetime' || $options['type'] === 'date' || $options['type'] === 'time' || $options['type'] === 'select') {
$options += array('empty' => false);
}
if ($options['type'] === 'datetime' || $options['type'] === 'date' || $options['type'] === 'time') {
$dateFormat = $this->_extractOption('dateFormat', $options, 'MDY');
$timeFormat = $this->_extractOption('timeFormat', $options, 12);
unset($options['dateFormat'], $options['timeFormat']);
}
$type = $options['type'];
$out = array_merge(
@ -938,6 +924,22 @@ class FormHelper extends AppHelper {
return $output;
}
/**
* Extracts a single option from an options array.
*
* @param string $name The name of the option to pull out.
* @param array $options The array of options you want to extract.
* @param mixed $default The default option value
* @return the contents of the option or default
* @access protected
*/
function _extractOption($name, $options, $default = null) {
if (array_key_exists($name, $options)) {
return $options[$name];
}
return $default;
}
/**
* Creates a checkbox input widget.
*
@ -1224,13 +1226,24 @@ class FormHelper extends AppHelper {
}
/**
* Creates a submit button element.
* Creates a submit button element. This method will generate `<input />` elements that
* can be used to submit, and reset forms by using $options. image submits can be created by supplying an
* image path for $caption.
*
* ### Options
*
* - `div` - Include a wrapping div? Defaults to true. Accepts sub options similar to
* FormHelper::input().
* - `before` - Content to include before the input.
* - `after` - Content to include after the input.
* - `type` - Set to 'reset' for reset inputs. Defaults to 'submit'
* - Other attributes will be assigned to the input element.
*
* @param string $caption The label appearing on the button OR if string contains :// or the
* extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension
* exists, AND the first character is /, image is relative to webroot,
* OR if the first character is not /, image is relative to webroot/img.
* @param array $options
* @param array $options Array of options. See above.
* @return string A HTML submit button
* @access public
*/

View file

@ -4857,6 +4857,7 @@ class ModelReadTest extends BaseModelTest {
* Tests that the database configuration assigned to the model can be changed using
* (before|after)Find callbacks
*
* @access public
* @return void
*/
function testCallbackSourceChange() {
@ -4865,9 +4866,6 @@ class ModelReadTest extends BaseModelTest {
$this->assertEqual(3, count($TestModel->find('all')));
$this->expectError(new PatternExpectation('/Non-existent data source foo/i'));
if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 50300) {
$this->expectError(new PatternExpectation('/Only variable references/i'));
}
$this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
}
@ -6380,6 +6378,21 @@ class ModelReadTest extends BaseModelTest {
$this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']);
}
/**
* Test that find('first') does not use the id set to the object.
*
* @return void
*/
function testFindFirstNoIdUsed() {
$this->loadFixtures('Project');
$Project =& new Project();
$Project->id = 3;
$result = $Project->find('first');
$this->assertEqual($result['Project']['name'], 'Project 1', 'Wrong record retrieved');
}
/**
* test find with COUNT(DISTINCT field)
*

View file

@ -2063,6 +2063,21 @@ class FormHelperTest extends CakeTestCase {
'/div'
);
$this->assertTags($result, $expected);
//Check that magic types still work for plural/singular vars
$view =& ClassRegistry::getObject('view');
$view->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.type');
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'ModelType'), 'Type', '/label',
'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'),
array('option' => array('value' => 'value')), 'good', '/option',
array('option' => array('value' => 'other')), 'bad', '/option',
'/select',
'/div'
);
$this->assertTags($result, $expected);
}
/**