-
-
Notifications
You must be signed in to change notification settings - Fork 840
/
changelog_getlastrevisionat.test.php
169 lines (135 loc) · 4.48 KB
/
changelog_getlastrevisionat.test.php
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
<?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_getlastrevisionat_test extends DokuWikiTest {
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->getLastRevisionAt($rev);
$this->assertEquals($revsexpected, $revs);
}
/**
* start at exact current revision of mailinglist page
*
*/
function test_startatexactcurrentrev() {
$rev = 1385051947;
$revsexpected = '';
//set a known timestamp
touch(wikiFN($this->pageid), $rev);
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revs = $pagelog->getLastRevisionAt($rev);
$this->assertEquals($revsexpected, $revs);
}
/**
* test a future revision
*
*/
function test_futurerev() {
$rev = 1385051947;
$revsexpected = '';
//set a known timestamp
touch(wikiFN($this->pageid), $rev);
$rev +=1;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revs = $pagelog->getLastRevisionAt($rev);
$this->assertEquals($revsexpected, $revs);
}
/**
* start at exact last revision of mailinglist page
*
*/
function test_exactlastrev() {
$rev = 1360110636;
$revsexpected = 1360110636;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revs = $pagelog->getLastRevisionAt($rev);
$this->assertEquals($revsexpected, $revs);
}
/**
* Request not existing revision
*
*/
function test_olderrev() {
$rev = 1;
$revexpected = false;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revfound = $pagelog->getLastRevisionAt($rev);
$this->assertEquals($revexpected, $revfound);
}
/**
* Start at non existing revision somewhere between existing revisions
*/
function test_notexistingrev() {
$rev = 1362525890;
$revexpected = 1362525359;
$pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
$revfound = $pagelog->getLastRevisionAt($rev);
$this->assertEquals($revexpected, $revfound);
}
/**
* request nonexisting page
*
*/
function test_notexistingpage() {
$rev = 1385051947;
$currentexpected = false;
$pagelog = new PageChangeLog('nonexistingpage', $chunk_size = 8192);
$current = $pagelog->getLastRevisionAt($rev);
$this->assertEquals($currentexpected, $current);
}
/**
* test get correct revision on deleted media
*
*/
function test_deletedimage() {
global $conf;
global $AUTH_ACL;
//we need to have a user with AUTH_DELETE rights
//save settings
$oldSuperUser = $conf['superuser'];
$oldUseacl = $conf['useacl'];
$oldRemoteUser = $_SERVER['REMOTE_USER'];
$conf['superuser'] = 'admin';
$conf['useacl'] = 1;
$_SERVER['REMOTE_USER'] = 'admin';
$image = 'wiki:imageat.png';
$ret = copy(mediaFn('wiki:kind_zu_katze.png'),mediaFn($image));
$revexpected = @filemtime(mediaFn($image));
$rev = $revexpected + 10;
$this->waitForTick(true);
$ret = media_delete($image, 0);
$medialog = new MediaChangelog($image);
$current = $medialog->getLastRevisionAt($rev);
// as we wait for a tick, we should get something greater than the timestamp
$this->assertGreaterThan($revexpected, $current);
// however, it should be less than the current time or equal to it
$this->assertLessThanOrEqual(time(), $current);
//restore settings
$_SERVER['REMOTE_USER'] = $oldRemoteUser;
$conf['superuser'] = $oldSuperUser;
$conf['useacl'] = $oldUseacl;
}
}