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 can upload media (File:) files containing valid UTF-8' '
 
  63         git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 
  66                 "$PERL_PATH" -e "print STDOUT \"UTF-8 content: éèàéê€.\";" >Bar.txt &&
 
  68                 git commit -m "add a text file with UTF-8 content" &&
 
  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
 
  80 test_expect_success 'git push & pull work with locally renamed media files' '
 
  82         git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 
  83         test_when_finished "rm -fr mw_dir" &&
 
  86                 echo "A File" >Foo.txt &&
 
  88                 git commit -m "add a file" &&
 
  89                 git mv Foo.txt Bar.txt &&
 
  90                 git commit -m "Rename a file" &&
 
  92                 echo "A File" >expect &&
 
  93                 test_cmp expect Bar.txt &&
 
  94                 test_path_is_missing Foo.txt
 
  98 test_expect_success 'git push can propagate local page deletion' '
 
 100         git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 
 101         test_when_finished "rm -fr mw_dir" &&
 
 104                 test_path_is_missing Foo.mw &&
 
 105                 echo "hello world" >Foo.mw &&
 
 107                 git commit -m "Add the page Foo" &&
 
 110                 git commit -am "Delete the page Foo" &&
 
 112                 test_path_is_missing Foo.mw
 
 116 test_expect_success 'git push can propagate local media file deletion' '
 
 118         git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 
 119         test_when_finished "rm -fr mw_dir" &&
 
 122                 echo "hello world" >Foo.txt &&
 
 124                 git commit -m "Add the text file Foo" &&
 
 126                 git commit -m "Delete the file Foo" &&
 
 128                 test_path_is_missing Foo.txt
 
 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' '
 
 138         git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 
 139         test_when_finished "rm -fr mw_dir" &&
 
 142                 echo "hello world" >Foo.txt &&
 
 144                 git commit -m "Add the text file Foo" &&
 
 147                 git commit -m "Delete the file Foo" &&
 
 149                 test_path_is_missing Foo.txt
 
 153 test_expect_success 'git push properly warns about insufficient permissions' '
 
 155         git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 
 156         test_when_finished "rm -fr mw_dir" &&
 
 159                 echo "A File" >foo.forbidden &&
 
 160                 git add foo.forbidden &&
 
 161                 git commit -m "add a file" &&
 
 163                 test_i18ngrep "foo.forbidden is not a permitted file" actual
 
 167 test_expect_success 'setup a repository with media files' '
 
 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
 
 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
 
 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
 
 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