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 WikiAdmin &&
31 git config --global remote.origin.mwPassword AdminPass &&
32 test_might_fail git config --global --unset remote.origin.mediaImport
35 test_expect_success
'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_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
61 test_expect_success
'git push & pull work with locally renamed media files' '
63 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
64 test_when_finished "rm -fr mw_dir" &&
67 echo "A File" >Foo.txt &&
69 git commit -m "add a file" &&
70 git mv Foo.txt Bar.txt &&
71 git commit -m "Rename a file" &&
73 echo "A File" >expect &&
74 test_cmp expect Bar.txt &&
75 test_path_is_missing Foo.txt
79 test_expect_success
'git push can propagate local page deletion' '
81 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
82 test_when_finished "rm -fr mw_dir" &&
85 test_path_is_missing Foo.mw &&
86 echo "hello world" >Foo.mw &&
88 git commit -m "Add the page Foo" &&
91 git commit -am "Delete the page Foo" &&
93 test_path_is_missing Foo.mw
97 test_expect_success
'git push can propagate local media file deletion' '
99 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
100 test_when_finished "rm -fr mw_dir" &&
103 echo "hello world" >Foo.txt &&
105 git commit -m "Add the text file Foo" &&
107 git commit -m "Delete the file Foo" &&
109 test_path_is_missing Foo.txt
113 # test failure: the file is correctly uploaded, and then deleted but
114 # as no page link to it, the import (which looks at page revisions)
115 # doesn't notice the file deletion on the wiki. We fetch the list of
116 # files from the wiki, but as the file is deleted, it doesn't appear.
117 test_expect_failure
'git pull correctly imports media file deletion when no page link to it' '
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" &&
128 git commit -m "Delete the file Foo" &&
130 test_path_is_missing Foo.txt
134 test_expect_success
'git push properly warns about insufficient permissions' '
136 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
137 test_when_finished "rm -fr mw_dir" &&
140 echo "A File" >foo.forbidden &&
141 git add foo.forbidden &&
142 git commit -m "add a file" &&
144 test_i18ngrep "foo.forbidden is not a permitted file" actual
148 test_expect_success
'setup a repository with media files' '
150 wiki_editpage testpage "I am linking a file [[File:File.txt]]" false &&
151 echo "File content" >File.txt &&
152 wiki_upload_file File.txt &&
153 echo "Another file content" >AnotherFile.txt &&
154 wiki_upload_file AnotherFile.txt
157 test_expect_success
'git clone works with one specific page cloned and mediaimport=true' '
158 git clone -c remote.origin.pages=testpage \
159 -c remote.origin.mediaimport=true \
160 mediawiki::'"$WIKI_URL"' mw_dir_15 &&
161 test_when_finished "rm -rf mw_dir_15" &&
162 test_contains_N_files mw_dir_15 3 &&
163 test_path_is_file mw_dir_15/Testpage.mw &&
164 test_path_is_file mw_dir_15/File:File.txt.mw &&
165 test_path_is_file mw_dir_15/File.txt &&
166 test_path_is_missing mw_dir_15/Main_Page.mw &&
167 test_path_is_missing mw_dir_15/File:AnotherFile.txt.mw &&
168 test_path_is_missing mw_dir_15/AnothetFile.txt &&
169 wiki_check_content mw_dir_15/Testpage.mw Testpage &&
170 test_cmp mw_dir_15/File.txt File.txt
173 test_expect_success
'git clone works with one specific page cloned and mediaimport=false' '
174 test_when_finished "rm -rf mw_dir_16" &&
175 git clone -c remote.origin.pages=testpage \
176 mediawiki::'"$WIKI_URL"' mw_dir_16 &&
177 test_contains_N_files mw_dir_16 1 &&
178 test_path_is_file mw_dir_16/Testpage.mw &&
179 test_path_is_missing mw_dir_16/File:File.txt.mw &&
180 test_path_is_missing mw_dir_16/File.txt &&
181 test_path_is_missing mw_dir_16/Main_Page.mw &&
182 wiki_check_content mw_dir_16/Testpage.mw Testpage
185 # should behave like mediaimport=false
186 test_expect_success
'git clone works with one specific page cloned and mediaimport unset' '
187 test_when_finished "rm -fr mw_dir_17" &&
188 git clone -c remote.origin.pages=testpage \
189 mediawiki::'"$WIKI_URL"' mw_dir_17 &&
190 test_contains_N_files mw_dir_17 1 &&
191 test_path_is_file mw_dir_17/Testpage.mw &&
192 test_path_is_missing mw_dir_17/File:File.txt.mw &&
193 test_path_is_missing mw_dir_17/File.txt &&
194 test_path_is_missing mw_dir_17/Main_Page.mw &&
195 wiki_check_content mw_dir_17/Testpage.mw Testpage