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

View file

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

View file

@ -109,20 +109,6 @@ class DboMssqlTest extends UnitTestCase {
* @access public * @access public
*/ */
var $Db = null; 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 * Sets up a Dbo class instance for testing
* *
@ -130,7 +116,7 @@ class DboMssqlTest extends UnitTestCase {
* @access public * @access public
*/ */
function setUp() { function setUp() {
require_once r('//', '/', APP) . 'config/database.php'; require_once APP . 'config' . DS . 'database.php';
$config = new DATABASE_CONFIG(); $config = new DATABASE_CONFIG();
$this->db =& new DboMssqlTestDb($config->default, false); $this->db =& new DboMssqlTestDb($config->default, false);
$this->db->fullDebug = false; $this->db->fullDebug = false;
@ -143,6 +129,7 @@ class DboMssqlTest extends UnitTestCase {
* @return void * @return void
* @access public * @access public
*/ */
function testQuoting() { function testQuoting() {
$result = $this->db->fields($this->model); $result = $this->db->fields($this->model);
$expected = array( $expected = array(
@ -175,16 +162,5 @@ class DboMssqlTest extends UnitTestCase {
$result = $this->db->value('1,2', 'float'); $result = $this->db->value('1,2', 'float');
$this->assertIdentical($expected, $result); $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')) { if(function_exists('mysql_connect')) {
$skip = false; $skip = false;
} }
$this->skipif ($skip, 'Mysql not installed'); $this->skipif ($skip, 'MySql not installed');
} }
/** /**
* Sets up a Dbo class instance for testing * Sets up a Dbo class instance for testing
* *
@ -129,9 +128,9 @@ class DboMysqlTest extends UnitTestCase {
* @access public * @access public
*/ */
function setUp() { function setUp() {
require_once r('//', '/', APP) . 'config/database.php'; require_once APP . 'config' . DS . 'database.php';
$config = new DATABASE_CONFIG(); $config = new DATABASE_CONFIG();
$this->Db =& new DboMysqlTestDb($config->default, false); $this->Db =& new DboMysqlTestDb($config->default);
$this->Db->fullDebug = false; $this->Db->fullDebug = false;
$this->model = new MysqlTestModel(); $this->model = new MysqlTestModel();
} }
@ -151,27 +150,27 @@ class DboMysqlTest extends UnitTestCase {
* @access public * @access public
*/ */
function testQuoting() { function testQuoting() {
$this->skipif ($this->Db->connected, 'Could not connect to database');
$result = $this->Db->fields($this->model); $result = $this->Db->fields($this->model);
$expected = array( $expected = array(
'MysqlTestModel`.`id` AS `MysqlTestModel__0`', '`MysqlTestModel`.`id`',
'`MysqlTestModel`.`client_id` AS `MysqlTestModel__1`', '`MysqlTestModel`.`client_id`',
'`MysqlTestModel`.`name` AS `MysqlTestModel__2`', '`MysqlTestModel`.`name`',
'`MysqlTestModel`.`login` AS `MysqlTestModel__3`', '`MysqlTestModel`.`login`',
'`MysqlTestModel`.`passwd` AS `MysqlTestModel__4`', '`MysqlTestModel`.`passwd`',
'`MysqlTestModel`.`addr_1` AS `MysqlTestModel__5`', '`MysqlTestModel`.`addr_1`',
'`MysqlTestModel`.`addr_2` AS `MysqlTestModel__6`', '`MysqlTestModel`.`addr_2`',
'`MysqlTestModel`.`zip_code` AS `MysqlTestModel__7`', '`MysqlTestModel`.`zip_code`',
'`MysqlTestModel`.`city` AS `MysqlTestModel__8`', '`MysqlTestModel`.`city`',
'`MysqlTestModel`.`country` AS `MysqlTestModel__9`', '`MysqlTestModel`.`country`',
'`MysqlTestModel`.`phone` AS `MysqlTestModel__10`', '`MysqlTestModel`.`phone`',
'`MysqlTestModel`.`fax` AS `MysqlTestModel__11`', '`MysqlTestModel`.`fax`',
'`MysqlTestModel`.`url` AS `MysqlTestModel__12`', '`MysqlTestModel`.`url`',
'`MysqlTestModel`.`email` AS `MysqlTestModel__13`', '`MysqlTestModel`.`email`',
'`MysqlTestModel`.`comments` AS `MysqlTestModel__14`', '`MysqlTestModel`.`comments`',
'`MysqlTestModel`.`last_login` AS `MysqlTestModel__15`', '`MysqlTestModel`.`last_login`',
'`MysqlTestModel`.`created` AS `MysqlTestModel__16`', '`MysqlTestModel`.`created`',
'`MysqlTestModel`.`updated` AS `MysqlTestModel__17`' '`MysqlTestModel`.`updated`'
); );
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);

View file

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