-
Notifications
You must be signed in to change notification settings - Fork 1
/
sfCacheTagLoggerTest.php
86 lines (64 loc) · 2.09 KB
/
sfCacheTagLoggerTest.php
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
<?php
/*
* This file is part of the sfCacheTaggingPlugin package.
* (c) 2009-2013 Ilya Sabelnikov <fruit.dev@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
include_once realpath(dirname(__FILE__) . '/../bootstrap/unit.php');
define('LOGS_DIR', sfConfig::get('sf_plugins_dir') . '/' . sfCacheTaggingToolkit::PLUGIN_NAME . '/test/temp/logs');
define('LOGS_FILE', LOGS_DIR . '/cache.log');
function cleanLogDir()
{
if (is_dir(LOGS_DIR))
{
if (file_exists(LOGS_FILE))
{
unlink(LOGS_FILE);
}
rmdir(LOGS_DIR);
}
}
class ExampleCacheTagLogger extends sfCacheTagLogger
{
protected function doLog ($char, $key)
{
printf("%s %s\n", $char, $key);
return true;
}
public function getExplanationForChar ($char)
{
return $this->explainChar($char);
}
}
$t = new lime_test();
$l = new ExampleCacheTagLogger(array());
$l->setOption('new_line', true);
$t->is($l->getOption('new_line'), true);
$t->is($l->getOption('new_line', 10), true);
$t->is($l->getOption('new_line_dir'), null);
$t->is($l->getOption('new_line_dir', 10), 10);
$t->is($l->getOptions(), array(
'auto_shutdown' => true,
'skip_chars' => '',
'new_line' => true,
));
$l->initialize(array('time_format' => '%T%z', 'format' => '%char%%EOL%'));
$t->is($l->getOption('time_format'), '%T%z');
$t->is($l->getOption('format'), '%char%%EOL%');
$l->initialize(array('skip_chars' => 'Ll'));
$t->ok(! $l->log('l', 'Air_68224'), 'l is skipped');
$t->ok(! $l->log('L', 'Air_68226'), 'L is skipped');
$t->ok($l->log('X', 'Air_68225'), 'X is written');
$chars = 'gGhHlLsSuUvVpPeEtTiI';
for ($i = 0; $i < strlen($chars); $i++)
{
$t->is(
gettype($explanation = $l->getExplanationForChar($chars[$i])),
'string',
sprintf('"%s" returns "%s"', $chars[$i], $explanation)
);
}
$t->is($l->getExplanationForChar('-'), 'Unregistered char', '"-" return "Unregistered char"');
$t->is($l->shutdown(), null);