1<?php
2/**
3 * @group plugin_const
4 * @group plugins
5 */
6class plugin_const_constants_test extends DokuWikiTest {
7
8    public function setup() {
9        $this->pluginsEnabled[] = 'const';
10        parent::setup();
11    }
12
13    public function test_page_user_constants() {
14        saveWikiText('test:plugin_const:pageconstants',
15            '<const>'.DOKU_LF
16            .'ID=%ID%'.DOKU_LF
17            .'namespace=%NAMESPACE%'.DOKU_LF
18            .'User=%USER%'.DOKU_LF
19            .'</const>'.DOKU_LF
20            .'ID:%%ID%%'.DOKU_LF
21            .'NAMESPACE:%%namespace%%'.DOKU_LF
22            .'User:%%User%%'.DOKU_LF,
23            'setup for test');
24
25        $request = new TestRequest();
26        $response = $request->get(array('id' => 'test:plugin_const:pageconstants'), '/doku.php');
27        $HTML = $response->queryHTML('.page p');
28
29        $this->assertTrue(strpos($HTML, 'ID:pageconstants') !== false, 'Page ID is pageconstants');
30        $this->assertTrue(strpos($HTML, 'NAMESPACE:test:plugin_const') !== false, 'Namespace is test:plugin_const');
31        $this->assertTrue(strpos($HTML, 'User:') !== false, 'anonymous');
32    }
33
34    public function test_date_constants() {
35        saveWikiText('test:plugin_const:dateconstants',
36            '<const>'.DOKU_LF
37            .'YEAR=%YEAR%'.DOKU_LF
38            .'MONTH=%MONTH%'.DOKU_LF
39            .'MONTHNAME=%MONTHNAME%'.DOKU_LF
40            .'WEEK=%WEEK%'.DOKU_LF
41            .'DAY=%DAY%'.DOKU_LF
42            .'DAYNAME=%DAYNAME%'.DOKU_LF
43            .'</const>'.DOKU_LF
44
45            .'YEAR:%%YEAR%%'.DOKU_LF
46            .'MONTH:%%MONTH%%'.DOKU_LF
47            .'MONTHNAME:%%MONTHNAME%%'.DOKU_LF
48            .'WEEK:%%WEEK%%'.DOKU_LF
49            .'DAY:%%DAY%%'.DOKU_LF
50            .'DAYNAME:%%DAYNAME%%'.DOKU_LF,
51
52            'setup for test');
53
54        $request = new TestRequest();
55        $response = $request->get(array('id' => 'test:plugin_const:dateconstants'), '/doku.php');
56        $HTML = $response->queryHTML('.page p');
57
58        $this->assertTrue(strpos($HTML, 'YEAR:'.date('Y')) !== false);
59        $this->assertTrue(strpos($HTML, 'MONTH:'.date('m')) !== false);
60        $this->assertTrue(strpos($HTML, 'MONTHNAME:'.date('F')) !== false);
61        $this->assertTrue(strpos($HTML, 'WEEK:'.date('W')) !== false);
62        $this->assertTrue(strpos($HTML, 'DAY:'.date('d')) !== false);
63        $this->assertTrue(strpos($HTML, 'DAYNAME:'.date('l')) !== false);
64    }
65
66    public function test_other_constants() {
67
68        saveWikiText('test:plugin_const:otherconstants',
69            '<const>'.DOKU_LF
70            .'RANDOM=%RANDOM%'.DOKU_LF
71            .'AUTOINDEX=%AUTOINDEX%'.DOKU_LF
72            .'</const>'.DOKU_LF
73            .'RANDOM:%%RANDOM%%'.DOKU_LF
74            .'AUTOINDEX1:%%AUTOINDEX%%'.DOKU_LF
75            .'AUTOINDEX2:%%AUTOINDEX%%'.DOKU_LF
76            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
77            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
78            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
79            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
80            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
81            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
82            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
83            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
84            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
85            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
86            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
87            .'AUTOINDEX_:%%AUTOINDEX%%'.DOKU_LF
88            .'AUTOINDEX15:%%AUTOINDEX%%'.DOKU_LF,
89
90            'setup for test');
91
92        $request = new TestRequest();
93        $response = $request->get(array('id' => 'test:plugin_const:otherconstants'), '/doku.php');
94        $HTML = $response->queryHTML('.page p');
95
96        $this->assertTrue(@preg_match('/RANDOM:\d+/',$HTML) === 1);
97        $this->assertTrue(strpos($HTML, 'AUTOINDEX1:1') !== false);
98        $this->assertTrue(strpos($HTML, 'AUTOINDEX2:2') !== false);
99        $this->assertTrue(strpos($HTML, 'AUTOINDEX15:15') !== false);
100
101    }
102}
103