Skip to content

Commit

Permalink
Changed uri_index to point to a page with content
Browse files Browse the repository at this point in the history
Crawl the subtree to find an object containing page elements
  • Loading branch information
niner committed Nov 3, 2009
1 parent 9f81312 commit 980b316
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
12 changes: 10 additions & 2 deletions lib/CiderCMS/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;

use Scalar::Util qw(weaken);
use List::MoreUtils qw(any);

use CiderCMS::Attribute;

Expand Down Expand Up @@ -189,14 +190,21 @@ sub uri {

=head2 uri_index()
Returns an URI to the index action for this object
Returns an URI to the first object in this subtree that contains page elements.
If none does, return the URI to the first child.
=cut

sub uri_index {
my ($self) = @_;

return $self->uri . '/index.html';
my @children = $self->children;
if (not @children or any { $_->type->{page_element} } @children) { # we contain no children at all or page elements
return $self->uri . '/index.html';
}
else {
return $children[0]->uri_index;
}
}

=head2 uri_management()
Expand Down
20 changes: 18 additions & 2 deletions t/controller_Content-Management.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use utf8;
eval "use Test::WWW::Mechanize::Catalyst 'CiderCMS'";
plan $@
? ( skip_all => 'Test::WWW::Mechanize::Catalyst required' )
: ( tests => 45 );
: ( tests => 49 );

ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' );

Expand Down Expand Up @@ -85,6 +85,13 @@ $mech->submit_form_ok({
},
button => 'save',
});
$mech->follow_link_ok({ url_regex => qr{manage_add\b.*\btype=folder} }, 'Add a folder');
$mech->submit_form_ok({
with_fields => {
title => 'Folder 0.1',
},
button => 'save',
});
$mech->follow_link_ok({ url_regex => qr(test.example/manage) }, 'Back to top level');
$mech->follow_link_ok({ url_regex => qr{manage_add\b.*\btype=folder}, n => 3 }, 'Add a folder');
$mech->submit_form_ok({
Expand All @@ -106,7 +113,7 @@ $mech->content_like(qr((?s)folder_0.*folder_1.*folder_2), 'Folders in correct or

SKIP: {
eval { require Test::XPath; };
skip 'Test::XPath not installed', 12 if $@;
skip 'Test::XPath not installed', 14 if $@;

my $xpath = Test::XPath->new( xml => $mech->content, is_html => 1 );
$xpath->like('//div[@class="child folder"][3]/@id', qr/\A child_(\d+) \z/x);
Expand Down Expand Up @@ -139,4 +146,13 @@ SKIP: {
$mech->get_ok($mech->uri . "_paste?attribute=children;id=$id;after=$folder_3_id");
$mech->content_like(qr((?s)folder_3.*folder_2), 'Folders in correct order');
$mech->follow_link_ok({ url_regex => qr{folder_2/manage} }, 'Folder 2 works');
$mech->back;

# now move the textarea to folder_3 to set up for the content tests
$xpath = Test::XPath->new( xml => $mech->content, is_html => 1 );
$xpc = $xpath->xpc;
my $textarea_id = $xpc->findvalue('//div[@class="child textarea"][1]/@id');
($textarea_id) = $textarea_id =~ /child_(\d+)/;
$mech->follow_link_ok({ url_regex => qr{folder_3/manage} });
$mech->get_ok($mech->uri . "_paste?attribute=children;id=$textarea_id");
}
8 changes: 5 additions & 3 deletions t/controller_Content_env_instance.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ BEGIN {
eval "use Test::WWW::Mechanize::Catalyst 'CiderCMS'";
plan $@
? ( skip_all => 'Test::WWW::Mechanize::Catalyst required' )
: ( tests => 11 );
: ( tests => 12 );

ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' );

$mech->get_ok('http://localhost/index.html');

$mech->title_like(qr/Testsite/, 'Title correct');
$mech->title_is('Testsite', 'Title correct');
$mech->content_like(qr/Foo bar baz!/, 'Textarea present');
my $styles = $mech->find_link(url_regex => qr{styles.css});
$mech->links_ok([ $styles ]);
Expand All @@ -32,13 +32,15 @@ $mech->back;
$mech->get_ok('http://localhost/', 'new layout works');
$mech->follow_link_ok({ url_regex => qr(folder_1) });

$mech->title_is('Folder 3', 'We got to the first subfolder with page elements');

SKIP: {
eval { require Test::XPath; };
skip 'Test::XPath not installed', 2 if $@;

my $xpath = Test::XPath->new( xml => $mech->content, is_html => 1 );
$xpath->ok('id("subnav")', 'subnav found');

$mech->follow_link_ok({ url_regex => qr(folder_3) });
$mech->follow_link_ok({ url_regex => qr(folder_2) });
}

0 comments on commit 980b316

Please sign in to comment.