summaryrefslogtreecommitdiff
path: root/_test/tests/inc/changelog_getrevisions.test.php
blob: a9be26dae9117f8928b0511bb1cc550e2d391155 (plain)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
 * Tests for requesting revisions of a page with getRevisions()
 *
 * This class uses the files:
 * - data/pages/mailinglist.txt
 * - data/meta/mailinglist.changes
 */
class changelog_getrevisions_test extends DokuWikiTest {

    /**
     * $first counts inclusive zero, after the current page
     */
    private $revsexpected = array(
        1374261194, //current page
        1371579614, 1368622240, // revisions, corresponds to respectively $first = 0 and 1
        1368622195, 1368622152,
        1368612599, 1368612506,
        1368609772, 1368575634,
        1363436892, 1362527164,
        1362527046, 1362526861, //10 and 11
        1362526767, 1362526167,
        1362526119, 1362526039,
        1362525926, 1362525899,
        1362525359, 1362525145,
        1362524799, 1361901536, //20 and 21
        1360110636
    );
    private $pageid = 'mailinglist';

    function setup() {
        parent::setup();
        global $cache_revinfo;
        $cache =& $cache_revinfo;
        if(isset($cache['nonexist'])) {
            unset($cache['nonexist']);
        }
        if(isset($cache['mailinglist'])) {
            unset($cache['nonexist']);
        }
    }

    /**
     * no nonexist.changes meta file available
     */
    function test_changemetadatanotexists() {
        $first = 0;
        $num   = 1;
        $id    = 'nonexist';

        $revs         = getRevisions($id, $first, $num, $chunk_size = 8192, $media = false);
        $revsexpected = array();
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * request first recentest revision
     * (so skips first line which belongs to the current existing page)
     */
    function test_requestlastrev() {
        $first        = 0;
        $num          = 1;
        $revsexpected = array($this->revsexpected[1]);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * request first recentest revision
     * (so skips first line which belongs to the current existing page)
     */
    function test_requestonebutlastrev() {
        $first        = 1;
        $num          = 1;
        $revsexpected = array($this->revsexpected[2]);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * request first recentest revision
     * (so skips first line of current existing page)
     */
    function test_requestrevswithoffset() {
        $first        = 10;
        $num          = 5;
        $revsexpected = array_slice($this->revsexpected, $first + 1, $num);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * first = -1 requests recentest logline, without skipping
     */
    function test_requestrecentestlogline() {
        $first        = -1;
        $num          = 1;
        $revsexpected = array($this->revsexpected[0]);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * chunck size = 0 skips chuncked loading
     */
    function test_wholefile() {
        $first        = 0;
        $num          = 1000;
        $revsexpected = array_slice($this->revsexpected, 1);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 0, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * Negative range returns no result
     */
    function test_negativenum() {
        $first        = 0;
        $num          = -10;
        $revsexpected = array();

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * Negative range returns no result
     */
    function test_negativennumoffset() {
        $first        = 2;
        $num          = -10;
        $revsexpected = array();

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * zero range returns no result
     */
    function test_zeronum() {
        $first        = 5;
        $num          = 0;
        $revsexpected = array();

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 512, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * get oldest revisions
     */
    function test_requestlargeoffset() {
        $first        = 22;
        $num          = 50;
        $revsexpected = array_slice($this->revsexpected, $first + 1);

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * request with too large offset and range
     */
    function test_requesttoolargenumberrevs() {
        $first        = 50;
        $num          = 50;
        $revsexpected = array();

        $revs = getRevisions($this->pageid, $first, $num, $chunk_size = 8192, $media = false);
        $this->assertEquals($revsexpected, $revs);
    }

}