File: special-page.t

package info (click to toggle)
libmojomojo-perl 1.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,524 kB
  • sloc: perl: 14,730; xml: 120; sh: 97; makefile: 8; ruby: 6
file content (94 lines) | stat: -rw-r--r-- 2,739 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl
use Test::More;
BEGIN {
    $ENV{CATALYST_CONFIG} = 't/var/mojomojo.yml';
};

BEGIN {
    eval "use Test::WWW::Mechanize::Catalyst 'MojoMojo'";
    plan skip_all => 'need Test::WWW::Mechanize::Catalyst' if $@;

    eval "use WWW::Mechanize::TreeBuilder";
    plan skip_all => 'need WWW::Mechanize::TreeBuilder' if $@;

    plan tests => 25;
};

use_ok('MojoMojo::Extensions::Counter');

my $elem;
my $mech = Test::WWW::Mechanize::Catalyst->new;
WWW::Mechanize::TreeBuilder->meta->apply($mech);

$mech->get('/special/counter');
ok $mech->success, 'testing a simple get';
ok(($elem) = $mech->look_down(
    _tag => 'p',
    id => 'count'
), 'counter display');
if ($elem) {
    is $elem->as_trimmed_text, 0, 'checking that counter starts at 0';
}

$mech->get_ok('/special/counter.add', 'checking the add controller');
ok(($elem) = $mech->look_down(
    _tag => 'p',
    id => 'count'
), 'checking that the counter has been incremented');
if($elem) {
    is $elem->as_trimmed_text, 1, 'checking the counter update';
}

$mech->get_ok('/special/counter.add', 'checking the counter again');
ok(($elem) = $mech->look_down(
    _tag => 'p',
    id => 'count'
), 'checking that the counter has been incremented again');
if($elem) {
    is $elem->as_trimmed_text, 2, 'checking the counter update again';
}

$mech->get_ok('/special/counter', 'checking the persistence of the counter');
ok(($elem) = $mech->look_down(
    _tag => 'p',
    id => 'count'
), 'checking the persistence of the counter');
if($elem) {
    is $elem->as_trimmed_text, 2, 'checking the persistence of the counter';
}

$mech->get_ok('/special/counter.subtract', 'checking the subtract controller');
ok(($elem) = $mech->look_down(
    _tag => 'p',
    id => 'count'
), 'checking that the counter has been decremented');
if($elem) {
    is $elem->as_trimmed_text, 1, 'checking the counter update';
}

$mech->get_ok('/special/counter.subtract', 'checking the subtract controller again');
ok(($elem) = $mech->look_down(
    _tag => 'p',
    id => 'count'
), 'checking that the counter has been decremented');
if($elem) {
    is $elem->as_trimmed_text, 0, 'checking the counter update again';
}

$mech->get_ok('/special/counter', 'checking the persistence of the counter again');
ok(($elem) = $mech->look_down(
    _tag => 'p',
    id => 'count'
), 'checking the persistence of the counter');
if($elem) {
    is $elem->as_trimmed_text, 0, 'checking the persistence of the counter again';
}

$mech->get_ok('/special/counter.view', 'checking that the view controller works');
ok(($elem) = $mech->look_down(
    _tag => 'p',
    id => 'count'
), 'checking the view controller');
if($elem) {
    is $elem->as_trimmed_text, 0, 'checking that the view controller works';
}