Merge branch '1.2' into 1.3-merger

Conflicts:
	cake/console/libs/tasks/controller.php
	cake/console/libs/tasks/model.php
This commit is contained in:
mark_story 2009-11-15 20:05:55 -05:00
commit 58383d3cb9
13 changed files with 72 additions and 36 deletions

View file

@ -280,7 +280,7 @@ class Dispatcher extends Object {
$params['form']['_method'] = env('HTTP_X_HTTP_METHOD_OVERRIDE'); $params['form']['_method'] = env('HTTP_X_HTTP_METHOD_OVERRIDE');
} }
if (isset($params['form']['_method'])) { if (isset($params['form']['_method'])) {
if (isset($_SERVER) && !empty($_SERVER)) { if (!empty($_SERVER)) {
$_SERVER['REQUEST_METHOD'] = $params['form']['_method']; $_SERVER['REQUEST_METHOD'] = $params['form']['_method'];
} else { } else {
$_ENV['REQUEST_METHOD'] = $params['form']['_method']; $_ENV['REQUEST_METHOD'] = $params['form']['_method'];

View file

@ -36,9 +36,11 @@ class MemcacheEngine extends CacheEngine {
var $__Memcache = null; var $__Memcache = null;
/** /**
* settings * Settings
* servers = string or array of memcache servers, default => 127.0.0.1 *
* compress = boolean, default => false * - servers = string or array of memcache servers, default => 127.0.0.1. If an
* array MemcacheEngine will use them as a pool.
* - compress = boolean, default => false
* *
* @var array * @var array
* @access public * @access public
@ -60,7 +62,10 @@ class MemcacheEngine extends CacheEngine {
return false; return false;
} }
parent::init(array_merge(array( parent::init(array_merge(array(
'engine'=> 'Memcache', 'prefix' => Inflector::slug(APP_DIR) . '_', 'servers' => array('127.0.0.1'), 'compress'=> false 'engine'=> 'Memcache',
'prefix' => Inflector::slug(APP_DIR) . '_',
'servers' => array('127.0.0.1'),
'compress'=> false
), $settings) ), $settings)
); );
@ -100,7 +105,7 @@ class MemcacheEngine extends CacheEngine {
*/ */
function write($key, &$value, $duration) { function write($key, &$value, $duration) {
$expires = time() + $duration; $expires = time() + $duration;
$this->__Memcache->set($key.'_expires', $expires, $this->settings['compress'], $expires); $this->__Memcache->set($key . '_expires', $expires, $this->settings['compress'], $expires);
return $this->__Memcache->set($key, $value, $this->settings['compress'], $expires); return $this->__Memcache->set($key, $value, $this->settings['compress'], $expires);
} }
@ -113,7 +118,7 @@ class MemcacheEngine extends CacheEngine {
*/ */
function read($key) { function read($key) {
$time = time(); $time = time();
$cachetime = intval($this->__Memcache->get($key.'_expires')); $cachetime = intval($this->__Memcache->get($key . '_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) { if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false; return false;
} }

View file

@ -267,20 +267,7 @@ class Configure extends Object {
$content = ''; $content = '';
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$content .= "\$config['$type']['$key']"; $content .= "\$config['$type']['$key'] = " . var_export($value, true) . ";\n";
if (is_array($value)) {
$content .= " = array(";
foreach ($value as $key1 => $value2) {
$value2 = addslashes($value2);
$content .= "'$key1' => '$value2', ";
}
$content .= ");\n";
} else {
$value = addslashes($value);
$content .= " = '$value';\n";
}
} }
if (is_null($type)) { if (is_null($type)) {
$write = false; $write = false;

View file

@ -577,7 +577,8 @@ class HttpSocket extends CakeSocket {
$stripIfEmpty = array( $stripIfEmpty = array(
'query' => '?%query', 'query' => '?%query',
'fragment' => '#%fragment', 'fragment' => '#%fragment',
'user' => '%user:%pass@' 'user' => '%user:%pass@',
'host' => '%host:%port/'
); );
foreach ($stripIfEmpty as $key => $strip) { foreach ($stripIfEmpty as $key => $strip) {
@ -590,7 +591,6 @@ class HttpSocket extends CakeSocket {
if (array_key_exists($uri['scheme'], $defaultPorts) && $defaultPorts[$uri['scheme']] == $uri['port']) { if (array_key_exists($uri['scheme'], $defaultPorts) && $defaultPorts[$uri['scheme']] == $uri['port']) {
$uriTemplate = str_replace(':%port', null, $uriTemplate); $uriTemplate = str_replace(':%port', null, $uriTemplate);
} }
foreach ($uri as $property => $value) { foreach ($uri as $property => $value) {
$uriTemplate = str_replace('%'.$property, $value, $uriTemplate); $uriTemplate = str_replace('%'.$property, $value, $uriTemplate);
} }

View file

@ -139,6 +139,7 @@ class Inflector {
'/(m)en$/i' => '\1an', '/(m)en$/i' => '\1an',
'/(c)hildren$/i' => '\1\2hild', '/(c)hildren$/i' => '\1\2hild',
'/(n)ews$/i' => '\1\2ews', '/(n)ews$/i' => '\1\2ews',
'/eaus$/' => 'eau',
'/^(.*us)$/' => '\\1', '/^(.*us)$/' => '\\1',
'/s$/i' => '' '/s$/i' => ''
), ),

View file

@ -851,12 +851,12 @@ class DboSource extends DataSource {
if (count($ins) > 1) { if (count($ins) > 1) {
$query = str_replace('{$__cakeID__$}', '(' .join(', ', $ins) .')', $query); $query = str_replace('{$__cakeID__$}', '(' .join(', ', $ins) .')', $query);
$query = str_replace('= (', 'IN (', $query); $query = str_replace('= (', 'IN (', $query);
$query = str_replace('= (', 'IN (', $query); $query = str_replace('= (', 'IN (', $query);
} else { } else {
$query = str_replace('{$__cakeID__$}',$ins[0], $query); $query = str_replace('{$__cakeID__$}',$ins[0], $query);
} }
$query = str_replace(' WHERE 1 = 1', '', $query); $query = str_replace(' WHERE 1 = 1', '', $query);
} }
$foreignKey = $model->hasAndBelongsToMany[$association]['foreignKey']; $foreignKey = $model->hasAndBelongsToMany[$association]['foreignKey'];
@ -930,7 +930,7 @@ class DboSource extends DataSource {
$this->__mergeAssociation($resultSet[$i], $fetch, $association, $type, $selfJoin); $this->__mergeAssociation($resultSet[$i], $fetch, $association, $type, $selfJoin);
} }
if (isset($resultSet[$i][$association])) { if (isset($resultSet[$i][$association])) {
$resultSet[$i][$association] = $linkModel->afterFind($resultSet[$i][$association]); $resultSet[$i][$association] = $linkModel->afterFind($resultSet[$i][$association], false);
} }
} else { } else {
$tempArray[0][$association] = false; $tempArray[0][$association] = false;
@ -952,7 +952,7 @@ class DboSource extends DataSource {
$query = str_replace('{$__cakeID__$}', join(', ', $ids), $query); $query = str_replace('{$__cakeID__$}', join(', ', $ids), $query);
if (count($ids) > 1) { if (count($ids) > 1) {
$query = str_replace('= (', 'IN (', $query); $query = str_replace('= (', 'IN (', $query);
$query = str_replace('= (', 'IN (', $query); $query = str_replace('= (', 'IN (', $query);
} }
return $this->fetchAll($query, $model->cacheQueries, $model->alias); return $this->fetchAll($query, $model->cacheQueries, $model->alias);
} }

View file

@ -597,6 +597,7 @@ class Router {
if (strcasecmp($name, $match) === 0) { if (strcasecmp($name, $match) === 0) {
$url = substr($url, 0, strpos($url, '.' . $name)); $url = substr($url, 0, strpos($url, '.' . $name));
$ext = $match; $ext = $match;
break;
} }
} }
} }

View file

@ -83,13 +83,15 @@ class MemcacheEngineTest extends CakeTestCase {
*/ */
function testSettings() { function testSettings() {
$settings = Cache::settings(); $settings = Cache::settings();
$expecting = array('prefix' => 'cake_', unset($settings['serialize'], $settings['path']);
'duration'=> 3600, $expecting = array(
'probability' => 100, 'prefix' => 'cake_',
'servers' => array('127.0.0.1'), 'duration'=> 3600,
'compress' => false, 'probability' => 100,
'engine' => 'Memcache' 'servers' => array('127.0.0.1'),
); 'compress' => false,
'engine' => 'Memcache'
);
$this->assertEqual($settings, $expecting); $this->assertEqual($settings, $expecting);
} }

View file

@ -233,14 +233,17 @@ class ConfigureTest extends CakeTestCase {
function testStoreAndLoad() { function testStoreAndLoad() {
Configure::write('Cache.disable', false); Configure::write('Cache.disable', false);
$expected = array('data' => 'value'); $expected = array('data' => 'value with backslash \, \'singlequote\' and "doublequotes"');
Configure::store('SomeExample', 'test', $expected); Configure::store('SomeExample', 'test', $expected);
Configure::load('test'); Configure::load('test');
$config = Configure::read('SomeExample'); $config = Configure::read('SomeExample');
$this->assertEqual($config, $expected); $this->assertEqual($config, $expected);
$expected = array('data' => array('first' => 'value', 'second' => 'value2')); $expected = array(
'data' => array('first' => 'value with backslash \, \'singlequote\' and "doublequotes"', 'second' => 'value2'),
'data2' => 'value'
);
Configure::store('AnotherExample', 'test.config', $expected); Configure::store('AnotherExample', 'test.config', $expected);
Configure::load('test.config'); Configure::load('test.config');

View file

@ -1068,6 +1068,9 @@ class HttpSocketTest extends CakeTestCase {
$r = $this->Socket->buildUri(array('host' => 'www.cakephp.org', 'port' => 23)); $r = $this->Socket->buildUri(array('host' => 'www.cakephp.org', 'port' => 23));
$this->assertIdentical($r, 'http://www.cakephp.org:23/'); $this->assertIdentical($r, 'http://www.cakephp.org:23/');
$r = $this->Socket->buildUri(array('path' => 'www.google.com/search', 'query' => 'q=cakephp'));
$this->assertIdentical($r, 'http://www.google.com/search?q=cakephp');
$r = $this->Socket->buildUri(array('host' => 'www.cakephp.org', 'scheme' => 'https', 'port' => 79)); $r = $this->Socket->buildUri(array('host' => 'www.cakephp.org', 'scheme' => 'https', 'port' => 79));
$this->assertIdentical($r, 'https://www.cakephp.org:79/'); $this->assertIdentical($r, 'https://www.cakephp.org:79/');

View file

@ -114,6 +114,7 @@ class InflectorTest extends CakeTestCase {
$this->assertEqual(Inflector::singularize('waxes'), 'wax'); $this->assertEqual(Inflector::singularize('waxes'), 'wax');
$this->assertEqual(Inflector::singularize('niches'), 'niche'); $this->assertEqual(Inflector::singularize('niches'), 'niche');
$this->assertEqual(Inflector::singularize('waves'), 'wave'); $this->assertEqual(Inflector::singularize('waves'), 'wave');
$this->assertEqual(Inflector::singularize('bureaus'), 'bureau');
$this->assertEqual(Inflector::singularize(''), ''); $this->assertEqual(Inflector::singularize(''), '');
} }
@ -160,6 +161,7 @@ class InflectorTest extends CakeTestCase {
$this->assertEqual(Inflector::pluralize('crisis'), 'crises'); $this->assertEqual(Inflector::pluralize('crisis'), 'crises');
$this->assertEqual(Inflector::pluralize('tax'), 'taxes'); $this->assertEqual(Inflector::pluralize('tax'), 'taxes');
$this->assertEqual(Inflector::pluralize('wave'), 'waves'); $this->assertEqual(Inflector::pluralize('wave'), 'waves');
$this->assertEqual(Inflector::pluralize('bureau'), 'bureaus');
$this->assertEqual(Inflector::pluralize(''), ''); $this->assertEqual(Inflector::pluralize(''), '');
} }
@ -266,6 +268,7 @@ class InflectorTest extends CakeTestCase {
$this->assertEqual(Inflector::classify('artists_genres'), 'ArtistsGenre'); $this->assertEqual(Inflector::classify('artists_genres'), 'ArtistsGenre');
$this->assertEqual(Inflector::classify('file_systems'), 'FileSystem'); $this->assertEqual(Inflector::classify('file_systems'), 'FileSystem');
$this->assertEqual(Inflector::classify('news'), 'News'); $this->assertEqual(Inflector::classify('news'), 'News');
$this->assertEqual(Inflector::classify('bureaus'), 'Bureau');
} }
/** /**
@ -278,6 +281,7 @@ class InflectorTest extends CakeTestCase {
$this->assertEqual(Inflector::tableize('ArtistsGenre'), 'artists_genres'); $this->assertEqual(Inflector::tableize('ArtistsGenre'), 'artists_genres');
$this->assertEqual(Inflector::tableize('FileSystem'), 'file_systems'); $this->assertEqual(Inflector::tableize('FileSystem'), 'file_systems');
$this->assertEqual(Inflector::tableize('News'), 'news'); $this->assertEqual(Inflector::tableize('News'), 'news');
$this->assertEqual(Inflector::tableize('Bureau'), 'bureaus');
} }
/** /**

View file

@ -4887,6 +4887,21 @@ class ModelReadTest extends BaseModelTest {
$this->assertFalse($TestModel->find('all', array('connection' => 'foo'))); $this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
} }
/**
* Tests that the database configuration assigned to the model can be changed using
* (before|after)Find callbacks
*
* @return void
*/
function testCallbackSourceChange() {
$this->loadFixtures('Post');
$TestModel = new Post();
$this->assertEqual(3, count($TestModel->find('all')));
$this->expectError(new PatternExpectation('/Non-existent data source foo/i'));
$this->expectError(new PatternExpectation('/Only variable references/i'));
$this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
}
/** /**
* testMultipleBelongsToWithSameClass method * testMultipleBelongsToWithSameClass method
* *

View file

@ -5064,6 +5064,21 @@ class FormHelperTest extends CakeTestCase {
'/fieldset' '/fieldset'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$this->Form->data = array();
$this->Form->params['controller'] = 'contacts';
$this->Form->params['models'] = array('Contact');
$result = $this->Form->create(array('url' => array('action' => 'index', 'param')));
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/index/param'
),
'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/fieldset'
);
$this->assertTags($result, $expected);
} }
/** /**