Merge branch '1.3' into merger

Conflicts:
	cake/console/cake.php
	cake/dispatcher.php
	cake/libs/controller/components/cookie.php
	cake/libs/view/helper.php
	cake/libs/view/helpers/ajax.php
	cake/tests/cases/dispatcher.test.php
	cake/tests/cases/libs/model/model_validation.test.php
	cake/tests/cases/libs/view/helpers/ajax.test.php
	cake/tests/lib/cake_test_fixture.php
This commit is contained in:
mark_story 2011-03-01 22:21:44 -05:00
commit 3ea8c2246a
20 changed files with 81 additions and 32 deletions

View file

@ -22,4 +22,3 @@
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR. 'shell_dispatcher.php');
return ShellDispatcher::run($argv);

View file

@ -174,6 +174,9 @@ class CookieComponent extends Component {
public function __construct(ComponentCollection $collection, $settings = array()) {
$this->key = Configure::read('Security.salt');
parent::__construct($collection, $settings);
if (isset($this->time)) {
$this->_expire($this->time);
}
}
/**

View file

@ -564,11 +564,7 @@ class EmailComponent extends Component {
$headers = array();
if ($this->delivery == 'smtp') {
if (is_array($this->to)) {
$headers['To'] = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
} else {
$headers['To'] = $this->_formatAddress($this->to);
}
$headers['To'] = implode(', ', array_map(array($this, '_formatAddress'), (array)$this->to));
}
$headers['From'] = $this->_formatAddress($this->from);
@ -583,11 +579,11 @@ class EmailComponent extends Component {
}
if (!empty($this->cc)) {
$headers['cc'] = implode(', ', array_map(array($this, '_formatAddress'), $this->cc));
$headers['Cc'] = implode(', ', array_map(array($this, '_formatAddress'), (array)$this->cc));
}
if (!empty($this->bcc) && $this->delivery != 'smtp') {
$headers['Bcc'] = implode(', ', array_map(array($this, '_formatAddress'), $this->bcc));
$headers['Bcc'] = implode(', ', array_map(array($this, '_formatAddress'), (array)$this->bcc));
}
if ($this->delivery == 'smtp') {
$headers['Subject'] = $this->_encode($this->subject);

View file

@ -320,7 +320,9 @@ class I18n {
return $domain;
}
if ($head = $this->__domains[$domain][$this->__lang][$this->category][""]) {
if (isset($this->__domains[$domain][$this->__lang][$this->category][""])) {
$head = $this->__domains[$domain][$this->__lang][$this->category][""];
foreach (explode("\n", $head) as $line) {
$header = strtok($line,":");
$line = trim(strtok("\n"));

View file

@ -87,7 +87,7 @@ class AclBehavior extends ModelBehavior {
}
$data = array(
'parent_id' => isset($parent[0][$type]['id']) ? $parent[0][$type]['id'] : null,
'model' => $model->alias,
'model' => $model->name,
'foreign_key' => $model->id
);
if (!$created) {

View file

@ -845,7 +845,7 @@ class Router {
} elseif (isset($url[$prefix]) && !$url[$prefix]) {
unset($url[$prefix]);
}
if (isset($url[$prefix]) && strpos($url['action'], $prefix) === 0) {
if (isset($url[$prefix]) && strpos($url['action'], $prefix . '_') === 0) {
$url['action'] = substr($url['action'], strlen($prefix) + 1);
}
}

View file

@ -20,6 +20,6 @@
$content = explode("\n", $content);
foreach ($content as $line):
echo '<p> ' . $line . '</p>';
echo '<p> ' . $line . "</p>\n";
endforeach;
?>

View file

@ -602,7 +602,7 @@ class Helper extends Object {
}
$habtmKey = $this->field();
if (empty($result) && isset($data[$habtmKey][$habtmKey])) {
if (empty($result) && isset($data[$habtmKey][$habtmKey]) && is_array($data[$habtmKey])) {
$result = $data[$habtmKey][$habtmKey];
} elseif (empty($result) && isset($data[$habtmKey]) && is_array($data[$habtmKey])) {
if (ClassRegistry::isKeySet($habtmKey)) {

View file

@ -263,7 +263,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
unset($options['update']);
}
$callbacks = array('success', 'error', 'beforeSend', 'complete');
if (isset($options['dataExpression'])) {
if (!empty($options['dataExpression'])) {
$callbacks[] = 'data';
unset($options['dataExpression']);
}

View file

@ -251,7 +251,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
}
$options['url'] = $url;
$options = $this->_prepareCallbacks('request', $options);
if (isset($options['dataExpression'])) {
if (!empty($options['dataExpression'])) {
$callbacks[] = 'data';
unset($options['dataExpression']);
} elseif (!empty($data)) {

View file

@ -44,10 +44,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
'error' => 'onFailure'
),
'sortable' => array(
'start' => 'onStart',
'sort' => 'onChange',
'complete' => 'onUpdate',
'distance' => 'snap',
),
'drag' => array(
'snapGrid' => 'snap',
@ -242,7 +240,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
}
$safe = array_keys($this->_callbackArguments['request']);
$options = $this->_prepareCallbacks('request', $options, $safe);
if (isset($options['dataExpression'])) {
if (!empty($options['dataExpression'])) {
$safe[] = 'parameters';
unset($options['dataExpression']);
}
@ -258,6 +256,9 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
*
* #### Note: Requires scriptaculous to be loaded.
*
* The scriptaculous implementation of sortables does not suppot the 'start'
* and 'distance' options.
*
* @param array $options Array of options for the sortable.
* @return string Completed sortable script.
* @access public
@ -326,10 +327,14 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
unset($options['handle']);
if (isset($options['min']) && isset($options['max'])) {
$options['range'] = array($options['min'], $options['max']);
$options['range'] = sprintf('$R(%s,%s)', $options['min'], $options['max']);
unset($options['min'], $options['max']);
}
$optionString = $this->_processOptions('slider', $options);
$options = $this->_mapOptions('slider', $options);
$options = $this->_prepareCallbacks('slider', $options);
$optionString = $this->_parseOptions(
$options, array_merge(array_keys($this->_callbackArguments['slider']), array('range'))
);
if (!empty($optionString)) {
$optionString = ', {' . $optionString . '}';
}

View file

@ -101,6 +101,15 @@ class TimeHelper extends AppHelper {
return sprintf("%02d", date('Y', $this->__time) / 100);
case 'D':
return '%m/%d/%y';
case 'e':
if (DS === '/') {
return '%e';
}
$day = date('j', $this->__time);
if ($day < 10) {
$day = ' ' . $day;
}
return $day;
case 'eS' :
return date('jS', $this->__time);
case 'b':

View file

@ -409,6 +409,6 @@ class CacheTest extends CakeTestCase {
$settings = Cache::settings('file_config');
$this->assertEquals('test_file_', $settings['prefix']);
$this->assertEquals(31536000, $settings['duration']);
$this->assertEquals(strtotime('+1 year') - time(), $settings['duration']);
}
}

View file

@ -387,6 +387,10 @@ class CakeTestFixtureTest extends CakeTestCase {
$return = $Fixture->drop($this->criticDb);
$this->assertFalse($return);
unset($Fixture->fields);
$return = $Fixture->drop($this->criticDb);
$this->assertFalse($return);
}
/**

View file

@ -746,6 +746,8 @@ HTMLBLOC;
function testSendDebug() {
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->cc = 'cc@example.com';
$this->Controller->EmailTest->bcc = 'bcc@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
$this->Controller->EmailTest->template = null;
@ -758,6 +760,8 @@ HTMLBLOC;
$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('/Cc: cc@example.com\n/', $result);
$this->assertPattern('/Bcc: bcc@example.com\n/', $result);
$this->assertPattern('/Date: ' . preg_quote(date(DATE_RFC2822)) . '\n/', $result);
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);

View file

@ -129,13 +129,14 @@ class ModelValidationTest extends BaseModelTest {
$TestModel = new ValidationTest1();
$TestModel->validate = $validate = array(
'title' => array(
'rule' => 'customValidator',
'rule' => 'alphaNumeric',
'required' => true
),
'name' => array(
'rule' => 'allowEmpty',
'rule' => 'alphaNumeric',
'required' => true
));
$TestModel->set(array('title' => '$$', 'name' => '##'));
$TestModel->invalidFields(array('fieldList' => array('title')));
$expected = array(
'title' => 'This field cannot be left blank'
@ -173,9 +174,9 @@ class ModelValidationTest extends BaseModelTest {
*/
function testInvalidFieldsWhitelist() {
$TestModel = new ValidationTest1();
$TestModel->validate = $validate = array(
$TestModel->validate = array(
'title' => array(
'rule' => 'customValidator',
'rule' => 'alphaNumeric',
'required' => true
),
'name' => array(
@ -184,7 +185,7 @@ class ModelValidationTest extends BaseModelTest {
));
$TestModel->whitelist = array('name');
$TestModel->save(array('name' => '#$$#'));
$TestModel->save(array('name' => '#$$#', 'title' => '$$$$'));
$expected = array('name' => 'This field cannot be left blank');
$this->assertEqual($TestModel->validationErrors, $expected);

View file

@ -1596,6 +1596,10 @@ class RouterTest extends CakeTestCase {
$expected = '/protected/images/edit/1';
$this->assertEqual($result, $expected);
$result = Router::url(array('action' => 'protectededit', 1, 'protected' => true));
$expected = '/protected/images/protectededit/1';
$this->assertEqual($result, $expected);
$result = Router::url(array('action' => 'edit', 1, 'protected' => true));
$expected = '/protected/images/edit/1';
$this->assertEqual($result, $expected);

View file

@ -272,13 +272,11 @@ class PrototypeEngineHelperTest extends CakeTestCase {
function testSortable() {
$this->Proto->get('#myList');
$result = $this->Proto->sortable(array(
'distance' => 5,
'start' => 'onStart',
'complete' => 'onComplete',
'sort' => 'onSort',
'wrapCallbacks' => false
));
$expected = 'var jsSortable = Sortable.create($("myList"), {onChange:onSort, onStart:onStart, onUpdate:onComplete, snap:5});';
$expected = 'var jsSortable = Sortable.create($("myList"), {onChange:onSort, onUpdate:onComplete});';
$this->assertEqual($result, $expected);
}
@ -352,9 +350,11 @@ class PrototypeEngineHelperTest extends CakeTestCase {
'handle' => '#handle',
'change' => 'change();',
'complete' => 'complete();',
'value' => 4
'value' => 4,
'min' => 10,
'max' => 100
));
$expected = 'var jsSlider = new Control.Slider($("handle"), $("element"), {onChange:function (value) {complete();}, onSlide:function (value) {change();}, sliderValue:4});';
$expected = 'var jsSlider = new Control.Slider($("handle"), $("element"), {onChange:function (value) {complete();}, onSlide:function (value) {change();}, range:$R(10,100), sliderValue:4});';
$this->assertEqual($result, $expected);
}

View file

@ -738,6 +738,25 @@ class TimeHelperTest extends CakeTestCase {
$this->assertEqual($result, $expected);
}
/**
* test convert %e on windows.
*
* @return void
*/
function testConvertPercentE() {
if ($this->skipIf(DS !== '\\', 'Cannot run windows tests on non-windows OS')) {
return;
}
$time = strtotime('Thu Jan 14 11:43:39 2010');
$result = $this->Time->convertSpecifiers('%e', $time);
$expected = '14';
$this->assertEqual($result, $expected);
$result = $this->Time->convertSpecifiers('%e', strtotime('2011-01-01'));
$expected = ' 1';
$this->assertEqual($result, $expected);
}
/**
* test formatting dates taking in account preferred i18n locale file
*

View file

@ -154,6 +154,9 @@ class CakeTestFixture {
* @return boolean True on success, false on failure
*/
public function drop(&$db) {
if (empty($this->fields)) {
return false;
}
$this->Schema->build(array($this->table => $this->fields));
return (
$db->execute($db->dropSchema($this->Schema), array('log' => false)) !== false