2 require_once 'include/utils/db_utils.php';
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
9 class DbUtilsTest extends Sugar_PHPUnit_Framework_TestCase
11 private $_old_toHTML = null;
12 private $_random = null;
14 public function setUp()
16 $this->_random = rand(100, 200);
17 $GLOBALS['from_html_cache_clear'] = true;
18 $this->_old_toHTML = $GLOBALS['toHTML'];
19 $GLOBALS['toHTML'] = array(
21 $this->_random => 'random',
25 public function tearDown()
27 $GLOBALS['toHTML'] = $this->_old_toHTML;
30 public function testReturnsSameValueOnNoneStrings()
32 $random = rand(100, 200);
33 $this->assertEquals(from_html($random), $random);
36 public function testSwapsValuesForKeysFromToHTMLGlobal()
38 $GLOBALS['toHTML']['foobar'] = 'barfoo';
39 $this->assertEquals(from_html('barfoo'), 'foobar');
42 public function testSwapsValuesForKeysFromToHTMLGlobalWithRandomData()
44 $this->assertEquals(from_html('random'), $this->_random);
47 public function testWillReturnTheSameValueTwiceInARow()
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');
55 public function testWillReturnRawValueIfEncodeParameterIsFalse()
57 $GLOBALS['toHTML']['foobar'] = 'barfoo';
58 $this->assertEquals(from_html('barfoo', false), 'barfoo');