Permalink
Browse files

Merge remote branch 'origin/1.2' into 1.2

  • Loading branch information...
2 parents 7e277e8 + a62e7bd commit 6d6f89b85f31c199fdde050ac3bc1f5e7ea320f6 @predominant predominant committed Apr 23, 2010
View
@@ -175,7 +175,10 @@ function set($settings = array(), $value = null) {
return false;
}
- $engine = $_this->__config[$_this->__name]['engine'];
+ $engine = $_this->__config[$_this->__name]['engine'];
+ if (isset($settings['engine'])) {
+ $engine = $settings['engine'];
+ }
if (!empty($settings)) {
$_this->__reset = true;
@@ -289,6 +292,7 @@ function read($key, $config = null) {
if (!$key = $_this->_Engine[$engine]->key($key)) {
return false;
}
+
$success = $_this->_Engine[$engine]->read($settings['prefix'] . $key);
if ($config !== null && $config !== $_this->__name) {
@@ -182,24 +182,35 @@ function beforeFind(&$Model, $query) {
}
$query['fields'] = (array)$query['fields'];
- if (!empty($Model->belongsTo)) {
- foreach ($Model->belongsTo as $assoc => $data) {
- if (!empty($data['fields'])) {
- foreach ((array) $data['fields'] as $field) {
- $query['fields'][] = (strpos($field, '.') === false ? $assoc . '.' : '') . $field;
+ foreach (array('hasOne', 'belongsTo') as $type) {
+ if (!empty($Model->{$type})) {
+ foreach ($Model->{$type} as $assoc => $data) {
+ if ($Model->useDbConfig == $Model->{$assoc}->useDbConfig && !empty($data['fields'])) {
+ foreach ((array) $data['fields'] as $field) {
+ $query['fields'][] = (strpos($field, '.') === false ? $assoc . '.' : '') . $field;
+ }
}
}
}
}
+
if (!empty($mandatory[$Model->alias])) {
foreach ($mandatory[$Model->alias] as $field) {
if ($field == '--primaryKey--') {
$field = $Model->primaryKey;
} else if (preg_match('/^.+\.\-\-[^-]+\-\-$/', $field)) {
list($modelName, $field) = explode('.', $field);
- $field = $modelName . '.' . (($field === '--primaryKey--') ? $Model->$modelName->primaryKey : $field);
+ if ($Model->useDbConfig == $Model->{$modelName}->useDbConfig) {
+ $field = $modelName . '.' . (
+ ($field === '--primaryKey--') ? $Model->$modelName->primaryKey : $field
+ );
+ } else {
+ $field = null;
+ }
+ }
+ if ($field !== null) {
+ $query['fields'][] = $field;
}
- $query['fields'][] = $field;
}
}
$query['fields'] = array_unique($query['fields']);
@@ -217,7 +217,12 @@ function &describe(&$model) {
if (!empty($c['char_length'])) {
$length = intval($c['char_length']);
} elseif (!empty($c['oct_length'])) {
- $length = intval($c['oct_length']);
+ if ($c['type'] == 'character varying') {
+ $length = null;
+ $c['type'] = 'text';
+ } else {
+ $length = intval($c['oct_length']);
+ }
} else {
$length = $this->length($c['type']);
}
View
@@ -448,18 +448,18 @@ function extract($path, $data = null, $options = array()) {
$ctext = array($context['key']);
if (!is_numeric($key)) {
$ctext[] = $token;
- $token = array_shift($tokens);
- if (isset($items[$token])) {
- $ctext[] = $token;
- $item = $items[$token];
+ $tok = array_shift($tokens);
+ if (isset($items[$tok])) {
+ $ctext[] = $tok;
+ $item = $items[$tok];
$matches[] = array(
'trace' => array_merge($context['trace'], $ctext),
- 'key' => $token,
+ 'key' => $tok,
'item' => $item,
);
break;
- } else {
- array_unshift($tokens, $token);
+ } elseif ($tok !== null) {
+ array_unshift($tokens, $tok);
}
} else {
$key = $token;
@@ -1673,7 +1673,12 @@ function __name($options = array(), $field = null, $key = 'name') {
if (is_array($options) && isset($options[$key])) {
return $options;
}
- $name = $this->field();
+
+ $view = ClassRegistry::getObject('view');
+ $name = $view->field;
+ if (!empty($view->fieldSuffix)) {
+ $name .= '[' . $view->fieldSuffix . ']';
+ }
if (is_array($options)) {
$options[$key] = $name;
@@ -103,14 +103,8 @@ function stripLinks($text) {
* @access public
*/
function autoLinkUrls($text, $htmlOptions = array()) {
- $options = 'array(';
- foreach ($htmlOptions as $option => $value) {
- $value = var_export($value, true);
- $options .= "'$option' => $value, ";
- }
- $options .= ')';
-
- $text = preg_replace_callback('#(?<!href="|">)((?:http|https|ftp|nntp)://[^ <]+)#i', create_function('$matches',
+ $options = var_export($htmlOptions, true);
+ $text = preg_replace_callback('#(?<!href="|">)((?:https?|ftp|nntp)://[^\s<>()]+)#i', create_function('$matches',
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text);
return preg_replace_callback('#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\.[^\n\%\ <]+[^<\n\%\,\.\ <])(?<!\))#i',
@@ -61,7 +61,11 @@ function skip() {
function setUp() {
$this->_cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', false);
- Cache::config('memcache', array('engine' => 'Memcache', 'prefix' => 'cake_'));
+ Cache::config('memcache', array(
+ 'engine' => 'Memcache',
+ 'prefix' => 'cake_',
+ 'duration' => 3600
+ ));
}
/**
* tearDown method
@@ -222,5 +226,41 @@ function testDeleteCache() {
$result = Cache::delete('delete_test');
$this->assertTrue($result);
}
+
+/**
+ * test that configurations don't conflict, when a file engine is declared after a memcache one.
+ *
+ * @return void
+ */
+ function testConfigurationConflict() {
+ Cache::config('long_memcache', array(
+ 'engine' => 'Memcache',
+ 'duration'=> '+2 seconds',
+ 'servers' => array('127.0.0.1:11211'),
+ ));
+ Cache::config('short_memcache', array(
+ 'engine' => 'Memcache',
+ 'duration'=> '+1 seconds',
+ 'servers' => array('127.0.0.1:11211'),
+ ));
+ Cache::config('some_file', array('engine' => 'File'));
+
+ $this->assertTrue(Cache::write('duration_test', 'yay', 'long_memcache'));
+ $this->assertTrue(Cache::write('short_duration_test', 'boo', 'short_memcache'));
+
+ $this->assertEqual(Cache::read('duration_test', 'long_memcache'), 'yay', 'Value was not read %s');
+ $this->assertEqual(Cache::read('short_duration_test', 'short_memcache'), 'boo', 'Value was not read %s');
+
+ sleep(1);
+ $this->assertEqual(Cache::read('duration_test', 'long_memcache'), 'yay', 'Value was not read %s');
+
+ sleep(2);
+ $this->assertFalse(Cache::read('short_duration_test', 'short_memcache'), 'Cache was not invalidated %s');
+ $this->assertFalse(Cache::read('duration_test', 'long_memcache'), 'Value did not expire %s');
+
+ Cache::delete('duration_test', 'long_memcache');
+ Cache::delete('short_duration_test', 'short_memcache');
+ }
+
}
?>
@@ -2872,23 +2872,34 @@ function testFindEmbeddedThirdLevelNonReset() {
* @return void
*/
function testEmbeddedFindFields() {
- $result = $this->Article->find('all', array('contain' => array('User(user)'), 'fields' => array('title')));
+ $result = $this->Article->find('all', array(
+ 'contain' => array('User(user)'),
+ 'fields' => array('title')
+ ));
$expected = array(
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
);
$this->assertEqual($result, $expected);
- $result = $this->Article->find('all', array('contain' => array('User(id, user)'), 'fields' => array('title')));
+ $result = $this->Article->find('all', array(
+ 'contain' => array('User(id, user)'),
+ 'fields' => array('title')
+ ));
$expected = array(
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
);
$this->assertEqual($result, $expected);
- $result = $this->Article->find('all', array('contain' => array('Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'), 'fields' => array('title')));
+ $result = $this->Article->find('all', array(
+ 'contain' => array(
+ 'Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'
+ ),
+ 'fields' => array('title')
+ ));
if (!empty($result)) {
foreach($result as $i=>$article) {
foreach($article['Comment'] as $j=>$comment) {
@@ -2926,13 +2937,51 @@ function testEmbeddedFindFields() {
$this->assertEqual($result, $expected);
}
/**
+ * test that hasOne and belongsTo fields act the same in a contain array.
+ *
+ * @return void
+ */
+ function testHasOneFieldsInContain() {
+ $this->Article->unbindModel(array(
+ 'hasMany' => array('Comment')
+ ), true);
+ unset($this->Article->Comment);
+ $this->Article->bindModel(array(
+ 'hasOne' => array('Comment')
+ ));
+
+ $result = $this->Article->find('all', array(
+ 'fields' => array('title', 'body'),
+ 'contain' => array(
+ 'Comment' => array(
+ 'fields' => array('comment')
+ ),
+ 'User' => array(
+ 'fields' => array('user')
+ )
+ )
+ ));
+ $this->assertTrue(isset($result[0]['Article']['title']), 'title missing %s');
+ $this->assertTrue(isset($result[0]['Article']['body']), 'body missing %s');
+ $this->assertTrue(isset($result[0]['Comment']['comment']), 'comment missing %s');
+ $this->assertTrue(isset($result[0]['User']['user']), 'body missing %s');
+ $this->assertFalse(isset($result[0]['Comment']['published']), 'published found %s');
+ $this->assertFalse(isset($result[0]['User']['password']), 'password found %s');
+ }
+/**
* testFindConditionalBinding method
*
* @access public
* @return void
*/
function testFindConditionalBinding() {
- $this->Article->contain(array('User(user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created >=' => '2007-03-18 12:24'))));
+ $this->Article->contain(array(
+ 'User(user)',
+ 'Tag' => array(
+ 'fields' => array('tag', 'created'),
+ 'conditions' => array('created >=' => '2007-03-18 12:24')
+ )
+ ));
$result = $this->Article->find('all', array('fields' => array('title')));
$expected = array(
array(
@@ -3009,7 +3058,13 @@ function testFindConditionalBinding() {
);
$this->assertEqual($result, $expected);
- $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created >=' => '2007-03-18 12:24'))));
+ $this->Article->contain(array(
+ 'User(id,user)',
+ 'Tag' => array(
+ 'fields' => array('tag', 'created'),
+ 'conditions' => array('created >=' => '2007-03-18 12:24')
+ )
+ ));
$result = $this->Article->find('all', array('fields' => array('title')));
$expected = array(
array(
@@ -3519,6 +3574,50 @@ function testResetMultipleHabtmAssociations() {
$this->assertEqual($expected, $this->Article->hasAndBelongsToMany);
}
/**
+ * test that autoFields doesn't splice in fields from other databases.
+ *
+ * @return void
+ */
+ function testAutoFieldsWithMultipleDatabases() {
+ $config = new DATABASE_CONFIG();
+
+ $skip = $this->skipIf(
+ !isset($config->test) || !isset($config->test2),
+ '%s Primary and secondary test databases not configured, skipping cross-database '
+ .'join tests.'
+ .' To run these tests, you must define $test and $test2 in your database configuration.'
+ );
+ if ($skip) {
+ return;
+ }
+
+ $db =& ConnectionManager::getDataSource('test2');
+ $this->_fixtures[$this->_fixtureClassMap['User']]->create($db);
+ $this->_fixtures[$this->_fixtureClassMap['User']]->insert($db);
+
+ $this->Article->User->setDataSource('test2');
+
+ $result = $this->Article->find('all', array(
+ 'fields' => array('Article.title'),
+ 'contain' => array('User')
+ ));
+ $this->assertTrue(isset($result[0]['Article']));
+ $this->assertTrue(isset($result[0]['User']));
+
+ $this->_fixtures[$this->_fixtureClassMap['User']]->drop($db);
+ }
+/**
+ * test that autoFields doesn't splice in columns that aren't part of the join.
+ *
+ * @return void
+ */
+ function testAutoFieldsWithRecursiveNegativeOne() {
+ $this->Article->recursive = -1;
+ $result = $this->Article->field('title', array('Article.title' => 'First Article'));
+ $this->assertNoErrors();
+ $this->assertEqual($result, 'First Article', 'Field is wrong');
+ }
+/**
* containments method
*
* @param mixed $Model
@@ -472,6 +472,7 @@ function testCakeSchema() {
$db1->query('CREATE TABLE ' . $db1->fullTableName('datatypes') . ' (
id serial NOT NULL,
"varchar" character varying(40) NOT NULL,
+ "full_length" character varying NOT NULL,
"timestamp" timestamp without time zone,
date date,
CONSTRAINT test_suite_data_types_pkey PRIMARY KEY (id)
@@ -484,7 +485,9 @@ function testCakeSchema() {
));
$schema->tables = array('datatypes' => $result['tables']['datatypes']);
$result = $db1->createSchema($schema, 'datatypes');
+
$this->assertNoPattern('/timestamp DEFAULT/', $result);
+ $this->assertPattern('/\"full_length\"\s*text\s.*,/', $result);
$this->assertPattern('/timestamp\s*,/', $result);
$db1->query('DROP TABLE ' . $db1->fullTableName('datatypes'));
Oops, something went wrong.

0 comments on commit 6d6f89b

Please sign in to comment.