/
FoswikiFnTestCase.pm
144 lines (110 loc) · 3.93 KB
/
FoswikiFnTestCase.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# See bottom of file for license and copyright
package FoswikiFnTestCase;
=begin TML
---+ package FoswikiFnTestCase
This base class layers some extra stuff on FoswikiTestCase to
try and make life for Foswiki testers even easier at higher levels.
Normally this will be the base class for tests that require an almost
complete user environment. However it does quite a lot of relatively
slow setup, so should not be used for simpler tests (such as those
targeting single classes).
1. Do not be afraid to modify Foswiki::cfg. You cannot break other
tests that way.
2. Never, ever write to any webs except the test_web and
users_web, or any other test webs you create and remove
(following the pattern shown below)
3. The password manager is set to HtPasswdUser, and you can create
users as shown in the creation of {test_user}
4. A single user has been pre-registered, wikinamed 'ScumBag'
=cut
use Foswiki();
#use Unit::Response();
use Foswiki::UI::Register();
use Try::Tiny;
use Carp qw(cluck);
use Moo;
use namespace::clean;
extends qw(FoswikiTestCase);
has test_user_forename => ( is => 'rw', );
has test_user_surname => ( is => 'rw', );
has test_user_wikiname => ( is => 'rw', );
has test_user_login => ( is => 'rw', );
has test_user_email => ( is => 'rw', );
has test_user_cuid => ( is => 'rw', );
has response => (
is => 'rw',
clearer => 1,
lazy => 1,
predicate => 1,
isa => Foswiki::Object::isaCLASS( 'response', 'Foswiki::Response' ),
default => sub { return $_[0]->app->response; },
);
=begin TML
---++ ObjectMethod loadExtraConfig()
This method can be overridden (overrides should call up to the base class)
to add extra stuff to Foswiki::cfg.
=cut
around loadExtraConfig => sub {
my $orig = shift;
my $this = shift;
$orig->( $this, @_ );
my $cfgData = $this->app->cfg->data;
#$cfgData->{Store}{Implementation} = "Foswiki::Store::RcsLite";
$cfgData->{Store}{Implementation} = "Foswiki::Store::PlainFile";
$cfgData->{RCS}{AutoAttachPubFiles} = 0;
$this->setupUserRegistration;
};
around set_up => sub {
my $orig = shift;
my $this = shift;
$orig->( $this, @_ );
$this->createNewFoswikiApp(
requestParams => { initializer => "" },
engineParams => {
initialAttributes =>
{ path_info => "/" . $this->test_web . "/" . $this->test_topic },
},
);
my $webObject = $this->populateNewWeb( $this->test_web );
undef $webObject;
$this->clear_test_topicObject;
$this->test_topicObject(
Foswiki::Func::readTopic( $this->test_web, $this->test_topic ) );
$this->test_topicObject->text("BLEEGLE\n");
$this->test_topicObject->save( forcedate => ( time() + 60 ) );
$webObject = $this->populateNewWeb( $this->users_web );
undef $webObject;
$this->test_user_forename('Scum');
$this->test_user_surname('Bag');
$this->test_user_wikiname(
$this->test_user_forename . $this->test_user_surname );
$this->test_user_login('scum');
$this->test_user_email('scumbag@example.com');
$this->registerUser(
$this->test_user_login, $this->test_user_forename,
$this->test_user_surname, $this->test_user_email
);
$this->test_user_cuid(
$this->app->users->getCanonicalUserID( $this->test_user_login ) );
};
around tear_down => sub {
my $orig = shift;
my $this = shift;
my $app = $this->app;
my $cfg = $app->cfg;
$this->removeWebFixture( $this->test_web );
$this->assert_str_not_equals( $cfg->data->{UsersWebName},
'Main', "UsersWebName equals to 'Main'" );
$this->removeWebFixture( $cfg->data->{UsersWebName} );
unlink( $Foswiki::cfg{Htpasswd}{FileName} );
$orig->( $this, @_ );
};
=begin TML
---++ ObjectMethod removeWeb($web)
Remove a temporary web fixture (data and pub)
=cut
sub removeWeb {
my ( $this, $web ) = @_;
$this->removeWebFixture($web);
}
1;