-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathloader_spec.php
More file actions
113 lines (89 loc) · 4.13 KB
/
loader_spec.php
File metadata and controls
113 lines (89 loc) · 4.13 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
require_once 'spec_helper.php';
class Describe_file_loader extends SimpleSpec {
function should_be_able_to_read_template() {
chdir(dirname(__FILE__));
$h2o = h2o('templates/a.html');
expects($h2o->nodelist)->should_be_a('Nodelist');
$h2o = h2o('templates/b.html');
expects($h2o->nodelist)->should_be_a('Nodelist');
$h2o = h2o('templates/emails/base.html');
expects($h2o->nodelist)->should_be_a('Nodelist');
}
function should_be_able_to_load_template_lazily() {
$h2o = new H2o('a.html', array('searchpath' => 'templates'));
expects($h2o->render())->should_not_be_empty();
$h2o = new H2o(null, array('searchpath' => 'templates'));
$h2o->loadTemplate('b.html');
expects($h2o->render())->should_not_be_empty();
}
function should_read_from_alternitive_working_path() {
$h2o = h2o('emails/base.html', array(
'searchpath' => dirname(__FILE__).DS.'templates'
));
expects($h2o->render())->should_match('/Dear Customer/');
}
function should_load_subtemplate_upon_extends_tag() {
$h2o = h2o('emails/campaign1.html', array(
'searchpath' => dirname(__FILE__).DS.'templates'
));
expects($h2o->render())->should_match('/Dear Customer/');
$h2o->loadTemplate('emails/campaign2.html');
expects($h2o->render())->should_match('/Hello Customer/');
}
function should_load_subtemplate_upon_include_tag() {
$h2o = h2o('emails/campaign3.html', array(
'searchpath' => dirname(__FILE__).DS.'templates'
));
expects($h2o->render())->should_match('/abcWidgets Logo are registered trademarks/');
}
function shouble_cache_main_template() {
$h2o = h2o('templates/a.html', array('cache' => false));
expects($h2o->cached)->should_be(false);
$h2o = h2o('template/a.html', array('cache'=>true));
expects($h2o->cached)->should_be(true);
}
function should_invalidate_cache_if_any_subtemplates_has_updated() {
$opt = array('searchpath' => dirname(__FILE__).DS.'templates');
# Load template twice to make sure its cached
$h2o = h2o('emails/campaign1.html', $opt);
$h2o->loadTemplate('emails/campaign1.html');
expects($h2o->loader->cached)->should_be(true);
# Touch parent template
sleep(1);
touch(dirname(__FILE__).DS.'templates/emails/base.html');
$h2o->loadTemplate('emails/campaign1.html');
expects($h2o->loader->cached)->should_be(false);
$h2o->loader->flush_cache();
}
function should_include_dynamic_filenames_in_include_tag() {
$opt = array('searchpath' => dirname(__FILE__).DS.'templates');
$h2o = h2o('dynamic_include.tpl',$opt);
expects($h2o->render())->should_match('/DYNAMIC TEMPLATE #1/');
expects($h2o->render())->should_match('/DYNAMIC TEMPLATE #2/');
}
}
class Describe_hash_loader extends SimpleSpec {
function prepare() {
$this->h2o = new H2o('layout.html', array('loader'=>hash_loader(array(
'layout.html' =>
"{% block body %}layout text{% endblock %} {% include '_menu.html' %}",
'index.html' =>
"{% extends 'layout.html' %} {% block body %} {{ block.depth }} {{ block.super }} - index text {% endblock %} ",
'_menu.html' =>
"<div id='menu'>page menu</div>",
))));
}
function should_read_files_to_loader() {
expects($this->h2o->loader->read('layout.html'))->should_be_a('Nodelist');
}
function should_read_sub_template_in_extends_tag() {
$this->h2o->loadTemplate('index.html');
expects($this->h2o->render())->should_match('/layout text - index text/');
}
function should_read_sub_template_in_include_tag() {
$this->h2o->loadTemplate('index.html');
expects($this->h2o->render())->should_match('/page menu/');
}
}
?>