patch #2602633 [core] support column name having square brackets
[phpmyadmin/crack.git] / test / PMA_cache_test.php
blob3283168a56f88bbc908559bb0025a128c5ea3fd4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for caching data in session
6 * @author Michal Biniek <michal@bystrzyca.pl>
7 * @package phpMyAdmin-test
8 * @version $Id: PMA_cache_test.php
9 */
11 /**
12 * Tests core.
14 require_once 'PHPUnit/Framework.php';
16 /**
17 * Include to test.
19 require_once './libraries/common.lib.php';
21 /**
22 * Test cache.
25 class PMA_cache_test extends PHPUnit_Framework_TestCase
28 /**
29 * @var array temporary variable for globals array
31 protected $tmpGlobals;
33 /**
34 * @var array temporary variable for session array
36 protected $tmpSession;
38 /**
39 * storing globals and session
41 public function setUp()
43 $this->tmpGlobals = $GLOBALS;
44 $this->tmpSession = $_SESSION;
47 /**
48 * Test if cached data is available after set
50 public function testCacheExists()
52 $GLOBALS['server'] = 'server';
53 PMA_cacheSet('test_data', 5, true);
54 PMA_cacheSet('test_data_2', 5, true);
56 $this->assertTrue(PMA_cacheExists('test_data', true));
57 $this->assertTrue(PMA_cacheExists('test_data_2', 'server'));
58 $this->assertFalse(PMA_cacheExists('fake_data_2', true));
61 /**
62 * Test if cacheGet does not return data for non existing caache entries
64 public function testCacheGet()
66 $GLOBALS['server'] = 'server';
67 PMA_cacheSet('test_data', 5, true);
68 PMA_cacheSet('test_data_2', 5, true);
70 $this->assertNotNull(PMA_cacheGet('test_data', true));
71 $this->assertNotNull(PMA_cacheGet('test_data_2', 'server'));
72 $this->assertNull(PMA_cacheGet('fake_data_2', true));
75 /**
76 * Test retrieval of cached data
78 public function testCacheSetGet()
80 $GLOBALS['server'] = 'server';
81 PMA_cacheSet('test_data', 25, true);
83 PMA_cacheSet('test_data', 5, true);
84 $this->assertEquals(5, $_SESSION['cache']['server_server']['test_data']);
85 PMA_cacheSet('test_data_3', 3, true);
86 $this->assertEquals(3, $_SESSION['cache']['server_server']['test_data_3']);
89 /**
90 * Test clearing cached values
92 public function testCacheUnSet()
94 $GLOBALS['server'] = 'server';
95 PMA_cacheSet('test_data', 25, true);
96 PMA_cacheSet('test_data_2', 25, true);
98 PMA_cacheUnset('test_data', true);
99 $this->assertArrayNotHasKey('test_data', $_SESSION['cache']['server_server']);
100 PMA_cacheUnset('test_data_2', true);
101 $this->assertArrayNotHasKey('test_data_2', $_SESSION['cache']['server_server']);