Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
s/Bugs/Issues/ as discussed in #720
Also, tidies t/controller/shared/release-info.t
  • Loading branch information
oalders committed Jan 13, 2014
1 parent 6aa9f93 commit 6932d8b
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 125 deletions.
2 changes: 1 addition & 1 deletion root/inc/release-info.html
Expand Up @@ -19,7 +19,7 @@
ELSE;
'https://rt.cpan.org/Public/Dist/Display.html?Name=' _ release.distribution | uri;
END;
%>">Bugs</a><% IF distribution.bugs %> (<% distribution.bugs.active %>)<% END %></li>
%>">Issues</a><% IF distribution.bugs %> (<% distribution.bugs.active %>)<% END %></li>
<% IF rating.count > 0 %>
<li><% INCLUDE inc/rating.html rating = rating, distribution = release.distribution %></li>
<% END %>
Expand Down
271 changes: 147 additions & 124 deletions t/controller/shared/release-info.t
Expand Up @@ -16,12 +16,12 @@ my @optional = qw(
);

# Use a counter to make sure we at least do each optional test once.
my %tested = map { ($_ => 0) } @optional;
my %tested = map { ( $_ => 0 ) } @optional;

# global var (eww) used for test names
my $current;

sub optional_test; # predeclare for non-parenthetical usage below
sub optional_test; # predeclare for non-parenthetical usage below

