These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | class RainTPLTest extends PHPUnit_Framework_TestCase |
||
3 | { |
||
4 | private static $error = 'foo bar'; |
||
5 | |||
6 | private static $status = '!*#@?$+'; |
||
0 ignored issues
–
show
Comprehensibility
introduced
by
Loading history...
|
|||
7 | |||
8 | private static $expire = array( |
||
9 | '5min' => '5 minutes', |
||
10 | '1hour' => '1 hour', |
||
11 | 'never' => 'Never', |
||
12 | ); |
||
13 | |||
14 | private static $expire_default = '1hour'; |
||
15 | |||
16 | private static $version = 'Version 1.2.3'; |
||
17 | |||
18 | private $_content; |
||
19 | |||
20 | public function setUp() |
||
21 | { |
||
22 | /* Setup Routine */ |
||
23 | $page = new RainTPL; |
||
24 | $page::configure(array('cache_dir' => 'tmp/')); |
||
25 | $page::$path_replace = false; |
||
26 | |||
27 | // We escape it here because ENT_NOQUOTES can't be used in RainTPL templates. |
||
28 | $page->assign('CIPHERDATA', htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES)); |
||
29 | $page->assign('ERROR', self::$error); |
||
30 | $page->assign('STATUS', self::$status); |
||
31 | $page->assign('VERSION', self::$version); |
||
32 | $page->assign('DISCUSSION', true); |
||
33 | $page->assign('OPENDISCUSSION', true); |
||
34 | $page->assign('MARKDOWN', true); |
||
35 | $page->assign('SYNTAXHIGHLIGHTING', true); |
||
36 | $page->assign('SYNTAXHIGHLIGHTINGTHEME', 'sons-of-obsidian'); |
||
37 | $page->assign('BURNAFTERREADINGSELECTED', false); |
||
38 | $page->assign('PASSWORD', true); |
||
39 | $page->assign('FILEUPLOAD', false); |
||
40 | $page->assign('BASE64JSVERSION', '2.1.9'); |
||
41 | $page->assign('NOTICE', 'example'); |
||
42 | $page->assign('LANGUAGESELECTION', ''); |
||
43 | $page->assign('LANGUAGES', i18n::getLanguageLabels(i18n::getAvailableLanguages())); |
||
44 | $page->assign('EXPIRE', self::$expire); |
||
45 | $page->assign('EXPIREDEFAULT', self::$expire_default); |
||
46 | $page->assign('EXPIRECLONE', true); |
||
47 | $page->assign('URLSHORTENER', ''); |
||
48 | ob_start(); |
||
49 | $page->draw('page'); |
||
50 | $this->_content = ob_get_contents(); |
||
51 | // run a second time from cache |
||
52 | $page->cache('page'); |
||
53 | $page->draw('page'); |
||
54 | ob_end_clean(); |
||
55 | } |
||
56 | |||
57 | public function tearDown() |
||
58 | { |
||
59 | /* Tear Down Routine */ |
||
60 | helper::rmdir(PATH . 'tmp'); |
||
61 | } |
||
62 | |||
63 | public function testTemplateRendersCorrectly() |
||
64 | { |
||
65 | $this->assertContains( |
||
66 | '<div id="cipherdata" class="hidden">' . |
||
67 | htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES) . |
||
68 | '</div>', |
||
69 | $this->_content, |
||
70 | 'outputs data correctly' |
||
71 | ); |
||
72 | $this->assertRegExp( |
||
73 | '#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#', |
||
74 | $this->_content, |
||
75 | 'outputs error correctly' |
||
76 | ); |
||
77 | $this->assertRegExp( |
||
78 | '#<[^>]+id="password"[^>]*>#', |
||
79 | $this->_content, |
||
80 | 'password available if configured' |
||
81 | ); |
||
82 | $this->assertRegExp( |
||
83 | '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', |
||
84 | $this->_content, |
||
85 | 'checked discussion if configured' |
||
86 | ); |
||
87 | $this->assertRegExp( |
||
88 | '#<[^>]+id="opendisc"[^>]*>#', |
||
89 | $this->_content, |
||
90 | 'discussions available if configured' |
||
91 | ); |
||
92 | // testing version number in JS address, since other instances may not be present in different templates |
||
93 | $this->assertRegExp( |
||
94 | '#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#', |
||
95 | $this->_content, |
||
96 | 'outputs version correctly' |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @expectedException RainTpl_Exception |
||
102 | */ |
||
103 | public function testMissingTemplate() |
||
104 | { |
||
105 | $test = new RainTPL; |
||
106 | $test->draw('123456789 does not exist!'); |
||
107 | } |
||
108 | } |
||
109 |