File: 404_node_image.t

package info (click to toggle)
openguides 0.84-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,612 kB
  • sloc: perl: 4,812; sh: 56; javascript: 56; makefile: 19
file content (205 lines) | stat: -rw-r--r-- 9,566 bytes parent folder | download | duplicates (5)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
use strict;
use OpenGuides;
use OpenGuides::Test;
use Test::More;
use Wiki::Toolkit::Setup::SQLite;

eval { require DBD::SQLite; };
if ( $@ ) {
    my ($error) = $@ =~ /^(.*?)\n/;
    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
}

eval { require Test::HTML::Content; };
if ( $@ ) {
    plan skip_all => "Test::HTML::Content not installed.";
}

plan tests => 30;

my ( $config, $guide, $wiki );

# Clear out the database from any previous runs.
    OpenGuides::Test::refresh_db();

# Make sure node image fields don't show up in edit form if config says
# they shouldn't.
$config = OpenGuides::Test->make_basic_config;
$config->enable_node_image( 0 );
$guide = OpenGuides->new( config => $config );
$wiki = $guide->wiki;

my $output = $guide->display_edit_form(
                                        id => "Red Lion",
                                        return_output => 1,
                                      );

# Strip Content-Type header to stop Test::HTML::Content getting confused.
$output =~ s/^Content-Type.*[\r\n]+//m;

Test::HTML::Content::no_tag( $output, "input", { name => "node_image" },
    "node_image field not in edit form if config says it shouldn't be" );
Test::HTML::Content::no_tag( $output, "input",
                             { name => "node_image_licence" },
                             "...ditto node_image_licence" );
Test::HTML::Content::no_tag( $output, "input",
                             { name => "node_image_copyright" },
                             "...ditto node_image_copyright" );
Test::HTML::Content::no_tag( $output, "input",
                             { name => "node_image_url" },
                             "...ditto node_image_url" );

# And make sure they do if it says they should.
$config->enable_node_image( 1 );
$guide = OpenGuides->new( config => $config );
$wiki = $guide->wiki;

$output = $guide->display_edit_form(
                                     id => "Red Lion",
                                     return_output => 1,
                                   );

# Strip Content-Type header to stop Test::HTML::Content getting confused.
$output =~ s/^Content-Type.*[\r\n]+//m;

Test::HTML::Content::tag_ok( $output, "input", { name => "node_image" },
    "node_image field appears in edit form if config says it should" );
Test::HTML::Content::tag_ok( $output, "input",
                             { name => "node_image_licence" },
                             "...ditto node_image_licence" );
Test::HTML::Content::tag_ok( $output, "input",
                             { name => "node_image_copyright" },
                             "...ditto node_image_copyright" );
Test::HTML::Content::tag_ok( $output, "input",
                             { name => "node_image_url" },
                             "...ditto node_image_url" );

# Write all four fields to database, and make sure they're there.
OpenGuides::Test->write_data(
                              guide => $guide,
                              node  => "Red Lion",
                              node_image => "http://example.com/foo.jpg",
                              node_image_licence => "http://example.com/bar/",
                              node_image_copyright => "Kake L Pugh",
                              node_image_url => "http://example.com/~kake/",
                            );

my %node_data = $wiki->retrieve_node( "Red Lion" );
is( $node_data{metadata}{node_image}[0], "http://example.com/foo.jpg",
    "node_image saved to database on node write" );
is( $node_data{metadata}{node_image_licence}[0], "http://example.com/bar/",
    "...node_image_licence too" );
is( $node_data{metadata}{node_image_copyright}[0], "Kake L Pugh",
    "...node_image_copyright too" );
is( $node_data{metadata}{node_image_url}[0], "http://example.com/~kake/",
    "...node_image_url too" );

# Make sure their content shows up in the edit form.
$output = $guide->display_edit_form(
                                     id => "Red Lion",
                                     return_output => 1,
                                   );

# Strip Content-Type header to stop Test::HTML::Content getting confused.
$output =~ s/^Content-Type.*[\r\n]+//m;

