summaryrefslogtreecommitdiff
path: root/_test/tests/inc/changelog_getrevisioninfo.test.php
blob: 79b31d68e34c2ec2ed1b4f3cdef0e8f14b72fd96 (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
<?php

/**
 * Tests for requesting revisioninfo of a revision of a page with getRevisionInfo()
 *
 * This class uses the files:
 * - data/pages/mailinglist.txt
 * - data/meta/mailinglist.changes
 */
class changelog_getrevisionsinfo_test extends DokuWikiTest {

    private $logline = "1362525899	127.0.0.1	E	mailinglist	pubcie	[Data entry] 	\n";
    private $firstlogline = "1374261194	127.0.0.1	E	mailinglist	pubcie		\n";
    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['mailinglist']);
        }
    }

    /**
     * no nonexist.changes meta file available
     */
    function test_changemetadatanotexists() {
        $rev = 1362525899;
        $id = 'nonexist';
        $revsexpected = false;

        $pagelog = new PageChangeLog($id, $chunk_size = 8192);
        $revs = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($revsexpected, $revs);
    }

    /**
     * request existing rev
     */
    function test_requestrev() {
        $rev = 1362525899;
        $infoexpected = parseChangelogLine($this->logline);

        $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($infoexpected, $info);
        //returns cached value
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($infoexpected, $info);
    }

    /**
     * request existing rev with chucked reading
     */
    function test_requestrev_chuncked() {
        $rev = 1362525899;
        $infoexpected = parseChangelogLine($this->logline);

        $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($infoexpected, $info);
    }

    /**
     * request existing rev with chucked reading
     */
    function test_requestrev_chunckedsmallerthanlinelength() {
        $rev = 1362525899;
        $infoexpected = parseChangelogLine($this->logline);

        $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($infoexpected, $info);
    }

    /**
     * request current version
     */
    function test_requestrecentestlogline() {
        $rev = 1374261194;
        $infoexpected = parseChangelogLine($this->firstlogline);

        $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($infoexpected, $info);
        //returns cached value
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($infoexpected, $info);
    }

    /**
     * request current version, with chuncked reading
     */
    function test_requestrecentestlogline_chuncked() {
        $rev = 1374261194;
        $infoexpected = parseChangelogLine($this->firstlogline);

        $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($infoexpected, $info);
    }

    /**
     * request negative revision
     */
    function test_negativerev() {
        $rev = -10;

        $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals(false, $info);
    }

    /**
     * request non existing revision somewhere between existing revisions
     */
    function test_notexistingrev() {
        $rev = 1362525890;

        $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals(false, $info);
    }

    /**
     * sometimes chuncksize is set to true
     */
    function test_chuncksizetrue() {
        $rev = 1362525899;
        $infoexpected = parseChangelogLine($this->logline);

        $pagelog = new PageChangeLog($this->pageid, true);
        $info = $pagelog->getRevisionInfo($rev);
        $this->assertEquals($infoexpected, $info);
    }
}