elexis-wiki-interface 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +25 -1
  4. data/README.textile +2 -3
  5. data/bin/wiki_pull +6 -3
  6. data/bin/wiki_pull_and_commit +38 -0
  7. data/bin/wiki_push +2 -2
  8. data/elexis-wiki-interface.gemspec +4 -3
  9. data/history.textile +14 -0
  10. data/lib/elexis/wiki/images.rb +338 -0
  11. data/lib/elexis/wiki/interface.rb +152 -2
  12. data/lib/elexis/wiki/version.rb +5 -0
  13. data/lib/elexis/wiki/workspace.rb +286 -0
  14. data/spec/data/images/ch.elexis.agenda/.project +36 -0
  15. data/spec/data/images/ch.elexis.agenda/META-INF/MANIFEST.MF +33 -0
  16. data/spec/data/images/ch.elexis.agenda/doc/fixmedikationaufruf.png +0 -0
  17. data/spec/data/images/ch.elexis.agenda/plugin.properties +8 -0
  18. data/spec/data/images/ch.elexis.agenda/plugin.xml +209 -0
  19. data/spec/data/images/ch.elexis.agenda/plugin_de.properties +8 -0
  20. data/spec/data/images/ch.elexis.agenda/plugin_en.properties +8 -0
  21. data/spec/data/images/ch.elexis.agenda/plugin_fr.properties +7 -0
  22. data/spec/data/images/ch.elexis.core.application.feature/.project +23 -0
  23. data/spec/data/images/ch.elexis.core.application.feature/build.properties +1 -0
  24. data/spec/data/images/ch.elexis.core.application.feature/feature.xml +699 -0
  25. data/spec/data/images/ch.elexis.core.application.feature/pom.xml +12 -0
  26. data/spec/data/images/ch.elexis.icpc/.project +28 -0
  27. data/spec/data/images/ch.elexis.icpc/META-INF/MANIFEST.MF +26 -0
  28. data/spec/data/images/ch.elexis.icpc/doc/Com.hilotec.elexis.opendocument_anleitung_opendocument_1.png +0 -0
  29. data/spec/data/images/ch.elexis.icpc/doc/FixmedikationAufruf.png +0 -0
  30. data/spec/data/images/ch.elexis.icpc/doc/Icpc8.png +0 -0
  31. data/spec/data/images/ch.elexis.icpc/doc/ch.elexis.icpc_icpc1.png +0 -0
  32. data/spec/data/images/ch.elexis.icpc/doc/disposan.gif +0 -0
  33. data/spec/data/images/ch.elexis.icpc/doc/elexis_logo.jpg +0 -0
  34. data/spec/data/images/ch.elexis.icpc/doc/favicon_green.png +0 -0
  35. data/spec/data/images/ch.elexis.icpc/doc/icpc0.png +0 -0
  36. data/spec/data/images/ch.elexis.icpc/doc/icpc1.png +0 -0
  37. data/spec/data/images/ch.elexis.icpc/doc/icpc2.png +0 -0
  38. data/spec/data/images/ch.elexis.icpc/doc/icpc3.png +0 -0
  39. data/spec/data/images/ch.elexis.icpc/doc/icpc4.png +0 -0
  40. data/spec/data/images/ch.elexis.icpc/doc/icpc5.png +0 -0
  41. data/spec/data/images/ch.elexis.icpc/doc/icpc6.png +0 -0
  42. data/spec/data/images/ch.elexis.icpc/doc/icpc7.png +0 -0
  43. data/spec/data/images/ch.elexis.icpc/doc/icpc9.png +0 -0
  44. data/spec/data/images/ch.elexis.icpc/doc/kabel.png +0 -0
  45. data/spec/data/images/ch.elexis.icpc/doc/medevit_inbox1.png +0 -0
  46. data/spec/data/images/ch.elexis.icpc/doc/test.mediawiki +15 -0
  47. data/spec/data/images/ch.elexis.icpc/doc/test2.mediawiki +19 -0
  48. data/spec/data/images/ch.elexis.icpc/plugin.xml +74 -0
  49. data/spec/data/images/ch.elexis.notes/.project +34 -0
  50. data/spec/data/images/ch.elexis.notes/META-INF/MANIFEST.MF +17 -0
  51. data/spec/data/images/ch.elexis.notes/doc/At.medevit.medelexis.text.msword:WordBriefe.png +0 -0
  52. data/spec/data/images/ch.elexis.notes/doc/Ch.medelexis.openoffice:TextverarbeitungSettings.png +0 -0
  53. data/spec/data/images/ch.elexis.notes/doc/Icpc1.png +0 -0
  54. data/spec/data/images/ch.elexis.notes/doc/kabel.png +0 -0
  55. data/spec/data/images/ch.elexis.notes/doc/medidirect:use2.png +0 -0
  56. data/spec/data/images/ch.elexis.notes/doc/test.mediawiki +13 -0
  57. data/spec/data/images/ch.elexis.notes/plugin.properties +1 -0
  58. data/spec/data/images/ch.elexis.notes/plugin.xml +36 -0
  59. data/spec/data/images/ch.elexis.notes/plugin_de.properties +3 -0
  60. data/spec/data/images/ch.elexis.notes/plugin_en.properties +3 -0
  61. data/spec/data/images/ch.elexis.notes/plugin_fr.properties +3 -0
  62. data/spec/data/images/doc_de/.project +42 -0
  63. data/spec/data/images/elexis_api_test.png +0 -0
  64. data/spec/data/push/elexis_api_test.png +0 -0
  65. data/spec/images_spec.rb +236 -0
  66. data/spec/interface_spec.rb +118 -0
  67. data/spec/pull_spec.rb +16 -5
  68. metadata +128 -13
  69. data/History.txt +0 -41
  70. data/bin/wiki_pull_daily +0 -28
  71. data/lib/elexis/wiki/interface/version.rb +0 -7
  72. data/lib/elexis/wiki/interface/workspace.rb +0 -404
  73. data/spec/push_spec.rb +0 -31
  74. data/spec/update_images_spec.rb +0 -95
  75. data/spec/user_spec.rb +0 -32
