From cd209ce0996605bb8296d82648c3fe6132b38f39 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Tue, 19 Jun 2012 23:20:08 +0200 Subject: [PATCH] Avoid using LC_ALL, on some installs this would cause error: "setlocale(): Specified locale name is too long" --- .../Case/Model/Datasource/Database/PostgresTest.php | 8 ++++---- lib/Cake/Test/Case/Model/ModelWriteTest.php | 6 +++--- lib/Cake/Test/Case/Utility/CakeNumberTest.php | 6 +++--- lib/Cake/Test/Case/Utility/ValidationTest.php | 11 ++++++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 54b331f48..ec5568794 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -347,8 +347,8 @@ class PostgresTest extends CakeTestCase { * @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); @@ -356,7 +356,7 @@ class PostgresTest extends CakeTestCase { $result = $this->db->value(3.14); $this->assertEquals("3.140000", $result); - setlocale(LC_ALL, $restore); + setlocale(LC_NUMERIC, $restore); } /** @@ -784,7 +784,7 @@ class PostgresTest extends CakeTestCase { } /** - * 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 diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 1be1bbf77..009cdcb4a 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -6313,8 +6313,8 @@ class ModelWriteTest extends BaseModelTest { * @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( @@ -6322,7 +6322,7 @@ class ModelWriteTest extends BaseModelTest { 'float' => 3.14593 )); $this->assertTrue((bool)$result); - setlocale(LC_ALL, $restore); + setlocale(LC_NUMERIC, $restore); } /** diff --git a/lib/Cake/Test/Case/Utility/CakeNumberTest.php b/lib/Cake/Test/Case/Utility/CakeNumberTest.php index 326773297..f17c2319e 100644 --- a/lib/Cake/Test/Case/Utility/CakeNumberTest.php +++ b/lib/Cake/Test/Case/Utility/CakeNumberTest.php @@ -490,14 +490,14 @@ class CakeNumberTest extends CakeTestCase { * @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); } /** diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index eec307d84..af9e074e5 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -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'); + } } /** @@ -115,7 +118,9 @@ class ValidationTest extends CakeTestCase { 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); + } } /**