test_psgi app, sub {
my $cb = shift;
Expand All @@ -30,164 +30,187 @@ test_psgi app, sub {
# Setting to false does not test for failure, it simply skips the test.

my @tests = (

# has all optional tests
{ module => 'Dist::Zilla' },

# release name different than just s/::/-/g
{ module => 'LWP::UserAgent', release => 'libwww-perl', repository => 0, home_page => 0 },
{ module => 'LWP::UserAgent',
release => 'libwww-perl',
repository => 0,
home_page => 0
},

# no optional tests
{ module => 'CGI::Bus', home_page => 0, reviews => 0, repository => 0, favorited => 0 },
{ module => 'CGI::Bus',
home_page => 0,
reviews => 0,
repository => 0,
favorited => 0
},
);

foreach my $test ( @tests ) {
($test->{release} = $test->{module}) =~ s/::/-/g
if !$test->{release};

# turn tests on by default
exists($test->{$_}) or $test->{$_} = 1
for @optional;

# short cuts
my ($module, $release) = @{$test}{qw(module release)};
my $first_letter = uc(substr($release, 0, 1));
foreach my $test (@tests) {
( $test->{release} = $test->{module} ) =~ s/::/-/g
if !$test->{release};

foreach my $type ( qw(module release) ) {
my $name = $test->{ $type };
$current = {desc => "$type $name", test => $test};
# turn tests on by default
exists( $test->{$_} ) or $test->{$_} = 1 for @optional;

my $req_uri = $type eq 'module' ? "/pod/$name" : "/release/$name";
# short cuts
my ( $module, $release ) = @{$test}{qw(module release)};
my $first_letter = uc( substr( $release, 0, 1 ) );

ok( my $res = $cb->( GET $req_uri ), "GET $req_uri" );
is( $res->code, 200, 'code 200' );
my $tx = tx($res);
foreach my $type (qw(module release)) {
my $name = $test->{$type};
$current = { desc => "$type $name", test => $test };

# these first tests are similar between the controllers only because of
# consistecy or coincidence and are not specifically related to release-info
$tx->like( '/html/head/title', qr/$name/, qq[title includes name "$name"] );
my $req_uri = $type eq 'module' ? "/pod/$name" : "/release/$name";

ok( $tx->find_value(qq<//a[\@href="$req_uri"]>),
'contains permalink to resource'
);
ok( my $res = $cb->( GET $req_uri ), "GET $req_uri" );
is( $res->code, 200, 'code 200' );
my $tx = tx($res);

ok( my $this = $tx->find_value('//a[text()="This version"]/@href'),
'contains link to "this" version' );
# these first tests are similar between the controllers only because of
# consistecy or coincidence and are not specifically related to release-info
$tx->like( '/html/head/title', qr/$name/,
qq[title includes name "$name"] );

# A fragile and unsure way to get the version, but at least an 80% solution.
# TODO: Set up a fake cpan; We'll know what version to expect; we can test that this matches
ok( my $version = ($this =~ m!(?:/pod)?/release/[^/]+/$release-([^/"]+)!)[0],
'got version from "this" link' );
ok( $tx->find_value(qq<//a[\@href="$req_uri"]>),
'contains permalink to resource' );

# TODO: latest version (should be where we already are)
# TODO: author
ok( my $this
= $tx->find_value('//a[text()="This version"]/@href'),
'contains link to "this" version'
);

# not in release-info.html but should be shown on both:
# A fragile and unsure way to get the version, but at least an 80% solution.
# TODO: Set up a fake cpan; We'll know what version to expect; we can test that this matches
ok( my $version
= (
$this =~ m!(?:/pod)?/release/[^/]+/$release-([^/"]+)! )
[0],
'got version from "this" link'
);

my $favs = '//*[contains(@class, "favorite")]';
$tx->like( $favs, qr/\+\+$/, 'tag for favorites (++)' );
# TODO: latest version (should be where we already are)
# TODO: author

# not in release-info.html but should be shown on both:

my $favs = '//*[contains(@class, "favorite")]';
$tx->like( $favs, qr/\+\+$/, 'tag for favorites (++)' );

optional_test favorited => sub {
ok( $tx->find_value("$favs/span") > 0,
'dist has been marked as favorite'
);
};

# Info about a release (either the one we're looking at or the one the module belongs to)

# TODO: Download
# TODO: Changes

optional_test home_page => sub {
ok( $tx->find_value('//a[text()="Homepage"]/@href'),
'link for resources.homepage' );
};

# test separate links for both web and url keys (if specified)
optional_test repository => sub {
ok( $tx->find_value('//a[text()="Repository"]/@href'),
'link for resources.repository.web' );

ok( $tx->find_value('//a[text()="git clone"]/@href'),
'link for resources.repository.url' );
};

# we could test the rt.cpan.org link... i think others are verbatim from the META file
ok( $tx->find_value('//a[text()="Issues"]/@href'),
'link for bug tracker' );

# not all dists have reviews
my $reviews
= '//div[@class="search-bar"]//div[starts-with(@class, "rating-")]/following-sibling::a';
optional_test reviews => sub {
$tx->is(
"$reviews/\@href",
"http://cpanratings.perl.org/dist/$release",
'link to current reviews'
);
$tx->like(
$reviews,
qr/\d+ reviews?/i,
'current rating and number of reviews listed'
);
};

# all dists should get a link to rate it; test built url
$tx->is(
'//div[@class="search-bar"]//a[text()="Rate this distribution"]/@href',
"http://cpanratings.perl.org/rate/?distribution=$release",
'cpanratings link to rate this dist'
);

optional_test favorited => sub {
ok( $tx->find_value("$favs/span") > 0,
'dist has been marked as favorite' );
};
# test format of cpantesters link
$tx->is(
'//a[text()="Test results"]/@href',
"http://www.cpantesters.org/distro/$first_letter/$release.html#$release-$version?oncpan=1&distmat=1",
'link to test results'
);

# Info about a release (either the one we're looking at or the one the module belongs to)
# TODO: release.tests.size

# TODO: Download
# TODO: Changes
$tx->is(
'//a[@title="Matrix"]/@href',
"http://matrix.cpantesters.org/?dist=$release+$version",
'link to test matrix'
);

optional_test home_page => sub {
ok( $tx->find_value('//a[text()="Homepage"]/@href'),
'link for resources.homepage' );
};
# version select box
ok( $tx->find_value(
'//select[@name="release"]/option[text()="Go to version"]'
),
'version select box'
);

# test separate links for both web and url keys (if specified)
optional_test repository => sub {
ok( $tx->find_value('//a[text()="Repository"]/@href'),
'link for resources.repository.web' );
$tx->like(

ok( $tx->find_value('//a[text()="git clone"]/@href'),
'link for resources.repository.url' );
};
# "go to" option has no value attr
'//select[@name="release"]/option[@value][1]',
qr/\([A-Z]{3,9} on \d{4}-\d{2}-\d{2}\)$/,
'version ends with pause id and date in common format'
);

# we could test the rt.cpan.org link... i think others are verbatim from the META file
ok( $tx->find_value('//a[text()="Bugs"]/@href'),
'link for bug tracker' );
# TODO: diff with version
# TODO: search
# TODO: toggle table of contents (module only)

# not all dists have reviews
my $reviews = '//div[@class="search-bar"]//div[starts-with(@class, "rating-")]/following-sibling::a';
optional_test reviews => sub {
$tx->is(
"$reviews/\@href",
"http://cpanratings.perl.org/dist/$release",
'link to current reviews'
);
$tx->like(
$reviews,
qr/\d+ reviews?/i,
'current rating and number of reviews listed'
'//a[text()="Reverse dependencies"]/@href',
qr{^/requires/distribution/$release(\?|$)},
'reverse deps link uses dist name'
);
};

# all dists should get a link to rate it; test built url
$tx->is(
'//div[@class="search-bar"]//a[text()="Rate this distribution"]/@href',
"http://cpanratings.perl.org/rate/?distribution=$release",
'cpanratings link to rate this dist'
);

# test format of cpantesters link
$tx->is(
'//a[text()="Test results"]/@href',
"http://www.cpantesters.org/distro/$first_letter/$release.html#$release-$version?oncpan=1&distmat=1",
'link to test results'
);

# TODO: release.tests.size

$tx->is(
'//a[@title="Matrix"]/@href',
"http://matrix.cpantesters.org/?dist=$release+$version",
'link to test matrix'
);

# version select box
ok( $tx->find_value('//select[@name="release"]/option[text()="Go to version"]'),
'version select box' );

$tx->like(
# "go to" option has no value attr
'//select[@name="release"]/option[@value][1]',
qr/\([A-Z]{3,9} on \d{4}-\d{2}-\d{2}\)$/,
'version ends with pause id and date in common format'
);

# TODO: diff with version
# TODO: search
# TODO: toggle table of contents (module only)

$tx->like(
'//a[text()="Reverse dependencies"]/@href',
qr{^/requires/distribution/$release(\?|$)},
'reverse deps link uses dist name'
);

# TODO: explorer
# TODO: activity

# TODO: explorer
# TODO: activity
}
}
}

ok( $tested{$_} > 0, "at least one module tested $_" )
for sort keys %tested;
ok( $tested{$_} > 0, "at least one module tested $_" )
for sort keys %tested;

};

done_testing;

sub optional_test {
my ($name, $sub) = @_;
my ( $name, $sub ) = @_;
subtest $name => sub {
plan skip_all => "$name test for $current->{desc}"
unless $current->{test}->{ $name };
unless $current->{test}->{$name};
$sub->();
++$tested{ $name };
++$tested{$name};
};
}

0 comments on commit 6932d8b

Please sign in to comment.