File: schema_DBIC_Page.t

package info (click to toggle)
libmojomojo-perl 1.11%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,496 kB
  • ctags: 927
  • sloc: perl: 14,671; sh: 148; xml: 120; makefile: 8; ruby: 6
file content (70 lines) | stat: -rwxr-xr-x 2,552 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
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

BEGIN {
    eval 'use DBD::SQLite';
    plan skip_all => 'need DBD::SQLite' if $@;

    eval 'use SQL::Translator';
    plan skip_all => 'need SQL::Translator' if $@;

    plan tests => 11;
}

use lib 't/lib';
use MojoMojoTestSchema;

my $schema = MojoMojoTestSchema->init_schema(populate => 1);

my ($root_path_pages, $root_proto_pages) = $schema->resultset('Page')->path_pages('/');
my $root_path_pages_count = @$root_path_pages;
my $root_proto_pages_count = @$root_proto_pages;
is( $root_path_pages_count, 1, 'exactly 1 page returned for path "/"...' );
is( $root_proto_pages_count, 0, '...and 0 "proto" pages' );
my $root = $root_path_pages->[0];
isa_ok($root,'MojoMojo::Schema::Result::Page');

my ($child_path_pages, $child_proto_pages) = $schema->resultset('Page')->path_pages('/child/grandchild');
my $child_path_pages_count = @$child_path_pages;
my $child_proto_pages_count = @$child_proto_pages;
is( $child_path_pages_count, 1, 'exactly 1 page returned for path "/child/grandchild"...' );
is( $child_proto_pages_count, 2, '...and 2 "proto" pages for the non-existent children' );

my $person = $schema->resultset('Person')->find( 1 );
$schema->resultset('Page')->create_path_pages(
    path_pages => $child_path_pages,
    proto_pages => $child_proto_pages,
    creator => $person->id,
);

($child_path_pages, $child_proto_pages) = $schema->resultset('Page')->path_pages('/child/grandchild');
$child_path_pages_count = @$child_path_pages;
$child_proto_pages_count = @$child_proto_pages;
is( $child_path_pages_count, 3, 'now 3 pages returned for path "/child/grandchild"...' );
is( $child_proto_pages_count, 0, '...and 0 "proto" pages, after creating the missing pages' );

my @child_names = map { $_->name } @$child_path_pages;
is_deeply( \@child_names, ['/', 'child', 'grandchild'], 'new children have the correct names');

my $root_page = $root_path_pages->[0];
my @descendant_names = map { $_->name } $root_page->descendants;

{
# test tagged_descendants
    my $tag = $schema->resultset('Tag')->create({
        tag => 'test',
        page => $root->id,
        person => 1
    });
    is(scalar $root->tagged_descendants('test'), 1, 'Got 1 tagged descendant.');

    my $tag2 = $schema->resultset('Tag')->create({
        tag => 'test',
        page => 2,
        person => 1
    });
    is(scalar $root->tagged_descendants('test'), 2, 'Got 2 tagged descendants.');
    is(scalar $root->tagged_descendants_by_date('test'), 2, 'Got 2 tagged descendants ordered by date.');
}