View | Details | Raw Unified | Return to bug 14468
Collapse All | Expand All

(-)a/t/db_dependent/Labels/t_Profile.t (-22 / +23 lines)
Lines 17-28 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use Test::More tests => 27;
22
use Test::More tests => 27;
24
use C4::Context;
23
use C4::Context;
25
use Data::Dumper;
26
24
27
BEGIN {
25
BEGIN {
28
    use_ok('C4::Labels::Profile');
26
    use_ok('C4::Labels::Profile');
Lines 42-57 my $expected_profile = { Link Here
42
40
43
my $err = 0;
41
my $err = 0;
44
42
45
diag "Testing Profile->new() method.";
43
# Testing Profile->new()
46
ok(my $profile = C4::Labels::Profile->new(printer_name => 'Circulation Desk',paper_bin => 'bypass')) || diag"Profile->new() FAILED.";
44
ok(my $profile = C4::Labels::Profile->new(printer_name => 'Circulation Desk',paper_bin => 'bypass'), "Profile->new() success");
47
is_deeply($profile, $expected_profile) || diag "New profile object FAILED to verify.";
45
is_deeply($profile, $expected_profile, "New profile object verify success");
48
46
49
diag "Testing Profile->get_attr() method.";
47
# Testing Profile->get_attr()
50
foreach my $key (keys %{$expected_profile}) {
48
foreach my $key (keys %{$expected_profile}) {
51
    ok($expected_profile->{$key} eq $profile->get_attr($key)) || diag "Profile->get_attr() FAILED on attribute $key.";
49
    ok($expected_profile->{$key} eq $profile->get_attr($key),
50
        "Profile->get_attr() success on attribute $key");
52
}
51
}
53
52
54
diag "Testing Profile->set_attr() method.";
53
# Testing Profile->set_attr()
55
my $new_attr = {
54
my $new_attr = {
56
    printer_name    => 'Cataloging Desk',
55
    printer_name    => 'Cataloging Desk',
57
    template_id     => '1',
56
    template_id     => '1',
Lines 66-97 my $new_attr = { Link Here
66
65
67
foreach my $key (keys %{$new_attr}) {
66
foreach my $key (keys %{$new_attr}) {
68
    $err = $profile->set_attr($key, $new_attr->{$key});
67
    $err = $profile->set_attr($key, $new_attr->{$key});
69
    ok(($new_attr->{$key} eq $profile->get_attr($key)) && ($err lt 1)) || diag "Profile->set_attr() FAILED on attribute $key.";
68
    ok(($new_attr->{$key} eq $profile->get_attr($key)) && ($err lt 1),
69
        "Profile->set_attr() success on attribute $key");
70
}
70
}
71
71
72
diag "Testing Profile->save() method with a new object.";
72
# Testing Profile->save()with a new object
73
74
my $sav_results = $profile->save();
73
my $sav_results = $profile->save();
75
ok($sav_results ne -1) || diag "Profile->save() FAILED.";
74
ok($sav_results ne -1, "Profile->save() success");
76
75
77
my $saved_profile;
76
my $saved_profile;
78
if ($sav_results ne -1) {
77
if ($sav_results ne -1) {
79
    diag "Testing Profile->retrieve() method.";
78
    # Testing Profile->retrieve()
80
    $new_attr->{'profile_id'} = $sav_results;
79
    $new_attr->{'profile_id'} = $sav_results;
81
    ok($saved_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results)) || diag "Profile->retrieve() FAILED.";
80
    ok($saved_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results),
82
    is_deeply($saved_profile, $new_attr) || diag "Retrieved profile object FAILED to verify.";
81
       "Profile->retrieve() success");
82
    is_deeply($saved_profile, $new_attr, "Retrieved profile object verify success");
83
}
83
}
84
84
85
diag "Testing Profile->save() method with an updated object.";
85
# Testing Profile->save() with an updated object
86
86
87
$err = 0; # Reset error code
87
$err = 0; # Reset error code
88
$err = $saved_profile->set_attr(units => 'CM');
88
$err = $saved_profile->set_attr(units => 'CM');
89
my $upd_results = $saved_profile->save();
89
my $upd_results = $saved_profile->save();
90
ok(($upd_results ne -1) && ($err lt 1)) || diag "Profile->save() FAILED.";
90
ok(($upd_results ne -1) && ($err lt 1), "Profile->save() success");
91
my $updated_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results);
91
my $updated_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results);
92
is_deeply($updated_profile, $saved_profile) || diag "Updated layout object FAILED to verify.";
92
is_deeply($updated_profile, $saved_profile, "Updated layout object verify success");
93
94
diag "Testing Profile->delete() method.";
95
93
94
# Testing Profile->delete()
96
my $del_results = $updated_profile->delete();
95
my $del_results = $updated_profile->delete();
97
ok($del_results ne -1) || diag "Profile->delete() FAILED.";
96
ok($del_results ne -1, "Profile->delete() success");
97
98
1;
(-)a/t/db_dependent/Labels/t_Template.t (-27 / +29 lines)
Lines 17-28 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use Test::More tests => 54;
22
use Test::More tests => 54;
24
use C4::Context;
23
use C4::Context;
25
use Data::Dumper;
26
24
27
BEGIN {
25
BEGIN {
28
    use_ok('C4::Labels::Template');
26
    use_ok('C4::Labels::Template');
Lines 51-66 my $expect_template = { Link Here
51
49
52
my $template;
50
my $template;
53
51
54
diag "Testing Template->new() method.";
52
# Testing Template->new()
55
ok($template = C4::Labels::Template->new(page_width => 8.5,cols => 3))  || diag "Template->new() FAILED.";
53
ok($template = C4::Labels::Template->new(page_width => 8.5,cols => 3),
56
is_deeply($template, $expect_template) || diag "New template object FAILED to verify.";
54
    "Template->new() success.");
55
is_deeply($template, $expect_template,  "New template object verify success");
57
56
58
diag "Testing Template->get_attr() method.";
57
# Testing Template->get_attr()
59
foreach my $key (keys %{$expect_template}) {
58
foreach my $key (keys %{$expect_template}) {
60
    ok($expect_template->{$key} eq $template->get_attr($key)) || diag "Template->get_attr() FAILED on attribute $key.";
59
    ok($expect_template->{$key} eq $template->get_attr($key),
60
        "Template->get_attr() success on attribute $key");
61
}
61
}
62
62
63
diag "Testing Template->set_attr() method.";
63
# Testing Template->set_attr()
64
my $new_attr = {
64
my $new_attr = {
65
    creator             => 'Labels',
65
    creator             => 'Labels',
66
    profile_id          => 0,
66
    profile_id          => 0,
Lines 85-116 my $new_attr = { Link Here
85
foreach my $key (keys %{$new_attr}) {
85
foreach my $key (keys %{$new_attr}) {
86
    next if ($key eq 'template_stat');
86
    next if ($key eq 'template_stat');
87
    $template->set_attr($key, $new_attr->{$key});
87
    $template->set_attr($key, $new_attr->{$key});
88
    ok($new_attr->{$key} eq $template->get_attr($key)) || diag "Template->set_attr() FAILED on attribute $key.";
88
    ok($new_attr->{$key} eq $template->get_attr($key),
89
       "Template->set_attr() success on attribute $key");
89
}
90
}
90
91
91
diag "Testing Template->save() method with a new object.";
92
# Testing Template->save() with a new object
92
93
my $sav_results = $template->save();
93
my $sav_results = $template->save();
94
ok($sav_results ne -1) || diag "Template->save() FAILED.";
94
ok($sav_results ne -1, "Template->save() success");
95
95
96
my $saved_template;
96
my $saved_template;
97
if ($sav_results ne -1) {
97
if ($sav_results ne -1) {
98
    diag "Testing Template->retrieve() method.";
98
    # Testing Template->retrieve()
99
    $new_attr->{'template_id'} = $sav_results;
99
    $new_attr->{'template_id'} = $sav_results;
100
    ok($saved_template = C4::Labels::Template->retrieve(template_id => $sav_results))  || diag "Template->retrieve() FAILED.";
100
    ok($saved_template = C4::Labels::Template->retrieve(template_id => $sav_results),
101
    is_deeply($saved_template, $new_attr) || diag "Retrieved template object FAILED to verify.";
101
       "Template->retrieve() success");
102
    is_deeply($saved_template, $new_attr,
103
              "Retrieved template object verify success");
102
}
104
}
103
105
104
diag "Testing Template->save method with an updated object.";
106
# Testing Template->save with an updated object
105
106
$saved_template->set_attr(template_desc => 'A test template');
107
$saved_template->set_attr(template_desc => 'A test template');
107
my $upd_results = $saved_template->save();
108
my $upd_results = $saved_template->save();
108
ok($upd_results ne -1) || diag "Template->save() FAILED.";
109
ok($upd_results ne -1, "Template->save() success");
109
my $updated_template = C4::Labels::Template->retrieve(template_id => $sav_results);
110
my $updated_template = C4::Labels::Template->retrieve(template_id => $sav_results);
110
is_deeply($updated_template, $saved_template) || diag "Updated template object FAILED to verify.";
111
is_deeply($updated_template, $saved_template, "Updated template object verify success");
111
112
diag "Testing Template->retrieve() convert points option.";
113
112
113
# Testing Template->retrieve() convert points option
114
my $conv_template = C4::Labels::Template->retrieve(template_id => $sav_results, convert => 1);
114
my $conv_template = C4::Labels::Template->retrieve(template_id => $sav_results, convert => 1);
115
my $expect_conv = {
115
my $expect_conv = {
116
    page_width          => 612,
116
    page_width          => 612,
Lines 126-135 my $expect_conv = { Link Here
126
};
126
};
127
127
128
foreach my $key (keys %{$expect_conv}) {
128
foreach my $key (keys %{$expect_conv}) {
129
    ok($expect_conv->{$key} eq $conv_template->get_attr($key)) || diag "Template->retrieve() convert points option FAILED. Expected " . $expect_conv->{$key} . " but got " . $conv_template->get_attr($key) . ".";
129
    ok($expect_conv->{$key} eq $conv_template->get_attr($key),
130
       "Template->retrieve() convert points option success ($expect_conv->{$key})")
131
       || diag("Expected " . $expect_conv->{$key} . " but got " . $conv_template->get_attr($key) . ".");
130
}
132
}
131
133
132
diag "Testing Template->delete() method.";
134
# Testing Template->delete()
133
134
my $del_results = $updated_template->delete();
135
my $del_results = $updated_template->delete();
135
ok($del_results ne -1) || diag "Template->delete() FAILED.";
136
ok($del_results ne -1, "Template->delete() success");
137
138
1;
136
- 

Return to bug 14468