| 1 | package Mason::t::Request; | ||
| 2 | 1 | $Mason::t::Request::VERSION = '2.24'; | |
| 3 | 1 | ▶ | use Test::Class::Most parent => 'Mason::Test::Class'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Log::Any::Test; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Log::Any qw($log); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 1 | ▶ | sub _get_current_comp_class { |
|
Subroutine
_get_current_comp_class: called CC=1 SCAR=0.0
| |||
| 8 | 1 | my $m = shift; | |
| 9 | 1 | return $m->current_comp_class; | |
| 10 | } | ||
| 11 | |||
| 12 | 1 | ▶ | sub test_add_cleanup : Tests { |
|
Subroutine
test_add_cleanup: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 13 | 1 | my $self = shift; | |
| 14 | 1 | my $foo = 1; | |
| 15 | 1 | $self->test_comp( | |
| 16 | src => ' | ||
| 17 | % my $ref = $.args->{ref}; | ||
| 18 | % $m->add_cleanup(sub { $$ref++ }); | ||
| 19 | foo = <% $$ref %> | ||
| 20 | ', | ||
| 21 | args => { ref => \$foo }, | ||
| 22 | expect => 'foo = 1' | ||
| 23 | ); | ||
| 24 | 1 | is( $foo, 2, "foo now 2" ); | |
| 25 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | 1 | ▶ | sub test_capture : Tests { |
|
Subroutine
test_capture: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 28 | 1 | my $self = shift; | |
| 29 | $self->run_test_in_comp( | ||
| 30 | 1 | ▶ | test => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 31 | 1 | my $comp = shift; | |
| 32 | 1 | my $m = $comp->m; | |
| 33 | 1 | ▶ | is( $m->capture( sub { print "abcde" } ), 'abcde' ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 34 | } | ||
| 35 | 1 | ); | |
| 36 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 37 | |||
| 38 | 1 | ▶ | sub test_comp_exists : Tests { |
|
Subroutine
test_comp_exists: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 39 | 1 | my $self = shift; | |
| 40 | |||
| 41 | 1 | $self->add_comp( path => '/comp_exists/one.mc', src => 'hi' ); | |
| 42 | 1 | $self->test_comp( | |
| 43 | path => '/comp_exists/two.mc', | ||
| 44 | src => ' | ||
| 45 | % foreach my $path (qw(/comp_exists/one.mc /comp_exists/two.mc /comp_exists/three.mc one.mc two.mc three.mc)) { | ||
| 46 | <% $path %>: <% $m->comp_exists($path) ? "yes" : "no" %> | ||
| 47 | % } | ||
| 48 | ', | ||
| 49 | expect => ' | ||
| 50 | /comp_exists/one.mc: yes | ||
| 51 | /comp_exists/two.mc: yes | ||
| 52 | /comp_exists/three.mc: no | ||
| 53 | one.mc: yes | ||
| 54 | two.mc: yes | ||
| 55 | three.mc: no | ||
| 56 | ', | ||
| 57 | ); | ||
| 58 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 59 | |||
| 60 | 1 | ▶ | sub test_current_comp_class : Tests { |
|
Subroutine
test_current_comp_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 61 | shift->test_comp( | ||
| 62 | 1 | path => '/current_comp_class.mc', | |
| 63 | src => '<% ' . __PACKAGE__ . '::_get_current_comp_class($m)->cmeta->path %>', | ||
| 64 | expect => '/current_comp_class.mc' | ||
| 65 | ); | ||
| 66 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 67 | |||
| 68 | 1 | ▶ | sub test_id : Tests { |
|
Subroutine
test_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 69 | 1 | my $self = shift; | |
| 70 | 1 | $self->setup_dirs; | |
| 71 | 1 | $self->add_comp( path => '/id.mc', src => 'id=<% $m->id %>' ); | |
| 72 | 1 | my ($id1) = ( $self->interp->run('/id')->output =~ /id=(\d+)/ ); | |
| 73 | 1 | my ($id2) = ( $self->interp->run('/id')->output =~ /id=(\d+)/ ); | |
| 74 | 1 | ok( $id1 != $id2 ); | |
| 75 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 76 | |||
| 77 | 1 | ▶ | sub test_log : Tests { |
|
Subroutine
test_log: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 78 | 1 | my $self = shift; | |
| 79 | 1 | $self->add_comp( path => '/log/one.mc', src => '% $m->log->info("message one")' ); | |
| 80 | $self->run_test_in_comp( | ||
| 81 | path => '/log.mc', | ||
| 82 | 1 | ▶ | test => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 83 | 1 | my $comp = shift; | |
| 84 | 1 | my $m = $comp->m; | |
| 85 | 1 | $m->comp('/log/one.mc'); | |
| 86 | 1 | $log->contains_ok("message one"); | |
| 87 | }, | ||
| 88 | 1 | ); | |
| 89 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 90 | |||
| 91 | 1 | ▶ | sub test_notes : Tests { |
|
Subroutine
test_notes: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 92 | 1 | my $self = shift; | |
| 93 | 1 | $self->add_comp( | |
| 94 | path => '/show', | ||
| 95 | src => ' | ||
| 96 | <% $m->notes("foo") %> | ||
| 97 | % $m->notes("foo", 3); | ||
| 98 | ', | ||
| 99 | ); | ||
| 100 | 1 | $self->test_comp( | |
| 101 | src => ' | ||
| 102 | % $m->notes("foo", 2); | ||
| 103 | <% $m->notes("foo") %> | ||
| 104 | <& /show &> | ||
| 105 | <% $m->notes("foo") %> | ||
| 106 | ', | ||
| 107 | expect => "2\n\n2\n\n3\n", | ||
| 108 | ); | ||
| 109 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 110 | |||
| 111 | 1 | ▶ | sub test_page : Tests { |
|
Subroutine
test_page: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 112 | 1 | my $self = shift; | |
| 113 | 1 | $self->add_comp( path => '/page/other.mi', src => '<% $m->page->cmeta->path %>' ); | |
| 114 | 1 | $self->test_comp( | |
| 115 | path => '/page/first.mc', | ||
| 116 | src => '<% $m->page->cmeta->path %>; <& other.mi &>', | ||
| 117 | expect => '/page/first.mc; /page/first.mc' | ||
| 118 | ); | ||
| 119 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 120 | |||
| 121 | 1 | ▶ | sub test_result_data : Tests { |
|
Subroutine
test_result_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 122 | 1 | my $self = shift; | |
| 123 | 1 | $self->test_comp( | |
| 124 | src => '% $m->result->data->{color} = "red"', | ||
| 125 | expect_data => { color => "red" } | ||
| 126 | ); | ||
| 127 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 128 | |||
| 129 | 1 | ▶ | sub test_scomp : Tests { |
|
Subroutine
test_scomp: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 130 | 1 | my $self = shift; | |
| 131 | 1 | $self->add_comp( path => '/str', src => 'abcde' ); | |
| 132 | $self->run_test_in_comp( | ||
| 133 | 1 | ▶ | test => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 134 | 1 | my $comp = shift; | |
| 135 | 1 | my $m = $comp->m; | |
| 136 | 1 | is( $m->scomp('/str'), 'abcde' ); | |
| 137 | 1 | ▶ | is( $m->capture( sub { $m->scomp('/str') } ), '' ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 138 | } | ||
| 139 | 1 | ); | |
| 140 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 141 | |||
| 142 | 1 | ▶ | sub test_go : Tests { |
|
Subroutine
test_go: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 143 | 1 | my $self = shift; | |
| 144 | |||
| 145 | 1 | my ( $buf, $result ); | |
| 146 | |||
| 147 | 1 | reset_id(); | |
| 148 | 1 | $self->add_comp( | |
| 149 | path => '/subreq/other.mc', | ||
| 150 | src => ' | ||
| 151 | id=<% $m->id %> | ||
| 152 | <% $m->page->cmeta->path %> | ||
| 153 | <% $m->request_path %> | ||
| 154 | args: <% Mason::Util::dump_one_line($m->request_args) %> | ||
| 155 | ', | ||
| 156 | ); | ||
| 157 | 1 | $self->test_comp( | |
| 158 | path => '/subreq/go.mc', | ||
| 159 | src => ' | ||
| 160 | This should not get printed. | ||
| 161 | <%perl>$m->go("/subreq/other", foo => 5);</%perl>', | ||
| 162 | expect => ' | ||
| 163 | id=1 | ||
| 164 | /subreq/other.mc | ||
| 165 | /subreq/other | ||
| 166 | args: {foo => 5} | ||
| 167 | ', | ||
| 168 | ); | ||
| 169 | 1 | reset_id(); | |
| 170 | 1 | $self->test_comp( | |
| 171 | path => '/subreq/go_with_req_params.mc', | ||
| 172 | src => ' | ||
| 173 | This should not get printed. | ||
| 174 | <%perl>my $buf; $m->go({out_method => \$buf}, "/subreq/other", foo => 5)</%perl>', | ||
| 175 | expect => '', | ||
| 176 | ); | ||
| 177 | |||
| 178 | 1 | reset_id(); | |
| 179 | 1 | $result = $self->interp->run( { out_method => \$buf }, '/subreq/go' ); | |
| 180 | 1 | is( $result->output, '', 'no output' ); | |
| 181 | 1 | is( | |
| 182 | $buf, ' | ||
| 183 | id=1 | ||
| 184 | /subreq/other.mc | ||
| 185 | /subreq/other | ||
| 186 | args: {foo => 5} | ||
| 187 | ', 'output in buf' | ||
| 188 | ); | ||
| 189 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 190 | |||
| 191 | 1 | ▶ | sub test_visit : Tests { |
|
Subroutine
test_visit: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 192 | 1 | my $self = shift; | |
| 193 | |||
| 194 | 1 | my ( $buf, $result ); | |
| 195 | |||
| 196 | 1 | reset_id(); | |
| 197 | 1 | $self->add_comp( | |
| 198 | path => '/subreq/other.mc', | ||
| 199 | src => ' | ||
| 200 | id=<% $m->id %> | ||
| 201 | <% $m->page->cmeta->path %> | ||
| 202 | <% $m->request_path %> | ||
| 203 | args: <% Mason::Util::dump_one_line($m->request_args) %> | ||
| 204 | ', | ||
| 205 | ); | ||
| 206 | 1 | $self->test_comp( | |
| 207 | path => '/subreq/visit.mc', | ||
| 208 | src => ' | ||
| 209 | begin | ||
| 210 | id=<% $m->id %> | ||
| 211 | <%perl>$m->visit("/subreq/other", foo => 5);</%perl> | ||
| 212 | id=<% $m->id %> | ||
| 213 | end | ||
| 214 | ', | ||
| 215 | expect => ' | ||
| 216 | begin | ||
| 217 | id=0 | ||
| 218 | id=1 | ||
| 219 | /subreq/other.mc | ||
| 220 | /subreq/other | ||
| 221 | args: {foo => 5} | ||
| 222 | id=0 | ||
| 223 | end | ||
| 224 | ', | ||
| 225 | ); | ||
| 226 | |||
| 227 | 1 | reset_id(); | |
| 228 | 1 | $self->test_comp( | |
| 229 | path => '/subreq/visit_with_req_params.mc', | ||
| 230 | src => ' | ||
| 231 | begin | ||
| 232 | id=<% $m->id %> | ||
| 233 | <%perl>my $buf; $m->visit({out_method => \$buf}, "/subreq/other", foo => 5); print uc($buf);</%perl> | ||
| 234 | id=<% $m->id %> | ||
| 235 | end | ||
| 236 | ', | ||
| 237 | expect => ' | ||
| 238 | begin | ||
| 239 | id=0 | ||
| 240 | ID=1 | ||
| 241 | /SUBREQ/OTHER.MC | ||
| 242 | /SUBREQ/OTHER | ||
| 243 | ARGS: {FOO => 5} | ||
| 244 | id=0 | ||
| 245 | end | ||
| 246 | ', | ||
| 247 | ); | ||
| 248 | |||
| 249 | 1 | reset_id(); | |
| 250 | 1 | $result = $self->interp->run( { out_method => \$buf }, '/subreq/visit' ); | |
| 251 | 1 | is( $result->output, '', 'no output' ); | |
| 252 | 1 | is( | |
| 253 | $buf, ' | ||
| 254 | begin | ||
| 255 | id=0 | ||
| 256 | id=1 | ||
| 257 | /subreq/other.mc | ||
| 258 | /subreq/other | ||
| 259 | args: {foo => 5} | ||
| 260 | id=0 | ||
| 261 | end | ||
| 262 | ', 'visit with initial out_method' | ||
| 263 | ); | ||
| 264 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 265 | |||
| 266 | 6 | ▶ | sub reset_id { |
|
Subroutine
reset_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 267 | 6 | Mason::Request->_reset_next_id; | |
| 268 | } | ||
| 269 | |||
| 270 | 1 | 1; | |