/
TestOfSmartyThinkUp.php
171 lines (148 loc) · 6.77 KB
/
TestOfSmartyThinkUp.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
*
* ThinkUp/tests/TestOfSmartyThinkUp.php
*
* Copyright (c) 2009-2011 Gina Trapani
*
* LICENSE:
*
* This file is part of ThinkUp (http://thinkupapp.com).
*
* ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
* later version.
*
* ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
* Test of SmartyThinkUp class
*
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2011 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';
class TestOfSmartyThinkUp extends ThinkUpBasicUnitTestCase {
/**
* Test constructor
*/
public function testNewSmartyThinkUp() {
$v_mgr = new SmartyThinkUp();
$this->assertTrue(isset($v_mgr));
}
/**
* Test default values
*/
public function testSmartyThinkUpDefaultValues() {
$cfg = Config::getInstance();
$cfg->setValue('source_root_path', '/path/to/thinkup/');
$cfg->setValue('cache_pages', true);
$cfg->setValue('cache_lifetime', 600);
$v_mgr = new SmartyThinkUp();
$this->assertTrue(sizeof($v_mgr->template_dir), 2);
$this->assertEqual($v_mgr->template_dir[1], '/path/to/thinkup/tests/view');
$this->assertTrue(sizeof($v_mgr->plugins_dir), 2);
$this->assertEqual($v_mgr->plugins_dir[0], 'plugins');
$this->assertEqual($v_mgr->cache_dir, THINKUP_WEBAPP_PATH.'_lib/view/compiled_view/cache');
$this->assertEqual($v_mgr->cache_lifetime, $cfg->getValue('cache_lifetime'));
$this->assertTrue($v_mgr->caching);
}
/**
* Test assigned variables get saved when debug is true
*/
public function testSmartyThinkUpAssignedValuesDebugOn() {
$cfg = Config::getInstance();
$cfg->setValue('debug', true);
$cfg->setValue('cache_lifetime', 1200);
$cfg->setValue('app_title', 'Testy ThinkUp Custom Application Name');
$cfg->setValue('site_root_path', '/my/thinkup/folder/');
$v_mgr = new SmartyThinkUp();
$v_mgr->assign('test_var_1', "Testing, testing, 123");
$this->assertEqual($v_mgr->getTemplateDataItem('test_var_1'), "Testing, testing, 123");
$this->assertEqual($v_mgr->getTemplateDataItem('app_title'), 'Testy ThinkUp Custom Application Name');
$this->assertEqual($v_mgr->getTemplateDataItem('logo_link'), '');
$this->assertEqual($v_mgr->getTemplateDataItem('site_root_path'), '/my/thinkup/folder/');
$this->assertEqual($v_mgr->cache_lifetime, 1200);
}
/**
* Test assigned variables don't get saved when debug is false
*/
public function testSmartyThinkUpAssignedValuesDebugOff() {
$cfg = Config::getInstance();
$cfg->setValue('debug', false);
$v_mgr = new SmartyThinkUp();
$v_mgr->assign('test_var_1', "Testing, testing, 123");
$this->assertEqual($v_mgr->getTemplateDataItem('test_var_1'), null);
$test_var_1 = $v_mgr->getTemplateDataItem('test_var_1');
$this->assertTrue(!isset($test_var_1));
}
/**
* Test override config with passed-in array
*/
public function testSmartyThinkUpPassedInArray() {
$cfg_array = array('debug'=>true,
'site_root_path'=>'/my/thinkup/folder/test',
'source_root_path'=>'/Users/gina/Sites/thinkup',
'app_title'=>"My ThinkUp",
'cache_pages'=>true, 'cache_lifetime'=>1000);
$v_mgr = new SmartyThinkUp($cfg_array);
$this->assertEqual($v_mgr->getTemplateDataItem('app_title'), 'My ThinkUp');
$this->assertEqual($v_mgr->getTemplateDataItem('logo_link'), '');
$this->assertEqual($v_mgr->getTemplateDataItem('site_root_path'), '/my/thinkup/folder/test');
$this->assertEqual($v_mgr->cache_lifetime, 1000);
}
public function testAddHelp() {
$cfg = Config::getInstance();
$cfg->setValue('debug', true);
$v_mgr = new SmartyThinkUp();
$v_mgr->addHelp('api', 'userguide/api/posts/index');
$v_mgr->addHelp('user_guide', 'userguide/index');
$help_array = array('api'=>'userguide/api/posts/index', 'user_guide'=>'userguide/index');
$this->assertEqual($v_mgr->getTemplateDataItem('help'), $help_array);
$debug_arr = $v_mgr->getTemplateDataItem('help');
$this->debug(Utils::varDumpToString($debug_arr));
$this->debug($debug_arr['api']);
}
public function testAddErrorMessage() {
$cfg = Config::getInstance();
$cfg->setValue('debug', true);
$v_mgr = new SmartyThinkUp();
$v_mgr->addErrorMessage('Page level error');
$v_mgr->addErrorMessage('Field level error', 'fieldname');
$this->assertEqual($v_mgr->getTemplateDataItem('error_msg'), 'Page level error');
$debug_arr = $v_mgr->getTemplateDataItem('error_msgs');
$this->assertEqual($debug_arr['fieldname'], 'Field level error');
$this->debug(Utils::varDumpToString($debug_arr));
}
public function testAddInfoMessage() {
$cfg = Config::getInstance();
$cfg->setValue('debug', true);
$v_mgr = new SmartyThinkUp();
$v_mgr->addInfoMessage('Field level info', 'fieldname');
$v_mgr->addInfoMessage('Page level info');
$this->assertEqual($v_mgr->getTemplateDataItem('info_msg'), 'Page level info');
$debug_arr = $v_mgr->getTemplateDataItem('info_msgs');
$this->assertEqual($debug_arr['fieldname'], 'Field level info');
$this->debug(Utils::varDumpToString($debug_arr));
}
public function testAddSuccessMessage() {
$cfg = Config::getInstance();
$cfg->setValue('debug', true);
$v_mgr = new SmartyThinkUp();
$v_mgr->addSuccessMessage('Field level info 1', 'fieldname1');
$v_mgr->addSuccessMessage('Page level info');
$v_mgr->addSuccessMessage('Field level info 2', 'fieldname2');
$this->assertEqual($v_mgr->getTemplateDataItem('success_msg'), 'Page level info');
$debug_arr = $v_mgr->getTemplateDataItem('success_msgs');
$this->assertEqual($debug_arr['fieldname1'], 'Field level info 1');
$this->assertEqual($debug_arr['fieldname2'], 'Field level info 2');
$this->debug(Utils::varDumpToString($debug_arr));
}
}