Merge remote branch 'origin/1.3' into 2.0

Conflicts:
	cake/console/libs/acl.php
	cake/tests/cases/libs/view/helpers/form.test.php
	cake/tests/cases/libs/view/helpers/javascript.test.php
This commit is contained in:
predominant 2010-04-23 12:52:56 +10:00
commit 015872445b
20 changed files with 245 additions and 28 deletions

View file

@ -366,7 +366,7 @@ class AclShell extends Shell {
*
*/
public function initdb() {
$this->Dispatch->args = array('schema', 'run', 'create', 'DbAcl');
$this->Dispatch->args = array('schema', 'create', 'DbAcl');
$this->Dispatch->dispatch();
}

View file

@ -406,7 +406,7 @@ class TestTask extends BakeTask {
*/
public function testCaseFileName($type, $className) {
$path = $this->getPath();;
$path .= 'cases' . DS . Inflector::tableize($type) . DS;
$path .= 'cases' . DS . strtolower($type) . 's' . DS;
if (strtolower($type) == 'controller') {
$className = $this->getRealClassName($type, $className);
}

View file

@ -44,8 +44,8 @@
/**
* As of 1.3, additional rules for the inflector are added below
*
* Inflector::rule('singular', array('rules' => array(), irregular' => array(), 'uninflected' => array()));
* Inflector::rule('plural', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
* Inflector::rules('singular', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
* Inflector::rules('plural', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
*
*/
?>

View file

@ -67,7 +67,7 @@ class PagesController extends AppController {
if (!$count) {
$this->redirect('/');
}
$page = $subpage = $title = null;
$page = $subpage = $title_for_layout = null;
if (!empty($path[0])) {
$page = $path[0];

View file

@ -79,7 +79,7 @@ ul, li {
}
#header h1 {
line-height:20px;
background: #003d4c url('../img/cake.icon.png') no-repeat left;
background: #003d4c url('../img/cake.icon.gif') no-repeat left;
color: #fff;
padding: 0px 30px;
}
@ -532,4 +532,4 @@ div.code-coverage-results span.result-ok {
}
div.code-coverage-results span.result-good {
color: #0a0;
}
}

View file

@ -916,8 +916,11 @@ class EmailComponent extends Object{
$fm .= sprintf('%s%3$s%3$s%s', 'Message:', $message, $nl);
$fm .= '</pre>';
$this->Controller->Session->setFlash($fm, 'default', null, 'email');
return true;
if (isset($this->Controller->Session)) {
$this->Controller->Session->setFlash($fm, 'default', null, 'email');
return true;
}
return $fm;
}
}

View file

@ -368,6 +368,11 @@ class Inflector {
$_this->{$var}[$rule] = array_merge($pattern, $_this->{$var}[$rule]);
}
unset($rules[$rule], $_this->{$var}['cache' . ucfirst($rule)], $_this->{$var}['merged'][$rule]);
if ($type === 'plural') {
$_this->_pluralized = $_this->_tableize = array();
} elseif ($type === 'singular') {
$_this->_singularized = array();
}
}
}
$_this->{$var}['rules'] = array_merge($rules, $_this->{$var}['rules']);

View file

