]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Currencies/CurrencyTest.php
Release 6.2.0RC1
[Github/sugarcrm.git] / tests / modules / Currencies / CurrencyTest.php
1 <?php
2 require_once('modules/Currencies/Currency.php');
3
4 class CurrencyTest extends Sugar_PHPUnit_Framework_TestCase {
5         
6         var $previousCurrentUser;
7         
8     public function setUp() 
9     {
10         global $current_user;
11         $this->previousCurrentUser = $current_user;       
12         $current_user = SugarTestUserUtilities::createAnonymousUser();
13         $current_user->setPreference('num_grp_sep', ',', 0, 'global');
14         $current_user->setPreference('dec_sep', '.', 0, 'global');
15         $current_user->save();
16         //Force reset on dec_sep and num_grp_sep because the dec_sep and num_grp_sep values are stored as static variables
17             get_number_seperators(true);  
18     }   
19
20     public function tearDown() 
21     {
22         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
23         global $current_user;
24         $current_user = $this->previousCurrentUser;
25     }    
26     
27     public function testUnformatNumber()
28     {
29         global $current_user;
30         $testValue = "$100,000.50";
31         
32         $unformattedValue = unformat_number($testValue);
33         $this->assertEquals($unformattedValue, 100000.50, "Assert that $100,000.50 becomes 100000.50");
34         
35         //Switch the num_grp_sep and dec_sep values
36         $current_user->setPreference('num_grp_sep', '.');
37         $current_user->setPreference('dec_sep', ',');
38         $current_user->save();
39
40         //Force reset on dec_sep and num_grp_sep because the dec_sep and num_grp_sep values are stored as static variables
41             get_number_seperators(true);       
42         
43         $testValue = "$100.000,50";
44         $unformattedValue = unformat_number($testValue);
45         $this->assertEquals($unformattedValue, 100000.50, "Assert that $100.000,50 becomes 100000.50");
46     }
47     
48     
49     public function testFormatNumber()
50     {
51         global $current_user;
52         $testValue = "100000.50";
53         
54         $formattedValue = format_number($testValue);
55         $this->assertEquals($formattedValue, "100,000.50", "Assert that 100000.50 becomes 100,000.50");
56         
57         //Switch the num_grp_sep and dec_sep values
58         $current_user->setPreference('num_grp_sep', '.');
59         $current_user->setPreference('dec_sep', ',');
60         $current_user->save();
61
62         //Force reset on dec_sep and num_grp_sep because the dec_sep and num_grp_sep values are stored as static variables
63             get_number_seperators(true);       
64         
65         $testValue = "100000.50";
66         $formattedValue = format_number($testValue);
67         $this->assertEquals($formattedValue, "100.000,50", "Assert that 100000.50 becomes 100.000,50");
68     }    
69     
70
71
72 ?>