|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright 2015 Open Source Freedom Fighters |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Test::More; |
| 22 |
use Try::Tiny; |
| 23 |
use Encode; |
| 24 |
|
| 25 |
use t::lib::TestObjects::ObjectFactory; |
| 26 |
use t::lib::TestObjects::AtomicUpdateFactory; |
| 27 |
use t::lib::TestObjects::FileFactory; |
| 28 |
use Koha::AtomicUpdater; |
| 29 |
|
| 30 |
my $testContext = {}; |
| 31 |
my $atomicupdates = t::lib::TestObjects::AtomicUpdateFactory->createTestGroup([ |
| 32 |
{issue_id => 'Bug12', |
| 33 |
filename => 'Bug12-WatchExMachinaYoullLikeIt.pl'}, |
| 34 |
{issue_id => 'Bug14', |
| 35 |
filename => 'Bug14-ReturnOfZorro.perl'}, |
| 36 |
{issue_id => '#14', |
| 37 |
filename => '#14-RobotronInDanger.sql'}, |
| 38 |
{issue_id => '#15', |
| 39 |
filename => '#15-ILikedPrometheusButAlienWasBetter.pl'}, |
| 40 |
], undef, $testContext); |
| 41 |
|
| 42 |
subtest "List all deployed atomicupdates" => \&listAtomicUpdates; |
| 43 |
sub listAtomicUpdates { |
| 44 |
eval { |
| 45 |
my $atomicUpdater = Koha::AtomicUpdater->new(); |
| 46 |
my $text = $atomicUpdater->listToConsole(); |
| 47 |
print $text; |
| 48 |
|
| 49 |
ok($text =~ m/Bug12-WatchExMachinaYoullLik/, |
| 50 |
"Bug12-WatchExMachinaYoullLikeIt"); |
| 51 |
ok($text =~ m/Bug14-ReturnOfZorro.perl/, |
| 52 |
"Bug14-ReturnOfZorro"); |
| 53 |
ok($text =~ m/#14-RobotronInDanger.sql/, |
| 54 |
"#14-RobotronInDanger"); |
| 55 |
ok($text =~ m/#15-ILikedPrometheusButAli/, |
| 56 |
"#15-ILikedPrometheusButAlienWasBetter"); |
| 57 |
|
| 58 |
}; |
| 59 |
if ($@) { |
| 60 |
ok(0, $@); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
subtest "Delete an atomicupdate entry" => \&deleteAtomicupdate; |
| 65 |
sub deleteAtomicupdate { |
| 66 |
eval { |
| 67 |
my $atomicUpdater = Koha::AtomicUpdater->new(); |
| 68 |
my $atomicupdate = $atomicUpdater->cast($atomicupdates->{Bug12}->id); |
| 69 |
ok($atomicupdate, |
| 70 |
"AtomicUpdate '".$atomicupdates->{Bug12}->issue_id."' exists prior to deletion"); |
| 71 |
|
| 72 |
$atomicUpdater->removeAtomicUpdate($atomicupdate->issue_id); |
| 73 |
$atomicupdate = $atomicUpdater->find($atomicupdates->{Bug12}->id); |
| 74 |
ok(not($atomicupdate), |
| 75 |
"AtomicUpdate '".$atomicupdates->{Bug12}->issue_id."' deleted"); |
| 76 |
|
| 77 |
}; |
| 78 |
if ($@) { |
| 79 |
ok(0, $@); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
subtest "Insert an atomicupdate entry" => \&insertAtomicupdate; |
| 84 |
sub insertAtomicupdate { |
| 85 |
eval { |
| 86 |
my $atomicUpdater = Koha::AtomicUpdater->new(); |
| 87 |
my $subtestContext = {}; |
| 88 |
my $atomicupdates = t::lib::TestObjects::AtomicUpdateFactory->createTestGroup([ |
| 89 |
{issue_id => 'Bug15', |
| 90 |
filename => 'Bug15-Inserted.pl'}, |
| 91 |
], undef, $subtestContext, $testContext); |
| 92 |
my $atomicupdate = $atomicUpdater->find({issue_id => 'Bug15'}); |
| 93 |
ok($atomicupdate, |
| 94 |
"Bug15-Inserted.pl"); |
| 95 |
|
| 96 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); |
| 97 |
|
| 98 |
$atomicupdate = $atomicUpdater->find({issue_id => 'Bug15'}); |
| 99 |
ok(not($atomicupdate), |
| 100 |
"Bug15-Inserted.pl deleted"); |
| 101 |
}; |
| 102 |
if ($@) { |
| 103 |
ok(0, $@); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
subtest "List pending atomicupdates" => \&listPendingAtomicupdates; |
| 108 |
sub listPendingAtomicupdates { |
| 109 |
my ($atomicUpdater, $files, $text, $atomicupdates); |
| 110 |
my $subtestContext = {}; |
| 111 |
eval { |
| 112 |
##Test adding update scripts and deploy them, confirm that no pending scripts detected |
| 113 |
$files = t::lib::TestObjects::FileFactory->createTestGroup([ |
| 114 |
{ filepath => 'atomicupdate/', |
| 115 |
filename => '#911-WhoYouGonnaCall.pl', |
| 116 |
content => '$ENV{ATOMICUPDATE_TESTS} = 1;',}, |
| 117 |
{ filepath => 'atomicupdate/', |
| 118 |
filename => 'Bug911-WhatchaGonnaDo.pl', |
| 119 |
content => '$ENV{ATOMICUPDATE_TESTS}++;',}, |
| 120 |
{ filepath => 'atomicupdate/', |
| 121 |
filename => 'Bug112-LapinlahdenLinnut.pl', |
| 122 |
content => '$ENV{ATOMICUPDATE_TESTS}++;',}, |
| 123 |
], |
| 124 |
undef, $subtestContext, $testContext); |
| 125 |
$atomicUpdater = Koha::AtomicUpdater->new({ |
| 126 |
scriptDir => $files->{'#911-WhoYouGonnaCall.pl'}->dirname() |
| 127 |
}); |
| 128 |
|
| 129 |
$text = $atomicUpdater->listPendingToConsole(); |
| 130 |
print $text; |
| 131 |
|
| 132 |
ok($text =~ m/#911-WhoYouGonnaCall.pl/, |
| 133 |
"#911-WhoYouGonnaCall is pending"); |
| 134 |
ok($text =~ m/Bug911-WhatchaGonnaDo.pl/, |
| 135 |
"Bug911-WhatchaGonnaDo is pending"); |
| 136 |
ok($text =~ m/Bug112-LapinlahdenLinnut.pl/, |
| 137 |
'Bug112-LapinlahdenLinnut is pending'); |
| 138 |
|
| 139 |
$atomicupdates = $atomicUpdater->applyAtomicUpdates(); |
| 140 |
t::lib::TestObjects::AtomicUpdateFactory->addToContext($atomicupdates, undef, $subtestContext, $testContext); #Keep track of changes |
| 141 |
|
| 142 |
is($atomicupdates->{'#911-WhoYouGonnaCall.pl'}->issue_id, |
| 143 |
'#911', |
| 144 |
"#911-WhoYouGonnaCall.pl deployed"); |
| 145 |
is($atomicupdates->{'Bug112-LapinlahdenLinnut.pl'}->issue_id, |
| 146 |
'Bug112', |
| 147 |
'Bug112-LapinlahdenLinnut.pl deployed'); |
| 148 |
is($atomicupdates->{'Bug911-WhatchaGonnaDo.pl'}->issue_id, |
| 149 |
'Bug911', |
| 150 |
"Bug911-WhatchaGonnaDo.pl deployed"); |
| 151 |
|
| 152 |
##Test adding scripts to the atomicupdates directory and how we deal with such change. |
| 153 |
$files = t::lib::TestObjects::FileFactory->createTestGroup([ |
| 154 |
{ filepath => 'atomicupdate/', |
| 155 |
filename => '#53-PlaceToBe.pl', |
| 156 |
content => '$ENV{ATOMICUPDATE_TESTS}++;',}, |
| 157 |
{ filepath => 'atomicupdate/', |
| 158 |
filename => '#54-KohaConInFinlandNextYear.pl', |
| 159 |
content => '$ENV{ATOMICUPDATE_TESTS}++;',}, |
| 160 |
{ filepath => 'atomicupdate/', |
| 161 |
filename => '#55-Fiftyfive.pl', |
| 162 |
content => '$ENV{ATOMICUPDATE_TESTS}++;',}, |
| 163 |
], |
| 164 |
undef, $subtestContext, $testContext); |
| 165 |
|
| 166 |
$text = $atomicUpdater->listPendingToConsole(); |
| 167 |
print $text; |
| 168 |
|
| 169 |
ok($text =~ m/#53-PlaceToBe.pl/, |
| 170 |
"#53-PlaceToBe.pl is pending"); |
| 171 |
ok($text =~ m/#54-KohaConInFinlandNextYear.pl/, |
| 172 |
"#54-KohaConInFinlandNextYear.pl is pending"); |
| 173 |
ok($text =~ m/#55-Fiftyfive.pl/u, |
| 174 |
'#55-Fiftyfive.pl'); |
| 175 |
|
| 176 |
$atomicupdates = $atomicUpdater->applyAtomicUpdates(); |
| 177 |
t::lib::TestObjects::AtomicUpdateFactory->addToContext($atomicupdates, undef, $subtestContext, $testContext); #Keep track of changes |
| 178 |
|
| 179 |
is($atomicupdates->{'#53-PlaceToBe.pl'}->issue_id, |
| 180 |
'#53', |
| 181 |
"#53-PlaceToBe.pl deployed"); |
| 182 |
is($atomicupdates->{'#54-KohaConInFinlandNextYear.pl'}->issue_id, |
| 183 |
'#54', |
| 184 |
'#54-KohaConInFinlandNextYear.pl deployed'); |
| 185 |
is($atomicupdates->{'#55-Fiftyfive.pl'}->issue_id, |
| 186 |
'#55', |
| 187 |
"#55-Fiftyfive.pl deployed"); |
| 188 |
|
| 189 |
is($ENV{ATOMICUPDATE_TESTS}, |
| 190 |
6, |
| 191 |
"All configured AtomicUpdates deployed"); |
| 192 |
}; |
| 193 |
if ($@) { |
| 194 |
ok(0, $@); |
| 195 |
} |
| 196 |
t::lib::TestObjects::AtomicUpdateFactory->tearDownTestContext($subtestContext); |
| 197 |
} |
| 198 |
|
| 199 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); |
| 200 |
done_testing; |