lock.t 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (C) 2015 Alex-Daniel Jakimenko <alex.jakimenko@gmail.com>
  2. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. require './t/test.pl';
  17. package OddMuse;
  18. use Test::More tests => 20;
  19. test_page(get_page('action=editlock'), 'operation is restricted');
  20. test_page(get_page('action=editlock pwd=foo'), 'Edit lock created');
  21. xpath_test(update_page('TestLock', 'mu!'),
  22. '//a[@href="http://localhost/wiki.pl?action=password"][@class="password"][text()="This page is read-only"]');
  23. test_page($redirect, '403 FORBIDDEN', 'Editing not allowed: TestLock is read-only');
  24. test_page(get_page('action=editlock set=0'), 'operation is restricted');
  25. test_page(get_page('action=editlock set=0 pwd=foo'), 'Edit lock removed');
  26. RequestLockDir('main');
  27. test_page(update_page('TestLock', 'mu!'), 'This page does not exist');
  28. test_page($redirect, 'Status: 503 SERVICE UNAVAILABLE',
  29. 'Could not get main lock', 'File exists',
  30. 'The lock was created (just now|1 second ago|2 seconds ago)');
  31. test_page(update_page('TestLock', 'mu!'), 'This page does not exist');
  32. test_page($redirect, 'Status: 503 SERVICE UNAVAILABLE',
  33. 'Could not get main lock', 'File exists',
  34. 'The lock was created \d+ seconds ago');
  35. # Lock cleaners
  36. AppendToConfig(<<'END');
  37. $Action{'jobinterrupted'} = sub {
  38. print GetHeader();
  39. RequestLockDir('importantjob');
  40. WriteStringToFile("$DataDir/deletemewhenfinished", 'bla-bla');
  41. print 'Ok, doing some lengthy job... ';
  42. sleep 15;
  43. print 'Done!';
  44. unlink "$DataDir/deletemewhenfinished"; # WHOOPS!
  45. ReleaseLockDir('importantjob');
  46. PrintFooter();
  47. };
  48. END
  49. RunAndTerminate('perl', 'wiki.pl', 'action=jobinterrupted');
  50. # first let's test that the action works (otherwise next test will give false "ok")
  51. ok(-f "$DataDir/deletemewhenfinished", 'deletemewhenfinished file was created but not deleted');
  52. ok(! -d "$TempDir/lockimportantjob", 'lock was deleted automatically');
  53. AppendToConfig(<<'END');
  54. $LockCleaners{'importantjob'} = sub {
  55. unlink "$DataDir/deletemewhenfinished" if -f "$DataDir/deletemewhenfinished";
  56. };
  57. END
  58. RunAndTerminate('perl', 'wiki.pl', 'action=jobinterrupted');
  59. ok(! -f "${LockDir}deletemewhenfinished", 'Custom lock cleaning code works');