@ -185,7 +185,7 @@ class ContainableBehavior extends ModelBehavior {
foreach (array('hasOne', 'belongsTo') as $type) {
if (!empty($Model->{$type})) {
foreach ($Model->{$type} as $assoc => $data) {
if (!empty($data['fields'])) {
if ($Model->useDbConfig == $Model->{$assoc}->useDbConfig && !empty($data['fields'])) {
foreach ((array) $data['fields'] as $field) {
$query['fields'][] = (strpos($field, '.') === false ? $assoc . '.' : '') . $field;
}
@ -193,15 +193,24 @@ class ContainableBehavior extends ModelBehavior {
}
}
}
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']);

View file

@ -130,7 +130,7 @@ class FormHelper extends AppHelper {
}
$defaults = array('fields' => array(), 'key' => 'id', 'validates' => array());
$key = $object->primaryKey;
$this->fieldset[$object->name] = array_merge($defaults, compact('fields', 'key', 'validates'));
$this->fieldset[$model] = array_merge($defaults, compact('fields', 'key', 'validates'));
}
return $object;
@ -214,8 +214,9 @@ class FormHelper extends AppHelper {
$object =& $this->_introspectModel($model);
$this->setEntity($model . '.', true);
if (isset($this->fieldset[$this->model()]['key'])) {
$data = $this->fieldset[$this->model()];
$modelEntity = $this->model();
if (isset($this->fieldset[$modelEntity]['key'])) {
$data = $this->fieldset[$modelEntity];
$recordExists = (
isset($this->data[$model]) &&
!empty($this->data[$model][$data['key']])
@ -466,7 +467,8 @@ class FormHelper extends AppHelper {
* - `class` string The classname for the error message
*
* @param string $field A field name, like "Modelname.fieldname"
* @param mixed $text Error message or array of $options
* @param mixed $text Error message or array of $options. If array, `attributes` key
* will get used as html attributes for error container
* @param array $options Rendering options for <div /> wrapper tag
* @return string If there are errors this method returns an error message, otherwise null.
* @access public
@ -491,7 +493,10 @@ class FormHelper extends AppHelper {
$error--;
}
if (is_array($text)) {
$options = array_merge($options, $text);
$options = array_merge($options, array_intersect_key($text, $defaults));
if (isset($text['attributes']) && is_array($text['attributes'])) {
$options = array_merge($options, $text['attributes']);
}
$text = isset($text[$error]) ? $text[$error] : null;
unset($options[$error]);
}
@ -1449,7 +1454,7 @@ class FormHelper extends AppHelper {
}
if (!empty($tag) || isset($template)) {
if (!isset($secure) || $secure == true) {
if (!isset($secure) || $secure == true) {
$this->__secure();
}
$select[] = sprintf($tag, $attributes['name'], $this->_parseAttributes(

View file

@ -158,9 +158,9 @@ class XmlHelper extends AppHelper {
*
* @param mixed $data The content to be converted to XML
* @param array $options The data formatting options. For a list of valid options, see
* XmlNode::__construct().
* Xml::__construct().
* @return string A copy of $data in XML format
* @see XmlNode
* @see Xml::__construct()
* @access public
* @link http://book.cakephp.org/view/1474/serialize
*/

View file

@ -281,4 +281,4 @@ class MediaView extends View {
@ob_flush();
}
}
?>
?>

View file

@ -36,7 +36,7 @@ if (!class_exists('AclShell')) {
Mock::generatePartial(
'ShellDispatcher', 'TestAclShellMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'dispatch')
);
Mock::generatePartial(
'AclShell', 'MockAclShell',
@ -316,5 +316,17 @@ class AclShellTest extends CakeTestCase {
$this->Task->expectAt(3, 'out', array(' [4] Elrond'));
$this->Task->getPath();
}
/**
* test that initdb makes the correct call.
*
* @return void
*/
function testInitDb() {
$this->Task->Dispatch->expectOnce('dispatch');
$this->Task->initdb();
$this->assertEqual($this->Task->Dispatch->args, array('schema', 'create', 'DbAcl'));
}
}
?>

View file

@ -52,7 +52,11 @@ class MemcacheEngineTest extends CakeTestCase {
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
));
}
/**
@ -266,5 +270,41 @@ class MemcacheEngineTest extends CakeTestCase {
$result = Cache::read('test_increment');
$this->assertEqual(8, $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');
}
}
?>

View file

@ -583,7 +583,34 @@ TEXTBLOC;
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
$this->assertPattern('/This is the body of the message/', $result);
}
/**
* test send with delivery = debug and not using sessions.
*
* @return void
*/
function testSendDebugWithNoSessions() {
$session =& $this->Controller->Session;
unset($this->Controller->Session);
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
$this->Controller->EmailTest->delivery = 'debug';
$result = $this->Controller->EmailTest->send('This is the body of the message');
$this->assertPattern('/To: postmaster@localhost\n/', $result);
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
$this->assertPattern('/From: noreply@example.com\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
$this->assertPattern('/This is the body of the message/', $result);
$this->Controller->Session = $session;
}
/**

View file

@ -399,6 +399,27 @@ class InflectorTest extends CakeTestCase {
$this->assertEqual(Inflector::slug('Testing æ ø å', '-', array('/ø/' => 'oe')), 'Testing-ae-oe-aa');
}
/**
* test that setting new rules clears the inflector caches.
*
* @return void
*/
function testRulesClearsCaches() {
$this->assertEqual(Inflector::singularize('Bananas'), 'Banana');
$this->assertEqual(Inflector::tableize('Banana'), 'bananas');
$this->assertEqual(Inflector::pluralize('Banana'), 'Bananas');
Inflector::rules('singular', array(
'rules' => array('/(.*)nas$/i' => '\1zzz')
));
$this->assertEqual(Inflector::singularize('Bananas'), 'Banazzz', 'Was inflected with old rules. %s');
Inflector::rules('plural', array(
'rules' => array('/(.*)na$/i' => '\1zzz')
));
$this->assertEqual(Inflector::pluralize('Banana'), 'Banazzz', 'Was inflected with old rules. %s');
}
/**
* Test resetting inflection rules.
*

View file

@ -3587,6 +3587,50 @@ class ContainableBehaviorTest extends CakeTestCase {
$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
*

View file

@ -1874,6 +1874,8 @@ class ValidationTest extends CakeTestCase {
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
$this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html'));
$this->assertTrue(Validation::url('http://www.zwischenraume.de'));
$this->assertTrue(Validation::url('http://www.zwischenraume.cz'));
$this->assertTrue(Validation::url('http://cakephp.org:80'));
$this->assertTrue(Validation::url('http://cakephp.org:443'));

View file

@ -129,6 +129,14 @@ class Contact extends CakeTestModel {
* @access public
*/
public $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact'));
/**
* hasAndBelongsToMany property
*
* @var array
* @access public
*/
public $belongsTo = array('User' => array('className' => 'UserForm'));
}
/**
@ -299,7 +307,7 @@ class UserForm extends CakeTestModel {
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null),
'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10),
'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
@ -1776,7 +1784,12 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
$this->Form->validationErrors['Model']['field'] = 'minLength';
$result = $this->Form->input('Model.field', array('error' => array('minLength' => __('Le login doit contenir au moins 2 caractères'))));
$result = $this->Form->input('Model.field', array(
'error' => array(
'minLength' => 'Le login doit contenir au moins 2 caractères',
'maxLength' => 'login too large'
)
));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ModelField'),
@ -1789,6 +1802,28 @@ class FormHelperTest extends CakeTestCase {
'/div'
);
$this->assertTags($result, $expected);
$this->Form->validationErrors['Model']['field'] = 'maxLength';
$result = $this->Form->input('Model.field', array(
'error' => array(
'wrap' => 'span',
'attributes' => array('rel' => 'fake'),
'minLength' => 'Le login doit contenir au moins 2 caractères',
'maxLength' => 'login too large',
)
));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'ModelField'),
'Field',
'/label',
'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField', 'class' => 'form-error'),
array('span' => array('class' => 'error-message', 'rel' => 'fake')),
'login too large',
'/span',
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test form->input() with datetime, date and time types
@ -3280,7 +3315,7 @@ class FormHelperTest extends CakeTestCase {
'first',
'/label',
'/div',
array('div' => array('class' => 'checkbox')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
@ -5626,6 +5661,20 @@ class FormHelperTest extends CakeTestCase {
'*/select'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.stuff');
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'UserStuff'),
'Stuff',
'/label',
'input' => array(
'type' => 'text', 'name' => 'data[User][stuff]',
'id' => 'UserStuff', 'maxlength' => 10
),
'/div'
);
$this->assertTags($result, $expected, true);
}
/**

View file

@ -782,4 +782,4 @@ class TimeHelperTest extends CakeTestCase {
$this->assertEqual($this->Time->format($time, '%c'), $this->Time->i18nFormat($time, '%c'));
}
}
?>
?>

View file

@ -178,4 +178,4 @@ class MediaViewTest extends CakeTestCase {
$this->assertFalse($result);
}
}
?>
?>