1<?php
2
3/**
4 *
5 *
6 * @author Michael Große <grosse@cosmocode.de>
7 *
8 * @group plugin_top
9 * @group plugins
10 */
11
12class best_top_test extends DokuWikiTest {
13    protected $pluginsEnabled = array('top','sqlite', 'translation');
14
15    function test_best() {
16
17        $top_helper = new helper_plugin_top();
18        $sqlite = $top_helper->getDBHelper();
19        $sql = "INSERT INTO toppages (page, value, lang, month) VALUES
20            ( ?, ?, ?, ?);";
21        $sqlite->query($sql,'wiki:start',3,'','201407');
22        $sqlite->query($sql,'wiki:start',2,'','201401');
23        $sqlite->query($sql,'wiki:start',6,'','201201');
24        $sqlite->query($sql,'wiki:start',1,'',null);
25        $sqlite->query($sql,'en:wiki:start',8,'en','201201');
26        $sqlite->query($sql,'en:wiki:start',1,'en','201303');
27        $sqlite->query($sql,'de:wiki:start',6,'de','201201');
28
29        $result = $top_helper->best(null,201312);
30        $this->assertEquals(
31            5,$result[0]['value'],
32            'We should see the sum of all visitis since the given month, not month by month.'
33        );
34
35        $result = $top_helper->best(null,null);
36        $this->assertEquals(
37            12,$result[0]['value'],
38            'We should see the total number of visitis. Including visits without date'
39        );
40
41        $result = $top_helper->best('en',null);
42        $this->assertEquals(
43            9,$result[0]['value'],
44            'We should see only pages with from given language.'
45        );
46
47        $result = $top_helper->best('en',201302);
48        $this->assertEquals(
49            1,$result[0]['value'],
50            'Time and language restrictions should work together.'
51        );
52    }
53
54    function test_vanilla_syntax_parsing() {
55        $parser_response = p_get_instructions('{{top}}')[2];
56        $expected_response = array(
57            0 => 'plugin',
58            1 => array(
59                0 => 'top',
60                1 => array(
61                    0 => DOKU_LEXER_SPECIAL,
62                    1 => array(
63                        'lang' => '',
64                        'month' => '',
65                        'tag' => 'ul',
66                        'score' => 'false',
67                    )
68                ),
69                2 => DOKU_LEXER_SPECIAL,
70                3 => '{{top}}',
71            ),
72            2 => 1,
73        );
74        $this->assertEquals($expected_response, $parser_response);
75    }
76
77    function test_ol_syntax_parsing() {
78        $parser_response = p_get_instructions('{{top|tag=ol}}')[2];
79        $expected_response = array(
80            0 => 'plugin',
81            1 => array(
82                0 => 'top',
83                1 => array(
84                    0 => DOKU_LEXER_SPECIAL,
85                    1 => array(
86                        'lang' => '',
87                        'month' => '',
88                        'tag' => 'ol',
89                        'score' => 'false',
90                    )
91                ),
92                2 => DOKU_LEXER_SPECIAL,
93                3 => '{{top|tag=ol}}',
94            ),
95            2 => 1,
96        );
97        $this->assertEquals($expected_response, $parser_response);
98    }
99
100    function test_score_syntax_parsing() {
101        $parser_response = p_get_instructions('{{top|score=true}}')[2];
102        $expected_response = array(
103            0 => 'plugin',
104            1 => array(
105                0 => 'top',
106                1 => array(
107                    0 => DOKU_LEXER_SPECIAL,
108                    1 => array(
109                        'lang' => '',
110                        'month' => '',
111                        'tag' => 'ul',
112                        'score' => 'true',
113                    )
114                ),
115                2 => DOKU_LEXER_SPECIAL,
116                3 => '{{top|score=true}}',
117            ),
118            2 => 1,
119        );
120        $this->assertEquals($expected_response, $parser_response);
121    }
122
123    function test_date_syntax_parsing() {
124        $parser_response = p_get_instructions('{{top|month=201501}}')[2];
125        $expected_response = array(
126            0 => 'plugin',
127            1 => array(
128                0 => 'top',
129                1 => array(
130                    0 => DOKU_LEXER_SPECIAL,
131                    1 => array(
132                        'lang' => '',
133                        'month' => '201501',
134                        'tag' => 'ul',
135                        'score' => 'false',
136                    )
137                ),
138                2 => DOKU_LEXER_SPECIAL,
139                3 => '{{top|month=201501}}',
140            ),
141            2 => 1,
142        );
143        $this->assertEquals($expected_response, $parser_response);
144    }
145
146    function test_lang_syntax_parsing() {
147        $parser_response = p_get_instructions('{{top|lang=en}}')[2];
148        $expected_response = array(
149            0 => 'plugin',
150            1 => array(
151                0 => 'top',
152                1 => array(
153                    0 => DOKU_LEXER_SPECIAL,
154                    1 => array(
155                        'lang' => 'en',
156                        'month' => '',
157                        'tag' => 'ul',
158                        'score' => 'false',
159                    )
160                ),
161                2 => DOKU_LEXER_SPECIAL,
162                3 => '{{top|lang=en}}',
163            ),
164            2 => 1,
165        );
166        $this->assertEquals($expected_response, $parser_response);
167    }
168
169    function test_datelang_syntax_parsing() {
170        $parser_response = p_get_instructions('{{top|month=201501,lang=en}}')[2];
171        $expected_response = array(
172            0 => 'plugin',
173            1 => array(
174                0 => 'top',
175                1 => array(
176                    0 => DOKU_LEXER_SPECIAL,
177                    1 => array(
178                        'lang' => 'en',
179                        'month' => '201501',
180                        'tag' => 'ul',
181                        'score' => 'false',
182                    )
183                ),
184                2 => DOKU_LEXER_SPECIAL,
185                3 => '{{top|month=201501,lang=en}}',
186            ),
187            2 => 1,
188        );
189        $this->assertEquals($expected_response, $parser_response);
190    }
191
192}
193