Skip to content

Commit

Permalink
Fix Set::insert() not overwriting values.
Browse files Browse the repository at this point in the history
Set::insert() failed to overwrite values that were previously
defined as strings.  Remove test in SessionComponentTest that was
ensuring this bug stuck around.

Fixes #2722
  • Loading branch information
markstory committed Mar 27, 2012
1 parent 08f0811 commit b3d886f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
Expand Up @@ -191,7 +191,6 @@ public function testSessionReadWrite() {

$this->assertTrue($Session->write('Test', 'some value'));
$this->assertEquals('some value', $Session->read('Test'));
$this->assertFalse($Session->write('Test.key', 'some value'));
$Session->delete('Test');

$this->assertTrue($Session->write('Test.key.path', 'some value'));
Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php
Expand Up @@ -281,6 +281,22 @@ public function testWriteEmptyKey() {
$this->assertFalse(TestCakeSession::write(''));
}

/**
* Test overwriting a string value as if it were an array.
*
* @return void
*/
public function testWriteOverwriteStringValue() {
TestCakeSession::write('Some.string', 'value');
$this->assertEquals('value', TestCakeSession::read('Some.string'));

TestCakeSession::write('Some.string.array', array('values'));
$this->assertEquals(
array('values'),
TestCakeSession::read('Some.string.array')
);
}

/**
* testId method
*
Expand Down
22 changes: 22 additions & 0 deletions lib/Cake/Test/Case/Utility/SetTest.php
Expand Up @@ -1700,6 +1700,28 @@ public function testInsert() {
$this->assertEquals($expected, $result);
}

/**
* Test that insert() can insert data over a string value.
*
* @return void
*/
public function testInsertOverwriteStringValue() {
$data = array(
'Some' => array(
'string' => 'value'
)
);
$result = Set::insert($data, 'Some.string.value', array('values'));
$expected = array(
'Some' => array(
'string' => array(
'value' => array( 'values')
)
)
);
$this->assertEquals($expected, $result);
}

/**
* testRemove method
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Set.php
Expand Up @@ -686,7 +686,7 @@ public static function insert($list, $path, $data = null) {
$_list =& $_list[$key];
}
if (!is_array($_list)) {
return array();
$_list = array();
}
}
return $list;
Expand Down

0 comments on commit b3d886f

Please sign in to comment.