The second batch
[alt-git.git] / contrib / mw-to-git / t / t9363-mw-to-git-export-import.sh
blob7139995a405cee9881f690ff892464c875984e27
1 #!/bin/sh
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>
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'
16 . ./test-gitmw-lib.sh
17 . $TEST_DIRECTORY/test-lib.sh
20 test_check_precond
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' '
36 wiki_reset &&
37 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
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
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' '
63 wiki_reset &&
64 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
66 cd mw_dir &&
67 "$PERL_PATH" -e "print STDOUT \"UTF-8 content: éèàéê€.\";" >Bar.txt &&
68 git add Bar.txt &&
69 git commit -m "add a text file with UTF-8 content" &&
70 git push
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' '
82 wiki_reset &&
83 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
84 test_when_finished "rm -fr mw_dir" &&
86 cd mw_dir &&
87 echo "A File" >Foo.txt &&
88 git add Foo.txt &&
89 git commit -m "add a file" &&
90 git mv Foo.txt Bar.txt &&
91 git commit -m "Rename a file" &&
92 test_git_reimport &&
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' '
100 wiki_reset &&
101 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
102 test_when_finished "rm -fr mw_dir" &&
104 cd mw_dir &&
105 test_path_is_missing Foo.mw &&
106 echo "hello world" >Foo.mw &&
107 git add Foo.mw &&
108 git commit -m "Add the page Foo" &&
109 git push &&
110 rm -f Foo.mw &&
111 git commit -am "Delete the page Foo" &&
112 test_git_reimport &&
113 test_path_is_missing Foo.mw
117 test_expect_success 'git push can propagate local media file deletion' '
118 wiki_reset &&
119 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
120 test_when_finished "rm -fr mw_dir" &&
122 cd mw_dir &&
123 echo "hello world" >Foo.txt &&
124 git add Foo.txt &&
125 git commit -m "Add the text file Foo" &&
126 git rm Foo.txt &&
127 git commit -m "Delete the file Foo" &&
128 test_git_reimport &&
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' '
138 wiki_reset &&
139 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
140 test_when_finished "rm -fr mw_dir" &&
142 cd mw_dir &&
143 echo "hello world" >Foo.txt &&
144 git add Foo.txt &&
145 git commit -m "Add the text file Foo" &&
146 git push &&
147 git rm Foo.txt &&
148 git commit -m "Delete the file Foo" &&
149 test_git_reimport &&
150 test_path_is_missing Foo.txt
154 test_expect_success 'git push properly warns about insufficient permissions' '
155 wiki_reset &&
156 git clone mediawiki::'"$WIKI_URL"' mw_dir &&
157 test_when_finished "rm -fr mw_dir" &&
159 cd mw_dir &&
160 echo "A File" >foo.forbidden &&
161 git add foo.forbidden &&
162 git commit -m "add a file" &&
163 git push 2>actual &&
164 test_grep "foo.forbidden is not a permitted file" actual
168 test_expect_success 'setup a repository with media files' '
169 wiki_reset &&
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
218 test_done