File Coverage

File:t/stickies.t
Coverage:100.0%

linestmtbrancondsubpodtimecode
1#!/usr/bin/env perl
2# ABSTRACT:
3# This is a whitebox test to see if "notice_stickie" pushes
4# stickies into session.
5
6
1
1
1
99
10
10
use strict;
7
1
1
1
10
2
11
use warnings;
8
1
1
1
114
6
5
use Moose ();
9
10
1
1
1
90
6
20
use Test::More tests => 2;
11
12
1
35
my $STICKIE_TEXT = "Foo" . time;
13
14package FooController;
15
1
1
1
86
5
14
use Railsish::Controller;
16
17sub index {
18
1
10
    notice_stickie($STICKIE_TEXT)
19}
20
21package main;
22
23
1
1
1
77
5
15
use HTTP::Engine;
24
1
1
1
87
4
80
use HTTP::Request;
25
1
1
1
11
3
10
use HTTP::Engine::Response;
26
1
1
1
85
6
16
use Railsish::Router;
27
1
1
1
86
5
20
use Railsish::Dispatcher;
28
1
1
1
87
4
17
use CGI::Cookie;
29
30Railsish::Router->draw(
31    sub {
32
1
5
        my ($map) = @_;
33
1
8
        $map->connect("", controller => "foo");
34    }
35
1
25
);
36
37my $engine = HTTP::Engine->new(
38    interface => {
39        module => "Test",
40        request_handler => sub {
41
1
40
            Railsish::Dispatcher->dispatch(@_);
42        }
43    }
44
1
36
);
45
46
1
1
1
12
3
18
use YAML;
47
1
1
1
11
3
8
use Crypt::CBC;
48
1
1
1
9
4
12
use MIME::Base64;
49
1
1
1
9
4
8
use JSON::XS;
50
51
1
85
my $response = $engine->run(HTTP::Request->new(GET => "http://localhost/"));
52
1
2
my $session_cookie = CGI::Cookie->parse($response->header('Set-Cookie'))->{_railsish_session};
53
54# diag YAML::Dump($session_cookie);
55
56# Decipher session from cookie.
57
1
1722
my $cipher = Crypt::CBC->new(-key => "railsish", -cipher => "Rijndael");
58
1
502
my $ciphertext_base64 = $session_cookie->value;
59
1
36
my $ciphertext_unbase64 = decode_base64($ciphertext_base64);
60
1
9
my $json = $cipher->decrypt($ciphertext_unbase64);
61
1
1226
my $session = decode_json($json);
62
63
1
1
5
7
my @notice_stickies = @{$session->{notice_stickies}};
64
1
12
ok(@notice_stickies > 0);
65
1
14
is_deeply(\@notice_stickies, [ { text => $STICKIE_TEXT }]);