Fixes #3282, Problem with _Token.fields and few submit buttons

Fixed failing Dbo*Test

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5725 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-10-06 04:37:58 +00:00
parent c740e02896
commit fda664d737
5 changed files with 60 additions and 82 deletions

View file

@ -351,7 +351,7 @@ class DboSource extends DataSource {
}
$data = $this->startQuote . str_replace('.', $this->endQuote . '.' . $this->startQuote, $data) . $this->endQuote;
$data = str_replace($this->startQuote . $this->startQuote, $this->startQuote, $data);
if (!empty($this->endQuote) && $this->endQuote == $this->startQuote) {
$oddMatches = substr_count($data, $this->endQuote);
if ($oddMatches % 2 == 1) {
@ -1831,7 +1831,6 @@ class DboSource extends DataSource {
$null = null;
$this->rollback($null);
}
$this->close();
parent::__destruct();
}
/**

View file

@ -247,7 +247,7 @@ class FormHelper extends AppHelper {
if (isset($submit)) {
$out .= $this->submit($submit, $submitOptions);
} elseif (isset($this->params['_Token']) && !empty($this->params['_Token']) && !empty($this->fields)) {
} elseif (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
$out .= $this->secure($this->fields);
$this->fields = array();
}
@ -256,16 +256,20 @@ class FormHelper extends AppHelper {
return $this->output($out);
}
function secure($fields) {
$append = '<p style="display: inline; margin: 0px; padding: 0px;">';
foreach ($fields as $key => $value) {
if(strpos($key, '_') !== 0) {
sort($fields[$key]);
if (!empty($fields)) {
$append = '<p style="display: inline; margin: 0px; padding: 0px;">';
foreach ($fields as $key => $value) {
if(strpos($key, '_') !== 0) {
sort($fields[$key]);
}
}
ksort($fields);
$append .= $this->hidden('_Token.fields', array('value' => urlencode(Security::hash(serialize($fields) . CAKE_SESSION_STRING)), 'id' => 'TokenFields' . mt_rand()));
$append .= '</p>';
return $append;
}
ksort($fields);
$append .= $this->hidden('_Token.fields', array('value' => urlencode(Security::hash(serialize($fields) . CAKE_SESSION_STRING)), 'id' => 'TokenFields' . mt_rand()));
$append .= '</p>';
return $append;
return null;
}
function __secure($model = null, $options = null) {
if (!$model) {

View file

@ -109,20 +109,6 @@ class DboMssqlTest extends UnitTestCase {
* @access public
*/
var $Db = null;
/**
* Skip if cannot connect to mysql
*
* @return void
* @access public
*/
function skip() {
$skip = true;
if(function_exists('mssql_connect')) {
$skip = false;
}
//$this->skipif ($skip, 'Mssql not installed');
$this->skipif (false, 'Mssql not installed');
}
/**
* Sets up a Dbo class instance for testing
*
@ -130,7 +116,7 @@ class DboMssqlTest extends UnitTestCase {
* @access public
*/
function setUp() {
require_once r('//', '/', APP) . 'config/database.php';
require_once APP . 'config' . DS . 'database.php';
$config = new DATABASE_CONFIG();
$this->db =& new DboMssqlTestDb($config->default, false);
$this->db->fullDebug = false;
@ -143,6 +129,7 @@ class DboMssqlTest extends UnitTestCase {
* @return void
* @access public
*/
function testQuoting() {
$result = $this->db->fields($this->model);
$expected = array(
@ -175,16 +162,5 @@ class DboMssqlTest extends UnitTestCase {
$result = $this->db->value('1,2', 'float');
$this->assertIdentical($expected, $result);
}
/**
* Sets up a Dbo class instance for testing
*
* @return void
* @access public
*/
function tearDown() {
unset($this->model);
//unset($this->db);
}
}
?>

View file

@ -119,9 +119,8 @@ class DboMysqlTest extends UnitTestCase {
if(function_exists('mysql_connect')) {
$skip = false;
}
$this->skipif ($skip, 'Mysql not installed');
$this->skipif ($skip, 'MySql not installed');
}
/**
* Sets up a Dbo class instance for testing
*
@ -129,9 +128,9 @@ class DboMysqlTest extends UnitTestCase {
* @access public
*/
function setUp() {
require_once r('//', '/', APP) . 'config/database.php';
require_once APP . 'config' . DS . 'database.php';
$config = new DATABASE_CONFIG();
$this->Db =& new DboMysqlTestDb($config->default, false);
$this->Db =& new DboMysqlTestDb($config->default);
$this->Db->fullDebug = false;
$this->model = new MysqlTestModel();
}
@ -151,27 +150,27 @@ class DboMysqlTest extends UnitTestCase {
* @access public
*/
function testQuoting() {
$this->skipif ($this->Db->connected, 'Could not connect to database');
$result = $this->Db->fields($this->model);
$expected = array(
'MysqlTestModel`.`id` AS `MysqlTestModel__0`',
'`MysqlTestModel`.`client_id` AS `MysqlTestModel__1`',
'`MysqlTestModel`.`name` AS `MysqlTestModel__2`',
'`MysqlTestModel`.`login` AS `MysqlTestModel__3`',
'`MysqlTestModel`.`passwd` AS `MysqlTestModel__4`',
'`MysqlTestModel`.`addr_1` AS `MysqlTestModel__5`',
'`MysqlTestModel`.`addr_2` AS `MysqlTestModel__6`',
'`MysqlTestModel`.`zip_code` AS `MysqlTestModel__7`',
'`MysqlTestModel`.`city` AS `MysqlTestModel__8`',
'`MysqlTestModel`.`country` AS `MysqlTestModel__9`',
'`MysqlTestModel`.`phone` AS `MysqlTestModel__10`',
'`MysqlTestModel`.`fax` AS `MysqlTestModel__11`',
'`MysqlTestModel`.`url` AS `MysqlTestModel__12`',
'`MysqlTestModel`.`email` AS `MysqlTestModel__13`',
'`MysqlTestModel`.`comments` AS `MysqlTestModel__14`',
'`MysqlTestModel`.`last_login` AS `MysqlTestModel__15`',
'`MysqlTestModel`.`created` AS `MysqlTestModel__16`',
'`MysqlTestModel`.`updated` AS `MysqlTestModel__17`'
'`MysqlTestModel`.`id`',
'`MysqlTestModel`.`client_id`',
'`MysqlTestModel`.`name`',
'`MysqlTestModel`.`login`',
'`MysqlTestModel`.`passwd`',
'`MysqlTestModel`.`addr_1`',
'`MysqlTestModel`.`addr_2`',
'`MysqlTestModel`.`zip_code`',
'`MysqlTestModel`.`city`',
'`MysqlTestModel`.`country`',
'`MysqlTestModel`.`phone`',
'`MysqlTestModel`.`fax`',
'`MysqlTestModel`.`url`',
'`MysqlTestModel`.`email`',
'`MysqlTestModel`.`comments`',
'`MysqlTestModel`.`last_login`',
'`MysqlTestModel`.`created`',
'`MysqlTestModel`.`updated`'
);
$this->assertEqual($result, $expected);

View file

@ -109,7 +109,7 @@ class DboPostgresTest extends UnitTestCase {
*/
var $Db = null;
/**
* Skip if cannot connect to mysql
* Skip if cannot connect to postgres
*
* @return void
* @access public
@ -119,7 +119,7 @@ class DboPostgresTest extends UnitTestCase {
if(function_exists('pg_connect')) {
$skip = false;
}
$this->skipif (true, 'Postgres not installed');
$this->skipif ($skip, 'Postgres not installed');
}
/**
@ -129,7 +129,7 @@ class DboPostgresTest extends UnitTestCase {
* @access public
*/
function setUp() {
require_once r('//', '/', APP) . 'config/database.php';
require_once APP . 'config' . DS . 'database.php';
$config = new DATABASE_CONFIG();
$this->Db =& new DboPostgresTestDb($config->default, false);
$this->Db->fullDebug = false;
@ -154,28 +154,28 @@ class DboPostgresTest extends UnitTestCase {
$result = $this->Db->fields($this->model);
$expected = array(
'PostgresTestModel`.`id` AS `PostgresTestModel__0`',
'`PostgresTestModel`.`client_id` AS `PostgresTestModel__1`',
'`PostgresTestModel`.`name` AS `PostgresTestModel__2`',
'`PostgresTestModel`.`login` AS `PostgresTestModel__3`',
'`PostgresTestModel`.`passwd` AS `PostgresTestModel__4`',
'`PostgresTestModel`.`addr_1` AS `PostgresTestModel__5`',
'`PostgresTestModel`.`addr_2` AS `PostgresTestModel__6`',
'`PostgresTestModel`.`zip_code` AS `PostgresTestModel__7`',
'`PostgresTestModel`.`city` AS `PostgresTestModel__8`',
'`PostgresTestModel`.`country` AS `PostgresTestModel__9`',
'`PostgresTestModel`.`phone` AS `PostgresTestModel__10`',
'`PostgresTestModel`.`fax` AS `PostgresTestModel__11`',
'`PostgresTestModel`.`url` AS `PostgresTestModel__12`',
'`PostgresTestModel`.`email` AS `PostgresTestModel__13`',
'`PostgresTestModel`.`comments` AS `PostgresTestModel__14`',
'`PostgresTestModel`.`last_login` AS `PostgresTestModel__15`',
'`PostgresTestModel`.`created` AS `PostgresTestModel__16`',
'`PostgresTestModel`.`updated` AS `PostgresTestModel__17`'
'"PostgresTestModel"."id" AS "PostgresTestModel__id"',
'"PostgresTestModel"."client_id" AS "PostgresTestModel__client_id"',
'"PostgresTestModel"."name" AS "PostgresTestModel__name"',
'"PostgresTestModel"."login" AS "PostgresTestModel__login"',
'"PostgresTestModel"."passwd" AS "PostgresTestModel__passwd"',
'"PostgresTestModel"."addr_1" AS "PostgresTestModel__addr_1"',
'"PostgresTestModel"."addr_2" AS "PostgresTestModel__addr_2"',
'"PostgresTestModel"."zip_code" AS "PostgresTestModel__zip_code"',
'"PostgresTestModel"."city" AS "PostgresTestModel__city"',
'"PostgresTestModel"."country" AS "PostgresTestModel__country"',
'"PostgresTestModel"."phone" AS "PostgresTestModel__phone"',
'"PostgresTestModel"."fax" AS "PostgresTestModel__fax"',
'"PostgresTestModel"."url" AS "PostgresTestModel__url"',
'"PostgresTestModel"."email" AS "PostgresTestModel__email"',
'"PostgresTestModel"."comments" AS "PostgresTestModel__comments"',
'"PostgresTestModel"."last_login" AS "PostgresTestModel__last_login"',
'"PostgresTestModel"."created" AS "PostgresTestModel__created"',
'"PostgresTestModel"."updated" AS "PostgresTestModel__updated"'
);
$this->assertEqual($result, $expected);
$expected = 1.2;
$expected = "'1.2'";
$result = $this->Db->value(1.2, 'float');
$this->assertIdentical($expected, $result);