contrib / mw-to-git / t / t9363-mw-to-git-export-import.shon commit Merge branch 'rt/maint-clone-single' (92f6e98)
   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
  14test_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
  20test_check_precond
  21
  22
  23test_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
  29test_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
  33'
  34
  35test_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
  51test_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
  61test_expect_success 'git push & pull work with locally renamed media files' '
  62        wiki_reset &&
  63        git clone mediawiki::'"$WIKI_URL"' mw_dir &&
  64        test_when_finished "rm -fr mw_dir" &&
  65        (
  66                cd mw_dir &&
  67                echo "A File" >Foo.txt &&
  68                git add Foo.txt &&
  69                git commit -m "add a file" &&
  70                git mv Foo.txt Bar.txt &&
  71                git commit -m "Rename a file" &&
  72                test_git_reimport &&
  73                echo "A File" >expect &&
  74                test_cmp expect Bar.txt &&
  75                test_path_is_missing Foo.txt
  76        )
  77'
  78
  79test_expect_success 'git push can propagate local page deletion' '
  80        wiki_reset &&
  81        git clone mediawiki::'"$WIKI_URL"' mw_dir &&
  82        test_when_finished "rm -fr mw_dir" &&
  83        (
  84                cd mw_dir &&
  85                test_path_is_missing Foo.mw &&
  86                echo "hello world" >Foo.mw &&
  87                git add Foo.mw &&
  88                git commit -m "Add the page Foo" &&
  89                git push &&
  90                rm -f Foo.mw &&
  91                git commit -am "Delete the page Foo" &&
  92                test_git_reimport &&
  93                test_path_is_missing Foo.mw
  94        )
  95'
  96
  97test_expect_success 'git push can propagate local media file deletion' '
  98        wiki_reset &&
  99        git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 100        test_when_finished "rm -fr mw_dir" &&
 101        (
 102                cd mw_dir &&
 103                echo "hello world" >Foo.txt &&
 104                git add Foo.txt &&
 105                git commit -m "Add the text file Foo" &&
 106                git rm Foo.txt &&
 107                git commit -m "Delete the file Foo" &&
 108                test_git_reimport &&
 109                test_path_is_missing Foo.txt
 110        )
 111'
 112
 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.
 117test_expect_failure 'git pull correctly imports media file deletion when no page link to it' '
 118        wiki_reset &&
 119        git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 120        test_when_finished "rm -fr mw_dir" &&
 121        (
 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 push &&
 127                git rm Foo.txt &&
 128                git commit -m "Delete the file Foo" &&
 129                test_git_reimport &&
 130                test_path_is_missing Foo.txt
 131        )
 132'
 133
 134test_expect_success 'git push properly warns about insufficient permissions' '
 135        wiki_reset &&
 136        git clone mediawiki::'"$WIKI_URL"' mw_dir &&
 137        test_when_finished "rm -fr mw_dir" &&
 138        (
 139                cd mw_dir &&
 140                echo "A File" >foo.forbidden &&
 141                git add foo.forbidden &&
 142                git commit -m "add a file" &&
 143                git push 2>actual &&
 144                test_i18ngrep "foo.forbidden is not a permitted file" actual
 145        )
 146'
 147
 148test_expect_success 'setup a repository with media files' '
 149        wiki_reset &&
 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
 155'
 156
 157test_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
 171'
 172
 173test_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
 183'
 184
 185# should behave like mediaimport=false
 186test_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
 196'
 197
 198test_done