Skip to content

Commit afc05c1

Browse files
committed
Adding test cases for using localized floats with mysql. Also added a generic model test case. Refs #1029
1 parent e23fe25 commit afc05c1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,24 @@ function testQuoting() {
277277
$this->assertEqual($expected, $result);
278278
}
279279

280+
/**
281+
* test that localized floats don't cause trouble.
282+
*
283+
* @return void
284+
*/
285+
function testLocalizedFloats() {
286+
$restore = setlocale(LC_ALL, null);
287+
setlocale(LC_ALL, 'de_DE');
288+
289+
$result = $this->db->value(3.141593, 'float');
290+
$this->assertEqual((string)$result, '3.141593');
291+
292+
$result = $this->db->value(3.141593);
293+
$this->assertEqual((string)$result, '3.141593');
294+
295+
setlocale(LC_ALL, $restore);
296+
}
297+
280298
/**
281299
* testTinyintCasting method
282300
*

cake/tests/cases/libs/model/model_write.test.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,4 +3880,22 @@ function testSaveAllEmptyData() {
38803880
$this->assertFalse($result);
38813881
}
38823882

3883+
/**
3884+
* test writing floats in german locale.
3885+
*
3886+
* @return void
3887+
*/
3888+
function testWriteFloatAsGerman() {
3889+
$restore = setlocale(LC_ALL, null);
3890+
setlocale(LC_ALL, 'de_DE');
3891+
3892+
$model = new DataTest();
3893+
$result = $model->save(array(
3894+
'count' => 1,
3895+
'float' => 3.14593
3896+
));
3897+
$this->assertTrue($result);
3898+
setlocale(LC_ALL, $restore);
3899+
}
3900+
38833901
}

0 commit comments

Comments
 (0)