]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/live_t/31-courses.t
da14e65b09bc8f47bfcf6d6157be057947153437
[Evergreen.git] / Open-ILS / src / perlmods / live_t / 31-courses.t
1 #!perl
2  
3 use strict; use warnings;
4 use Test::More tests => 3;
5 use OpenILS::Utils::TestUtils;
6 use OpenILS::Utils::CStoreEditor qw/:funcs/;
7 use OpenILS::Application::AppUtils;
8
9 diag("Test the course materials module.");
10
11 my $script = OpenILS::Utils::TestUtils->new();
12 our $apputils = 'OpenILS::Application::AppUtils';
13
14 # we need auth to access protected APIs
15 $script->authenticate({
16     username => 'admin',
17     password => 'demo123',
18     type => 'staff'});
19
20 my $authtoken = $script->authtoken;
21 ok($authtoken, 'Have an authtoken');
22
23 my $e = new_editor(xact => 1);
24 $e->init;
25
26
27 # -----------------------------------------------------------------------------
28 # 1. Let's attach an existing biblio record entry to course #1, then delete it
29 # -----------------------------------------------------------------------------
30
31 my $acmcm = Fieldmapper::asset::course_module_course_materials->new;
32 $acmcm->course(1);
33 $acmcm->id(9999);
34 $acmcm->record(55);
35 $acmcm->temporary_record(0);
36 $e->create_asset_course_module_course_materials( $acmcm ); # associated this bib record with a course
37 $e->commit;
38
39 $apputils->simplereq('open-ils.courses', 'open-ils.courses.detach.material', $authtoken, 9999);
40
41 my $results = $e->search_asset_course_module_course_materials({id => 9999});
42 is(scalar(@$results), 0, 'Successfully deleted acmcm');
43
44 $results = $e->search_biblio_record_entry({id => 55, deleted => 0});
45
46 is(scalar(@$results), 1,
47     'Did not inadvertantly delete bre');
48
49
50 # -----------------------------------------------------------------------------
51 # 2. Let's create a brief temporary bib record, attach it to course #1, then detach it
52 # -----------------------------------------------------------------------------
53
54 my $temp_tcn_source = 'temporary bib record for course materials module test';
55
56 $e->xact_begin;
57 my $bre = Fieldmapper::biblio::record_entry->new;
58 $bre->marc('<record></record>');
59 $bre->tcn_source($temp_tcn_source); #Use the tcn_source field, since Cstore rewrites the last_xact_id field
60 $e->create_biblio_record_entry($bre);
61 $e->commit;
62
63 my $bib_id = $e->search_biblio_record_entry({tcn_source=>$temp_tcn_source}, {idlist=>1})->[0];
64
65 $e->xact_begin;
66 $acmcm = Fieldmapper::asset::course_module_course_materials->new;
67 $acmcm->course(1);
68 $acmcm->id(9998);
69 $acmcm->record($bib_id);
70 $acmcm->temporary_record(1); # this one is temporary, like brief records created in the course module interface
71 $e->create_asset_course_module_course_materials( $acmcm ); # associated this bib record with a course
72 $e->commit;
73
74 $apputils->simplereq('open-ils.courses', 'open-ils.courses.detach.material', $authtoken, 9998);
75
76 $results = $e->search_asset_course_module_course_materials({id => 9998});
77 is(scalar(@$results), 0, 'Successfully deleted acmcm');
78
79 $results = $e->search_biblio_record_entry({tcn_source=>$temp_tcn_source,deleted=>0});
80 is(scalar(@$results), 0, 'Successfully deleted bre');
81
82