Merge branch '2.0' of github.com:cakephp/cakephp into 2.0

This commit is contained in:
mark_story 2011-03-01 22:23:57 -05:00
commit e3841955dc
4 changed files with 98 additions and 21 deletions

View file

@ -238,8 +238,12 @@ class FormHelper extends AppHelper {
$options);
$this->_inputDefaults = $options['inputDefaults'];
unset($options['inputDefaults']);
if (empty($options['url']) || is_array($options['url'])) {
if ($options['action'] === null && $options['url'] === null) {
$options['action'] = $this->request->here;
if (!isset($options['id'])) {
$options['id'] = $this->domId($this->request['action'] . 'Form');
}
} elseif (empty($options['url']) || is_array($options['url'])) {
if (empty($options['url']['controller'])) {
if (!empty($model) && $model != $this->defaultModel) {
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));

View file

@ -38,16 +38,16 @@ class NumberHelper extends AppHelper {
*/
protected $_currencies = array(
'USD' => array(
'before' => '$', 'after' => 'c', 'zero' => 0, 'places' => 2, 'thousands' => ',',
'decimals' => '.', 'negative' => '()', 'escape' => true
'wholeSymbol' => '$', 'wholePosition' => 'before', 'fractionSymbol' => 'c', 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()', 'escape' => true
),
'GBP' => array(
'before'=>'£', 'after' => 'p', 'zero' => 0, 'places' => 2, 'thousands' => ',',
'decimals' => '.', 'negative' => '()','escape' => false
'wholeSymbol'=>'£', 'wholePosition' => 'before', 'fractionSymbol' => 'p', 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => ',', 'decimals' => '.', 'negative' => '()','escape' => false
),
'EUR' => array(
'before'=>'€', 'after' => false, 'zero' => 0, 'places' => 2, 'thousands' => '.',
'decimals' => ',', 'negative' => '()', 'escape' => false
'wholeSymbol'=>'€', 'wholePosition' => 'before', 'fractionSymbol' => false, 'fractionPosition' => 'after',
'zero' => 0, 'places' => 2, 'thousands' => '.', 'decimals' => ',', 'negative' => '()', 'escape' => false
)
);
@ -58,8 +58,8 @@ class NumberHelper extends AppHelper {
* @access protected
*/
protected $_currencyDefaults = array(
'before'=>'', 'after' => '', 'zero' => '0', 'places' => 2, 'thousands' => ',',
'decimals' => '.','negative' => '()', 'escape' => true
'wholeSymbol'=>'', 'wholePosition' => 'before', 'fractionSymbol' => '', 'fractionPosition' => 'after',
'zero' => '0', 'places' => 2, 'thousands' => ',', 'decimals' => '.','negative' => '()', 'escape' => true
);
/**
@ -190,26 +190,32 @@ class NumberHelper extends AppHelper {
$options = array_merge($default, $options);
$result = null;
if (isset($options['before']) && $options['before'] !== '') {
$options['wholeSymbol'] = $options['before'];
}
if (isset($options['after']) && !$options['after'] !== '') {
$options['fractionSymbol'] = $options['after'];
}
$result = $options['before'] = $options['after'] = null;
$symbolKey = 'whole';
if ($number == 0 ) {
if ($options['zero'] !== 0 ) {
return $options['zero'];
}
$options['after'] = null;
} elseif ($number < 1 && $number > -1 ) {
if ($options['after'] !== false) {
if ($options['fractionSymbol'] !== false) {
$multiply = intval('1' . str_pad('', $options['places'], '0'));
$number = $number * $multiply;
$options['before'] = null;
$options['places'] = null;
$symbolKey = 'fraction';
}
} elseif (empty($options['before'])) {
$options['before'] = null;
} else {
$options['after'] = null;
}
$position = $options[$symbolKey.'Position'] != 'after' ? 'before' : 'after';
$options[$position] = $options[$symbolKey.'Symbol'];
$abs = abs($number);
$result = $this->format($abs, $options);

View file

@ -668,6 +668,7 @@ class FormHelperTest extends CakeTestCase {
$this->Form = new FormHelper($this->View);
$this->Form->Html = new HtmlHelper($this->View);
$this->Form->request = new CakeRequest(null, false);
$this->Form->request->here = '/contacts/add';
$this->Form->request['action'] = 'add';
$this->Form->request->webroot = '';
$this->Form->request->base = '';
@ -5547,6 +5548,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['id'] = 1;
$this->Form->request->here = '/contacts/edit/1';
$this->Form->request['action'] = 'edit';
$result = $this->Form->create('Contact');
$expected = array(
@ -5561,6 +5563,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
$this->Form->request->data['Contact']['id'] = 1;
$this->Form->request->here = '/contacts/edit/1';
$this->Form->request['action'] = 'edit';
$result = $this->Form->create('Contact', array('type' => 'file'));
$expected = array(
@ -5575,7 +5578,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
$this->Form->request->data['ContactNonStandardPk']['pk'] = 1;
$result = $this->Form->create('ContactNonStandardPk');
$result = $this->Form->create('ContactNonStandardPk', array('url' => array('action' => 'edit')));
$expected = array(
'form' => array(
'id' => 'ContactNonStandardPkEditForm', 'method' => 'post',
@ -5661,6 +5664,33 @@ class FormHelperTest extends CakeTestCase {
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->here = '/contacts/add/Contact:1';
$result = $this->Form->create();
$expected = array(
'form' => array(
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/Contact:1',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request['action'] = 'delete';
$this->Form->request->here = '/contacts/delete/10/User:42';
$result = $this->Form->create();
$expected = array(
'form' => array(
'id' => 'ContactDeleteForm', 'method' => 'post', 'action' => '/contacts/delete/10/User:42',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
@ -5854,7 +5884,8 @@ class FormHelperTest extends CakeTestCase {
*/
function testGetFormWithFalseModel() {
$encoding = strtolower(Configure::read('App.encoding'));
$result = $this->Form->create(false, array('type' => 'get'));
$this->Form->request['controller'] = 'contact_test';
$result = $this->Form->create(false, array('type' => 'get', 'url' => array('controller' => 'contact_test')));
$expected = array('form' => array(
'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',

View file

@ -114,7 +114,7 @@ class NumberHelperTest extends CakeTestCase {
$expected = '&#163;100,100,100.00';
$this->assertEqual($expected, $result);
$result = $this->Number->currency($value, '', array('thousands' =>' ', 'after' => '€', 'decimals' => ',', 'zero' => 'Gratuit'));
$result = $this->Number->currency($value, '', array('thousands' =>' ', 'wholeSymbol' => '€', 'wholePosition' => 'after', 'decimals' => ',', 'zero' => 'Gratuit'));
$expected = '100 100 100,00€';
$this->assertEqual($expected, $result);
@ -129,6 +129,42 @@ class NumberHelperTest extends CakeTestCase {
$result = $this->Number->currency(0.5, NULL, array('after'=>'øre'));
$expected = '50øre';
$this->assertEqual($expected,$result);
$result = $this->Number->currency(1, null, array('wholeSymbol' => '$ '));
$expected = '$ 1.00';
$this->assertEqual($result, $expected);
$result = $this->Number->currency(1, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after'));
$expected = '1.00 $';
$this->assertEqual($result, $expected);
$result = $this->Number->currency(.2, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after', 'fractionSymbol' => 'cents'));
$expected = '20cents';
$this->assertEqual($result, $expected);
$result = $this->Number->currency(.2, null, array('wholeSymbol' => ' $', 'wholePosition' => 'after', 'fractionSymbol' => 'cents', 'fractionPosition' => 'before'));
$expected = 'cents20';
$this->assertEqual($result, $expected);
$result = $this->Number->currency(311, 'USD', array('wholePosition' => 'after'));
$expected = '311.00$';
$this->assertEqual($result, $expected);
$result = $this->Number->currency(.2, 'EUR');
$expected = '&#8364;0,20';
$this->assertEqual($result, $expected);
$result = $this->Number->currency(12, null, array('wholeSymbol' => ' dollars', 'wholePosition' => 'after', 'fractionSymbol' => ' cents', 'fractionPosition' => 'after'));
$expected = '12.00 dollars';
$this->assertEqual($result, $expected);
$result = $this->Number->currency(.12, null, array('wholeSymbol' => ' dollars', 'wholePosition' => 'after', 'fractionSymbol' => ' cents', 'fractionPosition' => 'after'));
$expected = '12 cents';
$this->assertEqual($result, $expected);
$result = $this->Number->currency(.5, null, array('fractionSymbol' => false, 'fractionPosition' => 'before', 'wholeSymbol' => '$'));
$expected = '$0.50';
$this->assertEqual($result, $expected);
}
/**