forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-wp-cli.php
107 lines (82 loc) · 2.97 KB
/
test-timber-wp-cli.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
use Timber\Integration\CLI\TimberCommand;
use Timber\Loader;
class TestTimberWpCli extends Timber_UnitTestCase
{
protected function create_timber_database_cache()
{
Timber::compile('assets/single-post.twig', [
'post' => Timber::get_post($this->factory->post->create()),
], 600);
sleep(1);
}
protected function create_timber_object_cache()
{
Timber::compile('assets/single-post.twig', [
'post' => Timber::get_post($this->factory->post->create()),
], 600, Loader::CACHE_OBJECT);
sleep(1);
}
protected function enable_twig_cache()
{
$this->add_filter_temporarily('timber/twig/environment/options', function ($options) {
$options['cache'] = true;
return $options;
});
}
protected function create_twig_cache()
{
Timber::compile('assets/single-post.twig', [
'post' => Timber::get_post($this->factory->post->create()),
]);
sleep(1);
}
public function test_clear_cache_command_without_cache()
{
$command = new TimberCommand();
$command->clear_cache();
$this->expectOutputString('Clearing all caches …Success: Cleared all caches.');
}
public function test_clear_cache_command_with_caches()
{
// Make sure Timber and Twig caches exist.
$this->create_timber_database_cache();
$this->create_timber_object_cache();
$this->enable_twig_cache();
$this->create_twig_cache();
$command = new TimberCommand();
$command->clear_cache();
$this->expectOutputString('Clearing all caches …Success: Cleared all caches.');
}
public function test_clear_cache_timber_command()
{
// Make sure a Timber cache exists.
$this->create_timber_database_cache();
$this->create_timber_object_cache();
$command = new TimberCommand();
$command->clear_cache(['timber']);
$this->expectOutputString('Clearing Timber caches …Success: Cleared Timber caches.');
}
public function test_clear_cache_twig_command()
{
// Make sure a Twig cache exists.
$this->enable_twig_cache();
$this->create_twig_cache();
$command = new TimberCommand();
$command->clear_cache(['twig']);
$this->expectOutputString('Clearing Twig caches …Success: Cleared Twig caches.');
}
public function test_clear_cache_twig_command_without_cache()
{
$command = new TimberCommand();
$command->clear_cache(['twig']);
$this->expectOutputString('Clearing Twig caches …Success: Cleared Twig caches.');
}
public function test_clear_cache_twig_command_without_cache_but_twig_cache_activated()
{
$this->enable_twig_cache();
$command = new TimberCommand();
$command->clear_cache(['twig']);
$this->expectOutputString('Clearing Twig caches …Success: Cleared Twig caches.');
}
}