Lines 18-92
Link Here
|
18 |
|
18 |
|
19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
20 |
|
20 |
|
21 |
use Test::More tests => 2; |
21 |
use Test::More tests => 10; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
use Data::Dumper::Concise; |
|
|
24 |
|
23 |
|
25 |
use C4::Context; |
24 |
use C4::Context; |
26 |
use Koha::Database; |
25 |
use Koha::Database; |
27 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
28 |
|
27 |
|
29 |
BEGIN { |
28 |
BEGIN { |
30 |
use_ok('Koha::Objects'); |
|
|
31 |
use_ok('Koha::CmsPages'); |
29 |
use_ok('Koha::CmsPages'); |
|
|
30 |
use_ok('Koha::CmsPage'); |
32 |
} |
31 |
} |
33 |
|
32 |
|
34 |
my $builder = t::lib::TestBuilder->new(); |
33 |
my $database = Koha::Database->new(); |
|
|
34 |
my $schema = $database->schema(); |
35 |
my $dbh = C4::Context->dbh; |
36 |
my $builder = t::lib::TestBuilder->new(); |
35 |
|
37 |
|
36 |
# Start transaction |
38 |
$schema->storage->txn_begin(); |
37 |
my $dbh = C4::Context->dbh; |
39 |
$dbh->do( 'DELETE FROM cms_pages' ); |
38 |
$dbh->{ AutoCommit } = 0; |
40 |
$dbh->do( 'DELETE FROM issues' ); |
39 |
$dbh->{ RaiseError } = 1; |
|
|
40 |
$dbh->do( 'DELETE FROM items' ); |
41 |
$dbh->do( 'DELETE FROM borrowers' ); |
41 |
$dbh->do( 'DELETE FROM borrowers' ); |
|
|
42 |
$dbh->do( 'DELETE FROM items' ); |
42 |
$dbh->do( 'DELETE FROM branches' ); |
43 |
$dbh->do( 'DELETE FROM branches' ); |
43 |
$dbh->do( 'DELETE FROM cms_pages' ); |
|
|
44 |
|
44 |
|
45 |
my $branchcode = $builder->build({ source => 'Branch' }); |
45 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
46 |
|
46 |
my $borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'}; |
47 |
my $page10 = $builder->build({ |
47 |
|
48 |
source => 'CmsPage', |
48 |
# new parent page |
49 |
value => { |
49 |
my $parent_page = Koha::CmsPages->add({ |
50 |
parent => undef, |
50 |
id => 1, |
51 |
title_link => 'page 10', |
51 |
branchcode => $branchcode, |
52 |
title => 'full page 10', |
52 |
location => 2, |
53 |
published => 1, |
53 |
lang => '', |
54 |
sortorder => 1, |
54 |
parent => undef, |
55 |
} |
55 |
title_link => 'page1', |
56 |
}); |
56 |
title => 'Page 1', |
57 |
my $page11 = $builder->build({ |
57 |
publish => 0, |
58 |
source => 'CmsPage', |
58 |
sortorder => 1, |
59 |
value => { |
59 |
content => "This is the first page.", |
60 |
parent => $page10->{'id'}, |
|
|
61 |
title_link => 'subpage 11', |
62 |
title => 'full subpage 11', |
63 |
published => 1, |
64 |
sortorder => 0, |
65 |
} |
66 |
}); |
60 |
}); |
67 |
my $page12 = $builder->build({ |
61 |
|
68 |
source => 'CmsPage', |
62 |
is($parent_page->title, 'Page 1', "First page created"); |
69 |
value => { |
63 |
|
70 |
parent => $page10->{'id'}, |
64 |
# new child page |
71 |
title_link => 'subpage 12', |
65 |
my $child_page = Koha::CmsPages->add({ |
72 |
title => 'full subpage 12', |
66 |
id => 2, |
73 |
published => 1, |
67 |
branchcode => $branchcode, |
74 |
sortorder => 1, |
68 |
location => 2, |
75 |
} |
69 |
lang => '', |
|
|
70 |
parent => $parent_page->id, |
71 |
title_link => 'page2', |
72 |
title => 'Page 2', |
73 |
publish => 1, |
74 |
sortorder => 2, |
75 |
content => "This is the second page.", |
76 |
}); |
76 |
}); |
77 |
my $page20 = $builder->build({ |
77 |
|
78 |
source => 'CmsPage', |
78 |
# $page->parent specifies who this page is the parent of |
79 |
value => { |
79 |
is(Koha::CmsPages->find($child_page->parent)->title, 'Page 1', 'Child and parent page connected'); |
80 |
parent => undef, |
80 |
|
81 |
title_link => 'page 20', |
81 |
# Koha::CmsPages->list() with no specified ID should return all pages |
82 |
title => 'full page 20', |
82 |
my ( $page_list, $parent_list, $data ) = Koha::CmsPages->list( '' ); |
83 |
published => 0, |
83 |
is(scalar @{ $page_list }, 2, "Two pages have been created"); |
84 |
sortorder => 2, |
84 |
|
85 |
} |
85 |
# Koha::CmsPages->list() is used for filtering (filter display location) |
|
|
86 |
( $page_list, $parent_list, $data ) = Koha::CmsPages->list( '', 2, '', '' ); |
87 |
is(scalar @{ $page_list }, 2, "Both pages can be seen on staff interface"); |
88 |
|
89 |
is($parent_list->[0]->{id}, $parent_page->id, "Correct page is returned as a parent"); |
90 |
is($data, undef, "Data is undefined because no ID was given"); |
91 |
|
92 |
# Koha::CmsPages->list() is used to show data about a page when given an ID |
93 |
( $page_list, $parent_list, $data ) = Koha::CmsPages->list( 2 ); |
94 |
is($data->{content}, "This is the second page.", "Data is defined when given an ID"); |
95 |
|
96 |
# Try to add a child page under a page where their locations do not match up |
97 |
my $test_page = Koha::CmsPages->add({ |
98 |
id => 3, |
99 |
branchcode => $branchcode, |
100 |
location => 1, |
101 |
lang => '', |
102 |
parent => $child_page->id, |
103 |
title_link => 'failedadd', |
104 |
title => 'Failed add', |
105 |
publish => 0, |
106 |
sortorder => 3, |
107 |
content => "This page should not be added", |
86 |
}); |
108 |
}); |
87 |
|
109 |
|
88 |
my $result = Koha::CmsPages->child_links( undef ); |
110 |
is($test_page, undef, "Child page cannot be added under a page if their locations do not match"); |
89 |
is_deeply( $result, [ $page10, $page20 ]); |
|
|
90 |
|
111 |
|
91 |
$dbh->rollback(); |
112 |
$dbh->rollback(); |
92 |
|
113 |
|