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;
9 diag("Test the course materials module.");
11 my $script = OpenILS::Utils::TestUtils->new();
12 our $apputils = 'OpenILS::Application::AppUtils';
14 # we need auth to access protected APIs
15 $script->authenticate({
17 password => 'demo123',
20 my $authtoken = $script->authtoken;
21 ok($authtoken, 'Have an authtoken');
23 my $e = new_editor(xact => 1);
27 # -----------------------------------------------------------------------------
28 # 1. Let's attach an existing biblio record entry to course #1, then delete it
29 # -----------------------------------------------------------------------------
31 my $acmcm = Fieldmapper::asset::course_module_course_materials->new;
35 $acmcm->temporary_record(0);
36 $e->create_asset_course_module_course_materials( $acmcm ); # associated this bib record with a course
39 $apputils->simplereq('open-ils.courses', 'open-ils.courses.detach.material', $authtoken, 9999);
41 my $results = $e->search_asset_course_module_course_materials({id => 9999});
42 is(scalar(@$results), 0, 'Successfully deleted acmcm');
44 $results = $e->search_biblio_record_entry({id => 55, deleted => 0});
46 is(scalar(@$results), 1,
47 'Did not inadvertantly delete bre');
50 # -----------------------------------------------------------------------------
51 # 2. Let's create a brief temporary bib record, attach it to course #1, then detach it
52 # -----------------------------------------------------------------------------
54 my $temp_tcn_source = 'temporary bib record for course materials module test';
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);
63 my $bib_id = $e->search_biblio_record_entry({tcn_source=>$temp_tcn_source}, {idlist=>1})->[0];
66 $acmcm = Fieldmapper::asset::course_module_course_materials->new;
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
74 $apputils->simplereq('open-ils.courses', 'open-ils.courses.detach.material', $authtoken, 9998);
76 $results = $e->search_asset_course_module_course_materials({id => 9998});
77 is(scalar(@$results), 0, 'Successfully deleted acmcm');
79 $results = $e->search_biblio_record_entry({tcn_source=>$temp_tcn_source,deleted=>0});
80 is(scalar(@$results), 0, 'Successfully deleted bre');