Skip to content

Commit

Permalink
Avoid using LC_ALL, on some installs this would cause error:
Browse files Browse the repository at this point in the history
    "setlocale(): Specified locale name is too long"
  • Loading branch information
ceeram committed Jun 19, 2012
1 parent 8b94d9e commit cd209ce
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
Expand Up @@ -347,16 +347,16 @@ public function testValueQuoting() {
* @return void
*/
public function testLocalizedFloats() {
$restore = setlocale(LC_ALL, 0);
setlocale(LC_ALL, 'de_DE');
$restore = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'de_DE');

$result = $this->db->value(3.141593, 'float');
$this->assertEquals("3.141593", $result);

$result = $this->db->value(3.14);
$this->assertEquals("3.140000", $result);

setlocale(LC_ALL, $restore);
setlocale(LC_NUMERIC, $restore);
}

/**
Expand Down Expand Up @@ -784,7 +784,7 @@ public function testOrderAdditionalParams() {
}

/**
* Test it is possible to do a SELECT COUNT(DISTINCT Model.field)
* Test it is possible to do a SELECT COUNT(DISTINCT Model.field)
* query in postgres and it gets correctly quoted
*
* @return void
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Test/Case/Model/ModelWriteTest.php
Expand Up @@ -6313,16 +6313,16 @@ public function testUpdateAllWithoutForeignKey() {
* @return void
*/
public function testWriteFloatAsGerman() {
$restore = setlocale(LC_ALL, 0);
setlocale(LC_ALL, 'de_DE');
$restore = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'de_DE');

$model = new DataTest();
$result = $model->save(array(
'count' => 1,
'float' => 3.14593
));
$this->assertTrue((bool)$result);
setlocale(LC_ALL, $restore);
setlocale(LC_NUMERIC, $restore);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Test/Case/Utility/CakeNumberTest.php
Expand Up @@ -490,14 +490,14 @@ public function testToReadableSize() {
* @return void
*/
public function testReadableSizeLocalized() {
$restore = setlocale(LC_ALL, 0);
setlocale(LC_ALL, 'de_DE');
$restore = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'de_DE');
$result = $this->Number->toReadableSize(1321205);
$this->assertRegExp('/1[,.]26 MB/', $result);

$result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 512);
$this->assertRegExp('/512[,.]00 GB/', $result);
setlocale(LC_ALL, $restore);
setlocale(LC_NUMERIC, $restore);
}

/**
Expand Down
11 changes: 8 additions & 3 deletions lib/Cake/Test/Case/Utility/ValidationTest.php
Expand Up @@ -103,8 +103,11 @@ class ValidationTest extends CakeTestCase {
public function setUp() {
parent::setUp();
$this->_appEncoding = Configure::read('App.encoding');
$this->_appLocale = setlocale(LC_ALL, "0");
setlocale(LC_ALL, 'en_US');
$this->_appLocale = array();
foreach (array(LC_MONETARY, LC_NUMERIC, LC_TIME) as $category) {
$this->_appLocale[$category] = setlocale($category, 0);
setlocale($category, 'en_US');
}
}

/**
Expand All @@ -115,7 +118,9 @@ public function setUp() {
public function tearDown() {
parent::tearDown();
Configure::write('App.encoding', $this->_appEncoding);
setlocale(LC_ALL, $this->_appLocale);
foreach ($this->_appLocale as $category => $locale) {
setlocale($category, $locale);
}
}

/**
Expand Down

0 comments on commit cd209ce

Please sign in to comment.