|
1
|
# |
|
2
|
# Copyright (c) 2016 D. Richard Hipp |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
# Author contact information: |
|
13
|
# [email protected] |
|
14
|
# http://www.hwaci.com/drh/ |
|
15
|
# |
|
16
|
############################################################################ |
|
17
|
# |
|
18
|
# Test wiki and attachment command Support |
|
19
|
# |
|
20
|
|
|
21
|
test_setup |
|
22
|
|
|
23
|
# Disable backoffice for this test, otherwise its process lingers for some |
|
24
|
# time after the test has completed. |
|
25
|
# Perhaps, this should be done in test_setup and enabled explicitly only |
|
26
|
# when needed. |
|
27
|
fossil set backoffice-disable 1 |
|
28
|
|
|
29
|
# Return true if two files are similar (i.e. not only compress trailing spaces |
|
30
|
# from a line, but remove any final LF from the file as well) |
|
31
|
proc similar_file {a b} { |
|
32
|
set x "" |
|
33
|
if {[file exists $a]} { |
|
34
|
set x [read_file $a] |
|
35
|
regsub -all { +\n} $x \n x |
|
36
|
regsub -all {\n$} $x {} x |
|
37
|
} |
|
38
|
set y "" |
|
39
|
if {[file exists $b]} { |
|
40
|
set y [read_file $b] |
|
41
|
regsub -all { +\n} $y \n y |
|
42
|
regsub -all {\n$} $y {} y |
|
43
|
} |
|
44
|
return [expr {$x==$y}] |
|
45
|
} |
|
46
|
|
|
47
|
# Return the mime type in the manifest for a given wiki page |
|
48
|
# Defaults to "error: some text" if the manifest can't be located and |
|
49
|
# "text/x-fossil-wiki" (the default mimetype for rendering) |
|
50
|
# if the N card is omitted in the manifest. |
|
51
|
# Note: Makes fossil calls, so $CODE and $RESULT will be corrupted |
|
52
|
proc get_mime_type {name} { |
|
53
|
global CODE RESULT |
|
54
|
fossil http << "GET /wiki?name=$name" |
|
55
|
if {$CODE != 0} { |
|
56
|
return "error: /wiki?name=$name $CODE $RESULT" |
|
57
|
} |
|
58
|
fossil whatis --type w $name |
|
59
|
if {$CODE != 0} { |
|
60
|
return "error: fossil whatis --type w $name $CODE $RESULT" |
|
61
|
} |
|
62
|
set CODE [regexp -line {^artifact:\s*([0-9a-f]+)$} $RESULT match info] |
|
63
|
if {$CODE == 0} { |
|
64
|
return "error: whatis returned no info for wiki page $name" |
|
65
|
} |
|
66
|
fossil artifact $info |
|
67
|
if {$CODE != 0} { |
|
68
|
return "error: fossil artifact $info $CODE $RESULT" |
|
69
|
} |
|
70
|
set CODE [regexp -line {^N (.*)$} $RESULT match mimetype] |
|
71
|
if {$CODE == 0} { |
|
72
|
return "text/x-fossil-wiki" |
|
73
|
} |
|
74
|
return $mimetype |
|
75
|
} |
|
76
|
|
|
77
|
|
|
78
|
############################################################################### |
|
79
|
# Initially there should be no wiki entries |
|
80
|
fossil wiki list |
|
81
|
test wiki-0 {[normalize_result] eq {}} |
|
82
|
|
|
83
|
############################################################################### |
|
84
|
# Adding an entry should add it to the wiki list |
|
85
|
write_file f1 "first wiki note" |
|
86
|
fossil wiki create tcltest f1 |
|
87
|
test wiki-1 {$CODE == 0} |
|
88
|
fossil wiki list |
|
89
|
test wiki-2 {[normalize_result] eq {tcltest}} |
|
90
|
|
|
91
|
############################################################################### |
|
92
|
# Trying to add the same entry should fail |
|
93
|
fossil wiki create tcltest f1 -expectError |
|
94
|
test wiki-3 {$CODE != 0} |
|
95
|
|
|
96
|
############################################################################### |
|
97
|
# exporting the wiki page should give back similar text |
|
98
|
fossil wiki export tcltest a1 |
|
99
|
test wiki-4 {[similar_file f1 a1]} |
|
100
|
|
|
101
|
############################################################################### |
|
102
|
# commiting a change to an existing page should replace the page on export |
|
103
|
write_file f2 "second version of the page" |
|
104
|
fossil wiki commit tcltest f2 |
|
105
|
test wiki-5 {$CODE == 0} |
|
106
|
fossil wiki export tcltest a2 |
|
107
|
test wiki-6 {[similar_file f2 a2]} |
|
108
|
|
|
109
|
############################################################################### |
|
110
|
# But we shouldn't be able to update non-existant pages |
|
111
|
fossil wiki commit doesntexist f1 -expectError |
|
112
|
test wiki-7 {$CODE != 0} |
|
113
|
|
|
114
|
############################################################################### |
|
115
|
# There shouldn't be any tech notes at this point |
|
116
|
fossil wiki list --technote |
|
117
|
test wiki-8 {[normalize_result] eq {}} |
|
118
|
|
|
119
|
############################################################################### |
|
120
|
# Creating a tech note with a specified timestamp should add a technote |
|
121
|
write_file f3 "A technote" |
|
122
|
fossil wiki create technote f3 --technote {2016-01-01 12:34} |
|
123
|
test wiki-9 {$CODE == 0} |
|
124
|
fossil wiki list --technote |
|
125
|
test wiki-10 {[normalize_result] eq {2016-01-01 12:34:00}} |
|
126
|
fossil wiki list --technote --show-technote-ids |
|
127
|
set technotelist [split $RESULT "\n"] |
|
128
|
set veryfirsttechnoteid [lindex [split [lindex $technotelist 0]] 0] |
|
129
|
|
|
130
|
############################################################################### |
|
131
|
# exporting that technote should give back similar text |
|
132
|
fossil wiki export a3 --technote {2016-01-01 12:34:00} |
|
133
|
test wiki-11 {[similar_file f3 a3]} |
|
134
|
|
|
135
|
############################################################################### |
|
136
|
# Trying to add a technote with the same timestamp should succeed and create a |
|
137
|
# second tech note |
|
138
|
fossil wiki create 2ndnote f3 -technote {2016-01-01 12:34} |
|
139
|
test wiki-13 {$CODE == 0} |
|
140
|
fossil wiki list --technote |
|
141
|
set technotelist [split $RESULT "\n"] |
|
142
|
test wiki-13.1 {[llength $technotelist] == 2} |
|
143
|
|
|
144
|
############################################################################### |
|
145
|
# commiting a change to an existing technote should replace the page on export |
|
146
|
# (this should update the tech note from wiki-13 as that the most recently |
|
147
|
# updated one, that should also be the one exported by the export command) |
|
148
|
write_file f4 "technote 2nd variant" |
|
149
|
fossil wiki commit technote f4 --technote {2016-01-01 12:34} |
|
150
|
test wiki-14 {$CODE == 0} |
|
151
|
fossil wiki export a4 --technote {2016-01-01 12:34} |
|
152
|
test wiki-15 {[similar_file f4 a4]} |
|
153
|
# Also check that the tech note with the same timestamp, but modified less |
|
154
|
# recently still has its original text |
|
155
|
fossil wiki export a4.1 --technote $veryfirsttechnoteid |
|
156
|
test wiki-15.1 {[similar_file f3 a4.1]} |
|
157
|
|
|
158
|
############################################################################### |
|
159
|
# But we shouldn't be able to update non-existant pages |
|
160
|
fossil wiki commit doesntexist f1 -expectError |
|
161
|
test wiki-16 {$CODE != 0} |
|
162
|
|
|
163
|
############################################################################### |
|
164
|
# Check specifying tags for a technote is OK |
|
165
|
write_file f5 "technote with tags" |
|
166
|
fossil wiki create {tagged technote} f5 --technote {2016-01-02 12:34} --technote-tags {A B} |
|
167
|
test wiki-17 {$CODE == 0} |
|
168
|
write_file f5.1 "editted and tagged technote" |
|
169
|
fossil wiki commit {tagged technote} f5 --technote {2016-01-02 12:34} --technote-tags {C D} |
|
170
|
test wiki-18 {$CODE == 0} |
|
171
|
|
|
172
|
############################################################################### |
|
173
|
# Check specifying a bgcolor for a technote is OK |
|
174
|
write_file f6 "bgcolored technote" |
|
175
|
fossil wiki create bgcolor f6 --technote {2016-01-03 12:34} --technote-bgcolor red |
|
176
|
test wiki-19 {$CODE == 0} |
|
177
|
write_file f6.1 "editted technote with a background color" |
|
178
|
fossil wiki commit bgcolor f6.1 --technote {2016-01-03 12:34} --technote-bgcolor yellow |
|
179
|
test wiki-20 {$CODE == 0} |
|
180
|
|
|
181
|
############################################################################### |
|
182
|
# Test adding an attachment to both a non-existant (should fail) and existing wiki page |
|
183
|
write_file fa "This is a file to be attached" |
|
184
|
fossil attachment add doesntexist fa -expectError |
|
185
|
test wiki-21 {$CODE != 0} |
|
186
|
fossil attachment add tcltest fa |
|
187
|
test wiki-22 {$CODE == 0} |
|
188
|
|
|
189
|
############################################################################### |
|
190
|
# Test adding an attachment to both a non-existant (should fail) and existing tech note |
|
191
|
fossil attachment add fa --technote {2016-07-22 12:00} -expectError |
|
192
|
test wiki-23 {$CODE != 0} |
|
193
|
fossil attachment add fa --technote {2016-01-03 12:34} |
|
194
|
test wiki-24 {$CODE == 0} |
|
195
|
|
|
196
|
############################################################################### |
|
197
|
# Check that a wiki page with an attachment can be updated |
|
198
|
fossil wiki commit tcltest f1 |
|
199
|
test wiki-25 {$CODE == 0} |
|
200
|
|
|
201
|
############################################################################### |
|
202
|
# Check that a technote with an attachment can be updated |
|
203
|
fossil wiki commit technote f6 --technote {2016-01-03 12:34} |
|
204
|
test wiki-26 {$CODE == 0} |
|
205
|
fossil wiki commit technote f6 --technote {2016-01-03 12:34} --technote-tags {E F} |
|
206
|
test wiki-27 {$CODE == 0} |
|
207
|
fossil wiki commit technote f6 --technote {2016-01-03 12:34} --technote-bgcolor blue |
|
208
|
test wiki-28 {$CODE == 0} |
|
209
|
|
|
210
|
############################################################################### |
|
211
|
# Check longest form of timestamp for the technote |
|
212
|
write_file f7 "Different timestamps" |
|
213
|
fossil wiki create technotenow f7 --technote {2016-01-04 12:34:56+00:00} |
|
214
|
test wiki-29 {$CODE == 0} |
|
215
|
|
|
216
|
############################################################################### |
|
217
|
# Check a technote appears on the timeline |
|
218
|
write_file f8 "Contents of a 'unique' tech note" |
|
219
|
fossil wiki create {Unique technote} f8 --technote {2016-01-05 01:02:03} |
|
220
|
fossil timeline |
|
221
|
test wiki-30 {[string match *Unique*technote* $RESULT]} |
|
222
|
|
|
223
|
############################################################################### |
|
224
|
# Check for a collision between an attachment and a note, this was a |
|
225
|
# bug that resulted from some code treating the attachment entry as if it |
|
226
|
# were a technote when it isn't really. |
|
227
|
# |
|
228
|
# First, wait for the top of the next second so the attachment |
|
229
|
# happens at a known time, then add an attachment to an existing note |
|
230
|
# and a new note immediately after. |
|
231
|
|
|
232
|
set t0 [clock seconds] |
|
233
|
while {$t0 == [clock seconds]} { |
|
234
|
after 100 |
|
235
|
} |
|
236
|
set t1 [clock format [clock seconds] -gmt 1 -format "%Y-%m-%d %H:%M:%S"] |
|
237
|
write_file f9 "Timestamp: $t1" |
|
238
|
fossil attachment add f9 --technote {2016-01-05 01:02:03} |
|
239
|
test wiki-31 {$CODE == 0} |
|
240
|
fossil wiki create {Attachment collision} f9 --technote now |
|
241
|
test wiki-32 {$CODE == 0} |
|
242
|
# |
|
243
|
# Now waste time until the next second so that the remaining tests |
|
244
|
# don't have to worry about a potential collision |
|
245
|
set t0 [clock seconds] |
|
246
|
while {$t0 == [clock seconds]} { |
|
247
|
after 100 |
|
248
|
} |
|
249
|
|
|
250
|
############################################################################### |
|
251
|
# Check a technote with no timestamp cannot be created, but that |
|
252
|
# "now" is a valid stamp. |
|
253
|
set t2 [clock format [clock seconds] -gmt 1 -format "%Y-%m-%d %H:%M:%S"] |
|
254
|
write_file f10 "Even unstampted notes are delivered.\nStamped $t2" |
|
255
|
fossil wiki create "Unstamped Note" f10 --technote -expectError |
|
256
|
test wiki-33 {$CODE != 0} |
|
257
|
fossil wiki create "Unstamped Note" f10 --technote now |
|
258
|
test wiki-34 {$CODE == 0} |
|
259
|
fossil wiki list -t |
|
260
|
test wiki-35 {[string match "*$t2*" $RESULT]} |
|
261
|
|
|
262
|
############################################################################### |
|
263
|
# Check an attachment to it in the same second works. |
|
264
|
write_file f11 "Time Stamp was $t2" |
|
265
|
fossil attachment add f11 --technote $t2 |
|
266
|
test wiki-36 {$CODE == 0} |
|
267
|
fossil timeline |
|
268
|
test wiki-36-1 {$CODE == 0} |
|
269
|
fossil wiki list -t |
|
270
|
test wiki-36-2 {$CODE == 0} |
|
271
|
|
|
272
|
############################################################################### |
|
273
|
# Check that we have the expected number of tech notes on the list (and not |
|
274
|
# extra ones from other events (such as the attachments) - 8 tech notes |
|
275
|
# expected created by tests 9, 13, 17, 19, 29, 31, 32 and 34 |
|
276
|
fossil wiki list --technote |
|
277
|
set technotelist [split $RESULT "\n"] |
|
278
|
test wiki-37 {[llength $technotelist] == 8} |
|
279
|
|
|
280
|
############################################################################### |
|
281
|
# Check that using the show-technote-ids shows the same tech notes in the same |
|
282
|
# order (with the technote id as the first word of the line) |
|
283
|
fossil wiki list --technote --show-technote-ids |
|
284
|
set technoteidlist [split $RESULT "\n"] |
|
285
|
test wiki-38 {[llength $technotelist] == 8} |
|
286
|
for {set i 0} {$i < [llength $technotelist]} {incr i} { |
|
287
|
set match "???????????????????????????????????????? " |
|
288
|
append match [lindex $technotelist $i] |
|
289
|
test "wiki-39-$i" {[string match $match [lindex $technoteidlist $i]]} |
|
290
|
} |
|
291
|
|
|
292
|
############################################################################### |
|
293
|
# Create new tech note with a old timestamp so that it is oldest and then check that |
|
294
|
# the contents of the oldest tech note (by tech note id, both full and short) match up |
|
295
|
write_file f12 "A really old tech note" |
|
296
|
fossil wiki create {Old tech note} f12 --technote {2001-07-07 09:08:07} |
|
297
|
fossil wiki list --technote --show-technote-ids |
|
298
|
set technotelist [split $RESULT "\n"] |
|
299
|
set anoldtechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0] |
|
300
|
fossil wiki export a12 --technote $anoldtechnoteid |
|
301
|
test wiki-40 {[similar_file f12 a12]} |
|
302
|
|
|
303
|
############################################################################### |
|
304
|
# Also check that we can specify a prefix of the tech note id (note: with |
|
305
|
# 9 items in the tech note at this point there is a chance of a collision. |
|
306
|
# However with a 20 character prefix the chance of the collision is |
|
307
|
# approximately 1 in 10^22 so this test ignores that possibility.) |
|
308
|
fossil wiki export a12.1 --technote [string range $anoldtechnoteid 0 20] |
|
309
|
test wiki-41 {[similar_file f12 a12.1]} |
|
310
|
|
|
311
|
############################################################################### |
|
312
|
# Now we need to force a collision in the first four characters of the tech |
|
313
|
# note id if we don't already have one so we can check we get an error if the |
|
314
|
# tech note id is ambiguous |
|
315
|
set idcounts [dict create] |
|
316
|
set maxcount 0 |
|
317
|
fossil wiki list --technote --show-technote-ids |
|
318
|
set technotelist [split $RESULT "\n"] |
|
319
|
for {set i 0} {$i < [llength $technotelist]} {incr i} { |
|
320
|
set fullid [lindex $technotelist $i] |
|
321
|
set id [string range $fullid 0 3] |
|
322
|
dict incr idcounts $id |
|
323
|
if {[dict get $idcounts $id] > $maxcount} { |
|
324
|
set maxid $id |
|
325
|
incr maxcount |
|
326
|
} |
|
327
|
} |
|
328
|
# get i so that, as a julian date, it is in the 1800s, i.e., older than |
|
329
|
# any other tech note, but after 1 AD |
|
330
|
set i 2400000 |
|
331
|
while {$maxcount < 2} { |
|
332
|
# keep getting older |
|
333
|
incr i -1 |
|
334
|
write_file f13 "A tech note with timestamp of jday=$i" |
|
335
|
fossil wiki create "timestamp of $i" f13 --technote "$i" |
|
336
|
fossil wiki list --technote --show-technote-ids |
|
337
|
set technotelist [split $RESULT "\n"] |
|
338
|
set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0] |
|
339
|
set id [string range $oldesttechnoteid 0 3] |
|
340
|
dict incr idcounts $id |
|
341
|
if {[dict get $idcounts $id] > $maxcount} { |
|
342
|
set maxid $id |
|
343
|
incr maxcount |
|
344
|
} |
|
345
|
} |
|
346
|
# Save the duplicate id for this and later tests |
|
347
|
set duplicateid $maxid |
|
348
|
fossil wiki export a13 --technote $duplicateid -expectError |
|
349
|
test wiki-42 {$CODE != 0} |
|
350
|
|
|
351
|
############################################################################### |
|
352
|
# Check we can update technote by its id |
|
353
|
write_file f14 "Updated text for the really old tech note" |
|
354
|
fossil wiki commit {Old tech note} f14 --technote $anoldtechnoteid |
|
355
|
fossil wiki export a14 --technote $anoldtechnoteid |
|
356
|
test wiki-43 {[similar_file f14 a14]} |
|
357
|
|
|
358
|
############################################################################### |
|
359
|
# Check we can add attachments to a technote by its id |
|
360
|
fossil attachment add fa --technote $anoldtechnoteid |
|
361
|
test wiki-44 {$CODE == 0} |
|
362
|
|
|
363
|
############################################################################### |
|
364
|
# Also check that we can specify a prefix of the tech note id |
|
365
|
write_file f15 "Updated text for the really old tech note specified by its id" |
|
366
|
fossil wiki commit {Old tech note} f15 --technote [string range $anoldtechnoteid 0 20] |
|
367
|
fossil wiki export a15 --technote $anoldtechnoteid |
|
368
|
test wiki-45 {[similar_file f15 a15]} |
|
369
|
|
|
370
|
############################################################################### |
|
371
|
# Check we can add attachments to a technote by a prefix of its id |
|
372
|
fossil attachment add fa --technote [string range $anoldtechnoteid 0 20] |
|
373
|
test wiki-46 {$CODE == 0} |
|
374
|
|
|
375
|
############################################################################### |
|
376
|
# And we get an error for the ambiguous tech note id |
|
377
|
fossil wiki commit {Old tech note} f15 --technote $duplicateid -expectError |
|
378
|
test wiki-47 {$CODE != 0} |
|
379
|
fossil attachment add fa --technote $duplicateid -expectError |
|
380
|
test wiki-48 {$CODE != 0} |
|
381
|
|
|
382
|
############################################################################### |
|
383
|
# Check the default mimetype is text/x-fossil-wiki |
|
384
|
test wiki-49 {[get_mime_type tcltest] == "text/x-fossil-wiki"} |
|
385
|
|
|
386
|
############################################################################### |
|
387
|
# Check long form of the mimetypes are recorded correctly |
|
388
|
fossil wiki create tcltest-x-fossil f1 -mimetype text/x-fossil-wiki |
|
389
|
test wiki-50 {[get_mime_type tcltest-x-fossil] == "text/x-fossil-wiki"} |
|
390
|
fossil wiki create tcltest-x-markdown f1 -mimetype text/x-markdown |
|
391
|
test wiki-51 {[get_mime_type tcltest-x-markdown] == "text/x-markdown"} |
|
392
|
fossil wiki create tcltest-plain f1 -mimetype text/plain |
|
393
|
test wiki-52 {[get_mime_type tcltest-plain] == "text/plain"} |
|
394
|
fossil wiki create tcltest-x-random f1 -mimetype text/x-random |
|
395
|
test wiki-53 {[get_mime_type tcltest-x-random] == "text/x-fossil-wiki"} |
|
396
|
|
|
397
|
############################################################################### |
|
398
|
# Check short form of the mimetypes are recorded correctly |
|
399
|
fossil wiki create tcltest-x-fossil-short f1 -mimetype wiki |
|
400
|
test wiki-54 {[get_mime_type tcltest-x-fossil-short] == "text/x-fossil-wiki"} |
|
401
|
fossil wiki create tcltest-x-markdown-short f1 -mimetype markdown |
|
402
|
test wiki-55 {[get_mime_type tcltest-x-markdown-short] == "text/x-markdown"} |
|
403
|
fossil wiki create tcltest-plain-short f1 -mimetype plain |
|
404
|
test wiki-56 {[get_mime_type tcltest-plain-short] == "text/plain"} |
|
405
|
fossil wiki create tcltest-x-random-short f1 -mimetype random |
|
406
|
test wiki-57 {[get_mime_type tcltest-x-random-short] == "text/x-fossil-wiki"} |
|
407
|
|
|
408
|
|
|
409
|
############################################################################### |
|
410
|
test_cleanup |
|
411
|
|
|
412
|
|