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>
10 # License: GPL v2 or later
12 # tests for git-remote-mediawiki
14 test_description
='Test the Git Mediawiki remote helper: git push and git pull simple test cases'
17 .
$TEST_DIRECTORY/test-lib.sh
23 test_git_reimport
() {
24 git
-c remote.origin.dumbPush
=true push
&&
25 git
-c remote.origin.mediaImport
=true pull
--rebase
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
35 test_expect_failure
'git push can upload media (File:) files' '
37 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
40 echo "hello world" >Foo.txt &&
42 git commit -m "add a text file" &&
44 "$PERL_PATH" -e "print STDOUT \"binary content: \".chr(255);" >Foo.txt &&
46 git commit -m "add a text file with binary content" &&
51 test_expect_failure
'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_path_is_file mw_dir_clone/Foo.txt &&
59 test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt
62 test_expect_success
'git push can upload media (File:) files containing valid UTF-8' '
64 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
67 "$PERL_PATH" -e "print STDOUT \"UTF-8 content: éèàéê€.\";" >Bar.txt &&
69 git commit -m "add a text file with UTF-8 content" &&
74 test_expect_success
'git clone works on previously created wiki with media files containing valid UTF-8' '
75 test_when_finished "rm -rf mw_dir mw_dir_clone" &&
76 git clone -c remote.origin.mediaimport=true \
77 mediawiki::'"$WIKI_URL"' mw_dir_clone &&
78 test_cmp mw_dir_clone/Bar.txt mw_dir/Bar.txt
81 test_expect_success
'git push & pull work with locally renamed media files' '
83 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
84 test_when_finished "rm -fr mw_dir" &&
87 echo "A File" >Foo.txt &&
89 git commit -m "add a file" &&
90 git mv Foo.txt Bar.txt &&
91 git commit -m "Rename a file" &&
93 echo "A File" >expect &&
94 test_cmp expect Bar.txt &&
95 test_path_is_missing Foo.txt
99 test_expect_success
'git push can propagate local page deletion' '
101 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
102 test_when_finished "rm -fr mw_dir" &&
105 test_path_is_missing Foo.mw &&
106 echo "hello world" >Foo.mw &&
108 git commit -m "Add the page Foo" &&
111 git commit -am "Delete the page Foo" &&
113 test_path_is_missing Foo.mw
117 test_expect_success
'git push can propagate local media file deletion' '
119 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
120 test_when_finished "rm -fr mw_dir" &&
123 echo "hello world" >Foo.txt &&
125 git commit -m "Add the text file Foo" &&
127 git commit -m "Delete the file Foo" &&
129 test_path_is_missing Foo.txt
133 # test failure: the file is correctly uploaded, and then deleted but
134 # as no page link to it, the import (which looks at page revisions)
135 # doesn't notice the file deletion on the wiki. We fetch the list of
136 # files from the wiki, but as the file is deleted, it doesn't appear.
137 test_expect_failure
'git pull correctly imports media file deletion when no page link to it' '
139 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
140 test_when_finished "rm -fr mw_dir" &&
143 echo "hello world" >Foo.txt &&
145 git commit -m "Add the text file Foo" &&
148 git commit -m "Delete the file Foo" &&
150 test_path_is_missing Foo.txt
154 test_expect_success
'git push properly warns about insufficient permissions' '
156 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
157 test_when_finished "rm -fr mw_dir" &&
160 echo "A File" >foo.forbidden &&
161 git add foo.forbidden &&
162 git commit -m "add a file" &&
164 test_i18ngrep "foo.forbidden is not a permitted file" actual
168 test_expect_success
'setup a repository with media files' '
170 wiki_editpage testpage "I am linking a file [[File:File.txt]]" false &&
171 echo "File content" >File.txt &&
172 wiki_upload_file File.txt &&
173 echo "Another file content" >AnotherFile.txt &&
174 wiki_upload_file AnotherFile.txt
177 test_expect_success
'git clone works with one specific page cloned and mediaimport=true' '
178 git clone -c remote.origin.pages=testpage \
179 -c remote.origin.mediaimport=true \
180 mediawiki::'"$WIKI_URL"' mw_dir_15 &&
181 test_when_finished "rm -rf mw_dir_15" &&
182 test_contains_N_files mw_dir_15 3 &&
183 test_path_is_file mw_dir_15/Testpage.mw &&
184 test_path_is_file mw_dir_15/File:File.txt.mw &&
185 test_path_is_file mw_dir_15/File.txt &&
186 test_path_is_missing mw_dir_15/Main_Page.mw &&
187 test_path_is_missing mw_dir_15/File:AnotherFile.txt.mw &&
188 test_path_is_missing mw_dir_15/AnothetFile.txt &&
189 wiki_check_content mw_dir_15/Testpage.mw Testpage &&
190 test_cmp mw_dir_15/File.txt File.txt
193 test_expect_success
'git clone works with one specific page cloned and mediaimport=false' '
194 test_when_finished "rm -rf mw_dir_16" &&
195 git clone -c remote.origin.pages=testpage \
196 mediawiki::'"$WIKI_URL"' mw_dir_16 &&
197 test_contains_N_files mw_dir_16 1 &&
198 test_path_is_file mw_dir_16/Testpage.mw &&
199 test_path_is_missing mw_dir_16/File:File.txt.mw &&
200 test_path_is_missing mw_dir_16/File.txt &&
201 test_path_is_missing mw_dir_16/Main_Page.mw &&
202 wiki_check_content mw_dir_16/Testpage.mw Testpage
205 # should behave like mediaimport=false
206 test_expect_success
'git clone works with one specific page cloned and mediaimport unset' '
207 test_when_finished "rm -fr mw_dir_17" &&
208 git clone -c remote.origin.pages=testpage \
209 mediawiki::'"$WIKI_URL"' mw_dir_17 &&
210 test_contains_N_files mw_dir_17 1 &&
211 test_path_is_file mw_dir_17/Testpage.mw &&
212 test_path_is_missing mw_dir_17/File:File.txt.mw &&
213 test_path_is_missing mw_dir_17/File.txt &&
214 test_path_is_missing mw_dir_17/Main_Page.mw &&
215 wiki_check_content mw_dir_17/Testpage.mw Testpage