/** * Tests that cached table descriptions are saved under the sanitized key name * * @return void */ public function testCacheKeyName() { Configure::write('Cache.disable', false); $dbName = 'db' . rand() . '$(*%&).db'; $this->assertFalse(file_exists(TMP . $dbName)); $db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName))); $this->assertTrue(file_exists(TMP . $dbName)); $db->execute("CREATE TABLE test_list (id VARCHAR(255));"); $db->cacheSources = true; $this->assertEquals(array('test_list'), $db->listSources()); $db->cacheSources = false; $fileName = '_' . preg_replace('/[^A-Za-z0-9_\\-+]/', '_', TMP . $dbName) . '_list'; $result = Cache::read($fileName, '_cake_model_'); $this->assertEquals(array('test_list'), $result); Cache::delete($fileName, '_cake_model_'); Configure::write('Cache.disable', true); }
/** * Tests that cached table descriptions are saved under the sanitized key name * * @return void */ public function testCacheKeyName() { Configure::write('Cache.disable', false); $dbName = 'db' . rand() . '$(*%&).db'; $this->assertFalse(file_exists(TMP . $dbName)); try { $db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName))); } catch (MissingConnectionException $e) { // This might be caused by NTFS file systems, where '*' is a forbidden character. Repeat without this character. $dbName = str_replace('*', '', $dbName); $db = new Sqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName))); } $this->assertTrue(file_exists(TMP . $dbName)); $db->execute("CREATE TABLE test_list (id VARCHAR(255));"); $db->cacheSources = true; $this->assertEquals(array('test_list'), $db->listSources()); $db->cacheSources = false; $fileName = '_' . preg_replace('/[^A-Za-z0-9_\\-+]/', '_', TMP . $dbName) . '_list'; $result = Cache::read($fileName, '_cake_model_'); $this->assertEquals(array('test_list'), $result); Cache::delete($fileName, '_cake_model_'); Configure::write('Cache.disable', true); }