Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 92 lines (78 sloc) 2.541 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<?php
require_once(KERNEL_PKG_PATH.'BitPreferences.php');
#require_once(KERNEL_PKG_PATH.'test/TestBitPreferences.php');

class TestBitPreferencesCacheDatabase extends UnitTestCase {
    //class TestBitPreferencesCacheDatabase extends TestBitPreferences {

    var $name = "TestBitPreferencesCacheDatabase";
    var $test;
  
    function TestBitPreferencesCacheDatabase()
    {
    }
  
    function setUp ()
    {
global $gBitDb, $gBitCache;
$gBitCache = new BitCache();
if (!is_object($gBitDb) || !is_object($gBitCache)) {
$this = NULL;
return;
}
$name = "`".$this->name."`";
if (!$gBitDb->tableExists($name)) {
$tables = array(
$name => "
`name` C(50) PRIMARY,
`pref_value` C(255)
");
$gBitDb->createTables($tables);
}
$this->test = new BitPreferences($this->name);

// This test can not be performed in the constructor in simpleTest
$this->assertTrue($this->test != NULL, 'Error during initialisation');
    }


    function tearDown ()
    {
global $gBitDb;
$name = "`".$this->name."`";
$tables = array ($name);
$gBitDb->dropTables($tables);
$this->test = NULL;
    }


    // Tests duplicated from TestBitPreferences
    // Could not inherit them like in TestBitPreferencesCache for some reason.
    function testGetNonexistentItem()
    {
$this->assertNull($this->test->getPreference("test"));
    }
    
    function testSetNonexistentItem()
    {
        $this->test->setPreference("test", "123");
        $this->assertEqual($this->test->getPreference("test"), "123", "");
    }

    function testSetDefaultItem()
    {
        $this->test->setPreference("test", "123");
        $this->test->setDefaultPreference("test", "456");
        $this->assertEqual($this->test->getPreference("test"), "123");
    }

    function testSetAsDefaultItem()
    {
        $this->test->setPreference("test", "123");
        $this->test->setDefaultPreference("test", "456");
        $this->test->setPreference("test", "456");
        $this->assertEqual($this->test->getPreference("test"), "456");
    }

    function testReadDefaultItem()
    {
        $this->test->setPreference("test", "123");
        $this->test->setDefaultPreference("test", "456");
        $this->test->setPreference("test", NULL);
        $this->assertEqual($this->test->getPreference("test"), "456");
    }
    
    function testResetItem()
    {
        $this->test->setPreference("test", "123");
        $this->test->setPreference("test", NULL);
        $this->assertNull($this->test->getPreference("test"));
    }
}
?>
Something went wrong with that request. Please try again.