<commit_before><?php

defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);
require_once(dirname(__FILE__).'/../../fixtures/config/config.php');


require_once(AK_LIB_DIR.DS.'AkCache.php');

//$db =& Ak::db();
//$db->debug = true;

class Test_of_AkCache_Class extends  UnitTestCase
{
    
    var $_driverInstance = NULL;
    var $Cache = NULL;
    var $id = 'test case cache id';
    var $group = 'test case group to cacth';
    var $text_to_catch = 'this is the text to catch on the test case of the AkCache class';
    
    function setUp()
    {
        $this->Cache =& new AkCache();
    }
    
    function tearDown()
    {
        unset($this->Cache);
    }
    
        
    function Testinit()
    {
        //No driver is loaded
        $this->Cache->init(null,0);
        $this->assertNull($this->Cache->_driverInstance,'Checking that no driver is loaded when cache is disabled');
        
        //Pear Cache Lite driver is loaded
        $this->Cache->init(null,1);
        $this->assertIsA($this->Cache->_driverInstance,'cache_lite');
        
        //AdodbCache database cache driver loaded
        $this->Cache->init(null,2);
        $this->assertIsA($this->Cache->_driverInstance,'akadodbcache');
    }
    
    function Test_get_and_save()
    {
        
        //No cache
        $this->Cache->init(null,0);
        $data = $this->Cache->get('id');
        $this->assertFalse($data,'Cache not enabled so this must return false');
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache must not work because cache is disabled');
        
        //Cache Lite cache
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'This id must not be in the cache (File based)');
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the  cache (File based)');
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Getting cached data (File based)');
        sleep(2);
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache has expired and we recognize it (File based)');
        
        
        
        // Database cache
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'This id must not be in the cache (Database based)');
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (Database based)');
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Getting cached data (Database based)');
        sleep(2);
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache has expired and we recognize it (Database based)');
        

    }
    
    function Testremove()
    {
        
        $this->Cache->init(1,0);
        $this->assertFalse(!$this->Cache->remove($this->id, $this->group),'Removing cached file (Cache disabled must return success)');
        
        //Cache Lite cache
        $this->Cache->init(1,1);
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (File based)');
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
        $this->assertFalse(!$this->Cache->remove($this->id, $this->group),'Removing cached file (File based)');
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache must have been removed at this point but stills here (File based)');
        
        
        //Database cache
        $this->Cache->init(1,2);
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (Database based)');
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (Database based)');
        $this->Cache->remove($this->id, $this->group);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache must have been removed at this point but stills here (Database based)');

    }
    
    function Testclean()
    {
                
        //AkCache::clean($group = 'false', $mode = 'ingroup');
        $this->Cache->init(1,1);
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache');
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
        
        $this->Cache->init(1,1);
        $this->assertFalse(!$this->Cache->clean($this->group),'Removing all the items in cache');
        
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache must have been removed at this point but stills here');
        
        
        
        //AkCache::clean($group = 'false', $mode = 'ingroup');
        $this->Cache->init(1,2);
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache');
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
        
        $this->Cache->init(1,2);
        $this->assertFalse(!$this->Cache->clean($this->group),'Removing all the items in cache');
        
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache must have been removed at this point but stills here');

    }

}

ak_test('Test_of_AkCache_Class', true);

?><commit_msg>Fixing AkCache unit tests so the can be ran using ./script/test unit/lib/AkCache.php<commit_after><?php

defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);
require_once(dirname(__FILE__).'/../../fixtures/config/config.php');


require_once(AK_LIB_DIR.DS.'AkCache.php');

//$db =& Ak::db();
//$db->debug = true;

class AkCaheTestCase extends AkUnitTest 
{
    
    var $_driverInstance = NULL;
    var $Cache = NULL;
    var $id = 'test case cache id';
    var $group = 'test case group to cacth';
    var $text_to_catch = 'this is the text to catch on the test case of the AkCache class';
    
    function setUp()
    {
        $this->Cache =& new AkCache();
    }
    
    function tearDown()
    {
        unset($this->Cache);
    }
    
    function test_setup()
    {
        require_once(AK_LIB_DIR.DS.'AkInstaller.php');
        require_once(AK_APP_DIR.DS.'installers'.DS.'framework_installer.php');
        $installer = new FrameworkInstaller();
        $installer->uninstall();
        $installer->install();
    }
        
    function Testinit()
    {
        //No driver is loaded
        $this->Cache->init(null,0);
        $this->assertNull($this->Cache->_driverInstance,'Checking that no driver is loaded when cache is disabled');
        
        //Pear Cache Lite driver is loaded
        $this->Cache->init(null,1);
        $this->assertIsA($this->Cache->_driverInstance,'cache_lite');
        
        //AdodbCache database cache driver loaded
        $this->Cache->init(null,2);
        $this->assertIsA($this->Cache->_driverInstance,'akadodbcache');
    }
    
    function Test_get_and_save()
    {
        
        //No cache
        $this->Cache->init(null,0);
        $data = $this->Cache->get('id');
        $this->assertFalse($data,'Cache not enabled so this must return false');
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache must not work because cache is disabled');
        
        //Cache Lite cache
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'This id must not be in the cache (File based)');
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the  cache (File based)');
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Getting cached data (File based)');
        sleep(2);
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache has expired and we recognize it (File based)');
        
        
        
        // Database cache
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'This id must not be in the cache (Database based)');
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (Database based)');
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Getting cached data (Database based)');
        sleep(2);
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache has expired and we recognize it (Database based)');
        

    }
    
    function Testremove()
    {
        
        $this->Cache->init(1,0);
        $this->assertFalse(!$this->Cache->remove($this->id, $this->group),'Removing cached file (Cache disabled must return success)');
        
        //Cache Lite cache
        $this->Cache->init(1,1);
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (File based)');
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
        $this->assertFalse(!$this->Cache->remove($this->id, $this->group),'Removing cached file (File based)');
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache must have been removed at this point but stills here (File based)');
        
        
        //Database cache
        $this->Cache->init(1,2);
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving the cache (Database based)');
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (Database based)');
        $this->Cache->remove($this->id, $this->group);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache must have been removed at this point but stills here (Database based)');

    }
    
    function Testclean()
    {
                
        //AkCache::clean($group = 'false', $mode = 'ingroup');
        $this->Cache->init(1,1);
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache');
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
        
        $this->Cache->init(1,1);
        $this->assertFalse(!$this->Cache->clean($this->group),'Removing all the items in cache');
        
        $this->Cache->init(1,1);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache must have been removed at this point but stills here');
        
        
        
        //AkCache::clean($group = 'false', $mode = 'ingroup');
        $this->Cache->init(1,2);
        $this->assertFalse(!$this->Cache->save($this->text_to_catch, $this->id, $this->group),'saving on the file cache');
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertEqual($data, $this->text_to_catch,'Checking that cached data has been inserted (File based)');
        
        $this->Cache->init(1,2);
        $this->assertFalse(!$this->Cache->clean($this->group),'Removing all the items in cache');
        
        $this->Cache->init(1,2);
        $data = $this->Cache->get($this->id, $this->group);
        $this->assertFalse($data,'The cache must have been removed at this point but stills here');

    }

}


?>
{'fraction_non_alphanumeric': 0.18497595236277578, 'fraction_numerical': 0.006718070081685625, 'mean_word_length': 2.760045924225029, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 409, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1521069', 'n_tokens_mistral': 4102, 'n_tokens_neox': 4050, 'n_words': 860}