<?php
class
Pluf_Tests_Cache_File
extends
UnitTestCase {
private
$_config
;
private
$_arrayData
=
array
(
'hello'
=>
'world'
,
'foo'
=> false,
0 =>
array
(
'foo'
,
'bar'
)
);
public
function
__construct()
{
parent::__construct(
'Test the File cache API.'
);
}
public
function
setUp()
{
$this
->_config =
$GLOBALS
[
'_PX_config'
];
$GLOBALS
[
'_PX_config'
][
'cache_engine'
] =
'Pluf_Cache_File'
;
$GLOBALS
[
'_PX_config'
][
'cache_timeout'
] = 5;
$GLOBALS
[
'_PX_config'
][
'cache_file_folder'
] =
'/tmp/pluf_unittest_cache'
;
}
public
function
tearDown()
{
$GLOBALS
[
'_PX_config'
] =
$this
->_config;
}
public
function
testConstructor()
{
unset(
$GLOBALS
[
'_PX_config'
][
'cache_file_folder'
]);
try
{
$cache
= Pluf_Cache::factory();
}
catch
(Pluf_Exception_SettingError
$e
) {
$this
->pass();
return
;
}
$this
->fail(
'An exception as not been raised, "cache_file_folder" setting not defined.'
);
}
public
function
testBasic()
{
$cache
= Pluf_Cache::factory();
$success
=
$cache
->set(
'test1'
,
'foo1'
);
$this
->assertTrue(
$success
);
$this
->assertEqual(
'foo1'
,
$cache
->get(
'test1'
));
}
public
function
testGetUnknownKey()
{
$cache
= Pluf_Cache::factory();
$this
->assertNull(null,
$cache
->get(
'unknown'
));
}
public
function
testGetDefault()
{
$cache
= Pluf_Cache::factory();
$this
->assertEqual(
'default'
,
$cache
->get(
'unknown'
,
'default'
));
}
public
function
testSerialized()
{
$cache
= Pluf_Cache::factory();
$success
=
$cache
->set(
'array'
,
$this
->_arrayData);
$this
->assertTrue(
$success
);
$this
->assertCopy(
$this
->_arrayData,
$cache
->get(
'array'
));
$obj
=
new
stdClass();
$obj
->foo =
'bar'
;
$obj
->hello =
'world'
;
$success
=
$cache
->set(
'object'
,
$obj
);
$this
->assertTrue(
$success
);
$this
->assertCopy(
$obj
,
$cache
->get(
'object'
));
unset(
$obj
);
$this
->assertIsA(
$cache
->get(
'object'
),
'stdClass'
);
$this
->assertEqual(
'world'
,
$cache
->get(
'object'
)->hello);
}
}