File: tag.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 (60 lines) | stat: -rw-r--r-- 1,671 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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 16;

BEGIN{
    $ENV{CATALYST_CONFIG} = 't/var/mojomojo.yml';
    $ENV{CATALYST_DEBUG}  = 0;
};
use_ok('Test::WWW::Mechanize::Catalyst', 'MojoMojo' );

my $mech = Test::WWW::Mechanize::Catalyst->new;
my $uniq = time();

# login as admin so we can add tags
ok $mech->get('/.login');
$mech->submit_form(
    fields => {
        login => 'admin',
        pass => 'admin',
    }
);
ok $mech->success, 'logged in as admin via form';

# add three 'foo' tags
ok $mech->get("/.jsrpc/tag/foo_$uniq");
ok $mech->get("/help.jsrpc/tag/foo_$uniq");
ok $mech->get("/admin.jsrpc/tag/foo_$uniq");

# add two 'bar' tags
ok $mech->get("/.jsrpc/tag/bar_$uniq");
ok $mech->get("/help.jsrpc/tag/bar_$uniq");

# add one 'baz' tags
ok $mech->get("/.jsrpc/tag/baz_$uniq");

# fetch tags page
ok $mech->get('/.tags'), "got tags page";
ok $mech->success, "page ok";
my $content = $mech->content;

# check that the tags appear in the cloud successfully
my %cloud_class;
my @lines = split (/\n/, $content);
foreach my $line (@lines) {
   # <span class="tagcloud0"><a href="http://localhost/.list/foo_1250070923">foo_1250070923</a></span>
  my ($level, $tag) = $line =~ /tagcloud(\d+).*\>(\w+)_${uniq}\</;
  next unless (defined $level && $tag);

  # fail if we doubled up on tags somehow
  fail "we already saw $tag" if defined $cloud_class{$tag};
  $cloud_class{$tag} = $level;
}

ok defined $cloud_class{foo}, 'saw foo tag';
ok defined $cloud_class{bar}, 'saw bar tag';
ok defined $cloud_class{baz}, 'saw baz tag';

ok $cloud_class{bar} > $cloud_class{baz}, 'bar > baz';
ok $cloud_class{foo} == $cloud_class{bar}, 'foo = bar';