From 604b7e0a100b64ddeef7988e416645279f57ddaa Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 14 Oct 2009 20:10:32 -0400 Subject: [PATCH 01/82] Splitting a long test for FormHelper up into smaller test cases. --- .../cases/libs/view/helpers/form.test.php | 372 +++++++++--------- 1 file changed, 193 insertions(+), 179 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 5712d81e8..7911f200c 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -1499,50 +1499,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->input('email', array( - 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true) - ); - $expected = array( - 'div' => array('class' => 'input select'), - 'label' => array('for' => 'email'), - 'Email', - '/label', - array('select' => array('name' => 'data[email]', 'id' => 'email')), - array('option' => array('value' => '')), - '/option', - array('option' => array('value' => 'è')), - 'Firést', - '/option', - array('option' => array('value' => 'é')), - 'Secoènd', - '/option', - '/select', - '/div' - ); - $this->assertTags($result, $expected); - - $result = $this->Form->input('email', array( - 'options' => array('First', 'Second'), 'empty' => true) - ); - $expected = array( - 'div' => array('class' => 'input select'), - 'label' => array('for' => 'email'), - 'Email', - '/label', - array('select' => array('name' => 'data[email]', 'id' => 'email')), - array('option' => array('value' => '')), - '/option', - array('option' => array('value' => '0')), - 'First', - '/option', - array('option' => array('value' => '1')), - 'Second', - '/option', - '/select', - '/div' - ); - $this->assertTags($result, $expected); - $result = $this->Form->input('Contact.email', array( 'type' => 'file', 'class' => 'textbox' )); @@ -1559,84 +1515,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24)); - $result = explode(':', $result); - $this->assertPattern('/option value="23"/', $result[0]); - $this->assertNoPattern('/option value="24"/', $result[0]); - - $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24)); - $result = explode(':', $result); - $this->assertPattern('/option value="23"/', $result[0]); - $this->assertNoPattern('/option value="24"/', $result[0]); - - $result = $this->Form->input('Model.field', array( - 'type' => 'time', 'timeFormat' => 24, 'interval' => 15 - )); - $result = explode(':', $result); - $this->assertNoPattern('##', $result[1]); - $this->assertNoPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - - $result = $this->Form->input('Model.field', array( - 'type' => 'time', 'timeFormat' => 12, 'interval' => 15 - )); - $result = explode(':', $result); - $this->assertNoPattern('##', $result[1]); - $this->assertNoPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - - $result = $this->Form->input('prueba', array( - 'type' => 'time', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008, - 'maxYear' => date('Y') + 1 ,'interval' => 15 - )); - $result = explode(':', $result); - $this->assertNoPattern('##', $result[1]); - $this->assertNoPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - - $result = $this->Form->input('prueba', array( - 'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008, - 'maxYear' => date('Y') + 1 ,'interval' => 15 - )); - $result = explode(':', $result); - $this->assertNoPattern('##', $result[1]); - $this->assertNoPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - $this->assertPattern('##', $result[1]); - - //related to ticket #5013 - $result = $this->Form->input('Contact.date', array( - 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}' - )); - $this->assertPattern('/class="customClass"/', $result); - $this->assertPattern('/onChange="function\(\)\{\}"/', $result); - - $result = $this->Form->input('Contact.date', array( - 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}' - )); - $this->assertPattern('/id="customIdDay"/', $result); - $this->assertPattern('/id="customIdMonth"/', $result); - $this->assertPattern('/onChange="function\(\)\{\}"/', $result); - - $result = $this->Form->input('Model.field', array( - 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID' - )); - $this->assertPattern('/id="customIDDay"/', $result); - $this->assertPattern('/id="customIDHour"/', $result); - $result = explode('assertPattern('/option value="23"/', $result[0]); - $this->assertNoPattern('/option value="24"/', $result[0]); - - $result = $this->Form->input('Model.field', array( - 'type' => 'datetime', 'timeFormat' => 12 - )); - $result = explode('assertPattern('/option value="12"/', $result[0]); - $this->assertNoPattern('/option value="13"/', $result[0]); - $this->Form->data = array('Contact' => array('phone' => 'Hello & World > weird chars')); $result = $this->Form->input('Contact.phone'); $expected = array( @@ -1653,7 +1531,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->Form->data['Model']['0']['OtherModel']['field'] = 'My value'; $result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId')); $expected = array( @@ -1770,6 +1647,199 @@ 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', true)))); + $expected = array( + 'div' => array('class' => 'input text error'), + 'label' => array('for' => 'ModelField'), + 'Field', + '/label', + 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), + array('div' => array('class' => 'error-message')), + 'Le login doit contenir au moins 2 caractères', + '/div', + '/div' + ); + $this->assertTags($result, $expected); + } +/** + * test form->input() with datetime, date and time types + * + * @return void + **/ + function testInputDatetime() { + extract($this->dateRegex); + $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24)); + $result = explode(':', $result); + $this->assertPattern('/option value="23"/', $result[0]); + $this->assertNoPattern('/option value="24"/', $result[0]); + + $result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24)); + $result = explode(':', $result); + $this->assertPattern('/option value="23"/', $result[0]); + $this->assertNoPattern('/option value="24"/', $result[0]); + + $result = $this->Form->input('Model.field', array( + 'type' => 'time', 'timeFormat' => 24, 'interval' => 15 + )); + $result = explode(':', $result); + $this->assertNoPattern('##', $result[1]); + $this->assertNoPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + + $result = $this->Form->input('Model.field', array( + 'type' => 'time', 'timeFormat' => 12, 'interval' => 15 + )); + $result = explode(':', $result); + $this->assertNoPattern('##', $result[1]); + $this->assertNoPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + + $result = $this->Form->input('prueba', array( + 'type' => 'time', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008, + 'maxYear' => date('Y') + 1 ,'interval' => 15 + )); + $result = explode(':', $result); + $this->assertNoPattern('##', $result[1]); + $this->assertNoPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + + $result = $this->Form->input('prueba', array( + 'type' => 'datetime', 'timeFormat'=> 24 , 'dateFormat'=>'DMY' , 'minYear' => 2008, + 'maxYear' => date('Y') + 1 ,'interval' => 15 + )); + $result = explode(':', $result); + $this->assertNoPattern('##', $result[1]); + $this->assertNoPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + $this->assertPattern('##', $result[1]); + + //related to ticket #5013 + $result = $this->Form->input('Contact.date', array( + 'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}' + )); + $this->assertPattern('/class="customClass"/', $result); + $this->assertPattern('/onChange="function\(\)\{\}"/', $result); + + $result = $this->Form->input('Contact.date', array( + 'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}' + )); + $this->assertPattern('/id="customIdDay"/', $result); + $this->assertPattern('/id="customIdMonth"/', $result); + $this->assertPattern('/onChange="function\(\)\{\}"/', $result); + + $result = $this->Form->input('Model.field', array( + 'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID' + )); + $this->assertPattern('/id="customIDDay"/', $result); + $this->assertPattern('/id="customIDHour"/', $result); + $result = explode('assertPattern('/option value="23"/', $result[0]); + $this->assertNoPattern('/option value="24"/', $result[0]); + + $result = $this->Form->input('Model.field', array( + 'type' => 'datetime', 'timeFormat' => 12 + )); + $result = explode('assertPattern('/option value="12"/', $result[0]); + $this->assertNoPattern('/option value="13"/', $result[0]); + + $this->Form->data = array('Contact' => array('created' => null)); + $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown')); + $expected = array( + 'div' => array('class' => 'input date'), + 'label' => array('for' => 'ContactCreatedMonth'), + 'Created', + '/label', + array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')), + array('option' => array('value' => '')), 'Date Unknown', '/option', + $monthsRegex, + '/select', '-', + array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')), + array('option' => array('value' => '')), 'Date Unknown', '/option', + $daysRegex, + '/select', '-', + array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')), + array('option' => array('value' => '')), 'Date Unknown', '/option', + $yearsRegex, + '/select', + '/div' + ); + $this->assertTags($result, $expected); + } +/** + * Test generating checkboxes in a loop. + * + * @return void + **/ + function testInputCheckboxesInLoop() { + for ($i = 1; $i < 5; $i++) { + $result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i)); + $expected = array( + 'div' => array('class' => 'input checkbox'), + 'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"), + array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")), + 'label' => array('for' => "Contact{$i}Email"), + 'Email', + '/label', + '/div' + ); + $this->assertTags($result, $expected); + } + } +/** + * test form->input() with select type inputs. + * + * @return void + **/ + function testInputSelectType() { + $result = $this->Form->input('email', array( + 'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true) + ); + $expected = array( + 'div' => array('class' => 'input select'), + 'label' => array('for' => 'email'), + 'Email', + '/label', + array('select' => array('name' => 'data[email]', 'id' => 'email')), + array('option' => array('value' => '')), + '/option', + array('option' => array('value' => 'è')), + 'Firést', + '/option', + array('option' => array('value' => 'é')), + 'Secoènd', + '/option', + '/select', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->input('email', array( + 'options' => array('First', 'Second'), 'empty' => true) + ); + $expected = array( + 'div' => array('class' => 'input select'), + 'label' => array('for' => 'email'), + 'Email', + '/label', + array('select' => array('name' => 'data[email]', 'id' => 'email')), + array('option' => array('value' => '')), + '/option', + array('option' => array('value' => '0')), + 'First', + '/option', + array('option' => array('value' => '1')), + 'Second', + '/option', + '/select', + '/div' + ); + $this->assertTags($result, $expected); + $this->Form->data = array('Model' => array('user_id' => 'value')); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); @@ -1841,33 +1911,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - extract($this->dateRegex); - - $this->Form->data = array('Contact' => array('created' => null)); - $view =& ClassRegistry::getObject('view'); - $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); - $result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown')); - $expected = array( - 'div' => array('class' => 'input date'), - 'label' => array('for' => 'ContactCreatedMonth'), - 'Created', - '/label', - array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')), - array('option' => array('value' => '')), 'Date Unknown', '/option', - $monthsRegex, - '/select', '-', - array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')), - array('option' => array('value' => '')), 'Date Unknown', '/option', - $daysRegex, - '/select', '-', - array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')), - array('option' => array('value' => '')), 'Date Unknown', '/option', - $yearsRegex, - '/select', - '/div' - ); - $this->assertTags($result, $expected); - $this->Form->data = array('User' => array('User' => array('value'))); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); @@ -1891,35 +1934,6 @@ class FormHelperTest extends CakeTestCase { '/div' ); $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', true)))); - $expected = array( - 'div' => array('class' => 'input text error'), - 'label' => array('for' => 'ModelField'), - 'Field', - '/label', - 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), - array('div' => array('class' => 'error-message')), - 'Le login doit contenir au moins 2 caractères', - '/div', - '/div' - ); - $this->assertTags($result, $expected); - - for ($i = 1; $i < 5; $i++) { - $result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i)); - $expected = array( - 'div' => array('class' => 'input checkbox'), - 'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"), - array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")), - 'label' => array('for' => "Contact{$i}Email"), - 'Email', - '/label', - '/div' - ); - $this->assertTags($result, $expected); - } } /** * testFormInputs method From 082156f9a1842b3d3c5e0afca48c4dba69ccab12 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 14 Oct 2009 21:17:00 -0400 Subject: [PATCH 02/82] Fixing FormHelper::input() label's for attribute when a datetime type is created and dateFormat or timeFormat is set to NONE. Fixes #168 --- cake/libs/view/helpers/form.php | 16 ++++++++++------ cake/tests/cases/libs/view/helpers/form.test.php | 8 ++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 0a58cea16..e71fff9be 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -708,9 +708,13 @@ class FormHelper extends AppHelper { if ($label !== false) { $labelAttributes = $this->domId(array(), 'for'); - if (in_array($options['type'], array('date', 'datetime'))) { - $labelAttributes['for'] .= 'Month'; - } else if ($options['type'] === 'time') { + if ($options['type'] === 'date' || $options['type'] === 'datetime') { + if (isset($options['dateFormat']) && $options['dateFormat'] === 'NONE') { + $labelAttributes['for'] .= 'Hour'; + } else { + $labelAttributes['for'] .= 'Month'; + } + } elseif ($options['type'] === 'time') { $labelAttributes['for'] .= 'Hour'; } @@ -764,10 +768,10 @@ class FormHelper extends AppHelper { unset($options['dateFormat']); } - $type = $options['type']; - $before = $options['before']; + $type = $options['type']; + $before = $options['before']; $between = $options['between']; - $after = $options['after']; + $after = $options['after']; unset($options['type'], $options['before'], $options['between'], $options['after']); switch ($type) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 7911f200c..0a83d59c3 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -1769,6 +1769,14 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $this->Form->data = array('Contact' => array('created' => null)); + $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE')); + $this->assertPattern('/for\="ContactCreatedHour"/', $result); + + $this->Form->data = array('Contact' => array('created' => null)); + $result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE')); + $this->assertPattern('/for\="ContactCreatedMonth"/', $result); } /** * Test generating checkboxes in a loop. From 43dbf716241bc16c227b8e85ddae3e65bdce4c3e Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 15 Oct 2009 18:09:58 -0300 Subject: [PATCH 03/82] Doing a little optimization for php 5.1 <, also fixing tests on Windows. Fixes #155. --- cake/libs/session.php | 12 ++++++------ cake/tests/cases/libs/view/helpers/session.test.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cake/libs/session.php b/cake/libs/session.php index 136865689..38697ae23 100644 --- a/cake/libs/session.php +++ b/cake/libs/session.php @@ -592,15 +592,15 @@ class CakeSession extends Object { function __regenerateId() { $oldSessionId = session_id(); if ($oldSessionId) { - $sessionpath = session_save_path(); - if (empty($sessionpath)) { - $sessionpath = "/tmp"; - } - if (session_id() != "" || isset($_COOKIE[session_name()])) { + if (session_id() != ''|| isset($_COOKIE[session_name()])) { setcookie(Configure::read('Session.cookie'), '', time() - 42000, $this->path); } session_regenerate_id(true); if (PHP_VERSION < 5.1) { + $sessionPath = session_save_path(); + if (empty($sessionPath)) { + $sessionPath = '/tmp'; + } $newSessid = session_id(); if (function_exists('session_write_close')) { @@ -610,7 +610,7 @@ class CakeSession extends Object { session_id($oldSessionId); session_start(); session_destroy(); - $file = $sessionpath . DS . "sess_$oldSessionId"; + $file = $sessionPath . DS . 'sess_' . $oldSessionId; @unlink($file); $this->__initSession(); session_id($newSessid); diff --git a/cake/tests/cases/libs/view/helpers/session.test.php b/cake/tests/cases/libs/view/helpers/session.test.php index 6f98c2acd..eb6e295e7 100644 --- a/cake/tests/cases/libs/view/helpers/session.test.php +++ b/cake/tests/cases/libs/view/helpers/session.test.php @@ -224,7 +224,7 @@ class SessionHelperTest extends CakeTestCase { ob_clean(); $this->assertPattern("/Missing Layout/", $result); - $this->assertPattern("/layouts\/does_not_exist.ctp/", $result); + $this->assertPattern("/layouts(\\\|\/)does_not_exist.ctp/", $result); } /** * testID method From a36c2ec5bbaa7176ebf3403120fb6bc39f3b9fd5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 16 Oct 2009 09:19:23 -0400 Subject: [PATCH 04/82] Removing self inclusions for test cases. Refs #174 --- cake/tests/cases/libs/model/model_integration.test.php | 3 +-- cake/tests/cases/libs/model/model_validation.test.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/libs/model/model_integration.test.php b/cake/tests/cases/libs/model/model_integration.test.php index e213187b6..cc1d8b20c 100644 --- a/cake/tests/cases/libs/model/model_integration.test.php +++ b/cake/tests/cases/libs/model/model_integration.test.php @@ -1,7 +1,7 @@ Date: Sun, 18 Oct 2009 22:05:17 -0400 Subject: [PATCH 05/82] Fixing FormHelper::__selectOptions incorrectly selecting options due to type juggling. Fixes #167 --- cake/libs/view/helpers/form.php | 2 +- .../tests/cases/libs/view/helpers/form.test.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index e71fff9be..e1f3c4422 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1721,7 +1721,7 @@ class FormHelper extends AppHelper { } if ($name !== null) { - if ((!$selectedIsEmpty && $selected == $name) || ($selectedIsArray && in_array($name, $selected))) { + if ((!$selectedIsEmpty && (string)$selected == (string)$name) || ($selectedIsArray && in_array($name, $selected))) { if ($attributes['style'] === 'checkbox') { $htmlOptions['checked'] = true; } else { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 0a83d59c3..a0241322f 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2687,6 +2687,23 @@ class FormHelperTest extends CakeTestCase { '/select' ); $this->assertTags($result, $expected); + + $this->Form->data = array('Model' => array('contact_id' => 228)); + $result = $this->Form->select( + 'Model.contact_id', + array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'), + null, array('escape' => false), 'pick something' + ); + + $expected = array( + 'select' => array('name' => 'data[Model][contact_id]', 'id' => 'ModelContactId'), + array('option' => array('value' => '')), 'pick something', '/option', + array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option', + array('option' => array('value' => '228-1')), '228-1 value', '/option', + array('option' => array('value' => '228-2')), '228-2 value', '/option', + '/select' + ); + $this->assertTags($result, $expected); } /** * Tests that FormHelper::select() allows null to be passed in the $attributes parameter From 7ff3fcc4c4105e6a4475effff534f0429e1fe6aa Mon Sep 17 00:00:00 2001 From: jperras Date: Mon, 19 Oct 2009 12:51:06 -0400 Subject: [PATCH 06/82] Adding skip for non-existence of DateTimeZone class in time helper tests. --- cake/tests/cases/libs/view/helpers/time.test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index 94da2a997..fbaff45ab 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -639,6 +639,8 @@ class TimeHelperTest extends CakeTestCase { * @return void */ function testUserOffset() { + $this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.'); + $timezoneServer = new DateTimeZone(date_default_timezone_get()); $timeServer = new DateTime('now', $timezoneServer); $yourTimezone = $timezoneServer->getOffset($timeServer) / HOUR; From ae342c6f2c9e88290cdc4316bff7848a3a4a908e Mon Sep 17 00:00:00 2001 From: jperras Date: Mon, 19 Oct 2009 13:17:07 -0400 Subject: [PATCH 07/82] Fixing skip in previous commit: if skip condition evaluates to true, to prevent a fatal error from being produced. --- cake/tests/cases/libs/view/helpers/time.test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index fbaff45ab..7fd5c1b15 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -639,7 +639,10 @@ class TimeHelperTest extends CakeTestCase { * @return void */ function testUserOffset() { - $this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.'); + if ($this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.')) { + return; + } + $timezoneServer = new DateTimeZone(date_default_timezone_get()); $timeServer = new DateTime('now', $timezoneServer); From 79e96e5aefa5095500b3efd45b2426bc88fc7143 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 19 Oct 2009 16:36:44 -0400 Subject: [PATCH 08/82] Updating localePaths path. Fixes #184 --- cake/tests/cases/basics.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index 7baeeb60f..800cb7dc3 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -41,7 +41,7 @@ class BasicsTest extends CakeTestCase { */ function setUp() { $this->_localePaths = Configure::read('localePaths'); - Configure::write('localePaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale')); + Configure::write('localePaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale' .DS )); $this->_language = Configure::read('Config.language'); } /** From 3922f136dab019cbfe93ddb828d6a0dcba8cc72a Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 19 Oct 2009 20:54:02 -0400 Subject: [PATCH 09/82] Making DboMysqlTest pass when a connection with a prefix is used. Fixes #185 --- .../libs/model/datasources/dbo/dbo_mysql.test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index 691a86c1f..cf9cc833c 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -273,7 +273,7 @@ class DboMysqlTest extends CakeTestCase { $this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));'); $this->model = new CakeTestModel(array( - 'name' => 'Tinyint', 'table' => $this->db->fullTableName('tinyint', false) + 'name' => 'Tinyint', 'table' => 'tinyint', 'ds' => 'test_suite' )); $result = $this->model->schema(); @@ -312,7 +312,7 @@ class DboMysqlTest extends CakeTestCase { $name = $this->db->fullTableName('simple'); $this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));'); $expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1)); - $result = $this->db->index($name, false); + $result = $this->db->index('simple', false); $this->assertEqual($expected, $result); $this->db->query('DROP TABLE ' . $name); @@ -322,7 +322,7 @@ class DboMysqlTest extends CakeTestCase { 'PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0), ); - $result = $this->db->index($name, false); + $result = $this->db->index('with_a_key', false); $this->assertEqual($expected, $result); $this->db->query('DROP TABLE ' . $name); @@ -333,7 +333,7 @@ class DboMysqlTest extends CakeTestCase { 'pointless_bool' => array('column' => 'bool', 'unique' => 0), 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0), ); - $result = $this->db->index($name, false); + $result = $this->db->index('with_two_keys', false); $this->assertEqual($expected, $result); $this->db->query('DROP TABLE ' . $name); @@ -345,7 +345,7 @@ class DboMysqlTest extends CakeTestCase { 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0), 'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0), ); - $result = $this->db->index($name, false); + $result = $this->db->index('with_compound_keys', false); $this->assertEqual($expected, $result); $this->db->query('DROP TABLE ' . $name); @@ -358,7 +358,7 @@ class DboMysqlTest extends CakeTestCase { 'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0), 'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0), ); - $result = $this->db->index($name, false); + $result = $this->db->index('with_multiple_compound_keys', false); $this->assertEqual($expected, $result); $this->db->query('DROP TABLE ' . $name); } From 0a79822b9de901de6f5098990beb4086d98901c3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 19 Oct 2009 21:09:47 -0400 Subject: [PATCH 10/82] Expanding some doc blocks for DataSource. --- cake/libs/model/datasources/datasource.php | 34 +++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index b1b2baefb..c92f8aff6 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -287,42 +287,50 @@ class DataSource extends Object { return false; } /** + * Used to create new records. The "C" CRUD. + * * To-be-overridden in subclasses. * - * @param unknown_type $model - * @param unknown_type $fields - * @param unknown_type $values - * @return unknown + * @param Model $model The Model to be created. + * @param array $fields An Array of fields to be saved. + * @param array $values An Array of values to save. + * @return boolean success */ function create(&$model, $fields = null, $values = null) { return false; } /** + * Used to read records from the Datasource. The "R" in CRUD + * * To-be-overridden in subclasses. * - * @param unknown_type $model - * @param unknown_type $queryData - * @return unknown + * @param Model $model The model being read. + * @param array $queryData An array of query data used to find the data you want + * @return mixed */ function read(&$model, $queryData = array()) { return false; } /** + * Update a record(s) in the datasource. + * * To-be-overridden in subclasses. * - * @param unknown_type $model - * @param unknown_type $fields - * @param unknown_type $values - * @return unknown + * @param Model $model Instance of the model class being updated + * @param array $fields Array of fields to be updated + * @param array $values Array of values to be update $fields to. + * @return boolean Success */ function update(&$model, $fields = null, $values = null) { return false; } /** + * Delete a record(s) in the datasource. + * * To-be-overridden in subclasses. * - * @param unknown_type $model - * @param unknown_type $id + * @param Model $model The model class having record(s) deleted + * @param mixed $id Primary key of the model */ function delete(&$model, $id = null) { if ($id == null) { From a15289fba87f3b3b5a9add16efa3ac9250c85bd8 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Tue, 20 Oct 2009 16:16:31 -0200 Subject: [PATCH 11/82] Saving few Router::normalize() calls, will may increase performance. Fixes #179. --- cake/libs/controller/components/auth.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index a68e5b6f2..420305d57 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -421,10 +421,10 @@ class AuthComponent extends Object { return false; } $defaults = array( - 'loginAction' => Router::normalize(array( - 'controller'=> Inflector::underscore(Inflector::pluralize($this->userModel)), + 'loginAction' => array( + 'controller' => Inflector::underscore(Inflector::pluralize($this->userModel)), 'action' => 'login' - )), + ), 'sessionKey' => 'Auth.' . $this->userModel, 'logoutRedirect' => $this->loginAction, 'loginError' => __('Login failed. Invalid username or password.', true), From 072e1efc130fed9443783910fd6c4ddf884f40d3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 20 Oct 2009 16:11:31 -0400 Subject: [PATCH 12/82] Adding Datasource::enabled() Allows for checking a datasource's ability to be used before attempting to connect it. Added enabled() to all the core dbo's. Fixes whitescreen when trying to use a non installed database driver. Fixes #131 --- cake/libs/model/datasources/datasource.php | 10 ++++++++++ cake/libs/model/datasources/dbo/dbo_adodb.php | 12 +++++++++++- cake/libs/model/datasources/dbo/dbo_db2.php | 8 ++++++++ cake/libs/model/datasources/dbo/dbo_firebird.php | 9 +++++++++ cake/libs/model/datasources/dbo/dbo_mssql.php | 8 ++++++++ cake/libs/model/datasources/dbo/dbo_mysql.php | 8 ++++++++ cake/libs/model/datasources/dbo/dbo_mysqli.php | 8 ++++++++ cake/libs/model/datasources/dbo/dbo_odbc.php | 8 ++++++++ cake/libs/model/datasources/dbo/dbo_postgres.php | 8 ++++++++ cake/libs/model/datasources/dbo/dbo_sqlite.php | 8 ++++++++ cake/libs/model/datasources/dbo/dbo_sybase.php | 8 ++++++++ cake/libs/model/datasources/dbo_source.php | 4 +++- 12 files changed, 97 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index c92f8aff6..fa7b6632d 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -364,6 +364,16 @@ class DataSource extends Object { function lastAffected($source = null) { return false; } +/** + * Check whether the conditions for the Datasource being available + * are satisfied. Often used from connect() to check for support + * before establishing a connection. + * + * @return boolean Whether or not the Datasources conditions for use are met. + **/ + function enabled() { + return true; + } /** * Returns true if the DataSource supports the given interface (method) * diff --git a/cake/libs/model/datasources/dbo/dbo_adodb.php b/cake/libs/model/datasources/dbo/dbo_adodb.php index 53d6f9601..45fa4048e 100644 --- a/cake/libs/model/datasources/dbo/dbo_adodb.php +++ b/cake/libs/model/datasources/dbo/dbo_adodb.php @@ -102,7 +102,9 @@ class DboAdodb extends DboSource { $adodb_driver = substr($config['connect'], 0, $persistent); $connect = 'PConnect'; } - + if (!$this->enabled()) { + return false; + } $this->_adodb = NewADOConnection($adodb_driver); $this->_adodbDataDict = NewDataDictionary($this->_adodb, $adodb_driver); @@ -114,6 +116,14 @@ class DboAdodb extends DboSource { $this->_adodbMetatyper = &$this->_adodb->execute('Select 1'); return $this->connected; } +/** + * Check that AdoDB is available. + * + * @return boolean + **/ + function enabled() { + return function_exists('NewADOConnection'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_db2.php b/cake/libs/model/datasources/dbo/dbo_db2.php index 4e65d3b43..0942dee85 100644 --- a/cake/libs/model/datasources/dbo/dbo_db2.php +++ b/cake/libs/model/datasources/dbo/dbo_db2.php @@ -136,6 +136,14 @@ class DboDb2 extends DboSource { } return $this->connected; } +/** + * Check that the DB2 extension is installed/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('ibm_db2'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_firebird.php b/cake/libs/model/datasources/dbo/dbo_firebird.php index d02c45b76..dc9cec15f 100644 --- a/cake/libs/model/datasources/dbo/dbo_firebird.php +++ b/cake/libs/model/datasources/dbo/dbo_firebird.php @@ -127,9 +127,18 @@ class DboFirebird extends DboSource { $connect = $config['connect']; $this->connected = false; + $this->connection = $connect($config['host'] . ':' . $config['database'], $config['login'], $config['password']); $this->connected = true; } +/** + * Check that the interbase extension is loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('interbase'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_mssql.php b/cake/libs/model/datasources/dbo/dbo_mssql.php index 1b1219d59..b93192f95 100644 --- a/cake/libs/model/datasources/dbo/dbo_mssql.php +++ b/cake/libs/model/datasources/dbo/dbo_mssql.php @@ -152,6 +152,14 @@ class DboMssql extends DboSource { } return $this->connected; } +/** + * Check that MsSQL is installed/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('mssql'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 2d97e141c..58433beca 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -388,6 +388,14 @@ class DboMysql extends DboMysqlBase { return $this->connected; } +/** + * Check whether the MySQL extension is installed/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('mysql'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index b0adf8d2e..bf9797d43 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -83,6 +83,14 @@ class DboMysqli extends DboMysqlBase { } return $this->connected; } +/** + * Check that MySQLi is installed/enabled + * + * @return boolean + **/ + function enabled() { + return extension_loaded('mysqli'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_odbc.php b/cake/libs/model/datasources/dbo/dbo_odbc.php index a8572a713..e68948668 100644 --- a/cake/libs/model/datasources/dbo/dbo_odbc.php +++ b/cake/libs/model/datasources/dbo/dbo_odbc.php @@ -105,6 +105,14 @@ class DboOdbc extends DboSource { return $this->connected; } +/** + * Check if the ODBC extension is installed/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('odbc'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 2298fc019..192355fd6 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -122,6 +122,14 @@ class DboPostgres extends DboSource { } return $this->connected; } +/** + * Check if PostgreSQL is enabled/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('pgsql'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index c365b6fe0..005ffc6fe 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -113,6 +113,14 @@ class DboSqlite extends DboSource { } return $this->connected; } +/** + * Check that SQLite is enabled/installed + * + * @return boolean + **/ + function enabled() { + return extension_loaded('sqlite'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_sybase.php b/cake/libs/model/datasources/dbo/dbo_sybase.php index 4bed00e43..45e8fd057 100644 --- a/cake/libs/model/datasources/dbo/dbo_sybase.php +++ b/cake/libs/model/datasources/dbo/dbo_sybase.php @@ -102,6 +102,14 @@ class DboSybase extends DboSource { $this->connected = sybase_select_db($config['database'], $this->connection); return $this->connected; } +/** + * Check that one of the sybase extensions is installed + * + * @return boolean + **/ + function enabled() { + return extension_loaded('sybase') || extension_loaded('sybase_ct'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 1b10243d9..013a5baee 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -91,7 +91,9 @@ class DboSource extends DataSource { } parent::__construct($config); $this->fullDebug = Configure::read() > 1; - + if (!$this->enabled()) { + return false; + } if ($autoConnect) { return $this->connect(); } else { From c6f783ebfe04e33eb7b342a6ed18ccc5986e3990 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 20 Oct 2009 22:19:32 -0400 Subject: [PATCH 13/82] Fixing issues with CakeTestCase test case and debug = 3. Fixes #189 --- cake/tests/cases/libs/cake_test_case.test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index 895eaaf40..930683c75 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -78,6 +78,7 @@ class CakeTestCaseTest extends CakeTestCase { * @return void */ function setUp() { + $this->_debug = Configure::read('debug'); $this->Case =& new SubjectCakeTestCase(); $reporter =& new MockCakeHtmlReporter(); $this->Case->setReporter($reporter); @@ -90,6 +91,7 @@ class CakeTestCaseTest extends CakeTestCase { * @return void */ function tearDown() { + Configure::write('debug', $this->_debug); unset($this->Case); unset($this->Reporter); } @@ -239,6 +241,8 @@ class CakeTestCaseTest extends CakeTestCase { * @return void **/ function testTestAction() { + Configure::write('debug', 2); + $_back = array( 'controller' => Configure::read('controllerPaths'), 'view' => Configure::read('viewPaths'), From 0e23fdfbb3d2889870215cfa459e5bbae87acbdb Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 21 Oct 2009 00:22:36 -0400 Subject: [PATCH 14/82] Fixing infinitely nesting stack frames when TreeBehavior::reorder() is called and the models $cacheQueries = true and there are a sizable number of records being manipulated. Test cases added. Fixes #188 --- cake/libs/model/behaviors/tree.php | 5 ++++- .../cases/libs/model/behaviors/tree.test.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/behaviors/tree.php b/cake/libs/model/behaviors/tree.php index da23c193d..145d298e1 100644 --- a/cake/libs/model/behaviors/tree.php +++ b/cake/libs/model/behaviors/tree.php @@ -460,7 +460,7 @@ class TreeBehavior extends ModelBehavior { 'fields' => array($Model->primaryKey, $left, $right), 'recursive' => $recursive) ); if ($nextNode) { - list($nextNode)= array_values($nextNode); + list($nextNode) = array_values($nextNode); } else { return false; } @@ -640,6 +640,8 @@ class TreeBehavior extends ModelBehavior { $sort = $field . ' ' . $order; $nodes = $this->children($Model, $id, true, $fields, $sort, null, null, $recursive); + $cacheQueries = $Model->cacheQueries; + $Model->cacheQueries = false; if ($nodes) { foreach ($nodes as $node) { $id = $node[$Model->alias][$Model->primaryKey]; @@ -649,6 +651,7 @@ class TreeBehavior extends ModelBehavior { } } } + $Model->cacheQueries = $cacheQueries; return true; } /** diff --git a/cake/tests/cases/libs/model/behaviors/tree.test.php b/cake/tests/cases/libs/model/behaviors/tree.test.php index 147da89ae..86834122b 100644 --- a/cake/tests/cases/libs/model/behaviors/tree.test.php +++ b/cake/tests/cases/libs/model/behaviors/tree.test.php @@ -1172,6 +1172,25 @@ class NumberTreeTest extends CakeTestCase { $sortedNodes = $this->Tree->find('list', array('order' => $leftField)); $this->assertIdentical($nodes, $sortedNodes); } +/** + * test reordering large-ish trees with cacheQueries = true. + * This caused infinite loops when moving down elements as stale data is returned + * from the memory cache + * + * @access public + * @return void + */ + function testReorderBigTreeWithQueryCaching() { + extract($this->settings); + $this->Tree =& new $modelClass(); + $this->Tree->initialize(2, 10); + + $original = $this->Tree->cacheQueries; + $this->Tree->cacheQueries = true; + $this->Tree->reorder(array('field' => 'name', 'direction' => 'DESC')); + $this->assertTrue($this->Tree->cacheQueries, 'cacheQueries was not restored after reorder(). %s'); + $this->Tree->cacheQueries = $original; + } /** * testGenerateTreeListWithSelfJoin method * From 0cc1d84737a1445e4f2972b70b658bfb56e60997 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Aug 2009 22:51:10 -0400 Subject: [PATCH 15/82] Removing use of e() from core and test suite. --- cake/console/libs/templates/skel/views/layouts/xml/default.ctp | 2 +- cake/tests/test_app/views/layouts/xml/default.ctp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/console/libs/templates/skel/views/layouts/xml/default.ctp b/cake/console/libs/templates/skel/views/layouts/xml/default.ctp index c68870298..566ca2158 100644 --- a/cake/console/libs/templates/skel/views/layouts/xml/default.ctp +++ b/cake/console/libs/templates/skel/views/layouts/xml/default.ctp @@ -1,2 +1,2 @@ -header()); ?> +header(); ?> \ No newline at end of file diff --git a/cake/tests/test_app/views/layouts/xml/default.ctp b/cake/tests/test_app/views/layouts/xml/default.ctp index c68870298..566ca2158 100644 --- a/cake/tests/test_app/views/layouts/xml/default.ctp +++ b/cake/tests/test_app/views/layouts/xml/default.ctp @@ -1,2 +1,2 @@ -header()); ?> +header(); ?> \ No newline at end of file From 8b419d2dd8b0e2fa4bfa1c3e549aeba5a31c80c1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Aug 2009 22:54:57 -0400 Subject: [PATCH 16/82] Removing use of ife() from core classes. --- cake/libs/validation.php | 2 +- cake/libs/view/helpers/javascript.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/validation.php b/cake/libs/validation.php index be0d20c2a..6531d97d9 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -806,7 +806,7 @@ class Validation extends Object { $_this =& Validation::getInstance(); $_this->check = $check; $validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=') . '\/0-9a-z]|(%[0-9a-f]{2}))'; - $_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . ife($strict, '', '?') . + $_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') . '(?:' . $_this->__pattern['ip'] . '|' . $_this->__pattern['hostname'] . ')(?::[1-9][0-9]{0,3})?' . '(?:\/?|\/' . $validChars . '*)?' . '(?:\?' . $validChars . '*)?' . diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index 21eab7f44..aa8d7577f 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -678,7 +678,7 @@ class JavascriptHelper extends AppHelper { $val = 'null'; break; case (is_bool($val)): - $val = ife($val, 'true', 'false'); + $val = !empty($val) ? 'true' : 'false'; break; case (is_int($val)): $val = $val; From 0657afcf30763320664262bfd3f6fbfee0042c14 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 21 Oct 2009 13:03:24 -0400 Subject: [PATCH 17/82] Removing use of low() from core classes. Refs #6525 --- cake/basics.php | 2 +- cake/console/libs/api.php | 4 ++-- cake/console/libs/tasks/db_config.php | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 5e387c553..8a9c7b527 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -467,7 +467,7 @@ if (!function_exists('file_put_contents')) { $expires = strtotime($expires, $now); } - switch (low($target)) { + switch (strtolower($target)) { case 'cache': $filename = CACHE . $path; break; diff --git a/cake/console/libs/api.php b/cake/console/libs/api.php index 87aefc10a..c370d7310 100644 --- a/cake/console/libs/api.php +++ b/cake/console/libs/api.php @@ -169,8 +169,8 @@ class ApiShell extends Shell { foreach ($commands as $cmd) { $this->out("{$cmd}\n\n"); } - } elseif (isset($commands[low($this->args[1])])) { - $this->out($commands[low($this->args[1])] . "\n\n"); + } elseif (isset($commands[strtolower($this->args[1])])) { + $this->out($commands[strtolower($this->args[1])] . "\n\n"); } else { $this->out("Command '" . $this->args[1] . "' not found"); } diff --git a/cake/console/libs/tasks/db_config.php b/cake/console/libs/tasks/db_config.php index d2f05393b..3126c00d9 100644 --- a/cake/console/libs/tasks/db_config.php +++ b/cake/console/libs/tasks/db_config.php @@ -109,7 +109,7 @@ class DbConfigTask extends Shell { $persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n'); } - if (low($persistent) == 'n') { + if (strtolower($persistent) == 'n') { $persistent = 'false'; } else { $persistent = 'true'; @@ -125,7 +125,7 @@ class DbConfigTask extends Shell { $port = $this->in('Port?', null, 'n'); } - if (low($port) == 'n') { + if (strtolower($port) == 'n') { $port = null; } $login = ''; @@ -158,7 +158,7 @@ class DbConfigTask extends Shell { $prefix = $this->in('Table Prefix?', null, 'n'); } - if (low($prefix) == 'n') { + if (strtolower($prefix) == 'n') { $prefix = null; } $encoding = ''; @@ -167,7 +167,7 @@ class DbConfigTask extends Shell { $encoding = $this->in('Table encoding?', null, 'n'); } - if (low($encoding) == 'n') { + if (strtolower($encoding) == 'n') { $encoding = null; } $schema = ''; @@ -178,7 +178,7 @@ class DbConfigTask extends Shell { } } - if (low($schema) == 'n') { + if (strtolower($schema) == 'n') { $schema = null; } @@ -190,7 +190,7 @@ class DbConfigTask extends Shell { $dbConfigs[] = $config; $doneYet = $this->in('Do you wish to add another database configuration?', null, 'n'); - if (low($doneYet == 'n')) { + if (strtolower($doneYet == 'n')) { $done = true; } } From 1ee9771efbe2f6dd0431ac5b025e0f6fd55b9b89 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 21 Oct 2009 13:12:03 -0400 Subject: [PATCH 18/82] Removing ife() from AclShell. Refs #6562 --- cake/console/libs/acl.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index 5a7873da8..15b678404 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -225,7 +225,7 @@ class AclShell extends Shell { $this->_checkArgs(2, 'getPath'); $this->checkNodeType(); extract($this->__dataVars()); - $id = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]); + $id = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1]; $nodes = $this->Acl->{$class}->getPath($id); if (empty($nodes)) { $this->error(sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), __("No tree returned.", true)); @@ -304,7 +304,7 @@ class AclShell extends Shell { $this->checkNodeType(); extract($this->__dataVars()); if (isset($this->args[1]) && !is_null($this->args[1])) { - $key = ife(is_numeric($this->args[1]), $secondary_id, 'alias'); + $key = is_numeric($this->args[1]) ? $secondary_id : 'alias'; $conditions = array($class . '.' . $key => $this->args[1]); } else { $conditions = null; @@ -425,8 +425,8 @@ class AclShell extends Shell { foreach ($commands as $cmd) { $this->out("{$cmd}\n\n"); } - } elseif (isset($commands[low($this->args[0])])) { - $this->out($commands[low($this->args[0])] . "\n\n"); + } elseif (isset($commands[strtolower($this->args[0])])) { + $this->out($commands[strtolower($this->args[0])] . "\n\n"); } else { $this->out(sprintf(__("Command '%s' not found", true), $this->args[0])); } @@ -457,7 +457,7 @@ class AclShell extends Shell { return false; } extract($this->__dataVars($this->args[0])); - $key = (ife(is_numeric($this->args[1]), $secondary_id, 'alias')); + $key = is_numeric($this->args[1]) ? $secondary_id : 'alias'; $conditions = array($class . '.' . $key => $this->args[1]); $possibility = $this->Acl->{$class}->find('all', compact('conditions')); if (empty($possibility)) { @@ -472,8 +472,8 @@ class AclShell extends Shell { * @access private */ function __getParams() { - $aro = ife(is_numeric($this->args[0]), intval($this->args[0]), $this->args[0]); - $aco = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]); + $aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0]; + $aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1]; if (is_string($aro) && preg_match('/^([\w]+)\.(.*)$/', $aro, $matches)) { $aro = array( @@ -512,7 +512,7 @@ class AclShell extends Shell { } $vars = array(); $class = ucwords($type); - $vars['secondary_id'] = ife(strtolower($class) == 'aro', 'foreign_key', 'object_id'); + $vars['secondary_id'] = strtolower($class) == 'aro' ? 'foreign_key' : 'object_id'; $vars['data_name'] = $type; $vars['table_name'] = $type . 's'; $vars['class'] = $class; From 4e8c268536081966f124cea7c5947fe341cc6d6a Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Wed, 21 Oct 2009 19:19:21 -0200 Subject: [PATCH 19/82] Making the test more clear by avoind +-2 days thing. Fixes #186. --- .../cases/libs/view/helpers/time.test.php | 62 ++++--------------- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index 7fd5c1b15..997d3092b 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -470,57 +470,19 @@ class TimeHelperTest extends CakeTestCase { * @return void */ function testIsThisWeek() { - switch (date('D')) { - case 'Mon' : - for ($i = 0; $i < 6; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+7 days")); - $this->assertFalse($this->Time->isThisWeek("-1 days")); - break; - case 'Tue' : - for ($i = -1; $i < 5; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+6 days")); - $this->assertFalse($this->Time->isThisWeek("-2 days")); - break; - case 'Wed' : - for ($i = -2; $i < 5; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+5 days")); - $this->assertFalse($this->Time->isThisWeek("-3 days")); - break; - case 'Thu' : - for ($i = -3; $i < 4; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+4 days")); - $this->assertFalse($this->Time->isThisWeek("-4 days")); - break; - case 'Fri' : - for ($i = -4; $i < 3; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+3 days")); - $this->assertFalse($this->Time->isThisWeek("-5 days")); - break; - case 'Sat' : - for ($i = -5; $i < 2; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+2 days")); - $this->assertFalse($this->Time->isThisWeek("-6 days")); - break; - case 'Sun' : - for ($i = -6; $i < 1; $i++) { - $this->assertTrue($this->Time->isThisWeek("+$i days")); - } - $this->assertFalse($this->Time->isThisWeek("+1 days")); - $this->assertFalse($this->Time->isThisWeek("-7 days")); - break; + // A map of days which goes from -1 day of week to +1 day of week + $map = array( + 'Mon' => array(-1, 7), 'Tue' => array(-2, 6), 'Wed' => array(-3, 5), + 'Thu' => array(-4, 4), 'Fri' => array(-5, 3), 'Sat' => array(-6, 2), + 'Sun' => array(-7, 1) + ); + $days = $map[date('D')]; + + for ($day = $days[0] + 1; $day < $days[1]; $day++) { + $this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days')); } + $this->assertFalse($this->Time->isThisWeek($days[0] . ' days')); + $this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days')); } /** * testIsThisMonth method From 3dbae37aadc903f380647d9454e25635d3e560ab Mon Sep 17 00:00:00 2001 From: ceeram Date: Thu, 22 Oct 2009 12:34:25 +0200 Subject: [PATCH 20/82] fixing failing i18n testcase, caused by setting $category parameter for __c(), __dc() and __dcn() as LC_MONETARY instead of numeric value --- cake/tests/cases/libs/i18n.test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/tests/cases/libs/i18n.test.php b/cake/tests/cases/libs/i18n.test.php index 3aa5b2f57..01b271871 100644 --- a/cake/tests/cases/libs/i18n.test.php +++ b/cake/tests/cases/libs/i18n.test.php @@ -2557,7 +2557,7 @@ class I18nTest extends CakeTestCase { * @access private * @return void */ - function __domainCategorySingular($domain = 'test_plugin', $category = LC_MONETARY) { + function __domainCategorySingular($domain = 'test_plugin', $category = 3) { $singular = __dc($domain, 'Plural Rule 1', $category, true); return $singular; } @@ -2567,7 +2567,7 @@ class I18nTest extends CakeTestCase { * @access private * @return void */ - function __domainCategoryPlural($domain = 'test_plugin', $category = LC_MONETARY) { + function __domainCategoryPlural($domain = 'test_plugin', $category = 3) { $plurals = array(); for ($number = 0; $number <= 25; $number++) { $plurals[] = sprintf(__dcn($domain, '%d = 1', '%d = 0 or > 1', (float)$number, $category, true), (float)$number); @@ -2603,7 +2603,7 @@ class I18nTest extends CakeTestCase { * @access private * @return void */ - function __category($category = LC_MONETARY) { + function __category($category = 3) { $singular = __c('Plural Rule 1', $category, true); return $singular; } From d25497c52702e0962b85bc6f5692a948d0dbd17e Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 22 Oct 2009 13:51:55 -0400 Subject: [PATCH 21/82] Adding Skip to mb_strrpos test case. Skips the test if mbstring is installed and php version is 5.1.x. mb_strrpos had an incompatible function signature in these versions. --- cake/tests/cases/libs/multibyte.test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cake/tests/cases/libs/multibyte.test.php b/cake/tests/cases/libs/multibyte.test.php index 68950cc78..dd0ea371c 100644 --- a/cake/tests/cases/libs/multibyte.test.php +++ b/cake/tests/cases/libs/multibyte.test.php @@ -4786,6 +4786,10 @@ class MultibyteTest extends CakeTestCase { * @return void */ function testUsingMbStrrpos() { + $skip = extension_loaded('mbstring') && version_compare(PHP_VERSION, '5.2.0', '<'); + if ($this->skipIf($skip, '%s PHP version does not support $offset parameter in mb_strrpos().')) { + return; + } $string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $find = 'F'; $result = mb_strrpos($string, $find); From c6999aea7f66bad6bd98e460351e045a0a6d4374 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 24 Oct 2009 10:46:28 -0400 Subject: [PATCH 22/82] Moving DboMysqli::describe() and DboMysql::describe() into DboMysqlBase. Removes duplicated method code. --- cake/libs/model/datasources/dbo/dbo_mysql.php | 68 +++++++++---------- .../libs/model/datasources/dbo/dbo_mysqli.php | 37 ---------- 2 files changed, 34 insertions(+), 71 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 58433beca..ef61cb675 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -85,6 +85,40 @@ class DboMysqlBase extends DboSource { 'binary' => array('name' => 'blob'), 'boolean' => array('name' => 'tinyint', 'limit' => '1') ); +/** + * Returns an array of the fields in given table name. + * + * @param string $tableName Name of database table to inspect + * @return array Fields in table. Keys are name and type + */ + function describe(&$model) { + $cache = parent::describe($model); + if ($cache != null) { + return $cache; + } + $fields = false; + $cols = $this->query('DESCRIBE ' . $this->fullTableName($model)); + + foreach ($cols as $column) { + $colKey = array_keys($column); + if (isset($column[$colKey[0]]) && !isset($column[0])) { + $column[0] = $column[$colKey[0]]; + } + if (isset($column[0])) { + $fields[$column[0]['Field']] = array( + 'type' => $this->column($column[0]['Type']), + 'null' => ($column[0]['Null'] == 'YES' ? true : false), + 'default' => $column[0]['Default'], + 'length' => $this->length($column[0]['Type']), + ); + if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) { + $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']]; + } + } + } + $this->__cacheDescription($this->fullTableName($model, false), $fields); + return $fields; + } /** * Generates and executes an SQL UPDATE statement for given model, fields, and values. * @@ -442,40 +476,6 @@ class DboMysql extends DboMysqlBase { return $tables; } } -/** - * Returns an array of the fields in given table name. - * - * @param string $tableName Name of database table to inspect - * @return array Fields in table. Keys are name and type - */ - function describe(&$model) { - $cache = parent::describe($model); - if ($cache != null) { - return $cache; - } - $fields = false; - $cols = $this->query('DESCRIBE ' . $this->fullTableName($model)); - - foreach ($cols as $column) { - $colKey = array_keys($column); - if (isset($column[$colKey[0]]) && !isset($column[0])) { - $column[0] = $column[$colKey[0]]; - } - if (isset($column[0])) { - $fields[$column[0]['Field']] = array( - 'type' => $this->column($column[0]['Type']), - 'null' => ($column[0]['Null'] == 'YES' ? true : false), - 'default' => $column[0]['Default'], - 'length' => $this->length($column[0]['Type']), - ); - if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) { - $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']]; - } - } - } - $this->__cacheDescription($this->fullTableName($model, false), $fields); - return $fields; - } /** * Returns a quoted and escaped string of $data for use in an SQL statement. * diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index bf9797d43..910504082 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -157,43 +157,6 @@ class DboMysqli extends DboMysqlBase { parent::listSources($tables); return $tables; } -/** - * Returns an array of the fields in given table name. - * - * @param string $tableName Name of database table to inspect - * @return array Fields in table. Keys are name and type - */ - function describe(&$model) { - - $cache = parent::describe($model); - if ($cache != null) { - return $cache; - } - - $fields = false; - $cols = $this->query('DESCRIBE ' . $this->fullTableName($model)); - - foreach ($cols as $column) { - $colKey = array_keys($column); - if (isset($column[$colKey[0]]) && !isset($column[0])) { - $column[0] = $column[$colKey[0]]; - } - if (isset($column[0])) { - $fields[$column[0]['Field']] = array( - 'type' => $this->column($column[0]['Type']), - 'null' => ($column[0]['Null'] == 'YES' ? true : false), - 'default' => $column[0]['Default'], - 'length' => $this->length($column[0]['Type']) - ); - if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) { - $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']]; - } - } - } - - $this->__cacheDescription($this->fullTableName($model, false), $fields); - return $fields; - } /** * Returns a quoted and escaped string of $data for use in an SQL statement. * From 14bd47842ca767571596a1be159356dd8f66fb60 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 24 Oct 2009 11:06:27 -0400 Subject: [PATCH 23/82] Removing length() from DboMysqli, fixes incorrect float length parsing. Test case added. --- .../libs/model/datasources/dbo/dbo_mysqli.php | 19 ---------------- .../model/datasources/dbo/dbo_mysqli.test.php | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index 910504082..2742a7c31 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -298,25 +298,6 @@ class DboMysqli extends DboMysqlBase { } return 'text'; } -/** - * Gets the length of a database-native column description, or null if no length - * - * @param string $real Real database-layer column type (i.e. "varchar(255)") - * @return integer An integer representing the length of the column - */ - function length($real) { - $col = str_replace(array(')', 'unsigned'), '', $real); - $limit = null; - - if (strpos($col, '(') !== false) { - list($col, $limit) = explode('(', $col); - } - - if ($limit != null) { - return intval($limit); - } - return null; - } /** * Enter description here... * diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php index 3b19174c4..2e1e87a66 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php @@ -154,6 +154,7 @@ class MysqliTestModel extends Model { * @subpackage cake.tests.cases.libs.model.datasources.dbo */ class DboMysqliTest extends CakeTestCase { + var $fixtures = array('core.datatype'); /** * The Dbo instance to be tested * @@ -176,8 +177,6 @@ class DboMysqliTest extends CakeTestCase { * @access public */ function setUp() { - $db = ConnectionManager::getDataSource('test_suite'); - $this->db = new DboMysqliTestDb($db->config); $this->model = new MysqliTestModel(); } /** @@ -186,7 +185,8 @@ class DboMysqliTest extends CakeTestCase { * @access public */ function tearDown() { - unset($this->db); + unset($this->model); + ClassRegistry::flush(); } /** * testIndexDetection method @@ -195,7 +195,7 @@ class DboMysqliTest extends CakeTestCase { * @access public */ function testIndexDetection() { - $this->db->cacheSources = $this->db->testing = false; + $this->db->cacheSources = false; $name = $this->db->fullTableName('simple'); $this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));'); @@ -298,12 +298,14 @@ class DboMysqliTest extends CakeTestCase { $this->assertEqual($result, $expected); } /** - * undocumented function + * test mysqli transactions * * @return void * @access public */ function testTransactions() { + $this->db->cacheSources = false; + $this->db->begin($this->model); $this->assertTrue($this->db->_transactionStarted); @@ -313,5 +315,15 @@ class DboMysqliTest extends CakeTestCase { $this->db->commit($this->model); $this->assertFalse($this->db->_transactionStarted); } +/** + * test that float values are correctly identified + * + * @return void + **/ + function testFloatParsing() { + $model =& new Model(array('ds' => 'test_suite', 'table' => 'datatypes', 'name' => 'Datatype')); + $result = $this->db->describe($model); + $this->assertEqual((string)$result['float_field']['length'], '5,2'); + } } ?> \ No newline at end of file From 72830cb125204f27b7055c8d8f41fa9bfef1a808 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 24 Oct 2009 11:26:06 -0400 Subject: [PATCH 24/82] Adding test case for model task Fixing missing case for float datatypes when generating fixtures. Fixes #204 --- cake/console/libs/tasks/model.php | 6 +- .../cases/console/libs/tasks/model.test.php | 90 +++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 cake/tests/cases/console/libs/tasks/model.test.php diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index 779d088f8..2d75be9ba 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -99,6 +99,7 @@ class ModelTask extends Shell { if (count($connections) > 1) { $useDbConfig = $this->in(__('Use Database Config', true) .':', $connections, 'default'); } + $this->useDbConfig = $useDbConfig; $currentModelName = $this->getName($useDbConfig); $db =& ConnectionManager::getDataSource($useDbConfig); @@ -843,7 +844,7 @@ class ModelTask extends Shell { $out .= "\tvar \$table = '$useTable';\n"; } $schema = new CakeSchema(); - $data = $schema->read(array('models' => false)); + $data = $schema->read(array('models' => false, 'connection' => $this->useDbConfig)); if (!isset($data['tables'][$useTable])) { return false; @@ -865,6 +866,7 @@ class ModelTask extends Shell { $col = "\t\t'{$field}' => array('type'=>'" . $value['type'] . "', "; switch ($value['type']) { + case 'float': case 'integer': $insert = 1; break; @@ -898,7 +900,7 @@ class ModelTask extends Shell { $insert .= "feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.'"; break; } - $records[] = "\t\t'$field' => $insert"; + $records[] = "\t\t'$field' => $insert"; unset($value['type']); $col .= join(', ', $schema->__values($value)); } else { diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php new file mode 100644 index 000000000..b273b69cc --- /dev/null +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -0,0 +1,90 @@ +Dispatcher =& new TestModelTaskMockShellDispatcher(); + $this->Task =& new MockModelTask($this->Dispatcher); + $this->Task->Dispatch =& $this->Dispatcher; + } +/** + * tearDown method + * + * @return void + * @access public + */ + function tearDown() { + ClassRegistry::flush(); + } +/** + * test fixture generation with floats + * + * @return void + **/ + function testFixtureGeneration() { + $this->Task->useDbConfig = 'test_suite'; + $this->Task->setReturnValue('createFile', true); + $result = $this->Task->fixture('Datatype'); + $this->assertPattern('/float_field\' => 1/', $result); + + } +} +?> \ No newline at end of file From 79fdd8b341437287549ace1f413bd495e6db8d3e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 24 Oct 2009 12:53:22 -0400 Subject: [PATCH 25/82] Adding test to ensure blob integrity. Disproves #199 --- .../model/datasources/dbo/dbo_mysql.test.php | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index cf9cc833c..26a9bc9c0 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -153,6 +153,7 @@ class MysqlTestModel extends Model { * @subpackage cake.tests.cases.libs.model.datasources.dbo */ class DboMysqlTest extends CakeTestCase { + var $fixtures = array('core.binary_test'); /** * The Dbo instance to be tested * @@ -176,7 +177,6 @@ class DboMysqlTest extends CakeTestCase { */ function setUp() { $db = ConnectionManager::getDataSource('test_suite'); - $this->db = new DboMysqlTestDb($db->config); $this->model = new MysqlTestModel(); } /** @@ -185,7 +185,8 @@ class DboMysqlTest extends CakeTestCase { * @access public */ function tearDown() { - unset($this->db); + unset($this->model); + ClassRegistry::flush(); } /** * startCase @@ -269,7 +270,7 @@ class DboMysqlTest extends CakeTestCase { * @return void */ function testTinyintCasting() { - $this->db->cacheSources = $this->db->testing = false; + $this->db->cacheSources = false; $this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));'); $this->model = new CakeTestModel(array( @@ -307,7 +308,7 @@ class DboMysqlTest extends CakeTestCase { * @access public */ function testIndexDetection() { - $this->db->cacheSources = $this->db->testing = false; + $this->db->cacheSources = false; $name = $this->db->fullTableName('simple'); $this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));'); @@ -510,7 +511,7 @@ class DboMysqlTest extends CakeTestCase { */ function testAlterSchemaIndexes() { App::import('Core', 'Schema'); - $this->db->cacheSources = $this->db->testing = false; + $this->db->cacheSources = false; $schema1 =& new CakeSchema(array( 'name' => 'AlterTest1', @@ -574,5 +575,23 @@ class DboMysqlTest extends CakeTestCase { $this->db->query($this->db->dropSchema($schema1)); } +/** + * test saving and retrieval of blobs + * + * @return void + **/ + function testBlobSaving() { + $this->db->cacheSources = false; + $data = "GIF87ab + Ò4A¿¿¿ˇˇˇ,b + ¢îè©ÀÌ#¥⁄ã≥fi:¯Ü‚Héá¶jV∂ÓúÎL≥çÀóËıÎ…>ï≈ vFE%ÒâLFI<†µw˝±≈£7˘ç^H“≤« >Éâ*∑ÇnÖA•Ù|flêèj£:=ÿ6óUàµ5'∂®àA¬ñ∆ˆGE(gt’≈àÚyÁó«7 ‚VìöÇ√˙Ç™ + k”:;kÀAõ{*¡€Î˚˚[;;"; + + $model =& new AppModel(array('name' => 'BinaryTest', 'ds' => 'test_suite')); + $model->save(compact('data')); + + $result = $model->find('first'); + $this->assertEqual($result['BinaryTest']['data'], $data); + } } ?> \ No newline at end of file From 5a093e56272d614c7bb33adee0eb4dfd3cc701c1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 27 Oct 2009 13:22:34 -0400 Subject: [PATCH 26/82] Fixing issues in postgres with time columns and '' values. Tests added. Fixes #213 --- cake/libs/model/datasources/dbo/dbo_postgres.php | 1 + .../cases/libs/model/datasources/dbo/dbo_postgres.test.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 192355fd6..3ea5d8fa0 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -286,6 +286,7 @@ class DboPostgres extends DboSource { case 'date': case 'datetime': case 'timestamp': + case 'time': if ($data === '') { return $read ? 'NULL' : 'DEFAULT'; } diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index aec59ba4c..ff6588668 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -291,11 +291,11 @@ class DboPostgresTest extends CakeTestCase { $this->assertEqual($this->db2->value(null, 'boolean'), "NULL"); } /** - * test that date columns do not generate errors with null and nullish values. + * test that date and time columns do not generate errors with null and nullish values. * * @return void **/ - function testDateAsNull() { + function testDateAndTimeAsNull() { $this->assertEqual($this->db2->value(null, 'date'), 'NULL'); $this->assertEqual($this->db2->value('', 'date'), 'NULL'); @@ -304,6 +304,9 @@ class DboPostgresTest extends CakeTestCase { $this->assertEqual($this->db2->value('', 'timestamp'), 'NULL'); $this->assertEqual($this->db2->value(null, 'timestamp'), 'NULL'); + + $this->assertEqual($this->db2->value('', 'time'), 'NULL'); + $this->assertEqual($this->db2->value(null, 'time'), 'NULL'); } /** * Tests that different Postgres boolean 'flavors' are properly returned as native PHP booleans From 00d7c655ce57fd9b33250e3ba10441604a89bd87 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 27 Oct 2009 13:28:43 -0400 Subject: [PATCH 27/82] Improving documentation for PaginatorHelper::sort() Fixes #210 --- cake/libs/view/helpers/paginator.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 7b5dd09a2..0e8505ecf 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -207,11 +207,13 @@ class PaginatorHelper extends AppHelper { return $this->__pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions); } /** - * Generates a sorting link + * Generates a sorting link. Sets named parameters for the sort and direction. Handles + * direction switching automatically. * - * @param string $title Title for the link. - * @param string $key The name of the key that the recordset should be sorted. - * @param array $options Options for sorting link. See #options for list of keys. + * @param string $title Title for the link. + * @param string $key The name of the key that the recordset should be sorted. If $key is null + * $title will be used for the key, and a title will be generated by inflection. + * @param array $options Options for sorting link. See #options for list of keys. * @return string A link sorting default by 'asc'. If the resultset is sorted 'asc' by the specified * key the returned link will sort by 'desc'. */ From 23ab84596aa2083acea08d7b33e275f4322b7f2b Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 27 Oct 2009 21:04:14 -0400 Subject: [PATCH 28/82] Adding discrete tests to Folder::addPathElement --- cake/tests/cases/libs/folder.test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cake/tests/cases/libs/folder.test.php b/cake/tests/cases/libs/folder.test.php index 6fad570de..0793630c2 100644 --- a/cake/tests/cases/libs/folder.test.php +++ b/cake/tests/cases/libs/folder.test.php @@ -215,6 +215,18 @@ class FolderTest extends CakeTestCase { $result = $Folder->delete($new); $this->assertTrue($result); } +/** + * test Adding path elements to a path + * + * @return void + **/ + function testAddPathElement() { + $result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path'); + $this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path'); + + $result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path'); + $this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path'); + } /** * testFolderRead method * From ad305a890a9854f55b6da97d734f6e738a024066 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 27 Oct 2009 21:06:58 -0400 Subject: [PATCH 29/82] Applying optimization from 'ermayer' Reduces functions called from Folder::addPathElement() Fixes #178 --- cake/libs/folder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/folder.php b/cake/libs/folder.php index 28f32672a..a5331f80f 100644 --- a/cake/libs/folder.php +++ b/cake/libs/folder.php @@ -302,7 +302,7 @@ class Folder extends Object { * @static */ function addPathElement($path, $element) { - return Folder::slashTerm($path) . $element; + return rtrim($path, DS) . DS . $element; } /** * Returns true if the File is in a given CakePath. From 4bf807b4be5f35faad95f30bd77df01c3cb8d3ac Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 28 Oct 2009 18:32:04 -0400 Subject: [PATCH 30/82] Deprecating String::getInstance() --- cake/libs/string.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cake/libs/string.php b/cake/libs/string.php index fcfa76d91..d7bbf2036 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -34,8 +34,10 @@ class String { * @return object String instance * @access public * @static + * @deprecated */ function &getInstance() { + trigger_error('String::getInstance() is deprecated. All String methods are called statically.', E_USER_WARNING); static $instance = array(); if (!$instance) { From 6c18c0e0c726cf85f4d0c8bfc4ff3470b42b4b51 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 28 Oct 2009 18:41:29 -0400 Subject: [PATCH 31/82] Fixing escape parameter usage. --- cake/console/templates/skel/views/layouts/default.ctp | 2 +- cake/libs/view/layouts/default.ctp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/console/templates/skel/views/layouts/default.ctp b/cake/console/templates/skel/views/layouts/default.ctp index 047439e7a..5d61adc1b 100644 --- a/cake/console/templates/skel/views/layouts/default.ctp +++ b/cake/console/templates/skel/views/layouts/default.ctp @@ -55,7 +55,7 @@ link( $html->image('cake.power.gif', array('alt'=>__("CakePHP: the rapid development php framework", true), 'border'=>"0")), 'http://www.cakephp.org/', - array('target'=>'_blank', 'escape'=>false), null + array('target' => '_blank', 'escape' => false) ); ?> diff --git a/cake/libs/view/layouts/default.ctp b/cake/libs/view/layouts/default.ctp index 0b326d6c0..93b0e441a 100644 --- a/cake/libs/view/layouts/default.ctp +++ b/cake/libs/view/layouts/default.ctp @@ -55,7 +55,7 @@ link( $html->image('cake.power.gif', array('alt'=> __("CakePHP: the rapid development php framework", true), 'border'=>"0")), 'http://www.cakephp.org/', - array('target'=>'_blank'), null, false + array('target' => '_blank', 'escape' => false) ); ?> From e7074c1e5ce9bc9cea0ef8427a245cb91ad578f3 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 29 Oct 2009 01:23:44 -0200 Subject: [PATCH 32/82] Moving parameters to $options on Text::truncate() and Text::highlight(). --- cake/libs/view/helpers/text.php | 62 ++++++++++++------- .../cases/libs/view/helpers/text.test.php | 58 ++++++++--------- 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index d6f88d4fc..477c6de4f 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -46,43 +46,51 @@ class TextHelper extends AppHelper { * Highlights a given phrase in a text. You can specify any expression in highlighter that * may include the \1 expression to include the $phrase found. * + * Options: + * + * - 'format' The piece of html with that the phrase will be highlighted + * - 'html' If true, will ignore any HTML tags, ensuring that only the correct text is highlighted + * * @param string $text Text to search the phrase in * @param string $phrase The phrase that will be searched - * @param string $highlighter The piece of html with that the phrase will be highlighted - * @param boolean $considerHtml If true, will ignore any HTML tags, ensuring that only the correct text is highlighted + * @param array $options An array of html attributes and options. * @return string The highlighted text * @access public */ - function highlight($text, $phrase, $highlighter = '\1', $considerHtml = false) { + function highlight($text, $phrase, $options = array()) { if (empty($phrase)) { return $text; } - if (is_array($phrase)) { + $default = array( + 'format' => '\1', + 'html' => false + ); + $options = array_merge($default, $options); + extract($options); + if (is_array($phrase)) { $replace = array(); $with = array(); foreach ($phrase as $key => $segment) { $segment = "($segment)"; - - if ($considerHtml) { + if ($html) { $segment = "(?![^<]+>)$segment(?![^<]+>)"; } - $with[] = (is_array($highlighter)) ? $highlighter[$key] : $highlighter; + $with[] = (is_array($format)) ? $format[$key] : $format; $replace[] = "|$segment|iu"; } return preg_replace($replace, $with, $text); - } else { $phrase = "($phrase)"; - if ($considerHtml) { + if ($html) { $phrase = "(?![^<]+>)$phrase(?![^<]+>)"; } - return preg_replace("|$phrase|iu", $highlighter, $text); + return preg_replace("|$phrase|iu", $format, $text); } } @@ -160,24 +168,32 @@ class TextHelper extends AppHelper { * Cuts a string to the length of $length and replaces the last characters * with the ending if the text is longer than length. * + * Options: + * + * - 'ending' Will be used as Ending and appended to the trimmed string + * - 'exact' If false, $text will not be cut mid-word + * - 'html' If true, HTML tags would be handled correctly + * * @param string $text String to truncate. * @param integer $length Length of returned string, including ellipsis. - * @param mixed $ending If string, will be used as Ending and appended to the trimmed string. Can also be an associative array that can contain the last three params of this method. - * @param boolean $exact If false, $text will not be cut mid-word - * @param boolean $considerHtml If true, HTML tags would be handled correctly + * @param array $options An array of html attributes and options. * @return string Trimmed string. */ - function truncate($text, $length = 100, $ending = '...', $exact = true, $considerHtml = false) { - if (is_array($ending)) { - extract($ending); - } - if ($considerHtml) { + function truncate($text, $length = 100, $options = array()) { + $default = array( + 'ending' => '...', 'exact' => true, 'html' => false + ); + $options = array_merge($default, $options); + extract($options); + + if ($html) { if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { return $text; } $totalLength = mb_strlen($ending); $openTags = array(); $truncate = ''; + preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER); foreach ($tags as $tag) { if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2])) { @@ -217,7 +233,6 @@ class TextHelper extends AppHelper { break; } } - } else { if (mb_strlen($text) <= $length) { return $text; @@ -228,7 +243,7 @@ class TextHelper extends AppHelper { if (!$exact) { $spacepos = mb_strrpos($truncate, ' '); if (isset($spacepos)) { - if ($considerHtml) { + if ($html) { $bits = mb_substr($truncate, $spacepos); preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER); if (!empty($droppedTags)) { @@ -242,10 +257,9 @@ class TextHelper extends AppHelper { $truncate = mb_substr($truncate, 0, $spacepos); } } - $truncate .= $ending; - if ($considerHtml) { + if ($html) { foreach ($openTags as $tag) { $truncate .= ''; } @@ -276,9 +290,9 @@ class TextHelper extends AppHelper { * @return string Modified string * @access public */ - function excerpt($text, $phrase, $radius = 100, $ending = "...") { + function excerpt($text, $phrase, $radius = 100, $ending = '...') { if (empty($text) or empty($phrase)) { - return $this->truncate($text, $radius * 2, $ending); + return $this->truncate($text, $radius * 2, array('ending' => $ending)); } $phraseLen = mb_strlen($phrase); diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 748754073..294c6a17e 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -77,25 +77,24 @@ class TextHelperTest extends CakeTestCase { $text9 = 'НОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь'; $this->assertIdentical($this->Text->truncate($text1, 15), 'The quick br...'); - $this->assertIdentical($this->Text->truncate($text1, 15, '...', false), 'The quick...'); + $this->assertIdentical($this->Text->truncate($text1, 15, array('exact' => false)), 'The quick...'); $this->assertIdentical($this->Text->truncate($text1, 100), 'The quick brown fox jumps over the lazy dog'); - $this->assertIdentical($this->Text->truncate($text2, 10, '...'), 'Heiz&ou...'); - $this->assertIdentical($this->Text->truncate($text2, 10, '...', false), '...'); + $this->assertIdentical($this->Text->truncate($text2, 10), 'Heiz&ou...'); + $this->assertIdentical($this->Text->truncate($text2, 10, array('exact' => false)), '...'); $this->assertIdentical($this->Text->truncate($text3, 20), '© 2005-20...'); $this->assertIdentical($this->Text->truncate($text4, 15), ' This image ...'); - $this->assertIdentical($this->Text->truncate($text4, 45, '...', true, true), ' This image tag is not XHTML conform!

But t...'); - $this->assertIdentical($this->Text->truncate($text4, 90, '...', true, true), ' This image tag is not XHTML conform!

But the following image tag should be conform Me, myself and I
Grea...'); - $this->assertIdentical($this->Text->truncate($text5, 6, '', true, true), '012345'); - $this->assertIdentical($this->Text->truncate($text5, 20, '', true, true), $text5); - $this->assertIdentical($this->Text->truncate($text6, 57, '...', false, true), "

Extra dates have been announced for this year's...

"); + $this->assertIdentical($this->Text->truncate($text5, 6, array('ending' => '')), '01<'); + $this->assertIdentical($this->Text->truncate($text1, 15, array('html' => true)), 'The quick br...'); + $this->assertIdentical($this->Text->truncate($text1, 15, array('exact' => false, 'html' => true)), 'The quick...'); + $this->assertIdentical($this->Text->truncate($text2, 10, array('html' => true)), 'Heizölr...'); + $this->assertIdentical($this->Text->truncate($text2, 10, array('exact' => false, 'html' => true)), '...'); + $this->assertIdentical($this->Text->truncate($text3, 20, array('html' => true)), '© 2005-2007, Cake...'); + $this->assertIdentical($this->Text->truncate($text4, 15, array('html' => true)), ' This image ...'); + $this->assertIdentical($this->Text->truncate($text4, 45, array('html' => true)), ' This image tag is not XHTML conform!

But t...'); + $this->assertIdentical($this->Text->truncate($text4, 90, array('html' => true)), ' This image tag is not XHTML conform!

But the following image tag should be conform Me, myself and I
Grea...'); + $this->assertIdentical($this->Text->truncate($text5, 6, array('ending' => '', 'html' => true)), '012345'); + $this->assertIdentical($this->Text->truncate($text5, 20, array('ending' => '', 'html' => true)), $text5); + $this->assertIdentical($this->Text->truncate($text6, 57, array('exact' => false, 'html' => true)), "

Extra dates have been announced for this year's...

"); $this->assertIdentical($this->Text->truncate($text7, 255), $text7); $this->assertIdentical($this->Text->truncate($text7, 15), 'El moño está...'); $this->assertIdentical($this->Text->truncate($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...'); @@ -111,46 +110,47 @@ class TextHelperTest extends CakeTestCase { function testHighlight() { $text = 'This is a test text'; $phrases = array('This', 'text'); - $result = $this->Text->highlight($text, $phrases, '\1'); + $result = $this->Text->highlight($text, $phrases, array('format' => '\1')); $expected = 'This is a test text'; $this->assertEqual($expected, $result); $text = 'This is a test text'; $phrases = null; - $result = $this->Text->highlight($text, $phrases, '\1'); + $result = $this->Text->highlight($text, $phrases, array('format' => '\1')); $this->assertEqual($result, $text); $text = 'Ich saß in einem Café am Übergang'; $expected = 'Ich saß in einem Café am Übergang'; $phrases = array('saß', 'café', 'übergang'); - $result = $this->Text->highlight($text, $phrases, '\1'); + $result = $this->Text->highlight($text, $phrases, array('format' => '\1')); $this->assertEqual($result, $expected); } /** - * testHighlightConsiderHtml method + * testHighlightHtml method * * @access public * @return void */ - function testHighlightConsiderHtml() { + function testHighlightHtml() { $text1 = '

strongbow isn’t real cider

'; $text2 = '

strongbow isn’t real cider

'; $text3 = 'What a strong mouse!'; $text4 = 'What a strong mouse: What a strong mouse!'; + $options = array('format' => '\1', 'html' => true); $expected = '

strongbow isn’t real cider

'; - $this->assertEqual($this->Text->highlight($text1, 'strong', '\1', true), $expected); + $this->assertEqual($this->Text->highlight($text1, 'strong', $options), $expected); $expected = '

strongbow isn’t real cider

'; - $this->assertEqual($this->Text->highlight($text2, 'strong', '\1', true), $expected); + $this->assertEqual($this->Text->highlight($text2, 'strong', $options), $expected); - $this->assertEqual($this->Text->highlight($text3, 'strong', '\1', true), $text3); + $this->assertEqual($this->Text->highlight($text3, 'strong', $options), $text3); - $this->assertEqual($this->Text->highlight($text3, array('strong', 'what'), '\1', true), $text3); + $this->assertEqual($this->Text->highlight($text3, array('strong', 'what'), $options), $text3); $expected = 'What a strong mouse: What a strong mouse!'; - $this->assertEqual($this->Text->highlight($text4, array('strong', 'what'), '\1', true), $expected); + $this->assertEqual($this->Text->highlight($text4, array('strong', 'what'), $options), $expected); } /** @@ -162,7 +162,7 @@ class TextHelperTest extends CakeTestCase { function testHighlightMulti() { $text = 'This is a test text'; $phrases = array('This', 'text'); - $result = $this->Text->highlight($text, $phrases, array('\1', '\1')); + $result = $this->Text->highlight($text, $phrases, array('format' => array('\1', '\1'))); $expected = 'This is a test text'; $this->assertEqual($expected, $result); @@ -286,10 +286,10 @@ class TextHelperTest extends CakeTestCase { $text = 'This is a Test text'; $expected = 'This is a Test text'; - $result = $this->Text->highlight($text, 'test', '\1'); + $result = $this->Text->highlight($text, 'test', array('format' => '\1')); $this->assertEqual($expected, $result); - $result = $this->Text->highlight($text, array('test'), '\1'); + $result = $this->Text->highlight($text, array('test'), array('format' => '\1')); $this->assertEqual($expected, $result); } From 61845090ed288af7842ed6ead75e754c76d6183f Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 29 Oct 2009 01:31:55 -0200 Subject: [PATCH 33/82] Changing variable name to make consistency between others methods. --- cake/libs/view/helpers/text.php | 37 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 477c6de4f..6159c4962 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -110,56 +110,55 @@ class TextHelper extends AppHelper { * strings like http:// and ftp://. * * @param string $text Text to add links to - * @param array $htmlOptions Array of HTML options. + * @param array $options Array of HTML options. * @return string The text with links * @access public */ - function autoLinkUrls($text, $htmlOptions = array()) { - $options = 'array('; - foreach ($htmlOptions as $option => $value) { + function autoLinkUrls($text, $options = array()) { + $linkOptions = 'array('; + foreach ($options as $option => $value) { $value = var_export($value, true); - $options .= "'$option' => $value, "; + $linkOptions .= "'$option' => $value, "; } - $options .= ')'; + $linkOptions .= ')'; $text = preg_replace_callback('#(?)((?:http|https|ftp|nntp)://[^ <]+)#i', create_function('$matches', - '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text); + '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $linkOptions . ');'), $text); return preg_replace_callback('#(?)(?tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $options . ');'), $text); + create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . strtolower($matches[0]),' . $linkOptions . ');'), $text); } /** * Adds email links ( $value, "; + $linkOptions .= "'$option' => $value, "; } - $options .= ')'; + $linkOptions .= ')'; return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#', - create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $options . ');'), $text); + create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text); } /** * Convert all links and email adresses to HTML links. * * @param string $text Text - * @param array $htmlOptions Array of HTML options. + * @param array $options Array of HTML options. * @return string The text with links * @access public */ - function autoLink($text, $htmlOptions = array()) { - return $this->autoLinkEmails($this->autoLinkUrls($text, $htmlOptions), $htmlOptions); + function autoLink($text, $options = array()) { + return $this->autoLinkEmails($this->autoLinkUrls($text, $options), $options); } /** From 2a8858e928b9c447921a2860d8f4f904dc55126d Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 01:36:15 -0400 Subject: [PATCH 34/82] Adding tests to DboSqlite::buildColumn Adding collate field parameter to DboSqlite. Removing duplicated code from DboSource, adding parent call instead. --- .../libs/model/datasources/dbo/dbo_sqlite.php | 37 ++++-------- .../model/datasources/dbo/dbo_sqlite.test.php | 60 +++++++++++++++++++ 2 files changed, 71 insertions(+), 26 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index aa6311be3..d106dac34 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -107,6 +107,16 @@ class DboSqlite extends DboSource { 'boolean' => array('name' => 'boolean') ); +/** + * List of engine specific additional field parameters used on table creating + * + * @var array + * @access public + */ + var $fieldParameters = array( + 'collate' => array('value' => 'COLLATE', 'quote' => false, 'join' => ' ', 'column' => 'Collate', 'position' => 'afterDefault'), + ); + /** * Connects to the database using config['database'] as a filename. * @@ -481,32 +491,7 @@ class DboSqlite extends DboSource { if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') { return $this->name($name) . ' ' . $this->columns['primary_key']['name']; } - if (isset($real['limit']) || isset($real['length']) || isset($column['limit']) || isset($column['length'])) { - if (isset($column['length'])) { - $length = $column['length']; - } elseif (isset($column['limit'])) { - $length = $column['limit']; - } elseif (isset($real['length'])) { - $length = $real['length']; - } else { - $length = $real['limit']; - } - $out .= '(' . $length . ')'; - } - if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') { - $out .= ' ' . $this->columns['primary_key']['name']; - } elseif (isset($column['key']) && $column['key'] == 'primary') { - $out .= ' NOT NULL'; - } elseif (isset($column['default']) && isset($column['null']) && $column['null'] == false) { - $out .= ' DEFAULT ' . $this->value($column['default'], $type) . ' NOT NULL'; - } elseif (isset($column['default'])) { - $out .= ' DEFAULT ' . $this->value($column['default'], $type); - } elseif (isset($column['null']) && $column['null'] == true) { - $out .= ' DEFAULT NULL'; - } elseif (isset($column['null']) && $column['null'] == false) { - $out .= ' NOT NULL'; - } - return $out; + return parent::buildColumn($column); } /** diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php index 75acb73e6..34648b420 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php @@ -222,6 +222,66 @@ class DboSqliteTest extends CakeTestCase { Configure::write('Cache.disable', true); } +/** + * test building columns with SQLite + * + * @return void + **/ + function testBuildColumn() { + $data = array( + 'name' => 'int_field', + 'type' => 'integer', + 'null' => false, + ); + $result = $this->db->buildColumn($data); + $expected = '"int_field" integer(11) NOT NULL'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'name', + 'type' => 'string', + 'length' => 20, + 'null' => false, + ); + $result = $this->db->buildColumn($data); + $expected = '"name" varchar(20) NOT NULL'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'testName', + 'type' => 'string', + 'length' => 20, + 'default' => null, + 'null' => true, + 'collate' => 'NOCASE' + ); + $result = $this->db->buildColumn($data); + $expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'testName', + 'type' => 'string', + 'length' => 20, + 'default' => 'test-value', + 'null' => false, + ); + $result = $this->db->buildColumn($data); + $expected = '"testName" varchar(20) DEFAULT \'test-value\' NOT NULL'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'testName', + 'type' => 'integer', + 'length' => 10, + 'default' => 10, + 'null' => false, + ); + $result = $this->db->buildColumn($data); + $expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL'; + $this->assertEqual($result, $expected); + } + /** * test describe() and normal results. * From f299283dc4915646339718e74ff6b3d84abdad3a Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 01:47:25 -0400 Subject: [PATCH 35/82] Refactoring duplicated code into a method. --- cake/libs/model/datasources/dbo_source.php | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 141364da8..d956c4a51 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2459,16 +2459,7 @@ class DboSource extends DataSource { if (($column['type'] == 'integer' || $column['type'] == 'float' ) && isset($column['default']) && $column['default'] === '') { $column['default'] = null; } - - foreach ($this->fieldParameters as $paramName => $value) { - if (isset($column[$paramName]) && $value['position'] == 'beforeDefault') { - $val = $column[$paramName]; - if ($value['quote']) { - $val = $this->value($val); - } - $out .= ' ' . $value['value'] . $value['join'] . $val; - } - } + $out = $this->_buildFieldParameters($out, $column, 'beforeDefault'); if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') { $out .= ' ' . $this->columns['primary_key']['name']; @@ -2483,18 +2474,29 @@ class DboSource extends DataSource { } elseif (isset($column['null']) && $column['null'] == false) { $out .= ' NOT NULL'; } + $out = $this->_buildFieldParameters($out, $column, 'afterDefault'); + return $out; + } +/** + * Build the field parameters, in a position + * + * @param string $columnString The partially built column string + * @param array $columnData The array of column data. + * @param string $position The position type to use. 'beforeDefault' or 'afterDefault' are common + * @return string a built column with the field parameters added. + **/ + function _buildFieldParameters($columnString, $columnData, $position) { foreach ($this->fieldParameters as $paramName => $value) { - if (isset($column[$paramName]) && $value['position'] == 'afterDefault') { - $val = $column[$paramName]; + if (isset($columnData[$paramName]) && $value['position'] == $position) { + $val = $columnData[$paramName]; if ($value['quote']) { $val = $this->value($val); } - $out .= ' ' . $value['value'] . $value['join'] . $val; + $columnString .= ' ' . $value['value'] . $value['join'] . $val; } } - - return $out; + return $columnString; } /** From a33457155f81899c9aef0ddf1d979f903cf614c5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 02:03:21 -0400 Subject: [PATCH 36/82] Adding valid option checking to fieldParameters. Test case added. --- cake/libs/model/datasources/dbo_source.php | 3 ++ .../model/datasources/dbo_source.test.php | 32 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index d956c4a51..5f2ac8de8 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2489,6 +2489,9 @@ class DboSource extends DataSource { function _buildFieldParameters($columnString, $columnData, $position) { foreach ($this->fieldParameters as $paramName => $value) { if (isset($columnData[$paramName]) && $value['position'] == $position) { + if (isset($value['options']) && !in_array($columnData[$paramName], $value['options'])) { + continue; + } $val = $columnData[$paramName]; if ($value['quote']) { $val = $this->value($val); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index fa98837ae..801bbb7bf 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -3612,7 +3612,37 @@ class DboSourceTest extends CakeTestCase { $this->testDb->columns = array('integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), ); $result = $this->testDb->buildColumn($data); $expected = '`int_field` int(11) NOT NULL'; - $this->assertTrue($result, $expected); + $this->assertEqual($result, $expected); + + $this->testDb->fieldParameters['param'] = array( + 'value' => 'COLLATE', + 'quote' => false, + 'join' => ' ', + 'column' => 'Collate', + 'position' => 'beforeDefault', + 'options' => array('GOOD', 'OK') + ); + $data = array( + 'name' => 'int_field', + 'type' => 'integer', + 'default' => '', + 'null' => false, + 'param' => 'BAD' + ); + $result = $this->testDb->buildColumn($data); + $expected = '`int_field` int(11) NOT NULL'; + $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'int_field', + 'type' => 'integer', + 'default' => '', + 'null' => false, + 'param' => 'GOOD' + ); + $result = $this->testDb->buildColumn($data); + $expected = '`int_field` int(11) COLLATE GOOD NOT NULL'; + $this->assertEqual($result, $expected); } /** From 23831546b5da31ff21bb1d0c121d0098db7511f2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 02:03:50 -0400 Subject: [PATCH 37/82] Adding valid options for sqlite collation. Tests added. --- cake/libs/model/datasources/dbo/dbo_sqlite.php | 11 ++++++++++- .../libs/model/datasources/dbo/dbo_sqlite.test.php | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index d106dac34..215542628 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -114,7 +114,16 @@ class DboSqlite extends DboSource { * @access public */ var $fieldParameters = array( - 'collate' => array('value' => 'COLLATE', 'quote' => false, 'join' => ' ', 'column' => 'Collate', 'position' => 'afterDefault'), + 'collate' => array( + 'value' => 'COLLATE', + 'quote' => false, + 'join' => ' ', + 'column' => 'Collate', + 'position' => 'afterDefault', + 'options' => array( + 'BINARY', 'NOCASE', 'RTRIM' + ) + ), ); /** diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php index 34648b420..51ede159b 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php @@ -280,6 +280,18 @@ class DboSqliteTest extends CakeTestCase { $result = $this->db->buildColumn($data); $expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL'; $this->assertEqual($result, $expected); + + $data = array( + 'name' => 'testName', + 'type' => 'integer', + 'length' => 10, + 'default' => 10, + 'null' => false, + 'collate' => 'BADVALUE' + ); + $result = $this->db->buildColumn($data); + $expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL'; + $this->assertEqual($result, $expected); } /** From aa03756238ec45b47cce5163bf7bb84bf131b623 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 09:26:23 -0400 Subject: [PATCH 38/82] Updating tests to expand coverage of buildcolumn. --- .../cases/libs/model/datasources/dbo_source.test.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 801bbb7bf..c35a8314a 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -3591,16 +3591,16 @@ class DboSourceTest extends CakeTestCase { ); $this->testDb->buildColumn($data); - $this->testDb->columns = array('varchar(255)' => 1); $data = array( 'name' => 'testName', - 'type' => 'varchar(255)', + 'type' => 'string', + 'length' => 255, 'default', 'null' => true, 'key' ); $result = $this->testDb->buildColumn($data); - $expected = '`testName` DEFAULT NULL'; + $expected = '`testName` varchar(255) DEFAULT NULL'; $this->assertEqual($result, $expected); $data = array( @@ -3653,11 +3653,11 @@ class DboSourceTest extends CakeTestCase { function testHasAny() { $this->testDb->hasAny($this->Model, array()); $expected = 'SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE 1 = 1'; - $this->assertEqual($this->testDb->simulated[1], $expected); + $this->assertEqual(end($this->testDb->simulated), $expected); $this->testDb->hasAny($this->Model, array('TestModel.name' => 'harry')); $expected = "SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE `TestModel`.`name` = 'harry'"; - $this->assertEqual($this->testDb->simulated[2], $expected); + $this->assertEqual(end($this->testDb->simulated), $expected); } /** From 8b26d9ceb296fe2defa423397e07621f55edb054 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 19:10:04 -0400 Subject: [PATCH 39/82] Applying optimization from 'Ceeram' reduces merges in FormHelper. Fixes #225 --- cake/libs/view/helpers/form.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 88e71791b..64bde2ebe 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -632,8 +632,6 @@ class FormHelper extends AppHelper { $this->_inputDefaults, $options ); - $defaults = array('before' => null, 'between' => null, 'after' => null); - $options = array_merge($defaults, $options); if (!isset($this->fieldset[$this->model()])) { //Try to load fieldset for this model From df8895a26693b1aa82c0f1d47e06d2ee9b765d60 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 29 Oct 2009 21:26:59 -0200 Subject: [PATCH 40/82] Adding a optinal parameter and question for merge action. Refs #147. --- cake/console/libs/tasks/extract.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index e5c67d67c..31f0b29c3 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -45,6 +45,14 @@ class ExtractTask extends Shell { */ var $__files = array(); +/** + * Merge all domains string into the default.pot file + * + * @var boolean + * @access public + */ + var $__merge = false; + /** * Current file being processed * @@ -137,6 +145,14 @@ class ExtractTask extends Shell { } } + if (isset($this->params['merge'])) { + $this->__merge = !(strtolower($this->params['merge']) === 'no'); + } else { + $this->out(); + $response = $this->in(sprintf(__('Would you like to merge all domains strings into the default.pot file?', true)), array('y', 'n'), 'n'); + $this->__merge = strtolower($response) === 'y'; + } + if (empty($this->__files)) { $this->__searchFiles(); } @@ -176,15 +192,18 @@ class ExtractTask extends Shell { $this->out(__('By default the .pot file(s) will be place in the locale directory of -app', true)); $this->out(__('By default -app is ROOT/app', true)); $this->hr(); - $this->out(__('Usage: cake i18n extract [command] [path...]', true)); + $this->out(__('Usage: cake i18n extract ...', true)); $this->out(); - $this->out(__('Commands:', true)); + $this->out(__('Params:', true)); $this->out(__(' -app [path...]: directory where your application is located', true)); $this->out(__(' -root [path...]: path to install', true)); $this->out(__(' -core [path...]: path to cake directory', true)); $this->out(__(' -paths [comma separated list of paths, full path is needed]', true)); + $this->out(__(' -merge [yes|no]: Merge all domains strings into the default.pot file', true)); $this->out(__(' -output [path...]: Full path to output directory', true)); $this->out(__(' -files: [comma separated list of files, full path to file is needed]', true)); + $this->out(); + $this->out(__('Commands:', true)); $this->out(__(' cake i18n extract help: Shows this help message.', true)); $this->out(); } @@ -322,7 +341,7 @@ class ExtractTask extends Shell { } $this->__store($domain, $header, $sentence); - if ($domain != 'default') { + if ($domain != 'default' && $this->__merge) { $this->__store('default', $header, $sentence); } } From a31a2d264c2cd128de2db839fa2901680c7de2ba Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 19:47:29 -0400 Subject: [PATCH 41/82] Fixing Debugger::log() . The method used protected properties only available in test cases. No stack trace was being logged when called either. Method has been updated to match its doc block better. Fixes #222 --- cake/libs/debugger.php | 12 ++---------- cake/tests/cases/libs/debugger.test.php | 1 + 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index 1e942e5f6..a49b39abb 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -139,16 +139,8 @@ class Debugger extends Object { */ function log($var, $level = LOG_DEBUG) { $_this = Debugger::getInstance(); - $trace = $_this->trace(array('start' => 1, 'depth' => 2, 'format' => 'array')); - $source = null; - - if (is_object($trace[0]['object']) && isset($trace[0]['object']->_reporter->_test_stack)) { - $stack = $trace[0]['object']->_reporter->_test_stack; - $source = sprintf('[%1$s, %3$s::%2$s()]' . "\n", - array_shift($stack), array_pop($stack), array_pop($stack)); - } - - CakeLog::write($level, $source . $_this->exportVar($var)); + $source = $_this->trace(array('start' => 1)) . "\n"; + CakeLog::write($level, "\n" . $source . $_this->exportVar($var)); } /** diff --git a/cake/tests/cases/libs/debugger.test.php b/cake/tests/cases/libs/debugger.test.php index 6f1f0162c..8f57cbbd0 100644 --- a/cake/tests/cases/libs/debugger.test.php +++ b/cake/tests/cases/libs/debugger.test.php @@ -226,6 +226,7 @@ class DebuggerTest extends CakeTestCase { Debugger::log(array('whatever', 'here')); $result = file_get_contents(TMP . 'logs' . DS . 'debug.log'); $this->assertPattern('/DebuggerTest\:\:testLog/', $result); + $this->assertPattern('/\[main\]/', $result); $this->assertPattern('/array/', $result); $this->assertPattern('/"whatever",/', $result); $this->assertPattern('/"here"/', $result); From 17edec84607ad1a347113278bddc3eed988c5e21 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 20:14:36 -0400 Subject: [PATCH 42/82] Changin how HttpSocket parses query string parameters. Makes HttpSocket querystring parameter parsing more congruent with how PHP handles query string parameters in that it doesn't require urlencoded characters. Tests added. Fixes #156 --- cake/libs/http_socket.php | 2 +- cake/tests/cases/libs/http_socket.test.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 76d12d710..793618ece 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -672,7 +672,7 @@ class HttpSocket extends CakeSocket { foreach ($items as $item) { if (strpos($item, '=') !== false) { - list($key, $value) = explode('=', $item); + list($key, $value) = explode('=', $item, 2); } else { $key = $item; $value = null; diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index b3fa948b1..2dbc193d9 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -878,6 +878,28 @@ class HttpSocketTest extends CakeTestCase { 'host' => 'www.google.com', 'port' => 8080, )); + + $uri = $this->Socket->parseUri('http://www.cakephp.org/?param1=value1¶m2=value2%3Dvalue3'); + $this->assertIdentical($uri, array( + 'scheme' => 'http', + 'host' => 'www.cakephp.org', + 'path' => '/', + 'query' => array( + 'param1' => 'value1', + 'param2' => 'value2=value3' + ) + )); + + $uri = $this->Socket->parseUri('http://www.cakephp.org/?param1=value1¶m2=value2=value3'); + $this->assertIdentical($uri, array( + 'scheme' => 'http', + 'host' => 'www.cakephp.org', + 'path' => '/', + 'query' => array( + 'param1' => 'value1', + 'param2' => 'value2=value3' + ) + )); } /** * Tests that HttpSocket::buildUri can turn all kinds of uri arrays (and strings) into fully or partially qualified URI's From 5f1e6ba6a0b671dd6b72824a612a90ec41141f7c Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 29 Oct 2009 20:31:29 -0400 Subject: [PATCH 43/82] Making DboSource::fetchAll return $this->_result if it is a boolean and $out is empty. Allows for Model::query() to return boolean values for operations that do not return recordsets. Fixes #6404 --- cake/libs/model/datasources/dbo_source.php | 4 +++- .../libs/model/datasources/dbo_source.test.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 5f2ac8de8..acb433063 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -383,8 +383,10 @@ class DboSource extends DataSource { $this->_queryCache[$sql] = $out; } } + if (empty($out) && is_bool($this->_result)) { + return $this->_result; + } return $out; - } else { return false; } diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index c35a8314a..9e5c08d1f 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -4047,6 +4047,23 @@ class DboSourceTest extends CakeTestCase { $this->assertNotNull($this->db->took, 'Stats were not set %s'); $this->assertNotNull($this->db->affected, 'Stats were not set %s'); } + +/** + * test that query() returns boolean values from operations like CREATE TABLE + * + * @return void + **/ + function testFetchAllBooleanReturns() { + $name = $this->db->fullTableName('test_query'); + $query = "CREATE TABLE {$name} (name varchar(10));"; + $result = $this->db->query($query); + $this->assertTrue($result, 'Query did not return a boolean. %s'); + + $query = "DROP TABLE {$name};"; + $result = $this->db->fetchAll($query); + $this->assertTrue($result, 'Query did not return a boolean. %s'); + } + /** * test ShowQuery generation of regular and error messages * From 2e3bbe363dde2bfab61f783d4adea78d839e618c Mon Sep 17 00:00:00 2001 From: Gordon Pettey Date: Fri, 30 Oct 2009 16:30:11 -0400 Subject: [PATCH 44/82] Array coding convention and extraneous punctuation Signed-off-by: Mark Story --- cake/console/libs/tasks/controller.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index 736522a84..efc363106 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -267,10 +267,10 @@ class ControllerTask extends Shell { $actions .= "\tfunction {$admin}view(\$id = null) {\n"; $actions .= "\t\tif (!\$id) {\n"; if ($wannaUseSession) { - $actions .= "\t\t\t\$this->Session->setFlash(__('Invalid {$singularHumanName}.', true));\n"; - $actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n"; + $actions .= "\t\t\t\$this->Session->setFlash(__('Invalid {$singularHumanName}', true));\n"; + $actions .= "\t\t\t\$this->redirect(array('action' => 'index'));\n"; } else { - $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n"; + $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action' => 'index'));\n"; } $actions .= "\t\t}\n"; $actions .= "\t\t\$this->set('" . $singularName . "', \$this->{$currentModelName}->read(null, \$id));\n"; @@ -285,9 +285,9 @@ class ControllerTask extends Shell { $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n"; if ($wannaUseSession) { $actions .= "\t\t\t\t\$this->Session->setFlash(__('The " . $singularHumanName . " has been saved', true));\n"; - $actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'));\n"; + $actions .= "\t\t\t\t\$this->redirect(array('action' => 'index'));\n"; } else { - $actions .= "\t\t\t\t\$this->flash(__('{$currentModelName} saved.', true), array('action'=>'index'));\n"; + $actions .= "\t\t\t\t\$this->flash(__('{$currentModelName} saved.', true), array('action' => 'index'));\n"; } $actions .= "\t\t\t} else {\n"; if ($wannaUseSession) { @@ -324,18 +324,18 @@ class ControllerTask extends Shell { $actions .= "\t\tif (!\$id && empty(\$this->data)) {\n"; if ($wannaUseSession) { $actions .= "\t\t\t\$this->Session->setFlash(__('Invalid {$singularHumanName}', true));\n"; - $actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n"; + $actions .= "\t\t\t\$this->redirect(array('action' => 'index'));\n"; } else { - $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n"; + $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action' => 'index'));\n"; } $actions .= "\t\t}\n"; $actions .= "\t\tif (!empty(\$this->data)) {\n"; $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n"; if ($wannaUseSession) { $actions .= "\t\t\t\t\$this->Session->setFlash(__('The " . $singularHumanName . " has been saved', true));\n"; - $actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'));\n"; + $actions .= "\t\t\t\t\$this->redirect(array('action' => 'index'));\n"; } else { - $actions .= "\t\t\t\t\$this->flash(__('The " . $singularHumanName . " has been saved.', true), array('action'=>'index'));\n"; + $actions .= "\t\t\t\t\$this->flash(__('The " . $singularHumanName . " has been saved.', true), array('action' => 'index'));\n"; } $actions .= "\t\t\t} else {\n"; if ($wannaUseSession) { @@ -373,17 +373,17 @@ class ControllerTask extends Shell { $actions .= "\t\tif (!\$id) {\n"; if ($wannaUseSession) { $actions .= "\t\t\t\$this->Session->setFlash(__('Invalid id for {$singularHumanName}', true));\n"; - $actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n"; + $actions .= "\t\t\t\$this->redirect(array('action' => 'index'));\n"; } else { - $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n"; + $actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action' => 'index'));\n"; } $actions .= "\t\t}\n"; $actions .= "\t\tif (\$this->{$currentModelName}->del(\$id)) {\n"; if ($wannaUseSession) { $actions .= "\t\t\t\$this->Session->setFlash(__('{$singularHumanName} deleted', true));\n"; - $actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n"; + $actions .= "\t\t\t\$this->redirect(array('action' => 'index'));\n"; } else { - $actions .= "\t\t\t\$this->flash(__('{$singularHumanName} deleted', true), array('action'=>'index'));\n"; + $actions .= "\t\t\t\$this->flash(__('{$singularHumanName} deleted', true), array('action' => 'index'));\n"; } $actions .= "\t\t}\n"; $actions .= "\t}\n"; From 84a10904fb158a2f5ebbdc8e04ab06ad117138c5 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Fri, 30 Oct 2009 18:42:04 -0200 Subject: [PATCH 45/82] Fixing typo on variable name. --- cake/libs/configure.php | 2 +- cake/libs/view/helpers/cache.php | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 30aeaf56b..05cb2875e 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -254,7 +254,7 @@ class Configure extends Object { * 'key1' => 'value of the Configure::One[key1]', * 'key2' => 'value of the Configure::One[key2]' * ); - * + * * Configure::write(array( * 'One.key1' => 'value of the Configure::One[key1]', * 'One.key2' => 'value of the Configure::One[key2]' diff --git a/cake/libs/view/helpers/cache.php b/cake/libs/view/helpers/cache.php index afbf0ce57..8f43ecf9e 100644 --- a/cake/libs/view/helpers/cache.php +++ b/cake/libs/view/helpers/cache.php @@ -74,15 +74,15 @@ class CacheHelper extends AppHelper { $cacheTime = 0; $useCallbacks = false; if (is_array($this->cacheAction)) { - $contoller = Inflector::underscore($this->controllerName); + $controller = Inflector::underscore($this->controllerName); $check = str_replace('/', '_', $this->here); $replace = str_replace('/', '_', $this->base); $match = str_replace($this->base, '', $this->here); $match = str_replace('//', '/', $match); - $match = str_replace('/' . $contoller . '/', '', $match); + $match = str_replace('/' . $controller . '/', '', $match); $match = str_replace('/' . $this->controllerName . '/', '', $match); $check = str_replace($replace, '', $check); - $check = str_replace('_' . $contoller . '_', '', $check); + $check = str_replace('_' . $controller . '_', '', $check); $check = str_replace('_' . $this->controllerName . '_', '', $check); $check = Inflector::slug($check); $check = preg_replace('/^_+/', '', $check); @@ -171,7 +171,6 @@ class CacheHelper extends AppHelper { $outputResult = array_values($outputResult); } - if (!empty($fileResult)) { $i = 0; foreach ($fileResult as $cacheBlock) { @@ -193,24 +192,23 @@ class CacheHelper extends AppHelper { function __parseOutput($cache) { $count = 0; if (!empty($this->__match)) { - foreach ($this->__match as $found) { $original = $cache; $length = strlen($found); $position = 0; - for ($i = 1; $i <= 1; $i++) { - $position = strpos($cache, $found, $position); + for ($i = 1; $i <= 1; $i++) { + $position = strpos($cache, $found, $position); - if ($position !== false) { - $cache = substr($original, 0, $position); - $cache .= $this->__replace[$count]; - $cache .= substr($original, $position + $length); - } else { - break; - } + if ($position !== false) { + $cache = substr($original, 0, $position); + $cache .= $this->__replace[$count]; + $cache .= substr($original, $position + $length); + } else { + break; } - $count++; + } + $count++; } return $cache; } @@ -291,5 +289,4 @@ class CacheHelper extends AppHelper { return cache('views' . DS . $cache, $file, $timestamp); } } - ?> \ No newline at end of file From bc26a6ab67bd5bab11646ddd025aa5dbdc5aea45 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 30 Oct 2009 22:03:23 -0400 Subject: [PATCH 46/82] Updating fixture task to change when CakeSchema is loaded to fix issues with errors being generated when baking new projects. Fixes #226 --- cake/console/libs/tasks/fixture.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index f91b6d3c4..dc55c8720 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -73,9 +73,6 @@ class FixtureTask extends Shell { function __construct(&$dispatch) { parent::__construct($dispatch); $this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS; - if (!class_exists('CakeSchema')) { - App::import('Model', 'CakeSchema', false); - } } /** @@ -85,6 +82,10 @@ class FixtureTask extends Shell { * @access public */ function execute() { + if (!class_exists('CakeSchema')) { + App::import('Model', 'CakeSchema', false); + } + if (empty($this->args)) { $this->__interactive(); } From e6c58e80306b1b00f5b0c1276f729f5532cdd08f Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 30 Oct 2009 22:08:06 -0400 Subject: [PATCH 47/82] Fixing wierd workflows in bake when project baking was aborted, it would ask if you wanted to create a database config file for the aborted app. --- cake/console/libs/bake.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cake/console/libs/bake.php b/cake/console/libs/bake.php index f99010c4c..7f1f0ad67 100644 --- a/cake/console/libs/bake.php +++ b/cake/console/libs/bake.php @@ -81,6 +81,8 @@ class BakeShell extends Shell { if (!is_dir($this->DbConfig->path)) { if ($this->Project->execute()) { $this->DbConfig->path = $this->params['working'] . DS . 'config' . DS; + } else { + return false; } } From 4752fc04da09ff121579a9abf65a9f88ee4236b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Fri, 30 Oct 2009 00:02:33 -0430 Subject: [PATCH 48/82] Adding test case to prove it is possible to escape error messages using form::input options parameter, closes #2920 as invalid Signed-off-by: Mark Story --- cake/tests/cases/libs/view/helpers/form.test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 5c5995631..062643f8a 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -5579,5 +5579,15 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->error('2.city'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div')); } + + function testInputErrorEscape() { + $this->Form->create('ValidateProfile'); + $this->Form->validationErrors['ValidateProfile']['city'] = 'required
'; + $result = $this->Form->input('city',array('error' => array('escape' => true))); + $this->assertPattern('/required<br>/', $result); + + $result = $this->Form->input('city',array('error' => array('escape' => false))); + $this->assertPattern('/required
/', $result); + } } ?> \ No newline at end of file From 55fc72c5337b709ea207377d833c0d22b4fa472c Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 30 Oct 2009 22:25:49 -0400 Subject: [PATCH 49/82] Moving test method and adding doc block. --- .../cases/libs/view/helpers/form.test.php | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 062643f8a..919db63b2 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2372,6 +2372,21 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test error options when using form->input(); + * + * @return void + */ + function testInputErrorEscape() { + $this->Form->create('ValidateProfile'); + $this->Form->validationErrors['ValidateProfile']['city'] = 'required
'; + $result = $this->Form->input('city',array('error' => array('escape' => true))); + $this->assertPattern('/required<br>/', $result); + + $result = $this->Form->input('city',array('error' => array('escape' => false))); + $this->assertPattern('/required
/', $result); + } + /** * testPassword method * @@ -5579,15 +5594,5 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->error('2.city'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div')); } - - function testInputErrorEscape() { - $this->Form->create('ValidateProfile'); - $this->Form->validationErrors['ValidateProfile']['city'] = 'required
'; - $result = $this->Form->input('city',array('error' => array('escape' => true))); - $this->assertPattern('/required<br>/', $result); - - $result = $this->Form->input('city',array('error' => array('escape' => false))); - $this->assertPattern('/required
/', $result); - } } ?> \ No newline at end of file From dfc1014fba452a178cfb31e9693cb2d8c28d78d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Fri, 30 Oct 2009 00:15:31 -0430 Subject: [PATCH 50/82] Making current action be the default for new forms. Updating test accordingly. closes #5353 Signed-off-by: Mark Story --- cake/libs/view/helpers/form.php | 2 +- cake/tests/cases/libs/view/helpers/form.test.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 64bde2ebe..73915d738 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -209,7 +209,7 @@ class FormHelper extends AppHelper { } } if (empty($options['action'])) { - $options['action'] = ($created) ? 'edit' : 'add'; + $options['action'] = $this->params['action']; } $actionDefaults = array( diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 919db63b2..9365d7082 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -666,6 +666,7 @@ class FormHelperTest extends CakeTestCase { $this->Form->Html =& new HtmlHelper(); $this->Controller =& new ContactTestController(); $this->View =& new View($this->Controller); + $this->Form->params['action'] = 'add'; ClassRegistry::addObject('view', $view); ClassRegistry::addObject('Contact', new Contact()); @@ -4669,6 +4670,7 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $this->Form->data['Contact']['id'] = 1; + $this->Form->params['action'] = 'edit'; $result = $this->Form->create('Contact'); $expected = array( 'form' => array( @@ -4702,6 +4704,7 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $this->Form->params['action'] = 'add'; $result = $this->Form->create('User', array('url' => array('action' => 'login'))); $expected = array( 'form' => array('id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login/'), @@ -4841,7 +4844,7 @@ class FormHelperTest extends CakeTestCase { 'last_name' => 'Abele', 'email' => 'nate@example.com' )); - $this->Form->params = array('models' => array('Person'), 'controller' => 'people'); + $this->Form->params = array('models' => array('Person'), 'controller' => 'people', 'action' => 'add'); $options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry'); $this->Form->create(); From 1c47b2182e06b2455be7bc55969044e24d3f1eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Fri, 30 Oct 2009 00:32:54 -0430 Subject: [PATCH 51/82] Adding form encoding default in form create options. Default is always taken from Configure::read('App.encoding'). closes #6042 --- cake/libs/view/helpers/form.php | 7 ++ .../cases/libs/view/helpers/form.test.php | 104 ++++++++++++++---- 2 files changed, 87 insertions(+), 24 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 73915d738..6c0065c0c 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -195,6 +195,7 @@ class FormHelper extends AppHelper { 'action' => null, 'url' => null, 'default' => true, + 'encoding' => strtolower(Configure::read('App.encoding')), 'inputDefaults' => array()), $options); $this->_inputDefaults = $options['inputDefaults']; @@ -256,6 +257,12 @@ class FormHelper extends AppHelper { $htmlAttributes['onsubmit'] = 'event.returnValue = false; return false;'; } } + + if (!empty($options['encoding'])) { + $htmlAttributes['accept-charset'] = $options['encoding']; + unset($options['encoding']); + } + unset($options['default']); $htmlAttributes = array_merge($options, $htmlAttributes); diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 9365d7082..4619084e0 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -723,10 +723,10 @@ class FormHelperTest extends CakeTestCase { */ function testFormCreateWithSecurity() { $this->Form->params['_Token'] = array('key' => 'testKey'); - + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array('url' => '/contacts/add')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/contacts/add'), + 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding), 'fieldset' => array('style' => 'display:none;'), array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')), array('input' => array( @@ -734,7 +734,7 @@ class FormHelperTest extends CakeTestCase { )), '/fieldset' ); - $this->assertTags($result, $expected); + $this->assertTags($result, $expected,true); $result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm')); $expected['form']['id'] = 'MyForm'; @@ -1078,8 +1078,9 @@ class FormHelperTest extends CakeTestCase { $this->Form->params['_Token']['key'] = 'testKey'; $result = $this->Form->create('Contact', array('url' => '/contacts/add')); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/contacts/add'), + 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding), 'fieldset' => array('style' => 'display:none;'), array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')), array('input' => array( @@ -1275,9 +1276,11 @@ class FormHelperTest extends CakeTestCase { $this->assertFalse($this->UserForm->OpenidUrl->validates()); $result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login')); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( 'form' => array( - 'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm' + 'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -1318,8 +1321,9 @@ class FormHelperTest extends CakeTestCase { $this->assertFalse($this->ValidateUser->ValidateProfile->validates()); $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add')); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id'), + 'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id','accept-charset' => $encoding), 'fieldset' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/fieldset' @@ -1361,8 +1365,9 @@ class FormHelperTest extends CakeTestCase { $this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates()); $result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add')); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id'), + 'form' => array('method' => 'post', 'action' => '/validate_users/add/', 'id','accept-charset' => $encoding), 'fieldset' => array('style' => 'display:none;'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/fieldset' @@ -4636,9 +4641,11 @@ class FormHelperTest extends CakeTestCase { */ function testFormCreate() { $result = $this->Form->create('Contact'); + $encoding = strtolower(Configure::read('App.encoding')); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -4648,20 +4655,23 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('Contact', array('type' => 'GET')); $expected = array('form' => array( - 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/', + 'accept-charset' => $encoding )); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('type' => 'get')); $expected = array('form' => array( - 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/', + 'accept-charset' => $encoding )); $this->assertTags($result, $expected); $result = $this->Form->create('Contact', array('type' => 'put')); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), @@ -4674,7 +4684,8 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('Contact'); $expected = array( 'form' => array( - 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1' + 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), @@ -4687,7 +4698,7 @@ class FormHelperTest extends CakeTestCase { $expected = array( 'form' => array( 'id' => 'ContactNonStandardPkEditForm', 'method' => 'post', - 'action' => '/contact_non_standard_pks/edit/1' + 'action' => '/contact_non_standard_pks/edit/1','accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), @@ -4697,7 +4708,10 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('Contact', array('id' => 'TestId')); $expected = array( - 'form' => array('id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1'), + 'form' => array( + 'id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1', + 'accept-charset' => $encoding + ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), '/fieldset' @@ -4707,7 +4721,10 @@ class FormHelperTest extends CakeTestCase { $this->Form->params['action'] = 'add'; $result = $this->Form->create('User', array('url' => array('action' => 'login'))); $expected = array( - 'form' => array('id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login/'), + 'form' => array( + 'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login/', + 'accept-charset' => $encoding + ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/fieldset' @@ -4717,7 +4734,8 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('User', array('action' => 'login')); $expected = array( 'form' => array( - 'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login/' + 'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -4727,7 +4745,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('User', array('url' => '/users/login')); $expected = array( - 'form' => array('method' => 'post', 'action' => '/users/login'), + 'form' => array('method' => 'post', 'action' => '/users/login','accept-charset' => $encoding), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), '/fieldset' @@ -4739,7 +4757,8 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->create('User', array('action' => 'signup')); $expected = array( 'form' => array( - 'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup/' + 'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -4778,6 +4797,7 @@ class FormHelperTest extends CakeTestCase { * */ function testFormCreateQuerystringParams() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array( 'type' => 'post', 'escape' => false, @@ -4791,7 +4811,8 @@ class FormHelperTest extends CakeTestCase { 'form' => array( 'id' => 'ContactAddForm', 'method' => 'post', - 'action' => '/controller/action/?param1=value1&param2=value2' + 'action' => '/controller/action/?param1=value1&param2=value2', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -4807,14 +4828,16 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testGetFormCreate() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array('type' => 'get')); $this->assertTags($result, array('form' => array( - 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ))); $result = $this->Form->text('Contact.name'); $this->assertTags($result, array('input' => array( - 'name' => 'name', 'type' => 'text', 'value' => '', 'id' => 'ContactName' + 'name' => 'name', 'type' => 'text', 'value' => '', 'id' => 'ContactName', ))); $result = $this->Form->password('password'); @@ -4875,10 +4898,12 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testFormMagicInput() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -5101,10 +5126,12 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testForMagicInputNonExistingNorValidated() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -5161,10 +5188,12 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testFormMagicInputLabel() { + $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact'); $expected = array( 'form' => array( - 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/' + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding ), 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), @@ -5597,5 +5626,32 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->error('2.city'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div')); } + + function testInputErrorEscape() { + $this->Form->create('ValidateProfile'); + $this->Form->validationErrors['ValidateProfile']['city'] = 'required
'; + $result = $this->Form->input('city',array('error' => array('escape' => true))); + $this->assertPattern('/required<br>/', $result); + + $result = $this->Form->input('city',array('error' => array('escape' => false))); + $this->assertPattern('/required
/', $result); + } + + function testFormEncoding() { + $result = $this->Form->create('UserForm', array( + 'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1' + ) + ); + $expected = array( + 'form' => array( + 'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm', + 'accept-charset' => 'iso-8859-1' + ), + 'fieldset' => array('style' => 'display:none;'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/fieldset' + ); + $this->assertTags($result, $expected); + } } ?> \ No newline at end of file From adea104edbb6a703e117f3ab4bb2d7ed636fbbf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Fri, 30 Oct 2009 01:04:41 -0430 Subject: [PATCH 52/82] Allowing output disabling of hidden fields in checkbox and radio input types. closes #6185 Signed-off-by: Mark Story --- cake/libs/view/helpers/form.php | 30 +++++++++------ .../cases/libs/view/helpers/form.test.php | 37 ++++++++++++++++++- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 6c0065c0c..b08bde13b 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -899,20 +899,24 @@ class FormHelper extends AppHelper { function checkbox($fieldName, $options = array()) { $options = $this->_initInputField($fieldName, $options); $value = current($this->value()); + $output = ""; if (!isset($options['value']) || empty($options['value'])) { $options['value'] = 1; } elseif (!empty($value) && $value === $options['value']) { $options['checked'] = 'checked'; } - $hiddenOptions = array( - 'id' => $options['id'] . '_', 'name' => $options['name'], - 'value' => '0', 'secure' => false - ); - if (isset($options['disabled']) && $options['disabled'] == true) { - $hiddenOptions['disabled'] = 'disabled'; + if (!isset($options['hiddenField']) || $options['hiddenField'] != false) { + $hiddenOptions = array( + 'id' => $options['id'] . '_', 'name' => $options['name'], + 'value' => '0', 'secure' => false + ); + if (isset($options['disabled']) && $options['disabled'] == true) { + $hiddenOptions['disabled'] = 'disabled'; + } + $output = $this->hidden($fieldName, $hiddenOptions); } - $output = $this->hidden($fieldName, $hiddenOptions); + unset($options['hiddenField']); return $this->output($output . sprintf( $this->Html->tags['checkbox'], @@ -972,6 +976,8 @@ class FormHelper extends AppHelper { if (isset($value) && $optValue == $value) { $optionsHere['checked'] = 'checked'; } + $hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true; + unset($attributes['hiddenField']); $parsedOptions = $this->_parseAttributes( array_merge($attributes, $optionsHere), array('name', 'type', 'id'), '', ' ' @@ -990,10 +996,12 @@ class FormHelper extends AppHelper { } $hidden = null; - if (!isset($value) || $value === '') { - $hidden = $this->hidden($fieldName, array( - 'id' => $attributes['id'] . '_', 'value' => '', 'name' => $attributes['name'] - )); + if ($hiddenField) { + if (!isset($value) || $value === '') { + $hidden = $this->hidden($fieldName, array( + 'id' => $attributes['id'] . '_', 'value' => '', 'name' => $attributes['name'] + )); + } } $out = $hidden . join($inbetween, $out); diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 4619084e0..02e1e8943 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -3296,7 +3296,7 @@ class FormHelperTest extends CakeTestCase { array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_', 'disabled' => 'disabled')), array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName', 'disabled' => 'disabled')) ); - $this->assertTags($result, $expected); + $this->assertTags($result, $expected,true); } /** @@ -5636,7 +5636,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->input('city',array('error' => array('escape' => false))); $this->assertPattern('/required
/', $result); } - + function testFormEncoding() { $result = $this->Form->create('UserForm', array( 'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1' @@ -5653,5 +5653,38 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); } + + function testDisableHiddenField() { + $result = $this->Form->input('UserForm.something', array( + 'type' => 'checkbox', 'hiddenField' => false + ) + ); + $expected = array( + 'div' => array('class' => 'input checkbox'), + array('input' => array( + 'type' => 'checkbox', 'name' => 'data[UserForm][something]', + 'value' => '1', 'id' => 'UserFormSomething' + )), + 'label' => array('for' => 'UserFormSomething'), + 'Something', + '/label', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->input('Model.1.field', array( + 'type' => 'radio','options' => 'option A', 'hiddenField' => false + ) + ); + $expected = array( + 'div' => array('class' => 'input radio'), + 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'), + 'label' => array('for' => 'Model1Field0'), + 'option A', + '/label', + '/div' + ); + $this->assertTags($result, $expected,true); + } } ?> \ No newline at end of file From 15da4a70074b40873a7f078586b78e3394770b0f Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 30 Oct 2009 23:23:33 -0400 Subject: [PATCH 53/82] Moving tests around to be closer in the file to similar tests. Reformatting tests. Adding/updating doc blocks for test methods. --- .../cases/libs/view/helpers/form.test.php | 160 ++++++++++-------- 1 file changed, 87 insertions(+), 73 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 02e1e8943..e434d57dd 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2699,6 +2699,38 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test disabling the hidden input for radio buttons + * + * @return void + **/ + function testRadioHiddenInputDisabling() { + $result = $this->Form->input('Model.1.field', array( + 'type' => 'radio', + 'options' => array('option A'), + 'hiddenField' => false + ) + ); + $expected = array( + 'div' => array('class' => 'input radio'), + 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'), + 'label' => array('for' => 'Model1Field0'), + 'option A', + '/label', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false)); + $expected = array( + 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'), + 'label' => array('for' => 'Model1Field0'), + 'option A', + '/label' + ); + $this->assertTags($result, $expected); + } + /** * testSelect method * @@ -3313,6 +3345,31 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Test that the hidden input for checkboxes can be removed/omitted from the output. + * + * @return void + */ + function testCheckboxHiddenFieldOmission() { + $result = $this->Form->input('UserForm.something', array( + 'type' => 'checkbox', + 'hiddenField' => false + ) + ); + $expected = array( + 'div' => array('class' => 'input checkbox'), + array('input' => array( + 'type' => 'checkbox', 'name' => 'data[UserForm][something]', + 'value' => '1', 'id' => 'UserFormSomething' + )), + 'label' => array('for' => 'UserFormSomething'), + 'Something', + '/label', + '/div' + ); + $this->assertTags($result, $expected); + } + /** * testDateTime method * @@ -4792,6 +4849,28 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test automatic accept-charset overriding + * + * @return void + **/ + function testCreateWithAcceptCharset() { + $result = $this->Form->create('UserForm', array( + 'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1' + ) + ); + $expected = array( + 'form' => array( + 'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm', + 'accept-charset' => 'iso-8859-1' + ), + 'fieldset' => array('style' => 'display:none;'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/fieldset' + ); + $this->assertTags($result, $expected); + } + /** * Test base form url when url param is passed with multiple parameters (&) * @@ -4822,7 +4901,7 @@ class FormHelperTest extends CakeTestCase { } /** - * testGetFormCreate method + * test creating a get form, and get form inputs. * * @access public * @return void @@ -4862,10 +4941,10 @@ class FormHelperTest extends CakeTestCase { */ function testEditFormWithData() { $this->Form->data = array('Person' => array( - 'id' => 1, - 'first_name' => 'Nate', - 'last_name' => 'Abele', - 'email' => 'nate@example.com' + 'id' => 1, + 'first_name' => 'Nate', + 'last_name' => 'Abele', + 'email' => 'nate@example.com' )); $this->Form->params = array('models' => array('Person'), 'controller' => 'people', 'action' => 'add'); $options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry'); @@ -4877,15 +4956,9 @@ class FormHelperTest extends CakeTestCase { 'select' => array( 'name' => 'data[People][People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople' ), - array('option' => array('value' => 1)), - 'Nate', - '/option', - array('option' => array('value' => 2)), - 'Garrett', - '/option', - array('option' => array('value' => 3)), - 'Larry', - '/option', + array('option' => array('value' => 1)), 'Nate', '/option', + array('option' => array('value' => 2)), 'Garrett', '/option', + array('option' => array('value' => 3)), 'Larry', '/option', '/select' ); $this->assertTags($result, $expected); @@ -5627,64 +5700,5 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div')); } - function testInputErrorEscape() { - $this->Form->create('ValidateProfile'); - $this->Form->validationErrors['ValidateProfile']['city'] = 'required
'; - $result = $this->Form->input('city',array('error' => array('escape' => true))); - $this->assertPattern('/required<br>/', $result); - - $result = $this->Form->input('city',array('error' => array('escape' => false))); - $this->assertPattern('/required
/', $result); - } - - function testFormEncoding() { - $result = $this->Form->create('UserForm', array( - 'type' => 'post', 'action' => 'login','encoding' => 'iso-8859-1' - ) - ); - $expected = array( - 'form' => array( - 'method' => 'post', 'action' => '/user_forms/login/', 'id' => 'UserFormLoginForm', - 'accept-charset' => 'iso-8859-1' - ), - 'fieldset' => array('style' => 'display:none;'), - 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), - '/fieldset' - ); - $this->assertTags($result, $expected); - } - - function testDisableHiddenField() { - $result = $this->Form->input('UserForm.something', array( - 'type' => 'checkbox', 'hiddenField' => false - ) - ); - $expected = array( - 'div' => array('class' => 'input checkbox'), - array('input' => array( - 'type' => 'checkbox', 'name' => 'data[UserForm][something]', - 'value' => '1', 'id' => 'UserFormSomething' - )), - 'label' => array('for' => 'UserFormSomething'), - 'Something', - '/label', - '/div' - ); - $this->assertTags($result, $expected); - - $result = $this->Form->input('Model.1.field', array( - 'type' => 'radio','options' => 'option A', 'hiddenField' => false - ) - ); - $expected = array( - 'div' => array('class' => 'input radio'), - 'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'), - 'label' => array('for' => 'Model1Field0'), - 'option A', - '/label', - '/div' - ); - $this->assertTags($result, $expected,true); - } } ?> \ No newline at end of file From ac302bb6c2da6f25820827fbb0fc3b7c9f5c21a9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 00:08:49 -0400 Subject: [PATCH 54/82] Minor refactoring. Adding tests for form->create() with file type forms. --- cake/libs/view/helpers/form.php | 7 ++-- .../cases/libs/view/helpers/form.test.php | 34 ++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index b08bde13b..38cc1914a 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -181,7 +181,6 @@ class FormHelper extends AppHelper { $data = $this->fieldset[$this->model()]; $recordExists = ( isset($this->data[$model]) && - isset($this->data[$model][$data['key']]) && !empty($this->data[$model][$data['key']]) ); @@ -190,6 +189,7 @@ class FormHelper extends AppHelper { $id = $this->data[$model][$data['key']]; } } + $options = array_merge(array( 'type' => ($created && empty($options['action'])) ? 'put' : 'post', 'action' => null, @@ -970,14 +970,15 @@ class FormHelper extends AppHelper { } $out = array(); + $hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true; + unset($attributes['hiddenField']); + foreach ($options as $optValue => $optTitle) { $optionsHere = array('value' => $optValue); if (isset($value) && $optValue == $value) { $optionsHere['checked'] = 'checked'; } - $hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true; - unset($attributes['hiddenField']); $parsedOptions = $this->_parseAttributes( array_merge($attributes, $optionsHere), array('name', 'type', 'id'), '', ' ' diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index e434d57dd..0ffa77f39 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -721,7 +721,7 @@ class FormHelperTest extends CakeTestCase { * @access public * @return void */ - function testFormCreateWithSecurity() { + function testCreateWithSecurity() { $this->Form->params['_Token'] = array('key' => 'testKey'); $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array('url' => '/contacts/add')); @@ -4691,12 +4691,12 @@ class FormHelperTest extends CakeTestCase { } /** - * testFormCreate method + * test the create() method * * @access public * @return void */ - function testFormCreate() { + function testCreate() { $result = $this->Form->create('Contact'); $encoding = strtolower(Configure::read('App.encoding')); $expected = array( @@ -4736,6 +4736,18 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $result = $this->Form->create('Contact', array('type' => 'file')); + $expected = array( + 'form' => array( + 'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add/', + 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data' + ), + 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/fieldset' + ); + $this->assertTags($result, $expected); + $this->Form->data['Contact']['id'] = 1; $this->Form->params['action'] = 'edit'; $result = $this->Form->create('Contact'); @@ -4750,6 +4762,20 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $this->Form->data['Contact']['id'] = 1; + $this->Form->params['action'] = 'edit'; + $result = $this->Form->create('Contact', array('type' => 'file')); + $expected = array( + 'form' => array( + 'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1', + 'accept-charset' => $encoding, 'enctype' => 'multipart/form-data' + ), + 'fieldset' => array('style' => 'preg:/display\s*\:\s*none;\s*/'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'), + '/fieldset' + ); + $this->assertTags($result, $expected); + $this->Form->data['ContactNonStandardPk']['pk'] = 1; $result = $this->Form->create('ContactNonStandardPk'); $expected = array( @@ -4875,7 +4901,7 @@ class FormHelperTest extends CakeTestCase { * Test base form url when url param is passed with multiple parameters (&) * */ - function testFormCreateQuerystringParams() { + function testCreateQuerystringParams() { $encoding = strtolower(Configure::read('App.encoding')); $result = $this->Form->create('Contact', array( 'type' => 'post', From 9ed7a5cd5538dd8f659d0bf22feb05ff1fd98b7c Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 00:58:21 -0400 Subject: [PATCH 55/82] Adding new options into doc blocks. Removing todo as its implemented already. --- cake/libs/view/helpers/form.php | 6 ++++-- cake/tests/cases/libs/view/helpers/form.test.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 38cc1914a..4137fd95b 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -889,11 +889,11 @@ class FormHelper extends AppHelper { * * - `value` - the value of the checkbox * - `checked` - boolean indicate that this checkbox is checked. + * - `hiddenField` - boolean to indicate if you want the results of radio() to include + * a hidden input with a value of ''. This is useful for creating radio sets that non-continuous * * @param string $fieldName Name of a field, like this "Modelname.fieldname" * @param array $options Array of HTML attributes. - * @todo Right now, automatically setting the 'checked' value is dependent on whether or not the - * checkbox is bound to a model. This should probably be re-evaluated in future versions. * @return string An HTML text input element */ function checkbox($fieldName, $options = array()) { @@ -934,6 +934,8 @@ class FormHelper extends AppHelper { * - `legend` - control whether or not the widget set has a fieldset & legend * - `value` - indicate a value that is should be checked * - `label` - boolean to indicate whether or not labels for widgets show be displayed + * - `hiddenField` - boolean to indicate if you want the results of radio() to include + * a hidden input with a value of ''. This is useful for creating radio sets that non-continuous * * @param string $fieldName Name of a field, like this "Modelname.fieldname" * @param array $options Radio button options array. diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 0ffa77f39..b98e08ca5 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -3279,7 +3279,7 @@ class FormHelperTest extends CakeTestCase { $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Contact']['published'] = 1; - $result = $this->Form->checkbox('Contact.published', array('id'=>'theID')); + $result = $this->Form->checkbox('Contact.published', array('id' => 'theID')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID', 'checked' => 'checked')) From 83caf5091860ef04c909b6f803698e0f7f7b5cb7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 01:04:33 -0400 Subject: [PATCH 56/82] Fixing doc blocks and minor refactoring. --- cake/libs/view/helpers/form.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 4137fd95b..936164aab 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -889,24 +889,24 @@ class FormHelper extends AppHelper { * * - `value` - the value of the checkbox * - `checked` - boolean indicate that this checkbox is checked. - * - `hiddenField` - boolean to indicate if you want the results of radio() to include - * a hidden input with a value of ''. This is useful for creating radio sets that non-continuous + * - `hiddenField` - boolean to indicate if you want the results of checkbox() to include + * a hidden input with a value of ''. * * @param string $fieldName Name of a field, like this "Modelname.fieldname" * @param array $options Array of HTML attributes. * @return string An HTML text input element */ function checkbox($fieldName, $options = array()) { - $options = $this->_initInputField($fieldName, $options); + $options = $this->_initInputField($fieldName, $options) + array('hiddenField' => true); $value = current($this->value()); $output = ""; - if (!isset($options['value']) || empty($options['value'])) { + if (empty($options['value'])) { $options['value'] = 1; } elseif (!empty($value) && $value === $options['value']) { $options['checked'] = 'checked'; } - if (!isset($options['hiddenField']) || $options['hiddenField'] != false) { + if ($options['hiddenField']) { $hiddenOptions = array( 'id' => $options['id'] . '_', 'name' => $options['name'], 'value' => '0', 'secure' => false From ade96b7ea5fcfcb46343eb143933279e08836f18 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 01:11:02 -0400 Subject: [PATCH 57/82] Updating doc blocks. --- cake/libs/view/helpers/form.php | 43 ++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 936164aab..f9fe29609 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -72,8 +72,30 @@ class FormHelper extends AppHelper { */ var $requestType = null; +/** + * The default model being used for the current form. + * + * @var string + */ var $defaultModel = null; + +/** + * Persistent default options used by input(). Set by FormHelper::create(). + * + * @var array + * @access protected + */ + var $_inputDefaults = array(); + +/** + * Introspects model information and extracts information related + * to validation, field length and field type. Appends information into + * $this->fieldset. + * + * @return Model Returns a model instance + * @access protected + */ function &_introspectModel($model) { $object = null; if (is_string($model) && strpos($model, '.') !== false) { @@ -122,27 +144,20 @@ class FormHelper extends AppHelper { return $object; } -/** - * Persistent default options used by input(). Set by FormHelper::create(). - * - * @var array - * @access protected - */ - var $_inputDefaults = array(); - /** * Returns an HTML FORM element. * * #### Options: * - * - 'type' Form method defaults to POST - * - 'action' The Action the form submits to. Can be a string or array, - * - 'url' The url the form submits to. Can be a string or a url array, - * - 'default' Allows for the creation of Ajax forms. - * - 'onsubmit' Used in conjunction with 'default' to create ajax forms. - * - 'inputDefaults' set the default $options for FormHelper::input(). Any options that would + * - `type` Form method defaults to POST + * - `action` The Action the form submits to. Can be a string or array, + * - `url` The url the form submits to. Can be a string or a url array, + * - `default` Allows for the creation of Ajax forms. + * - `onsubmit` Used in conjunction with 'default' to create ajax forms. + * - `inputDefaults' set the default $options for FormHelper::input(). Any options that would * be set when using FormHelper::input() can be set here. Options set with `inputDefaults` * can be overridden when calling input() + * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')` * * @access public * @param string $model The model object which the form is being defined for From 6726b76077f17d02eb018f31b9ef88fa65c8bde3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 01:45:17 -0400 Subject: [PATCH 58/82] Refactoring input() to reduce number of method calls. Applying patch from 'j3ffy' to allow user defined types to override magic select type. Test case added. Fixes #5109 --- cake/libs/view/helpers/form.php | 34 ++++++++++--------- .../cases/libs/view/helpers/form.test.php | 22 ++++++++++-- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index f9fe29609..43cdf9e03 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -646,7 +646,6 @@ class FormHelper extends AppHelper { * @return string Completed form widget */ function input($fieldName, $options = array()) { - $view =& ClassRegistry::getObject('view'); $this->setEntity($fieldName); $options = array_merge( @@ -654,23 +653,26 @@ class FormHelper extends AppHelper { $this->_inputDefaults, $options ); - - if (!isset($this->fieldset[$this->model()])) { - //Try to load fieldset for this model - $this->_introspectModel($this->model()); + + $modelKey = $this->model(); + $fieldKey = $this->field(); + if (!isset($this->fieldset[$modelKey])) { + $this->_introspectModel($modelKey); } - if (!isset($options['type'])) { + $userType = isset($options['type']) ? true : false; + + if (!$userType) { $options['type'] = 'text'; $fieldDef = array(); if (isset($options['options'])) { $options['type'] = 'select'; - } elseif (in_array($this->field(), array('psword', 'passwd', 'password'))) { + } elseif (in_array($fieldKey, array('psword', 'passwd', 'password'))) { $options['type'] = 'password'; - } elseif (isset($this->fieldset[$this->model()]['fields'][$this->field()])) { - $fieldDef = $this->fieldset[$this->model()]['fields'][$this->field()]; + } elseif (isset($this->fieldset[$modelKey]['fields'][$fieldKey])) { + $fieldDef = $this->fieldset[$modelKey]['fields'][$fieldKey]; $type = $fieldDef['type']; - $primaryKey = $this->fieldset[$this->model()]['key']; + $primaryKey = $this->fieldset[$modelKey]['key']; } if (isset($type)) { @@ -686,12 +688,12 @@ class FormHelper extends AppHelper { } elseif (isset($map[$type])) { $options['type'] = $map[$type]; } - if ($this->field() == $primaryKey) { + if ($fieldKey == $primaryKey) { $options['type'] = 'hidden'; } } - if ($this->model() === $this->field()) { + if ($modelKey === $fieldKey) { $options['type'] = 'select'; if (!isset($options['multiple'])) { $options['multiple'] = 'multiple'; @@ -700,10 +702,10 @@ class FormHelper extends AppHelper { } $types = array('text', 'checkbox', 'radio', 'select'); - if (!isset($options['options']) && in_array($options['type'], $types)) { + if (!isset($options['options']) && in_array($options['type'], $types) && !$userType) { $view =& ClassRegistry::getObject('view'); $varName = Inflector::variable( - Inflector::pluralize(preg_replace('/_id$/', '', $this->field())) + Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey)) ); $varOptions = $view->getVar($varName); if (is_array($varOptions)) { @@ -740,8 +742,8 @@ class FormHelper extends AppHelper { $divOptions = array_merge($divOptions, $div); } if ( - isset($this->fieldset[$this->model()]) && - in_array($this->field(), $this->fieldset[$this->model()]['validates']) + isset($this->fieldset[$modelKey]) && + in_array($fieldKey, $this->fieldset[$modelKey]['validates']) ) { $divOptions = $this->addClass($divOptions, 'required'); } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index b98e08ca5..086d40e88 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -1509,14 +1509,14 @@ class FormHelperTest extends CakeTestCase { } /** - * testFormInput method + * testInput method * * Test various incarnations of input(). * * @access public * @return void */ - function testFormInput() { + function testInput() { $result = $this->Form->input('ValidateUser.balance'); $expected = array( 'div' => array('class'), @@ -2014,6 +2014,24 @@ class FormHelperTest extends CakeTestCase { } } +/** + * test that overriding the magic select type widget is possible + * + * @return void + **/ + function testInputOverridingMagicSelectType() { + $view =& ClassRegistry::getObject('view'); + $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); + $result = $this->Form->input('Model.user_id', array('type' => 'text')); + $expected = array( + 'div' => array('class' => 'input text'), + 'label' => array('for' => 'ModelUserId'), 'User', '/label', + 'input' => array('name' => 'data[Model][user_id]', 'type' => 'text', 'id' => 'ModelUserId', 'value' => ''), + '/div' + ); + $this->assertTags($result, $expected); + } + /** * testFormInputs method * From bed9b6e58d33de1a2842d22c6fd95b58f77b3e83 Mon Sep 17 00:00:00 2001 From: predominant Date: Sat, 31 Oct 2009 18:30:59 +1100 Subject: [PATCH 59/82] Extending TextReporter from SimpleTest to provide memory usage and execution time information for text output test results. --- cake/tests/lib/cake_text_reporter.php | 60 ++++++++++++++++++++++++ cake/tests/lib/code_coverage_manager.php | 2 +- cake/tests/lib/test_manager.php | 3 +- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 cake/tests/lib/cake_text_reporter.php diff --git a/cake/tests/lib/cake_text_reporter.php b/cake/tests/lib/cake_text_reporter.php new file mode 100644 index 000000000..1d1424641 --- /dev/null +++ b/cake/tests/lib/cake_text_reporter.php @@ -0,0 +1,60 @@ +_timeStart)) { + $this->_timeStart = $this->_getTime(); + } + parent::paintGroupStart($test_name, $size); + } + +/** + * Signals/Paints the end of a TestSuite. All test cases have run + * and timers are stopped. + * + * @return void + **/ + function paintGroupEnd($test_name) { + $this->_timeEnd = $this->_getTime(); + $this->_timeDuration = $this->_timeEnd - $this->_timeStart; + parent::paintGroupEnd($test_name); + } + +/** + * Get the current time in microseconds. Similar to getMicrotime in basics.php + * but in a separate function to reduce dependancies. + * + * @return float Time in microseconds + **/ + function _getTime() { + list($usec, $sec) = explode(' ', microtime()); + return ((float)$sec + (float)$usec); + } + +/** + * Paints the end of the test with a summary of + * the passes and failures. + * + * @param string $test_name Name class of test. + * @access public + */ + function paintFooter($test_name) { + parent::paintFooter($test_name); + echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n"; + if (function_exists('memory_get_peak_usage')) { + echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n"; + } + } +} +?> \ No newline at end of file diff --git a/cake/tests/lib/code_coverage_manager.php b/cake/tests/lib/code_coverage_manager.php index 3ccee53f9..3bdbb28f4 100644 --- a/cake/tests/lib/code_coverage_manager.php +++ b/cake/tests/lib/code_coverage_manager.php @@ -790,4 +790,4 @@ class CodeCoverageManager { return false; } } -?> \ No newline at end of file +?> diff --git a/cake/tests/lib/test_manager.php b/cake/tests/lib/test_manager.php index 596c8da3a..1e4717bf2 100644 --- a/cake/tests/lib/test_manager.php +++ b/cake/tests/lib/test_manager.php @@ -637,7 +637,8 @@ if (function_exists('caketestsgetreporter')) { $Reporter =& new CakeHtmlReporter(); break; default: - $Reporter =& new TextReporter(); + require_once CAKE_TESTS_LIB . 'cake_text_reporter.php'; + $Reporter =& new CakeTextReporter(); break; } } From a91970b7b221628d7398f19286509222e33df666 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 13:41:16 -0400 Subject: [PATCH 60/82] Fixing security component test failures when run as part of a group. --- cake/tests/cases/libs/controller/components/security.test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/cake/tests/cases/libs/controller/components/security.test.php b/cake/tests/cases/libs/controller/components/security.test.php index f744f2dce..0aa80c393 100644 --- a/cake/tests/cases/libs/controller/components/security.test.php +++ b/cake/tests/cases/libs/controller/components/security.test.php @@ -202,6 +202,7 @@ class SecurityComponentTest extends CakeTestCase { * @return void */ function testRequireSecureFail() { + $_SERVER['HTTPS'] = 'off'; $_SERVER['REQUEST_METHOD'] = 'POST'; $this->Controller->action = 'posted'; $this->Controller->Security->requireSecure('posted'); From 59566d4587fe365c6ddb215c3b06575d5c92de2e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 14:08:56 -0400 Subject: [PATCH 61/82] Updating component test case to no fail in group test. Updating controller group to only run controller classes. --- .../cases/libs/controller/component.test.php | 18 +++++++++++++++--- cake/tests/groups/controller.group.php | 7 +++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cake/tests/cases/libs/controller/component.test.php b/cake/tests/cases/libs/controller/component.test.php index e3f78b28c..8ab7227c2 100644 --- a/cake/tests/cases/libs/controller/component.test.php +++ b/cake/tests/cases/libs/controller/component.test.php @@ -353,6 +353,7 @@ class ComponentTest extends CakeTestCase { function testNestedComponentLoading() { $Controller =& new ComponentTestController(); $Controller->components = array('Apple'); + $Controller->uses = false; $Controller->constructClasses(); $Controller->Component->initialize($Controller); @@ -372,6 +373,7 @@ class ComponentTest extends CakeTestCase { function testComponentStartup() { $Controller =& new ComponentTestController(); $Controller->components = array('Apple'); + $Controller->uses = false; $Controller->constructClasses(); $Controller->Component->initialize($Controller); $Controller->beforeFilter(); @@ -391,6 +393,7 @@ class ComponentTest extends CakeTestCase { */ function testMultipleComponentInitialize() { $Controller =& new ComponentTestController(); + $Controller->uses = false; $Controller->components = array('Orange', 'Banana'); $Controller->constructClasses(); $Controller->Component->initialize($Controller); @@ -411,7 +414,7 @@ class ComponentTest extends CakeTestCase { $Controller =& new ComponentTestController(); $Controller->components = array('ParamTest' => array('test' => 'value', 'flag'), 'Apple'); - + $Controller->uses = false; $Controller->constructClasses(); $Controller->Component->initialize($Controller); @@ -443,8 +446,12 @@ class ComponentTest extends CakeTestCase { * @return void **/ function testComponentParamsNoDuplication() { + if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) { + return; + } $Controller =& new ComponentTestController(); $Controller->components = array('Orange' => array('setting' => array('itemx'))); + $Controller->uses = false; $Controller->constructClasses(); $Controller->Component->initialize($Controller); @@ -459,6 +466,7 @@ class ComponentTest extends CakeTestCase { function testMutuallyReferencingComponents() { $Controller =& new ComponentTestController(); $Controller->components = array('MutuallyReferencingOne'); + $Controller->uses = false; $Controller->constructClasses(); $Controller->Component->initialize($Controller); @@ -483,6 +491,7 @@ class ComponentTest extends CakeTestCase { function testSomethingReferencingEmailComponent() { $Controller =& new ComponentTestController(); $Controller->components = array('SomethingWithEmail'); + $Controller->uses = false; $Controller->constructClasses(); $Controller->Component->initialize($Controller); $Controller->beforeFilter(); @@ -508,14 +517,17 @@ class ComponentTest extends CakeTestCase { * @access public */ function testDoubleLoadingOfSessionComponent() { - $this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController'); + if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) { + return; + } $Controller =& new ComponentTestController(); - $Controller->uses = array(); + $Controller->uses = false; $Controller->components = array('Session'); $Controller->constructClasses(); $this->assertEqual($Controller->components, array('Session' => '', 'Orange' => array('colour' => 'blood orange'))); } + } ?> \ No newline at end of file diff --git a/cake/tests/groups/controller.group.php b/cake/tests/groups/controller.group.php index a76073c2a..2a4dcbe80 100644 --- a/cake/tests/groups/controller.group.php +++ b/cake/tests/groups/controller.group.php @@ -37,7 +37,7 @@ class ControllerGroupTest extends GroupTest { * @var string 'All cake/libs/controller/* (Not yet implemented)' * @access public */ - var $label = 'All Controllers and Components'; + var $label = 'Component, Controllers, Scaffold test cases.'; /** * LibControllerGroupTest method * @@ -45,7 +45,10 @@ class ControllerGroupTest extends GroupTest { * @return void */ function ControllerGroupTest() { - TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'controller'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'scaffold'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'pages_controller'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'component'); } } ?> From 403bd15cca2b0acc549813961f7df1f23d4446cc Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 14:17:24 -0400 Subject: [PATCH 62/82] Removing Validation::file() It was never implemented, and file validation can be a lengthy and complicated process. This is better implemented at the application level. --- cake/libs/validation.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 59cf68c08..98e7d3c55 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -546,26 +546,6 @@ class Validation extends Object { return false; } -/** - * Check that value is a file name - * - * @param mixed $check Value to check - * @access public - * @todo finish implementation - */ - function file($check) { - // if (is_array($check)) { - // foreach ($check as $value) { - // if (!Validation::file($value)) { - // return false; - // } - // } - // return true; - // } - // - // return preg_match('/[\w| |_]+\.[\w]+/', $check); - } - /** * Validation of an IPv4 address. * From 0637272bd2532f7b37c62764562be871df94d3c0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 14:25:33 -0400 Subject: [PATCH 63/82] Updating doc block on Controller to include more information about $uses. --- cake/libs/controller/controller.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 6a582bfce..b1d3c4d72 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -73,6 +73,9 @@ class Controller extends Object { * * Example: var $uses = array('Product', 'Post', 'Comment'); * + * Can be set to array() to use no models. Can be set to false to + * use no models and prevent the merging of $uses with AppController + * * @var mixed A single name as a string or a list of names as an array. * @access protected * @link http://book.cakephp.org/view/53/components-helpers-and-uses From 24a75a27bf2eee0a6a50e2024452e89533c37b65 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 14:25:52 -0400 Subject: [PATCH 64/82] Updating Javacsript helper to use a real skipIf --- cake/tests/cases/libs/view/helpers/javascript.test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/javascript.test.php b/cake/tests/cases/libs/view/helpers/javascript.test.php index fceb01343..e44a0271a 100644 --- a/cake/tests/cases/libs/view/helpers/javascript.test.php +++ b/cake/tests/cases/libs/view/helpers/javascript.test.php @@ -218,8 +218,7 @@ class JavascriptTest extends CakeTestCase { * @return void */ function testFilteringAndTimestamping() { - if (!is_writable(JS)) { - echo "
JavaScript directory not writable, skipping JS asset timestamp tests
"; + if ($this->skipIf(!is_writable(JS), 'JavaScript directory not writable, skipping JS asset timestamp tests. %s')) { return; } From 76019513e1d7723116741ee9b2d10412490cc4b1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 14:33:53 -0400 Subject: [PATCH 65/82] Updating lib group to run non-mvc libs. Removing no_database group. It was redundant. --- cake/tests/groups/lib.group.php | 12 ++++- cake/tests/groups/no_database.group.php | 59 ------------------------- 2 files changed, 10 insertions(+), 61 deletions(-) delete mode 100644 cake/tests/groups/no_database.group.php diff --git a/cake/tests/groups/lib.group.php b/cake/tests/groups/lib.group.php index 07e6ab41b..999ba7da2 100644 --- a/cake/tests/groups/lib.group.php +++ b/cake/tests/groups/lib.group.php @@ -39,7 +39,7 @@ class LibGroupTest extends GroupTest { * @var string 'All cake/libs/* (Not yet implemented)' * @access public */ - var $label = 'All Libs'; + var $label = 'All core, non MVC element libs'; /** * LibGroupTest method * @@ -47,7 +47,15 @@ class LibGroupTest extends GroupTest { * @return void */ function LibGroupTest() { - TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'cake_log'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'overloadable'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'sanitize'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'security'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'set'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'string'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'validation'); } } ?> \ No newline at end of file diff --git a/cake/tests/groups/no_database.group.php b/cake/tests/groups/no_database.group.php deleted file mode 100644 index f23f6be7f..000000000 --- a/cake/tests/groups/no_database.group.php +++ /dev/null @@ -1,59 +0,0 @@ - - * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) - * - * Licensed under The Open Group Test Suite License - * Redistributions of files must retain the above copyright notice. - * - * @filesource - * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) - * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests - * @package cake - * @subpackage cake.tests.groups - * @since CakePHP(tm) v 1.2.0.4206 - * @version $Revision$ - * @modifiedby $LastChangedBy$ - * @lastmodified $Date$ - * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License - */ -/** - * NoDatabaseGroupTest class - * - * This test group will run all test in the cases/libs directory. - * - * @package cake - * @subpackage cake.tests.groups - */ -class NoDatabaseGroupTest extends GroupTest { -/** - * label property - * - * @var string 'All tests without a database connection' - * @access public - */ - var $label = 'All Libs not requiring a database connection'; -/** - * NoDatabaseGroupTest method - * - * @access public - * @return void - */ - function NoDatabaseGroupTest() { - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'dispatcher'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'router'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'validation'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'session'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'socket'); - TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs' . DS . 'view'); - } -} -?> \ No newline at end of file From 6b616b7171cce0eba4fbff88d9934378fe33e543 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 14:48:37 -0400 Subject: [PATCH 66/82] Adding skip for validation test, for DNS servers that reply for non-existant domains. --- cake/tests/cases/libs/validation.test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cake/tests/cases/libs/validation.test.php b/cake/tests/cases/libs/validation.test.php index 98c3e6866..4c7721cbc 100644 --- a/cake/tests/cases/libs/validation.test.php +++ b/cake/tests/cases/libs/validation.test.php @@ -1584,6 +1584,10 @@ class ValidationTest extends CakeTestCase { * @return void */ function testEmailDeep() { + $found = gethostbynamel('example.abcd'); + if ($this->skipIf($found, 'Your DNS service responds for non-existant domains, skipping deep email checks. %s')) { + return; + } $this->assertTrue(Validation::email('abc.efg@cakephp.org', true)); $this->assertFalse(Validation::email('abc.efg@caphpkeinvalid.com', true)); $this->assertFalse(Validation::email('abc@example.abcd', true)); From 51244907d1e9e754528e3e66a88ac7366024890b Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 14:55:04 -0400 Subject: [PATCH 67/82] Updating merge vars test to skip itself if run in a group context. Updating controller group. --- .../cases/libs/controller/controller_merge_vars.test.php | 9 ++++++++- cake/tests/groups/controller.group.php | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/controller/controller_merge_vars.test.php b/cake/tests/cases/libs/controller/controller_merge_vars.test.php index b405d3eca..4ca4db328 100644 --- a/cake/tests/cases/libs/controller/controller_merge_vars.test.php +++ b/cake/tests/cases/libs/controller/controller_merge_vars.test.php @@ -124,7 +124,14 @@ class MergePostsController extends MergeVarPluginAppController { * @package cake.tests.cases.libs.controller **/ class ControllerMergeVarsTestCase extends CakeTestCase { - +/** + * Skips the case if APP_CONTROLLER_EXISTS is defined + * + * @return void + **/ + function skip() { + $this->skipIf(defined('APP_CONTROLLER_EXISTS'), 'APP_CONTROLLER_EXISTS cannot run. %s'); + } /** * end test * diff --git a/cake/tests/groups/controller.group.php b/cake/tests/groups/controller.group.php index 2a4dcbe80..8bbc801ac 100644 --- a/cake/tests/groups/controller.group.php +++ b/cake/tests/groups/controller.group.php @@ -49,6 +49,7 @@ class ControllerGroupTest extends GroupTest { TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'scaffold'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'pages_controller'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'component'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'controller' . DS . 'controller_merge_vars'); } } ?> From 3a59bf5ed6dbdec469052eacae2944fe27be94fc Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 16:06:20 -0400 Subject: [PATCH 68/82] Updating Scaffold to work with any single prefix. You can set $scaffold = to any prefix defined in Routing.prefixes. Tests added. --- cake/libs/controller/scaffold.php | 37 ++++++---- .../cases/libs/controller/scaffold.test.php | 67 ++++++++++++++++--- 2 files changed, 80 insertions(+), 24 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 3490c7169..04102c4d9 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -434,10 +434,7 @@ class Scaffold extends Object { /** * When methods are now present in a controller * scaffoldView is used to call default Scaffold methods if: - * - * var $scaffold; - * - * is placed in the controller's class definition. + * `var $scaffold;` is placed in the controller's class definition. * * @param array $params Parameters for scaffolding * @return mixed A rendered view of scaffold action, or showing the error @@ -445,23 +442,30 @@ class Scaffold extends Object { */ function __scaffold($params) { $db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig); - $admin = Configure::read('Routing.admin'); - + $prefixes = Configure::read('Routing.prefixes'); + $scaffoldPrefix = $this->scaffoldActions; + if (isset($db)) { if (empty($this->scaffoldActions)) { $this->scaffoldActions = array( 'index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete' ); - } elseif (!empty($admin) && $this->scaffoldActions === $admin) { + } elseif (!empty($prefixes) && in_array($this->scaffoldActions, $prefixes)) { $this->scaffoldActions = array( - $admin .'_index', $admin .'_list', $admin .'_view', $admin .'_add', - $admin .'_create', $admin .'_edit', $admin .'_update', $admin .'_delete' + $scaffoldPrefix . '_index', + $scaffoldPrefix . '_list', + $scaffoldPrefix . '_view', + $scaffoldPrefix . '_add', + $scaffoldPrefix . '_create', + $scaffoldPrefix . '_edit', + $scaffoldPrefix . '_update', + $scaffoldPrefix . '_delete' ); } if (in_array($params['action'], $this->scaffoldActions)) { - if (!empty($admin)) { - $params['action'] = str_replace($admin . '_', '', $params['action']); + if (!empty($prefixes)) { + $params['action'] = str_replace($scaffoldPrefix . '_', '', $params['action']); } switch ($params['action']) { case 'index': @@ -556,10 +560,15 @@ class ScaffoldView extends ThemeView { $name = $this->action; } $name = Inflector::underscore($name); - $admin = Configure::read('Routing.admin'); + $prefixes = Configure::read('Routing.prefixes'); - if (!empty($admin) && strpos($name, $admin . '_') !== false) { - $name = substr($name, strlen($admin) + 1); + if (!empty($prefixes)) { + foreach ($prefixes as $prefix) { + if (strpos($name, $prefix . '_') !== false) { + $name = substr($name, strlen($prefix) + 1); + break; + } + } } if ($name === 'add') { diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 3d6f5f64b..c0a4a0fcd 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -315,8 +315,8 @@ class ScaffoldViewTest extends CakeTestCase { * @return void */ function testGetViewFilename() { - $_admin = Configure::read('Routing.admin'); - Configure::write('Routing.admin', 'admin'); + $_admin = Configure::read('Routing.prefixes'); + Configure::write('Routing.prefixes', array('admin')); $this->Controller->action = 'index'; $ScaffoldView =& new TestScaffoldView($this->Controller); @@ -385,7 +385,7 @@ class ScaffoldViewTest extends CakeTestCase { . DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp'; $this->assertEqual($result, $expected); - Configure::write('Routing.admin', $_admin); + Configure::write('Routing.prefixes', $_admin); } /** @@ -499,7 +499,7 @@ class ScaffoldViewTest extends CakeTestCase { new Scaffold($this->Controller, $params); $result = ob_get_clean(); - $this->assertPattern('/
/', $result); + $this->assertPattern('/assertPattern('/Edit Scaffold Mock<\/legend>/', $result); $this->assertPattern('/input type="hidden" name="data\[ScaffoldMock\]\[id\]" value="1" id="ScaffoldMockId"/', $result); @@ -509,6 +509,7 @@ class ScaffoldViewTest extends CakeTestCase { $this->assertPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result); $this->assertPattern('/
  • ]*>Delete<\/a>\s*<\/li>/', $result); } + /** * Test Admin Index Scaffolding. * @@ -516,9 +517,9 @@ class ScaffoldViewTest extends CakeTestCase { * @return void **/ function testAdminIndexScaffold() { - $_backAdmin = Configure::read('Routing.admin'); + $_backAdmin = Configure::read('Routing.prefixes'); - Configure::write('Routing.admin', 'admin'); + Configure::write('Routing.prefixes', array('admin')); $params = array( 'plugin' => null, 'pass' => array(), @@ -551,7 +552,7 @@ class ScaffoldViewTest extends CakeTestCase { //TODO: add testing for table generation $this->assertPattern('/
  • New Scaffold Mock<\/a><\/li>/', $result); - Configure::write('Routing.admin', $_backAdmin); + Configure::write('Routing.prefixes', $_backAdmin); } /** @@ -561,9 +562,9 @@ class ScaffoldViewTest extends CakeTestCase { * @return void **/ function testAdminEditScaffold() { - $_backAdmin = Configure::read('Routing.admin'); + $_backAdmin = Configure::read('Routing.prefixes'); - Configure::write('Routing.admin', 'admin'); + Configure::write('Routing.prefixes', array('admin')); $params = array( 'plugin' => null, 'pass' => array(), @@ -594,8 +595,54 @@ class ScaffoldViewTest extends CakeTestCase { $this->assertPattern('#admin/scaffold_mock/edit/1#', $result); $this->assertPattern('#Scaffold Mock#', $result); - Configure::write('Routing.admin', $_backAdmin); + Configure::write('Routing.prefixes', $_backAdmin); } + +/** + * Test Admin Index Scaffolding. + * + * @access public + * @return void + **/ + function testMultiplePrefixScaffold() { + $_backAdmin = Configure::read('Routing.prefixes'); + + Configure::write('Routing.prefixes', array('admin', 'member')); + $params = array( + 'plugin' => null, + 'pass' => array(), + 'form' => array(), + 'named' => array(), + 'prefix' => 'member', + 'url' => array('url' =>'member/scaffold_mock'), + 'controller' => 'scaffold_mock', + 'action' => 'member_index', + 'member' => 1, + ); + //reset, and set router. + Router::reload(); + Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/member/scaffold_mock', 'webroot' => '/'))); + $this->Controller->params = $params; + $this->Controller->controller = 'scaffold_mock'; + $this->Controller->base = '/'; + $this->Controller->action = 'member_index'; + $this->Controller->here = '/tests/member/scaffold_mock'; + $this->Controller->webroot = '/'; + $this->Controller->scaffold = 'member'; + $this->Controller->constructClasses(); + + ob_start(); + $Scaffold = new Scaffold($this->Controller, $params); + $result = ob_get_clean(); + + $this->assertPattern('/

    Scaffold Mock<\/h2>/', $result); + $this->assertPattern('//', $result); + //TODO: add testing for table generation + $this->assertPattern('/
  • New Scaffold Mock<\/a><\/li>/', $result); + + Configure::write('Routing.prefixes', $_backAdmin); + } + } /** From cab64b780c5a3480e884a2ea63469f7e6bcb1cfc Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 16:16:25 -0400 Subject: [PATCH 69/82] Refactoring switch in Scaffold. --- cake/libs/controller/scaffold.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 04102c4d9..54db20119 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -469,23 +469,17 @@ class Scaffold extends Object { } switch ($params['action']) { case 'index': + case 'list': $this->__scaffoldIndex($params); break; case 'view': $this->__scaffoldView($params); break; - case 'list': - $this->__scaffoldIndex($params); - break; case 'add': - $this->__scaffoldSave($params, 'add'); - break; - case 'edit': - $this->__scaffoldSave($params, 'edit'); - break; case 'create': $this->__scaffoldSave($params, 'add'); break; + case 'edit': case 'update': $this->__scaffoldSave($params, 'edit'); break; From a855a6aa418cee2d9d0e15b680ddc13beda4e8b4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 16:16:58 -0400 Subject: [PATCH 70/82] Renaming variable. --- cake/libs/controller/scaffold.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 54db20119..234ea3053 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -450,7 +450,7 @@ class Scaffold extends Object { $this->scaffoldActions = array( 'index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete' ); - } elseif (!empty($prefixes) && in_array($this->scaffoldActions, $prefixes)) { + } elseif (!empty($prefixes) && in_array($scaffoldPrefix, $prefixes)) { $this->scaffoldActions = array( $scaffoldPrefix . '_index', $scaffoldPrefix . '_list', From 2331cfde60d92bd23b325f15e28ac1a0136f6333 Mon Sep 17 00:00:00 2001 From: tPl0ch Date: Sat, 31 Oct 2009 20:50:49 +0100 Subject: [PATCH 71/82] Added 'before' and 'after' options to FormHelper::submit(). Test cases updated. Signed-off-by: Mark Story --- cake/libs/view/helpers/form.php | 23 ++++-- .../cases/libs/view/helpers/form.test.php | 70 +++++++++++++++++++ 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 43cdf9e03..c92c78ed1 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1206,13 +1206,24 @@ class FormHelper extends AppHelper { $divOptions = array_merge(array('class' => 'submit', 'tag' => 'div'), $div); } + $before = ""; + $after = ""; + if (isset($options['before'])) { + $before = $options['before']; + unset($options['before']); + } + if (isset($options['after'])) { + $after = $options['after']; + unset($options['after']); + } + if (strpos($caption, '://') !== false) { unset($options['type']); - $out .= $this->output(sprintf( + $out .= $this->output($before . sprintf( $this->Html->tags['submitimage'], $caption, $this->_parseAttributes($options, null, '', ' ') - )); + ) . $after); } elseif (preg_match('/\.(jpg|jpe|jpeg|gif|png|ico)$/', $caption)) { unset($options['type']); if ($caption{0} !== '/') { @@ -1221,17 +1232,17 @@ class FormHelper extends AppHelper { $caption = trim($caption, '/'); $url = $this->webroot($caption); } - $out .= $this->output(sprintf( + $out .= $this->output($before . sprintf( $this->Html->tags['submitimage'], $url, $this->_parseAttributes($options, null, '', ' ') - )); + ) . $after); } else { $options['value'] = $caption; - $out .= $this->output(sprintf( + $out .= $this->output($before . sprintf( $this->Html->tags['submit'], $this->_parseAttributes($options, null, '', ' ') - )); + ). $after); } if (isset($divOptions)) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 086d40e88..f626834f9 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -4667,6 +4667,36 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $before = '--before--'; + $after = '--after--'; + $result = $this->Form->submit('Test', array('before' => $before)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Test'), + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Test', array('after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + 'input' => array('type' => 'submit', 'value' => 'Test'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Test', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Test'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); } /** @@ -4706,6 +4736,46 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $after = '--after--'; + $before = '--before--'; + $result = $this->Form->submit('cake.power.gif', array('after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('cake.power.gif', array('before' => $before)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Not.an.image'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); } /** From 44d7742b85926840a30a828af55079738c021282 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 31 Oct 2009 16:28:43 -0400 Subject: [PATCH 72/82] Minor refactoring and removal of duplicate test. --- cake/libs/view/helpers/form.php | 15 ++++----------- cake/tests/cases/libs/view/helpers/form.test.php | 14 +++----------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index c92c78ed1..9bc47d633 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1193,7 +1193,7 @@ class FormHelper extends AppHelper { $div = $options['div']; unset($options['div']); } - $options += array('type' => 'submit'); + $options += array('type' => 'submit', 'before' => null, 'after' => null); $divOptions = array('tag' => 'div'); if ($div === true) { @@ -1206,16 +1206,9 @@ class FormHelper extends AppHelper { $divOptions = array_merge(array('class' => 'submit', 'tag' => 'div'), $div); } - $before = ""; - $after = ""; - if (isset($options['before'])) { - $before = $options['before']; - unset($options['before']); - } - if (isset($options['after'])) { - $after = $options['after']; - unset($options['after']); - } + $before = $options['before']; + $after = $options['after']; + unset($options['before'], $options['after']); if (strpos($caption, '://') !== false) { unset($options['type']); diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index f626834f9..9f022e980 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2724,7 +2724,7 @@ class FormHelperTest extends CakeTestCase { **/ function testRadioHiddenInputDisabling() { $result = $this->Form->input('Model.1.field', array( - 'type' => 'radio', + 'type' => 'radio', 'options' => array('option A'), 'hiddenField' => false ) @@ -3370,7 +3370,7 @@ class FormHelperTest extends CakeTestCase { */ function testCheckboxHiddenFieldOmission() { $result = $this->Form->input('UserForm.something', array( - 'type' => 'checkbox', + 'type' => 'checkbox', 'hiddenField' => false ) ); @@ -4652,14 +4652,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->submit('Next >', array('escape' => false)); - $expected = array( - 'div' => array('class' => 'submit'), - 'input' => array('type' => 'submit', 'value' => 'Next >'), - '/div' - ); - $this->assertTags($result, $expected); - $result = $this->Form->submit('Reset!', array('type' => 'reset')); $expected = array( 'div' => array('class' => 'submit'), @@ -4766,7 +4758,7 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); - + $result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after)); $expected = array( 'div' => array('class' => 'submit'), From 35fa099f6a4c735799bc46207c3181723aa22f95 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 1 Nov 2009 12:20:37 -0500 Subject: [PATCH 73/82] Updating ajax helper test to reflect changes in FormHelper parameter usage. --- cake/tests/cases/libs/view/helpers/ajax.test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/ajax.test.php b/cake/tests/cases/libs/view/helpers/ajax.test.php index 233d1fa00..12cf40c85 100644 --- a/cake/tests/cases/libs/view/helpers/ajax.test.php +++ b/cake/tests/cases/libs/view/helpers/ajax.test.php @@ -165,6 +165,12 @@ class AjaxHelperTest extends CakeTestCase { $view =& new View(new AjaxTestController()); ClassRegistry::addObject('view', $view); ClassRegistry::addObject('PostAjaxTest', new PostAjaxTest()); + + $this->Ajax->Form->params = array( + 'plugin' => null, + 'action' => 'view', + 'controller' => 'users' + ); } /** * tearDown method From ac97dfd70d1b2b1ac7462a7024915976b43d0c4d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 1 Nov 2009 12:25:40 -0500 Subject: [PATCH 74/82] Fixing api shell test case. --- cake/tests/cases/console/libs/api.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/console/libs/api.test.php b/cake/tests/cases/console/libs/api.test.php index 2ad67d2a0..dc977006f 100644 --- a/cake/tests/cases/console/libs/api.test.php +++ b/cake/tests/cases/console/libs/api.test.php @@ -95,7 +95,7 @@ class ApiShellTest extends CakeTestCase { '3. beforeRender()', '4. constructClasses()', '5. disableCache()', - '6. flash($message, $url, $pause = 1)', + '6. flash($message, $url, $pause = 1, $layout = \'flash\')', '7. header($status)', '8. isAuthorized()', '9. loadModel($modelClass = null, $id = null)', From d956378d48fe599ea9560917bc15623e9239fe22 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 1 Nov 2009 12:31:41 -0500 Subject: [PATCH 75/82] Improving console group test suite. Still getting intermittant fails from controller task. --- .../cases/console/libs/tasks/model.test.php | 12 ++++++------ cake/tests/groups/console.group.php | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index a8cccb151..431fb4130 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -21,7 +21,7 @@ * @since CakePHP v 1.2.6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ -App::import('Core', 'Shell'); +App::import('Shell', 'Shell', false); if (!defined('DISABLE_AUTO_DISPATCH')) { define('DISABLE_AUTO_DISPATCH', true); @@ -34,9 +34,9 @@ if (!class_exists('ShellDispatcher')) { ob_end_clean(); } -if (!class_exists('TestTask')) { - require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php'; -} +require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php'; +require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php'; +require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php'; Mock::generatePartial( 'ShellDispatcher', 'TestModelTaskMockShellDispatcher', @@ -216,9 +216,9 @@ class ModelTaskTest extends CakeTestCase { function testInteractiveFieldValidation() { $this->Task->initValidations(); $this->Task->interactive = true; - $this->Task->setReturnValueAt(0, 'in', '20'); + $this->Task->setReturnValueAt(0, 'in', '19'); $this->Task->setReturnValueAt(1, 'in', 'y'); - $this->Task->setReturnValueAt(2, 'in', '16'); + $this->Task->setReturnValueAt(2, 'in', '15'); $this->Task->setReturnValueAt(3, 'in', 'n'); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); diff --git a/cake/tests/groups/console.group.php b/cake/tests/groups/console.group.php index 491a7d5fd..3008303e2 100644 --- a/cake/tests/groups/console.group.php +++ b/cake/tests/groups/console.group.php @@ -46,7 +46,24 @@ class ConsoleGroupTest extends TestSuite { * @return void */ function ConsoleGroupTest() { - TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'console'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'cake'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'acl'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'api'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'bake'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'schema'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'shell'); + + $path = CORE_TEST_CASES . DS . 'console' . DS . 'libs' . DS . 'tasks' . DS; + + TestManager::addTestFile($this, $path . 'controller'); + TestManager::addTestFile($this, $path . 'model'); + TestManager::addTestFile($this, $path . 'view'); + TestManager::addTestFile($this, $path . 'fixture'); + TestManager::addTestFile($this, $path . 'test'); + TestManager::addTestFile($this, $path . 'db_config'); + TestManager::addTestFile($this, $path . 'plugin'); + TestManager::addTestFile($this, $path . 'project'); + } } ?> \ No newline at end of file From d77761e03b6a213905479d91890cfe4d9b39976d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 1 Nov 2009 12:31:57 -0500 Subject: [PATCH 76/82] Fixing merged test from 1.2 --- cake/tests/cases/libs/view/helpers/form.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 231fee6f7..ecc84393d 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2858,7 +2858,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->select( 'Model.contact_id', array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'), - null, array('escape' => false), 'pick something' + null, array('escape' => false, 'empty' => 'pick something') ); $expected = array( From f033516fccdac2750508e76731188afc463a431d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 1 Nov 2009 12:53:47 -0500 Subject: [PATCH 77/82] Moving inflector test around, fixes group test fails. --- cake/tests/groups/lib.group.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/groups/lib.group.php b/cake/tests/groups/lib.group.php index 1e2fc11b4..4ca7bb73d 100644 --- a/cake/tests/groups/lib.group.php +++ b/cake/tests/groups/lib.group.php @@ -46,9 +46,9 @@ class LibGroupTest extends TestSuite { * @return void */ function LibGroupTest() { + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'cake_log'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'inflector'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'overloadable'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'sanitize'); TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'security'); From b39df8ce2bd5d051758fb783a2dd684f8920c82a Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 1 Nov 2009 12:58:09 -0500 Subject: [PATCH 78/82] Removing reference to deprecated method. --- cake/tests/cases/libs/code_coverage_manager.test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/code_coverage_manager.test.php b/cake/tests/cases/libs/code_coverage_manager.test.php index 97c22a915..74722ab4d 100644 --- a/cake/tests/cases/libs/code_coverage_manager.test.php +++ b/cake/tests/cases/libs/code_coverage_manager.test.php @@ -89,7 +89,7 @@ class CodeCoverageManagerTest extends CakeTestCase { App::import('Core', 'Folder'); $folder = new Folder(); $folder->cd($path); - $contents = $folder->ls(); + $contents = $folder->read(); /** * remove method From df4cd12d0fb7c6c8bdf91408baf30f87b9ded13c Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 3 Nov 2009 17:19:02 -0500 Subject: [PATCH 79/82] Fixing RequestHandler test case when app/views/posts/index.ctp is available. --- .../libs/controller/components/request_handler.test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index cc702d48e..f8a971734 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -561,7 +561,9 @@ class RequestHandlerComponentTest extends CakeTestCase { function testAjaxRedirectAsRequestAction() { $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->_init(); - App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS))); + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + ), true); $this->Controller->RequestHandler = new NoStopRequestHandler($this); $this->Controller->RequestHandler->expectOnce('_stop'); @@ -574,6 +576,7 @@ class RequestHandlerComponentTest extends CakeTestCase { $this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.'); unset($_SERVER['HTTP_X_REQUESTED_WITH']); + App::build(); } } ?> \ No newline at end of file From 3b3ceddfdb39b07ade8744efd099de34d7b4e346 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 3 Nov 2009 17:39:59 -0500 Subject: [PATCH 80/82] Fixing Email test to account for whitespace changes done on view files. --- .../cases/libs/controller/components/email.test.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index d010c0f08..1560080a1 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -408,8 +408,6 @@ HEADBLOC; This is the body of the message This email was sent using the CakePHP Framework, http://cakephp.org. - - TEXTBLOC; $html = << - EmailTest + Email Test @@ -425,7 +423,6 @@ TEXTBLOC;

    This email was sent using the CakePHP Framework

    - HTMLBLOC; $this->Controller->EmailTest->sendAs = 'text'; @@ -452,7 +449,7 @@ HTMLBLOC; - EmailTest + Email Test @@ -477,8 +474,6 @@ standards. This is the body of the message This email was sent using the CakePHP Framework, http://cakephp.org. - - TEXTBLOC; $this->Controller->EmailTest->sendAs = 'text'; From 4632402a2538736855ae2929fefad9aa58104ada Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 3 Nov 2009 17:42:42 -0500 Subject: [PATCH 81/82] Fixing controller test to run when app/views/posts/index.ctp is present. --- cake/tests/cases/libs/controller/controller.test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index bd1041da9..4c200d1e9 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -772,7 +772,9 @@ class ControllerTest extends CakeTestCase { * @return void */ function testRender() { - App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS))); + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + ), true); $Controller =& new Controller(); $Controller->viewPath = 'posts'; @@ -797,6 +799,7 @@ class ControllerTest extends CakeTestCase { $Controller->ControllerComment->validationErrors = array(); ClassRegistry::flush(); + App::build(); } /** From d17c526dc345c4e6499bc61b56e06590206a9742 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 3 Nov 2009 18:21:01 -0500 Subject: [PATCH 82/82] Fixing String::insert() when $data is an empty array. Which was happening in the dbo source tests. --- cake/libs/string.php | 3 +++ cake/tests/cases/libs/string.test.php | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/cake/libs/string.php b/cake/libs/string.php index d7bbf2036..15bd9cb6f 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -229,6 +229,9 @@ class String { $options += $defaults; $format = $options['format']; $data = (array)$data; + if (empty($data)) { + return ($options['clean']) ? String::cleanInsert($str, $options) : $str; + } if (!isset($format)) { $format = sprintf( diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index 52ac2867c..e17a5b895 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -71,6 +71,11 @@ class StringTest extends CakeTestCase { * @return void */ function testInsert() { + $string = 'some string'; + $expected = 'some string'; + $result = String::insert($string, array()); + $this->assertEqual($result, $expected); + $string = '2 + 2 = :sum. Cake is :adjective.'; $expected = '2 + 2 = 4. Cake is yummy.'; $result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'));