Untitled
By: a guest | Feb 20th, 2010 | Syntax:
PHP | Size: 4.36 KB | Hits: 78 | Expires: Never
<?php
/*
* Limb PHP Framework
*
* @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/cache2/src/lmbCacheFactory.class.php');
lmb_require('limb/cache2/src/lmbCacheHelper.class.php');
class lmbCacheFactoryTest extends UnitTestCase
{
function testVars()
{
'ttl' => 60,
'vars' => array('to_int'),
)
);
$helper = $this->_createHelper($conf);
$time1 = $helper->callCache('mtime', 'microtime', array(false), array('to_int' => false));
$time2 = $helper->callCache('mtime', 'microtime', array(false), array('to_int' => false));
$time3 = $helper->callCache('mtime', 'microtime', array(true), array('to_int' => true));
$time4 = $helper->callCache('mtime', 'microtime', array(true), array('to_int' => true));
$this->assertEqual($time1, $time2);
$this->assertEqual($time3, $time4);
$this->assertNotEqual($time1, $time3);
}
function testTags()
{
'ttl' => 60,
'tags' => array('reset', 'member'),
)
);
$helper = $this->_createHelper($conf, 'prefix');
$time1 = $helper->callCache('mtime', 'microtime');
$time2 = $helper->callCache('mtime', 'microtime');
$this->assertEqual($time1, $time2);
// string
$helper->deleteByTagsFor('reset');
$time1 = $helper->callCache('mtime', 'microtime');
$this->assertNotEqual($time1, $time2);
$time2 = $helper->callCache('mtime', 'microtime');
$this->assertEqual($time1, $time2);
// emulate lmbActiveRecoed
$helper->deleteByTagsFor(new lmbObject
(array('table_name' => 'member')));
$time1 = $helper->callCache('mtime', 'microtime');
$this->assertNotEqual($time1, $time2);
}
function testTagsIds()
{
'ttl' => 60,
'tags' => array('reset'),
'tag_ids' => array('member' => 'member_id'),
)
);
$helper = $this->_createHelper($conf, 'prefix');
$time1 = $helper->callCache('mtime', 'microtime', array(), array('member_id' => 100
));
$time2 = $helper->callCache('mtime', 'microtime', array(), array('member_id' => 100
));
$this->assertEqual($time1, $time2);
// refresh by id
$helper->deleteByTagsFor(new lmbObject
(array('table_name' => 'member', 'id' => 100
)));
$time1 = $helper->callCache('mtime', 'microtime', array(), array('member_id' => 100
));
$this->assertNotEqual($time1, $time2);
// refresh if change relation
$time2 = $helper->callCache('mtime', 'microtime', array(), array('member_id' => 100
));
$this->assertEqual($time1, $time2);
$time1 = $helper->callCache('mtime', 'microtime', array(), array('member_id' => 200
));
$this->assertNotEqual($time1, $time2);
}
function testRequireVars()
{
'ttl' => 60,
'vars' => array('to_int'),
),
'ttl' => 10,
'tag_ids' => array('member' => 'member_id'),
),
);
$helper = $this->_createHelper($conf);
try
{
$helper->callCache('mtime', 'microtime');
$this->assertTrue(false);
}
catch(lmbException $e)
{
$this->assertTrue(true);
}
try
{
$helper->callCache('m_time', 'microtime');
$this->assertTrue(false);
}
catch(lmbException $e)
{
$this->assertTrue(true);
}
try
{
$helper->callCache('m_time', 'microtime', array(), array('member_id' => 1
));
$this->assertTrue(true);
}
catch(lmbException $e)
{
$this->assertTrue(false);
}
}
function testBadCacheName()
{
$helper = $this->_createHelper
(array('mtime' => array('ttl' => 100
)));
try
{
$helper->callCache('m_time', 'microtime');
$this->assertTrue(false);
}
catch(lmbException $e)
{
$this->assertTrue(true);
}
}
protected function _createHelper($conf, $prefix = '')
{
$connection = lmbCacheFactory :: createConnection('file:///'.lmb_var_dir().'/cache2_helper');
$connection->flush();
return new lmbCacheHelper($connection, $conf, $prefix);
}
}