Updated String::insert() so that when using ? as parameter it offsets the length of the parameter. Added tests to model, and string. Closes #5035

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7307 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-07-03 02:19:19 +00:00
parent c25ed9016a
commit 3da913f392
4 changed files with 15 additions and 4 deletions

View file

@ -233,8 +233,8 @@ class String extends Object {
if (array_keys($data) === array_keys(array_values($data))) { if (array_keys($data) === array_keys(array_values($data))) {
$offset = 0; $offset = 0;
while ($pos = strpos($str, '?', $offset)) { while ($pos = strpos($str, '?', $offset)) {
$offset = $pos;
$val = array_shift($data); $val = array_shift($data);
$offset = $pos + strlen($val);
$str = substr_replace($str, $val, $pos, 1); $str = substr_replace($str, $val, $pos, 1);
} }
} else { } else {

View file

@ -4902,6 +4902,14 @@ class ModelTest extends CakeTestCase {
isset($result[0][$this->db->fullTableName('articles', false)]['title']) || isset($result[0][$this->db->fullTableName('articles', false)]['title']) ||
isset($result[0][0]['title']) isset($result[0][0]['title'])
); );
//related to ticket #5035
$query = 'SELECT title FROM ' . $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?';
$params = array('First? Article', 'Y');
$Article->query($query, $params);
$expected = 'SELECT title FROM ' . $this->db->fullTableName('articles') . " WHERE title = 'First? Article' AND published = 'Y'";
$this->assertTrue(isset($this->db->_queryCache[$expected]));
} }
/** /**
* testParameterMismatch method * testParameterMismatch method

View file

@ -160,6 +160,11 @@ class StringTest extends UnitTestCase {
$result = String::insert("this is a ? string", "test"); $result = String::insert("this is a ? string", "test");
$expected = "this is a test string"; $expected = "this is a test string";
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
//related to ticket #5035
$result = String::insert("this is a ? string with a ? ? ?", array('long', 'few?', 'params', 'you know'));
$expected = "this is a long string with a few? params you know";
$this->assertEqual($result, $expected);
} }
/** /**
* testTokenize method * testTokenize method

View file

@ -1220,12 +1220,10 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/class="customClass"/', $result); $this->assertPattern('/class="customClass"/', $result);
$this->assertPattern('/onChange="function\(\)\{\}"/', $result); $this->assertPattern('/onChange="function\(\)\{\}"/', $result);
Configure::write('test', true);
$result = $this->Form->input('Contact.date', array('type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}')); $result = $this->Form->input('Contact.date', array('type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'));
$this->assertPattern('/id="customIdDay"/', $result); $this->assertPattern('/id="customIdDay"/', $result);
$this->assertPattern('/id="customIdMonth"/', $result); $this->assertPattern('/id="customIdMonth"/', $result);
$this->assertPattern('/onChange="function\(\)\{\}"/', $result); $this->assertPattern('/onChange="function\(\)\{\}"/', $result);
Configure::write('test', false);
$result = $this->Form->input('Model.field', array('type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID')); $result = $this->Form->input('Model.field', array('type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'));
$this->assertPattern('/id="customIDDay"/', $result); $this->assertPattern('/id="customIDDay"/', $result);