~allison/ubuntu/raring/libsvn-web-perl/fix-for-1106378

« back to all changes in this revision

Viewing changes to t/2basic.t

  • Committer: Package Import Robot
  • Author(s): Hilko Bengen
  • Date: 2012-10-22 21:08:14 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20121022210814-5wru25mlw6dakkr8
Tags: 0.63-1
* New Upstream version
* Updated dependencies
* Switched to Debhelper 8
* Set locale for running tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -w
 
1
#!/usr/bin/perl
 
2
 
2
3
use strict;
 
4
use warnings;
 
5
 
3
6
use SVN::Web::Test;
4
7
use Test::More;
5
8
 
8
11
my $can_tidy = eval { require Test::HTML::Tidy; 1 };
9
12
my $can_parse_rss = eval { require XML::RSS::Parser; 1 };
10
13
 
11
 
plan 'no_plan';
12
 
 
13
14
my $tidy;
14
15
if($can_tidy) {
15
 
    $tidy = new HTML::Tidy;
 
16
    $tidy = HTML::Tidy->new();
16
17
    $tidy->ignore(text => [ qr/trimming empty <span>/,
17
18
                            qr/<table> lacks "summary" attribute/, ]);
18
19
}
35
36
                    });
36
37
 
37
38
my $mech = $test->mech();
 
39
 
38
40
$mech->get_ok('http://localhost/svnweb/repos/browse/');
39
 
$mech->title_is('browse: /repos (Rev: HEAD, via SVN::Web)',
40
 
                        "'browse' has correct title") or diag $mech->content();
 
41
$mech->title_is(
 
42
    'browse: /repos (Rev: HEAD, via SVN::Web)',
 
43
    "'browse' has correct title")
 
44
    or diag $mech->content();
41
45
 
42
46
$mech->get('http://localhost/svnweb/repos/browse/?rev=1');
43
47
$mech->title_is(
44
48
    'browse: /repos (Rev: 1, via SVN::Web)',
45
 
    "'browse' with rev has correct title"
46
 
);
 
49
    "'browse' with rev has correct title")
 
50
    or diag $mech->content();
47
51
 
48
52
$mech->get('http://localhost/svnweb/repos/revision/?rev=2');
49
53
$mech->title_is('revision: /repos (Rev: 2, via SVN::Web)',
50
 
    "'revision' has correct title");
 
54
    "'revision' has correct title")
 
55
    or diag $mech->content();
51
56
 
52
57
$mech->get('http://localhost/svnweb/');
53
 
$mech->title_is('Repository List (via SVN::Web)', "'list' has correct title");
 
58
$mech->title_is('Repository List (via SVN::Web)', "'list' has correct title")
 
59
    or diag $mech->content();
54
60
 
55
 
diag "Recursively checking all links";
 
61
note "Recursively checking all links";
56
62
 
57
63
my $test_sub = sub {
58
 
    is($mech->status, 200, 'Fetched ' . $mech->uri());
 
64
    note('skip static files checks in local tests: '.$mech->uri), return
 
65
        if $mech->uri->path eq '/' or $mech->uri->path =~ m{/css/};
 
66
 
 
67
    is($mech->status, 200, 'Fetched ' . $mech->uri())
 
68
        or diag $mech->status;
59
69
 
60
70
    # Make sure that there are no '//' in the URI, unless preceeded by
61
71
    # a ':'.  This catches template bugs with too many slashes.
62
 
    unlike($mech->uri(), qr{(?<!:)//}, 'URI does not contain "//"');
63
 
 
64
 
    $mech->content_unlike(qr'An error occured', '  and content was correct');
 
72
    unlike($mech->uri(), qr{(?<!:)//}, 'URI does not contain "//"')
 
73
        or diag $mech->uri();
 
74
 
 
75
    $mech->content_unlike(qr'An error occured', '  and content was correct')
 
76
        or diag $mech->content;
 
77
 
65
78
    if($can_tidy 
66
79
       and ($mech->uri() !~ m{ (?:
67
80
                                   / (?: rss | checkout )
68
81
                                 | mime=text/plain
69
82
                               )}x)) {
70
83
        Test::HTML::Tidy::html_tidy_ok($tidy, $mech->content(),
71
 
                                       '  and is valid HTML')
 
84
                                       '  and is valid HTML ('.$mech->uri.')')
72
85
            or diag($mech->content());
73
86
    }
74
87
 
 
88
    # Make sure that all local links (like <a href="#anchor"...) has
 
89
    # appropriate anchors in code
 
90
    my @local_links = $mech->find_all_links(tag=>'a',url_regex=>qr/^\#/);
 
91
    foreach (@local_links) {
 
92
        my $name = $_->url;
 
93
        $name =~ s/^#//;
 
94
        $mech->content_like(qr/(?:id|name)=['"]$name(?:['"])/, "  and has element with name='$name' (".$mech->uri.")");
 
95
    }
 
96
 
75
97
    if($can_parse_rss and ($mech->uri() =~ m{/rss/})) {
76
 
        my $feed = $rss->parse_string($mech->content());
77
 
        ok(defined $feed, 'RSS parsed successfully')
78
 
          or diag $rss->errstr(), diag $mech->content();
 
98
        my $feed = $rss->parse_string($mech->content());
 
99
        ok(defined $feed, 'RSS parsed successfully')
 
100
          or diag $rss->errstr(), diag $mech->content();
79
101
 
80
 
        # Make sure that each item's <link> element is a full URL
81
 
        foreach my $item ($feed->query('//item')) {
82
 
            my $node = $item->query('link');
83
 
            like($node->text_content(), qr/^http/, 'RSS link is fully qualified')
84
 
              or diag $node->text_content();
85
 
        }
 
102
        {
 
103
            local $TODO = "I'am unsure about this test, in some environments full URL can't be"
 
104
                        ." obtained, so may be we can introduce canonical_uri in config?"
 
105
                        ." Anyway mark as todo for now";
 
106
            # Make sure that each item's <link> element is a full URL
 
107
            for my $item ($feed->query('//item')) {
 
108
                my $node = $item->query('link');
 
109
                like($node->text_content(), qr/^http/, 'RSS link is fully qualified')
 
110
                  or diag $node->text_content();
 
111
            }
 
112
        }
86
113
    }
87
114
};
88
115
 
89
116
$test->walk_site($test_sub);
 
117
 
 
118
done_testing;