Advisor: mark that 'Rate of reading fixed position' may be wrong, requires further...
[phpmyadmin/thilanka.git] / test / libraries / common / PMA_cache_test.php
blob2284078c4a9c44dda40c41ff7cd6d563ede5b7f2
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for caching data in session
6 * @package phpMyAdmin-test
7 * @version $Id: PMA_cache_test.php
8 * @group common.lib-tests
9 */
12 * Include to test.
14 require_once 'libraries/common.lib.php';
16 class PMA_cache_test extends PHPUnit_Framework_TestCase
19 /**
20 * @var array temporary variable for globals array
22 protected $tmpGlobals;
24 /**
25 * @var array temporary variable for session array
27 protected $tmpSession;
29 /**
30 * storing globals and session
32 public function setUp()
34 $this->tmpGlobals = $GLOBALS;
35 $this->tmpSession = $_SESSION;
38 /**
39 * Test if cached data is available after set
41 public function testCacheExists()
43 $GLOBALS['server'] = 'server';
44 PMA_cacheSet('test_data', 5, true);
45 PMA_cacheSet('test_data_2', 5, true);
47 $this->assertTrue(PMA_cacheExists('test_data', true));
48 $this->assertTrue(PMA_cacheExists('test_data_2', 'server'));
49 $this->assertFalse(PMA_cacheExists('fake_data_2', true));
52 /**
53 * Test if cacheGet does not return data for non existing caache entries
55 public function testCacheGet()
57 $GLOBALS['server'] = 'server';
58 PMA_cacheSet('test_data', 5, true);
59 PMA_cacheSet('test_data_2', 5, true);
61 $this->assertNotNull(PMA_cacheGet('test_data', true));
62 $this->assertNotNull(PMA_cacheGet('test_data_2', 'server'));
63 $this->assertNull(PMA_cacheGet('fake_data_2', true));
66 /**
67 * Test retrieval of cached data
69 public function testCacheSetGet()
71 $GLOBALS['server'] = 'server';
72 PMA_cacheSet('test_data', 25, true);
74 PMA_cacheSet('test_data', 5, true);
75 $this->assertEquals(5, $_SESSION['cache']['server_server']['test_data']);
76 PMA_cacheSet('test_data_3', 3, true);
77 $this->assertEquals(3, $_SESSION['cache']['server_server']['test_data_3']);
80 /**
81 * Test clearing cached values
83 public function testCacheUnSet()
85 $GLOBALS['server'] = 'server';
86 PMA_cacheSet('test_data', 25, true);
87 PMA_cacheSet('test_data_2', 25, true);
89 PMA_cacheUnset('test_data', true);
90 $this->assertArrayNotHasKey('test_data', $_SESSION['cache']['server_server']);
91 PMA_cacheUnset('test_data_2', true);
92 $this->assertArrayNotHasKey('test_data_2', $_SESSION['cache']['server_server']);
95 /**
96 * Test clearing user cache
98 public function testClearUserCache()
100 $GLOBALS['server'] = 'server';
101 PMA_cacheSet('is_superuser', 'yes', true);
102 $this->assertEquals('yes', $_SESSION['cache']['server_server']['is_superuser']);
104 PMA_clearUserCache();
105 $this->assertArrayNotHasKey('is_superuser', $_SESSION['cache']['server_server']);