Test::HTML::Content::tag_ok( $output, "input",
                             { name  => "node_image",
                               value => "http://example.com/foo.jpg" },
                             "node_image field has correct value in edit form",
                           );
Test::HTML::Content::tag_ok( $output, "input",
                             { name  => "node_image_licence",
                               value => "http://example.com/bar/" },
                             "...ditto node_image_licence" );
Test::HTML::Content::tag_ok( $output, "input",
                             { name  => "node_image_copyright",
                               value => "Kake L Pugh" },
                             "...ditto node_image_copyright" );
Test::HTML::Content::tag_ok( $output, "input",
                             { name  => "node_image_url",
                               value => "http://example.com/~kake/" },
                             "...ditto node_image_url" );

# Make sure they're displayed when a page is viewed.
$output = $guide->display_node(
                                   id            => "Red Lion",
                                   return_output => 1,
                                 );

# Strip Content-Type header to stop Test::HTML::Content getting confused.
$output =~ s/^Content-Type.*[\r\n]+//m;

Test::HTML::Content::tag_ok( $output, "img",
                             { src => "http://example.com/foo.jpg" },
                             "node_image displayed on page" );
Test::HTML::Content::tag_ok( $output, "a",
                             { href => "http://example.com/bar/" },
                             "...ditto node_image_licence" );
Test::HTML::Content::text_ok( $output, qr/Kake L Pugh/,
                              "...ditto node_image_copyright" );
Test::HTML::Content::tag_ok( $output, "a",
                             { href => "http://example.com/~kake/" },
                             "...ditto node_image_url" );

# Now try to commit some edits without giving the checksum.
$output = OpenGuides::Test->write_data(
                                        guide => $guide,
                                        node => "Red Lion",
                                        node_image => "http://eg.com/foo.jpg",
                                        node_image_licence
                                                     => "http://eg.com/bar/",
                                        node_image_copyright => "NotKakeNo",
                                        node_image_url
                                                     => "http://eg.com/~kake/",
                                        omit_checksum => 1,
                                        return_output => 1,
                                      );

# Strip Content-Type header to stop Test::HTML::Content getting confused.
$output =~ s/^Content-Type.*[\r\n]+//m;

Test::HTML::Content::tag_ok( $output, "input",
                             { name => "node_image",
                               value => "http://example.com/foo.jpg" },
                             "Edit conflict form has input box with old "
                             . "node_image value in" );
Test::HTML::Content::tag_ok( $output, "input",
                             { name => "node_image_licence",
                               value => "http://example.com/bar/" },
                              "...and one with old node_image_licence value" );
Test::HTML::Content::tag_ok( $output, "input",
                             { name => "node_image_copyright",
                               value => "Kake L Pugh" },
                            "...and one with old node_image_copyright value" );
Test::HTML::Content::tag_ok( $output, "input",
                             { name => "node_image_url",
                               value => "http://example.com/~kake/" },
                              "...and one with old node_image_url value" );
Test::HTML::Content::text_ok( $output, "http://eg.com/foo.jpg",
                              "...new node_image value appears too" );
Test::HTML::Content::text_ok( $output, "http://eg.com/bar/",
                              "...as does new node_image_licence value" );
Test::HTML::Content::text_ok( $output, "NotKakeNo",
                              "...as does new node_image_copyright value" );
Test::HTML::Content::text_ok( $output, "http://eg.com/~kake/",
                              "...as does new node_image_url value" );

# Write node with node_image field consisting only of whitespace, make
# sure it gets stripped.
OpenGuides::Test->write_data(
                              guide => $guide,
                              node  => "Angel and Greyhound",
                              node_image => " ",
                            );
%node_data = $wiki->retrieve_node( "Angel and Greyhound" );
ok( !$node_data{metadata}{node_image},
    "node_image of whitespace only isn't saved to database" );

$output = $guide->display_node(
                                id            => "Angel and Greyhound",
                                return_output => 1,
                              );
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "img" => { id => "node_image" },
                             "...or displayed on page" );