]> git.ipfire.org Git - thirdparty/git.git/blob - contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
remote-mediawiki tests: use the login/password variables
[thirdparty/git.git] / contrib / mw-to-git / t / t9363-mw-to-git-export-import.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2012
4 # Charles Roussel <charles.roussel@ensimag.imag.fr>
5 # Simon Cathebras <simon.cathebras@ensimag.imag.fr>
6 # Julien Khayat <julien.khayat@ensimag.imag.fr>
7 # Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>
8 # Simon Perrat <simon.perrat@ensimag.imag.fr>
9 #
10 # License: GPL v2 or later
11
12 # tests for git-remote-mediawiki
13
14 test_description='Test the Git Mediawiki remote helper: git push and git pull simple test cases'
15
16 . ./test-gitmw-lib.sh
17 . $TEST_DIRECTORY/test-lib.sh
18
19
20 test_check_precond
21
22
23 test_git_reimport () {
24 git -c remote.origin.dumbPush=true push &&
25 git -c remote.origin.mediaImport=true pull --rebase
26 }
27
28 # Don't bother with permissions, be administrator by default
29 test_expect_success 'setup config' '
30 git config --global remote.origin.mwLogin "$WIKI_ADMIN" &&
31 git config --global remote.origin.mwPassword "$WIKI_PASSW" &&
32 test_might_fail git config --global --unset remote.origin.mediaImport
33 '
34
35 test_expect_success 'git push can upload media (File:) files' '
36 wiki_reset &&
37 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
38 (
39 cd mw_dir &&
40 echo "hello world" >Foo.txt &&
41 git add Foo.txt &&
42 git commit -m "add a text file" &&
43 git push &&
44 "$PERL_PATH" -e "print STDOUT \"binary content: \".chr(255);" >Foo.txt &&
45 git add Foo.txt &&
46 git commit -m "add a text file with binary content" &&
47 git push
48 )
49 '
50
51 test_expect_success 'git clone works on previously created wiki with media files' '
52 test_when_finished "rm -rf mw_dir mw_dir_clone" &&
53 git clone -c remote.origin.mediaimport=true \
54 mediawiki::'"$WIKI_URL"' mw_dir_clone &&
55 test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt &&
56 (cd mw_dir_clone && git checkout HEAD^) &&
57 (cd mw_dir && git checkout HEAD^) &&
58 test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt
59 '
60
61 test_expect_success 'git push can upload media (File:) files containing valid UTF-8' '
62 wiki_reset &&
63 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
64 (
65 cd mw_dir &&
66 "$PERL_PATH" -e "print STDOUT \"UTF-8 content: éèàéê€.\";" >Bar.txt &&
67 git add Bar.txt &&
68 git commit -m "add a text file with UTF-8 content" &&
69 git push
70 )
71 '
72
73 test_expect_success 'git clone works on previously created wiki with media files containing valid UTF-8' '
74 test_when_finished "rm -rf mw_dir mw_dir_clone" &&
75 git clone -c remote.origin.mediaimport=true \
76 mediawiki::'"$WIKI_URL"' mw_dir_clone &&
77 test_cmp mw_dir_clone/Bar.txt mw_dir/Bar.txt
78 '
79
80 test_expect_success 'git push & pull work with locally renamed media files' '
81 wiki_reset &&
82 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
83 test_when_finished "rm -fr mw_dir" &&
84 (
85 cd mw_dir &&
86 echo "A File" >Foo.txt &&
87 git add Foo.txt &&
88 git commit -m "add a file" &&
89 git mv Foo.txt Bar.txt &&
90 git commit -m "Rename a file" &&
91 test_git_reimport &&
92 echo "A File" >expect &&
93 test_cmp expect Bar.txt &&
94 test_path_is_missing Foo.txt
95 )
96 '
97
98 test_expect_success 'git push can propagate local page deletion' '
99 wiki_reset &&
100 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
101 test_when_finished "rm -fr mw_dir" &&
102 (
103 cd mw_dir &&
104 test_path_is_missing Foo.mw &&
105 echo "hello world" >Foo.mw &&
106 git add Foo.mw &&
107 git commit -m "Add the page Foo" &&
108 git push &&
109 rm -f Foo.mw &&
110 git commit -am "Delete the page Foo" &&
111 test_git_reimport &&
112 test_path_is_missing Foo.mw
113 )
114 '
115
116 test_expect_success 'git push can propagate local media file deletion' '
117 wiki_reset &&
118 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
119 test_when_finished "rm -fr mw_dir" &&
120 (
121 cd mw_dir &&
122 echo "hello world" >Foo.txt &&
123 git add Foo.txt &&
124 git commit -m "Add the text file Foo" &&
125 git rm Foo.txt &&
126 git commit -m "Delete the file Foo" &&
127 test_git_reimport &&
128 test_path_is_missing Foo.txt
129 )
130 '
131
132 # test failure: the file is correctly uploaded, and then deleted but
133 # as no page link to it, the import (which looks at page revisions)
134 # doesn't notice the file deletion on the wiki. We fetch the list of
135 # files from the wiki, but as the file is deleted, it doesn't appear.
136 test_expect_failure 'git pull correctly imports media file deletion when no page link to it' '
137 wiki_reset &&
138 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
139 test_when_finished "rm -fr mw_dir" &&
140 (
141 cd mw_dir &&
142 echo "hello world" >Foo.txt &&
143 git add Foo.txt &&
144 git commit -m "Add the text file Foo" &&
145 git push &&
146 git rm Foo.txt &&
147 git commit -m "Delete the file Foo" &&
148 test_git_reimport &&
149 test_path_is_missing Foo.txt
150 )
151 '
152
153 test_expect_success 'git push properly warns about insufficient permissions' '
154 wiki_reset &&
155 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
156 test_when_finished "rm -fr mw_dir" &&
157 (
158 cd mw_dir &&
159 echo "A File" >foo.forbidden &&
160 git add foo.forbidden &&
161 git commit -m "add a file" &&
162 git push 2>actual &&
163 test_i18ngrep "foo.forbidden is not a permitted file" actual
164 )
165 '
166
167 test_expect_success 'setup a repository with media files' '
168 wiki_reset &&
169 wiki_editpage testpage "I am linking a file [[File:File.txt]]" false &&
170 echo "File content" >File.txt &&
171 wiki_upload_file File.txt &&
172 echo "Another file content" >AnotherFile.txt &&
173 wiki_upload_file AnotherFile.txt
174 '
175
176 test_expect_success 'git clone works with one specific page cloned and mediaimport=true' '
177 git clone -c remote.origin.pages=testpage \
178 -c remote.origin.mediaimport=true \
179 mediawiki::'"$WIKI_URL"' mw_dir_15 &&
180 test_when_finished "rm -rf mw_dir_15" &&
181 test_contains_N_files mw_dir_15 3 &&
182 test_path_is_file mw_dir_15/Testpage.mw &&
183 test_path_is_file mw_dir_15/File:File.txt.mw &&
184 test_path_is_file mw_dir_15/File.txt &&
185 test_path_is_missing mw_dir_15/Main_Page.mw &&
186 test_path_is_missing mw_dir_15/File:AnotherFile.txt.mw &&
187 test_path_is_missing mw_dir_15/AnothetFile.txt &&
188 wiki_check_content mw_dir_15/Testpage.mw Testpage &&
189 test_cmp mw_dir_15/File.txt File.txt
190 '
191
192 test_expect_success 'git clone works with one specific page cloned and mediaimport=false' '
193 test_when_finished "rm -rf mw_dir_16" &&
194 git clone -c remote.origin.pages=testpage \
195 mediawiki::'"$WIKI_URL"' mw_dir_16 &&
196 test_contains_N_files mw_dir_16 1 &&
197 test_path_is_file mw_dir_16/Testpage.mw &&
198 test_path_is_missing mw_dir_16/File:File.txt.mw &&
199 test_path_is_missing mw_dir_16/File.txt &&
200 test_path_is_missing mw_dir_16/Main_Page.mw &&
201 wiki_check_content mw_dir_16/Testpage.mw Testpage
202 '
203
204 # should behave like mediaimport=false
205 test_expect_success 'git clone works with one specific page cloned and mediaimport unset' '
206 test_when_finished "rm -fr mw_dir_17" &&
207 git clone -c remote.origin.pages=testpage \
208 mediawiki::'"$WIKI_URL"' mw_dir_17 &&
209 test_contains_N_files mw_dir_17 1 &&
210 test_path_is_file mw_dir_17/Testpage.mw &&
211 test_path_is_missing mw_dir_17/File:File.txt.mw &&
212 test_path_is_missing mw_dir_17/File.txt &&
213 test_path_is_missing mw_dir_17/Main_Page.mw &&
214 wiki_check_content mw_dir_17/Testpage.mw Testpage
215 '
216
217 test_done