]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/utils/DbUtilsTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / include / utils / DbUtilsTest.php
1 <?php
2 require_once 'include/utils/db_utils.php';
3
4 /**
5  * @todo refactor this test to not use test-level fixtures.  Will require
6  *       refactoring from_html() so it doesn't create static caches within
7  *       itself
8  */
9 class DbUtilsTest extends Sugar_PHPUnit_Framework_TestCase
10 {
11     private $_old_toHTML = null;
12     private $_random = null;
13     
14     public function setUp() 
15     {
16         $this->_random = rand(100, 200);
17         $GLOBALS['from_html_cache_clear'] = true;
18         $this->_old_toHTML = $GLOBALS['toHTML'];
19         $GLOBALS['toHTML'] = array(
20             'foobar' => 'barfoo',
21             $this->_random => 'random',
22         );
23     }
24
25     public function tearDown() 
26     {
27         $GLOBALS['toHTML'] = $this->_old_toHTML;
28     }
29
30     public function testReturnsSameValueOnNoneStrings() 
31     {
32         $random = rand(100, 200);
33         $this->assertEquals(from_html($random), $random);
34     }
35
36     public function testSwapsValuesForKeysFromToHTMLGlobal() 
37     {
38         $GLOBALS['toHTML']['foobar'] = 'barfoo';
39         $this->assertEquals(from_html('barfoo'), 'foobar');
40     }
41
42     public function testSwapsValuesForKeysFromToHTMLGlobalWithRandomData() 
43     {
44         $this->assertEquals(from_html('random'), $this->_random);
45     }
46
47     public function testWillReturnTheSameValueTwiceInARow() 
48     {
49         unset($GLOBALS['from_html_clear_cache']);
50         $GLOBALS['toHTML']['foobar'] = 'barfoo';
51         $this->assertEquals(from_html('barfoo'), 'foobar');
52         $this->assertEquals(from_html('barfoo'), 'foobar');
53     }
54
55     public function testWillReturnRawValueIfEncodeParameterIsFalse() 
56     {
57         $GLOBALS['toHTML']['foobar'] = 'barfoo';
58         $this->assertEquals(from_html('barfoo', false), 'barfoo');
59     }
60 }
61