lock.t 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 2 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, write to the
  16. # Free Software Foundation, Inc.
  17. # 59 Temple Place, Suite 330
  18. # Boston, MA 02111-1307 USA
  19. require 't/test.pl';
  20. package OddMuse;
  21. use Test::More tests => 20;
  22. test_page(get_page('action=editlock'), 'operation is restricted');
  23. test_page(get_page('action=editlock pwd=foo'), 'Edit lock created');
  24. xpath_test(update_page('TestLock', 'mu!'),
  25. '//a[@href="http://localhost/wiki.pl?action=password"][@class="password"][text()="This page is read-only"]');
  26. test_page($redirect, '403 FORBIDDEN', 'Editing not allowed: TestLock is read-only');
  27. test_page(get_page('action=editlock set=0'), 'operation is restricted');
  28. test_page(get_page('action=editlock set=0 pwd=foo'), 'Edit lock removed');
  29. RequestLockDir('main');
  30. test_page(update_page('TestLock', 'mu!'), 'This page does not exist');
  31. test_page($redirect, 'Status: 503 SERVICE UNAVAILABLE',
  32. 'Could not get main lock', 'File exists',
  33. 'The lock was created (just now|1 second ago|2 seconds ago)');
  34. test_page(update_page('TestLock', 'mu!'), 'This page does not exist');
  35. test_page($redirect, 'Status: 503 SERVICE UNAVAILABLE',
  36. 'Could not get main lock', 'File exists',
  37. 'The lock was created \d+ seconds ago');
  38. # Lock cleaners
  39. AppendToConfig(<<'END');
  40. $Action{'jobinterrupted'} = sub {
  41. print GetHeader();
  42. RequestLockDir('importantjob');
  43. WriteStringToFile("$DataDir/deletemewhenfinished", 'bla-bla');
  44. print 'Ok, doing some lengthy job... ';
  45. sleep 15;
  46. print 'Done!';
  47. unlink "$DataDir/deletemewhenfinished"; # WHOOPS!
  48. ReleaseLockDir('importantjob');
  49. PrintFooter();
  50. };
  51. END
  52. RunAndTerminate('perl', 'wiki.pl', 'action=jobinterrupted');
  53. # first let's test that the action works (otherwise next test will give false "ok")
  54. ok(-f "$DataDir/deletemewhenfinished", 'deletemewhenfinished file was created but not deleted');
  55. ok(! -d "$TempDir/lockimportantjob", 'lock was deleted automatically');
  56. AppendToConfig(<<'END');
  57. $LockCleaners{'importantjob'} = sub {
  58. unlink "$DataDir/deletemewhenfinished" if -f "$DataDir/deletemewhenfinished";
  59. };
  60. END
  61. RunAndTerminate('perl', 'wiki.pl', 'action=jobinterrupted');
  62. ok(! -f "${LockDir}deletemewhenfinished", 'Custom lock cleaning code works');