@@ -1,404 +0,0 @@
1
- #encoding: utf-8
2
-
3
- require 'eclipse/plugin'
4
- require 'media_wiki' # TODO: port it to require 'mediawiki_api'
5
- require 'fileutils'
6
- require 'open-uri'
7
- require 'time'
8
- require 'yaml'
9
-
10
- module Elexis
11
- module Wiki
12
- module Interface
13
- ImagePrefix = /Datei:|Image:/i
14
- ImagePattern = /(\[Datei:|\[Image:)([\w\.\:\/]*)/i
15
- TestPattern = /[\._]test[s]*$/i
16
- $ws_errors = []
17
-
18
- def Interface.return_canonical_image_name(pagename, filename)
19
- pagename = pagename.sub('.feature.feature.group', '')
20
- short = File.basename(filename.downcase.sub(ImagePrefix, ''))
21
- short = short.split(':')[-1]
22
- /[:\/]/.match(filename) ? pagename + '/' + short : short
23
- end
24
-
25
- def Interface.remove_image_ignoring_case(filename)
26
- files = Dir.glob(filename, File::FNM_CASEFOLD)
27
- return if files.size == 1
28
- files.each{
29
- |file|
30
- next if File.basename(file).eql?(File.basename(filename))
31
- cmd = "git rm -f #{file}"
32
- res = system(cmd)
33
- }
34
- end
35
-
36
- def Interface.fix_image_locations(filename, pagename)
37
- return unless File.exists?(filename)
38
- pagename = pagename.sub('.feature.feature.group', '')
39
- lines = IO.readlines(filename)
40
- dirName = File.dirname(filename)
41
- newLines = ''
42
- showDetails = $VERBOSE
43
- if /icpc.mediawiki/i.match(filename)
44
- showDetails = true
45
- end
46
- lines.each{
47
- |line|
48
- unless m =ImagePattern.match(line)
49
- newLines += line
50
- else
51
- new_name = Interface.return_canonical_image_name(pagename, m[2])
52
- unless new_name.eql?(File.basename(new_name))
53
- FileUtils.ln_s('.', File.dirname(new_name), :verbose => true) unless File.exists?(File.dirname(new_name))
54
- end
55
- simpleName = File.join(dirName, File.basename(new_name))
56
- if files = Dir.glob(simpleName, File::FNM_CASEFOLD) and files.size >= 1
57
- new_line = line.sub(m[2], new_name)
58
- newLines += new_line
59
- Interface.remove_image_ignoring_case(simpleName)
60
- else
61
- next if defined?(RSpec)
62
- msg = "Could not find image for #{m[0]} searched for #{simpleName} in #{Dir.pwd}. files are #{files}"
63
- puts msg
64
- $ws_errors << msg
65
- newLines += line.sub(ImagePattern, "#{m[1]}#{m[2].sub(':', '_')}")
66
- end
67
- end
68
- }
69
- File.open(filename, "w") {|f| f.write newLines.gsub(/\[\[Datei:|\[\[Image:/i, '[[File:')}
70
- end
71
-
72
- class Workspace
73
- attr_reader :info, :mw, :wiki, :views_missing_documentation, :perspectives_missing_documentation, :features_missing_documentation,
74
- :doc_project, :features, :info
75
- def initialize(dir, wiki = 'http://wiki.elexis.info/api.php')
76
- $ws_errors = []
77
- @wiki = wiki
78
- @mw = MediaWiki::Gateway.new(@wiki)
79
- @info = Eclipse::Workspace.new(dir)
80
- @doc_projects = Dir.glob(File.join(dir, "doc_??", ".project"))
81
- @info.parse_sub_dirs
82
- @info.show if $VERBOSE
83
- @views_missing_documentation =[]
84
- @perspectives_missing_documentation =[]
85
- @features_missing_documentation =[]
86
- end
87
- def show_missing(details = false)
88
- puts
89
- msg = "Show errors for #{@info.workspace_dir}"
90
- puts "-" * msg.size
91
- puts msg
92
- puts "-" * msg.size
93
-
94
- if views_missing_documentation.size and
95
- features_missing_documentation.size == 0 and
96
- perspectives_missing_documentation.size == 0
97
- puts "Eclipse-Workspace #{@info.workspace_dir} seems to have documented all views, features, plugins and perspectives"
98
- else
99
- puts "Eclipse-Workspace #{@info.workspace_dir} needs documenting "
100
- if views_missing_documentation.size > 0
101
- puts " #{views_missing_documentation.size} views"
102
- puts " #{views_missing_documentation.inspect}" if details
103
- end
104
- if features_missing_documentation.size > 0
105
- puts " #{features_missing_documentation.size} features"
106
- puts " #{features_missing_documentation.inspect}" if details
107
- end
108
- if perspectives_missing_documentation.size > 0
109
- puts " #{perspectives_missing_documentation.size} perspectives"
110
- puts " #{perspectives_missing_documentation.inspect}" if details
111
- end
112
- end
113
- puts $ws_errors
114
- puts "Displayed #{$ws_errors.size} errors"
115
- end
116
- def push_doc_dir(id, docDir = nil)
117
- docDir ||= File.join(@info.workspace_dir, id, 'doc')
118
- to_push = Dir.glob("#{docDir}/*.mediawiki")
119
- to_push.each{
120
- |file|
121
- # verify that locally committed file is newer than the page in the wiki
122
- # verify that the content after the push matches the local content
123
- my_new_content = File.new(file).read
124
- to_verify = my_new_content.gsub(/\n+/,"\n").chomp
125
- pagename = File.basename(file, '.mediawiki').capitalize
126
- last_wiki_modification = get_page_modification_time(pagename)
127
- last_git_modification = get_git_modification(file)
128
- unless last_wiki_modification
129
- puts "first upload #{File.basename(file)} last_git_modification is #{last_git_modification}" if $VERBOSE
130
- @mw.create(pagename, my_new_content,{:overwrite => true, :summary => "pushed by #{File.basename(__FILE__)}" })
131
- else
132
- got = @mw.get(pagename).gsub(/\n+/,"\n")
133
- if got == to_verify
134
- puts "No changes to push for #{file}"
135
- next
136
- end
137
- @mw.edit(pagename, to_verify,{:overwrite => true, :summary => "pushed by #{File.basename(__FILE__)}" })
138
- puts "Uploaded #{file} to #{pagename}" # if $VERBOSE
139
- end
140
- }
141
- if to_push.size > 0 # then upload also all *.png files
142
- images_to_push = Dir.glob("#{docDir}/*.png")
143
- images_to_push.each{
144
- |image|
145
- if /:/.match(File.basename(image))
146
- puts "You may not add a file containg ':' or it will break git for Windows. Remove/rename #{image}"
147
- exit
148
- end
149
-
150
- git_mod = get_git_modification(image)
151
- wiki_mod = get_image_modification_name(image)
152
-
153
- if wiki_mod == nil
154
- puts "first upload #{File.basename(image)} as last_git_modification is #{git_mod}" if $VERBOSE
155
- else
156
- to_verify = File.new(image, 'rb').read
157
- got = @mw.get(File.basename(image))
158
- if got == to_verify
159
- puts "nothing to upload for #{image}" if $VERBOSE
160
- next
161
- end
162
- end
163
- begin
164
- res = @mw.upload(image, 'filename' => File.basename(image))
165
- puts "res für #{image} exists? #{File.exists?(image)} ist #{res.to_s}" if $VERBOSE
166
- rescue MediaWiki::APIError => e
167
- puts "rescue für #{image} #{e}" # if $VERBOSE
168
- if /verification-error/.match(e.to_s)
169
- puts "If you received API error: code 'verification-error', info 'This file did not pass file verification'"
170
- puts "this means that the file type and content do not match, e.g. you have a *png file but in reality it is a JPEG file."
171
- puts "In this case convert file.png file.png fixes this problem"
172
- end
173
- end
174
- }
175
- end
176
- end
177
- def push
178
- check_config_file
179
- raise "must define wiki with user and password in #{@config_yml}" unless @user and @password and @wiki
180
- @mw.login(@user, @password)
181
- @doc_projects.each{
182
- |prj|
183
- dir = File.dirname(prj)
184
- push_doc_dir(File.basename(dir), dir)
185
- }
186
- @info.features.each{ |id, info| push_doc_dir(id) }
187
- @info.plugins.each{ |id,plugin| push_doc_dir(id) }
188
- end
189
-
190
- def get_git_modification(file)
191
- return nil unless File.exists?(file)
192
- git_time = `git log -1 --pretty=format:%ai #{file}`
193
- return nil unless git_time.length > 8
194
- Time.parse(git_time.chomp).utc
195
- end
196
-
197
- def get_page_modification_time(pagename)
198
- json_url = "#{@wiki}?action=query&format=json&prop=revisions&titles=#{pagename}&rvprop=timestamp"
199
- json = RestClient.get(json_url)
200
- wiki_json_timestamp_to_time(json, pagename)
201
- end
202
-
203
- def remove_image_files_with_id(id, info, docDir = nil)
204
- docDir ||= File.join(@info.workspace_dir, id, 'doc')
205
- files = Dir.glob(File.join(docDir, "#{id}_*jpg"), File::FNM_CASEFOLD) +
206
- Dir.glob(File.join(docDir, "#{id}_*gif"), File::FNM_CASEFOLD) +
207
- Dir.glob(File.join(docDir, "#{id}_*png"), File::FNM_CASEFOLD)
208
- system("git rm #{files.join(' ')}") if files.size > 0
209
- end
210
-
211
- def pull
212
- savedDir = Dir.pwd
213
- @doc_projects.each{
214
- |prj|
215
- dir = File.dirname(prj)
216
- get_content_from_wiki(dir, File.basename(dir))
217
- remove_image_files_with_id(File.basename(File.dirname(prj)), info, dir)
218
- } # unless defined?(RSpec)
219
-
220
- @info.plugins.each{
221
- |id, info|
222
- # next if not defined?(RSpec) and not /org.iatrix/i.match(id)
223
- puts "Pulling for plugin #{id}" if $VERBOSE
224
- pull_docs_views(info)
225
- pull_docs_plugins(info)
226
- pull_docs_perspectives(info)
227
- remove_image_files_with_id(id, info)
228
- }
229
-
230
- @info.features.each{
231
- |id, info|
232
- # next if not defined?(RSpec) and not /ehc|icp/i.match(id)
233
- puts "Pulling for feature #{id}" if $VERBOSE
234
- check_page_in_matrix(id)
235
- pull_docs_features(info)
236
- remove_image_files_with_id(id, info)
237
- }
238
-
239
- Dir.chdir(savedDir)
240
- end
241
-
242
- def perspectiveToPageName(perspective)
243
- # http://wiki.elexis.info/P_Abrechnungen
244
- name = 'P_'+ perspective.id.gsub(' ', '')
245
- puts "perspectiveToPageName for #{perspective.inspect} is '#{name}'" if $VERBOSE
246
- name
247
- end
248
- def viewToPageName(plugin_id, view)
249
- # für ch.elexis.agenda.views.TagesView (= view.id)
250
- # http://wiki.elexis.info/ChElexisAgendaViewsTagesview
251
- # wurde unter http://wiki.elexis.info/Hauptseite ein Link Agenda (= view.name) angelegt.
252
- # evtl. sollten wir testen, ob dieser Link vorhanden ist
253
- # http://wiki.elexis.info/ChElexisIcpcViewsEpisodesview
254
- comps = view.id.split('.')
255
- pageName = comps[0..-2].collect{|x| x.capitalize}.join + 'Views'+view.id.split('.').last.capitalize
256
- puts "viewToPageName for #{plugin_id}/#{view.id} is #{pageName}" if $VERBOSE
257
- pageName
258
- end
259
-
260
- def check_page_in_matrix(pagename, matrix_name = 'Matrix_3.0')
261
- puts Dir.pwd
262
- res = get_content_from_wiki('.', matrix_name)
263
- return true if res.index("[[#{pagename}]]") or res.index("[[#{pagename}.feature.group]]")
264
- $ws_errors << "#{matrix_name}: could not find #{pagename}"
265
- end
266
-
267
- private
268
- def wiki_json_timestamp_to_time(json, page_or_img)
269
- return nil unless json
270
- begin
271
- m = json.match(/timestamp['"]:['"]([^'"]+)/)
272
- return Time.parse(m[1]) if m
273
- end
274
- nil
275
- end
276
-
277
- def check_config_file
278
- possibleCfgs = ['/etc/elexis-wiki-interface/config.yml', File.join(Dir.pwd, 'config.yml'), ]
279
- possibleCfgs.each{ |cfg| @config_yml = cfg; break if File.exists?(cfg) }
280
- raise "need a config file #{possibleCfgs.join(' or ')} for wiki with user/password" unless File.exists?(@config_yml)
281
- yaml = YAML.load_file(@config_yml)
282
- @user = yaml['user']
283
- @password = yaml['password']
284
- @wiki = yaml['wiki']
285
- puts "MediWiki #{@wiki} user #{@user} with password #{@password}" if $VERBOSE
286
- end
287
-
288
- # http://wiki.elexis.info/api.php?action=query&format=json&list=allimages&ailimit=5&aiprop=timestamp&aiprefix=Ch.elexis.notes:config.png&*
289
- def get_image_modification_name(image)
290
- short_image = image.sub(ImagePrefix, '')
291
- json_url = "#{@wiki}?action=query&format=json&list=allimages&ailimit=5&aiprop=timestamp&iiprop=url&aiprefix=#{short_image}"
292
- json = RestClient.get(json_url)
293
- wiki_json_timestamp_to_time(json, image)
294
- end
295
-
296
- # helper function, as mediawiki-gateway does not handle this situation correctly
297
- def download_image_file(pageName, image)
298
- downloaded_image = File.basename(Interface.return_canonical_image_name(pageName, image))
299
- unless File.exist? downloaded_image
300
- # first search by pagename and imagename
301
- json_url = "#{@wiki}?action=query&format=json&list=allimages&ailimit=5&aiprefix=#{pageName}&aifrom=#{image.sub(ImagePrefix, '')}"
302
- json = RestClient.get(json_url)
303
- unless json
304
- puts "JSON: Could not fetch for image #{image} for #{pageName} using #{json_url}"
305
- return
306
- end
307
- begin
308
- answer = JSON.parse(json)
309
- image_url = nil
310
- image_url = answer['query'].first[1].first['url'] if answer['query'] and answer['query'].size >= 1 and answer['query'].first[1].size > 0
311
- unless image_url
312
- # as we did not find it search imagename only
313
- json_url = "#{@wiki}?action=query&format=json&list=allimages&ailimit=5&aifrom=#{image.sub(ImagePrefix, '')}"
314
- json = RestClient.get(json_url)
315
- if json
316
- answer = JSON.parse(json)
317
- image_url = answer['query'].first[1].first['url'] if answer['query'] and answer['query'].size >= 1 and answer['query'].first[1].size > 0
318
- end
319
- end
320
- if image_url
321
- m = /#{downloaded_image}/i.match(image_url)
322
- # downloaded_image = m[0] if m # Sometimes the filename is capitalized
323
- File.open(downloaded_image, 'w') do |file|
324
- file.write(open(image_url).read)
325
- end
326
- files = Dir.glob(downloaded_image, File::FNM_CASEFOLD)
327
- Interface.remove_image_ignoring_case(downloaded_image)
328
- else
329
- puts "skipping image #{image} for page #{pageName}"
330
- end
331
- rescue => e
332
- puts "JSON: Could not fetch for image #{image} for #{pageName} using #{json_url}"
333
- puts " was '#{json}'"
334
- puts " error was #{e.inspect}"
335
- end
336
- end
337
- puts "Downloaded image #{downloaded_image} #{File.size(downloaded_image)} bytes" if $VERBOSE and File.exists?(downloaded_image)
338
- end
339
-
340
- def get_content_from_wiki(out_dir, pageName)
341
- puts "get_content_from_wiki page #{pageName} -> #{out_dir}" if $VERBOSE
342
- out_name = File.join(out_dir, pageName + '.mediawiki')
343
- FileUtils.makedirs(out_dir) unless File.directory?(out_dir)
344
- savedDir = Dir.pwd
345
- Dir.chdir(out_dir)
346
- begin
347
- content = @mw.get(pageName)
348
- rescue MediaWiki::Gateway::Exception => e
349
- puts "Unable to get #{pageName} for #{out_dir} from #{File.dirname(@mw.wiki_url)}"
350
- return nil
351
- end
352
- if content
353
- ausgabe = File.open(out_name, 'w+') { |f| f.write content }
354
- @mw.images(pageName).each{
355
- |image|
356
- download_image_file(pageName, image.gsub(' ', '_'))
357
- break if defined?(RSpec) and not /icpc|ehc/i.match(pageName) # speed up RSpec
358
- }
359
- Elexis::Wiki::Interface.fix_image_locations(out_name, pageName)
360
- else
361
- puts "Could not fetch #{pageName} from #{@mw}" if $VERBOSE
362
- end
363
- Dir.chdir(savedDir)
364
- content
365
- end
366
- def pull_docs_views(plugin)
367
- id = plugin.symbolicName
368
- plugin.views.each{
369
- |id, view|
370
- pageName = viewToPageName(plugin.symbolicName, view)
371
- content = get_content_from_wiki(File.join(@info.workspace_dir, File.basename(plugin.jar_or_src), 'doc'), pageName)
372
- next if TestPattern.match(id)
373
- @views_missing_documentation << pageName unless content
374
- }
375
- end
376
- def pull_docs_perspectives(plugin)
377
- id = plugin.symbolicName
378
- plugin.perspectives.each{
379
- |id, perspective|
380
- pageName = perspectiveToPageName(perspective)
381
- content = get_content_from_wiki(File.join(@info.workspace_dir, File.basename(plugin.jar_or_src), 'doc'), pageName)
382
- next if TestPattern.match(id)
383
- @perspectives_missing_documentation << pageName unless content
384
- }
385
- end
386
- def pull_docs_plugins(plugin)
387
- id = plugin.symbolicName
388
- pageName = id.capitalize
389
- content = get_content_from_wiki(File.join(@info.workspace_dir, File.basename(plugin.jar_or_src), 'doc'), pageName)
390
- return if TestPattern.match(id)
391
- end
392
- def pull_docs_features(feature)
393
- id = feature.symbolicName
394
- pageName = id.capitalize
395
- content = get_content_from_wiki(File.join(@info.workspace_dir, id, 'doc'), pageName)
396
- unless content
397
- content = get_content_from_wiki(File.join(@info.workspace_dir, id, 'doc'), pageName.sub(/feature$/, 'feature.feature.group'))
398
- puts "pull_docs_features failed #{id} #{pageName}" unless content
399
- end
400
- end
401
- end
402
- end
403
- end
404
- end
data/spec/push_spec.rb DELETED
@@ -1,31 +0,0 @@
1
- #encoding : utf-8
2
- require 'spec_helper'
3
-
4
- require 'elexis/wiki/interface'
5
- require "elexis/wiki/interface/workspace"
6
-
7
- describe 'Plugin' do
8
-
9
- before :all do
10
- @dataDir = File.expand_path(File.join(File.dirname(__FILE__), 'data', 'push'))
11
- end
12
-
13
- before :each do
14
- end
15
-
16
- it "should push a test page to the wiki.elexis.info" do
17
- if ENV['TRAVIS']
18
- puts "Skipping some tests under travis"
19
- else
20
- hasConfig = File.exists?('/etc/elexis-wiki-interface/config.yml') or File.exists?(File.join(Dir.pwd, 'config.yml'))
21
- pending 'no config file' unless hasConfig
22
- search = "#{@dataDir}/**/*.mediawiki"
23
- mediawikis = Dir.glob(search)
24
- expect mediawikis.size == 1
25
- workspace = Elexis::Wiki::Interface::Workspace.new(@dataDir)
26
- workspace.push
27
- content = workspace.mw.get('test')
28
- expect content != nil
29
- end
30
- end
31
- end
@@ -1,95 +0,0 @@
1
- #encoding : utf-8
2
- require 'spec_helper'
3
-
4
- require 'elexis/wiki/interface'
5
- require "elexis/wiki/interface/workspace"
6
-
7
- describe 'ImageHandling' do
8
-
9
- before :all do
10
- @originDir = File.expand_path(File.join(File.dirname(__FILE__), 'data', 'push', 'ch.elexis.icpc'))
11
- @dataDir = File.expand_path(File.join(File.dirname(__FILE__), 'run', 'push'))
12
- FileUtils.rm_rf(@dataDir)
13
- FileUtils.makedirs(@dataDir)
14
- FileUtils.cp_r(@originDir, @dataDir, :preserve => true)
15
- end
16
-
17
- it "should return corret canonical_names for a plugin" do
18
- expected = "ch.elexis.icpc/icpc0.png"
19
- ["xxxx/icpc0.png",
20
- "icpc0.png",
21
- "ch.elexis.icpc/icpc0.png",
22
- "ch.elexis.icpc_icpc0.png",
23
- "ch.elexis.icpc:icpc0.png",
24
- ].each{ |variant|
25
- res = Elexis::Wiki::Interface.return_canonical_image_name("ch.elexis.icpc", expected)
26
- expect(res).to eq expected
27
- }
28
- end
29
-
30
- it "should return corret canonical_names for a feature" do
31
- expected = "com.hilotec.elexis.opendocument/anleitung_opendocument_1.png"
32
- [ "xxx/anleitung_opendocument_1.png",
33
- "com.hilotec.elexis.opendocument:anleitung_opendocument_1.png",
34
- "com.hilotec.elexis.opendocument/anleitung_opendocument_1.png",
35
- "com.hilotec.elexis.opendocument_anleitung_opendocument_1.png",
36
- ].each{ |variant|
37
- res = Elexis::Wiki::Interface.return_canonical_image_name("com.hilotec.elexis.opendocument", expected)
38
- expect(res).to eq expected
39
-
40
- res2 = Elexis::Wiki::Interface.return_canonical_image_name("com.hilotec.elexis.opendocument.feature.feature.group", expected)
41
- expect(res2).to eq expected
42
- }
43
- end
44
-
45
- it "should adapt correctly the image name being in in #{Dir.pwd}" do
46
- wiki_file = File.join(@dataDir, 'ch.elexis.icpc', 'doc', 'test.mediawiki')
47
- expect(File.exists?(wiki_file)).to eq true
48
- before = ['tag_one [[Image:ch.elexis.icpc:icpc1.png|image]]',
49
- 'tag_two [[Image:ch.elexis.icpc:icpc2.png|image]]',
50
- 'tag_three [[Image:icpc3.png|image]]',
51
- 'tag_four [[Datei:ch.elexis.icpc:icpc4.png|image]]',
52
- 'tag_five [[Datei:Ch.elexis.icpc:icpc5.png|image]]',
53
- ]
54
- original = IO.read(wiki_file)
55
- before.each{|string| expect(original).to include string }
56
-
57
- Elexis::Wiki::Interface.fix_image_locations(wiki_file, 'ch.elexis.icpc')
58
- after =['tag_one [[File:ch.elexis.icpc/icpc1.png|image]]',
59
- 'tag_two [[File:ch.elexis.icpc/icpc2.png|image]]',
60
- 'tag_three [[File:icpc3.png|image]]',
61
- 'tag_four [[File:ch.elexis.icpc/icpc4.png|image]]',
62
- 'tag_five [[File:ch.elexis.icpc/icpc5.png|image]]',
63
- ]
64
- changed = IO.read(wiki_file)
65
- after.each{|string| expect(changed).to include string }
66
- end
67
-
68
- it "should adapt allow the image names without an ID" do
69
- wiki_file = File.join(@dataDir, 'ch.elexis.icpc', 'doc', 'test.mediawiki')
70
- Dir.chdir(@dataDir)
71
-
72
- Elexis::Wiki::Interface.fix_image_locations(wiki_file, 'ch.elexis.icpc')
73
- after =['tag_three [[File:icpc3.png|image]]',
74
- ]
75
- changed = IO.read(wiki_file)
76
- after.each{|string| expect(changed).to include string }
77
- end
78
-
79
- it "should not add an EOL if nothing changed" do
80
- id = 'ch.elexis.core.application'
81
- @originDir = File.expand_path(File.join(File.dirname(__FILE__), 'data', 'push', id))
82
- @dataDir = File.expand_path(File.join(File.dirname(__FILE__), 'run', 'push'))
83
- FileUtils.rm_rf(@dataDir)
84
- FileUtils.makedirs(@dataDir)
85
- FileUtils.cp_r(@originDir, @dataDir, :preserve => true)
86
- wiki_file = File.join(@dataDir, id, 'doc', 'ChElexisViewsBestellblatt.mediawiki')
87
- orig_content = IO.read(wiki_file)
88
- Dir.chdir(@dataDir)
89
- Elexis::Wiki::Interface.fix_image_locations(wiki_file, id)
90
- changed = IO.read(wiki_file)
91
- expect(changed).to eql orig_content
92
- end
93
-
94
- end
95
-