Annotation of loncom/metadata_database/lonmetadata_test.pl, revision 1.1
1.1 ! matthew 1: #!/usr/bin/perl -w
! 2: # The LearningOnline Network with CAPA
! 3: #
! 4: # $Id$
! 5: #
! 6: # Copyright Michigan State University Board of Trustees
! 7: #
! 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 9: #
! 10: # LON-CAPA is free software; you can redistribute it and/or modify
! 11: # it under the terms of the GNU General Public License as published by
! 12: # the Free Software Foundation; either version 2 of the License, or
! 13: # (at your option) any later version.
! 14: #
! 15: # LON-CAPA is distributed in the hope that it will be useful,
! 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 18: # GNU General Public License for more details.
! 19: #
! 20: # You should have received a copy of the GNU General Public License
! 21: # along with LON-CAPA; if not, write to the Free Software
! 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 23: #
! 24: # /home/httpd/html/adm/gpl.txt
! 25: #
! 26: # http://www.lon-capa.org/
! 27: #
! 28: ######################################################################
! 29: use strict;
! 30:
! 31: use DBI;
! 32: use LONCAPA::lonmetadata();
! 33: use Test::Simple tests => 3;
! 34:
! 35:
! 36: ok(&create_test_db(),'database creation');
! 37: ok(&test_creation(),'table creation');
! 38: ok(&test_inserts(),'insert test');
! 39:
! 40: exit;
! 41:
! 42: #####################################################################
! 43: #####################################################################
! 44: ##
! 45: ## Tests live down below
! 46: ##
! 47: #####################################################################
! 48: #####################################################################
! 49: sub create_test_db {
! 50: my $dbh = DBI->connect("DBI:mysql:test","root","123",
! 51: { RaiseError =>0,PrintError=>0});
! 52: if (! defined($dbh)) {
! 53: return 0;
! 54: }
! 55: my $request = 'DROP DATABASE IF EXISTS lonmetatest';
! 56: $dbh->do($request);
! 57: $request = 'CREATE DATABASE lonmetatest';
! 58: $dbh->do($request);
! 59: if ($dbh->err) {
! 60: return 0;
! 61: } else {
! 62: return 1;
! 63: }
! 64: $dbh->disconnect();
! 65: }
! 66:
! 67: sub test_creation {
! 68: my $dbh = DBI->connect("DBI:mysql:lonmetatest","root","123",
! 69: { RaiseError =>0,PrintError=>0});
! 70: my $request = &LONCAPA::lonmetadata::create_metadata_storage();
! 71: $dbh->do($request);
! 72: if ($dbh->err) {
! 73: $dbh->disconnect();
! 74: return 0;
! 75: } else {
! 76: $dbh->disconnect();
! 77: return 1;
! 78: }
! 79: }
! 80:
! 81: sub test_inserts {
! 82: my $dbh = DBI->connect("DBI:mysql:lonmetatest","root","123",
! 83: { RaiseError =>0,PrintError=>0});
! 84: my @TestRecords = (
! 85: { url => 'm/b/h/test1' },
! 86: { title => 'test document 1',
! 87: author => 'matthew',
! 88: subject => 'subject 1',
! 89: url => 'm/b/h/test2',
! 90: keywords => 'key word',
! 91: version => '1.4',
! 92: notes => 'note note note',
! 93: abstract => 'probably',
! 94: mime => 'none',
! 95: language => 'english',
! 96: creationdate =>'',
! 97: lastrevisiondate =>'',
! 98: owner => 'hallmat3',
! 99: copyright => 'default',
! 100: dependencies => undef,
! 101: modifyinguser => 'hallmat3',
! 102: authorspace => 'hallmat3',
! 103: lowestgradelevel =>'1',
! 104: highestgradelevel => 16,
! 105: standards => 'Delaware Required Instruction Program',
! 106: count => '2544444',
! 107: course => '4',
! 108: course_list => 'course 1, course 2, course 3, course 4',
! 109: goto => '1',
! 110: goto_list =>'m/b/h/test1',
! 111: comefrom => '0',
! 112: comefrom_list =>'',
! 113: sequsage => '1',
! 114: sequsage_list =>'mbhtest.sequence',
! 115: stdno => '0',
! 116: stdno_list => '',
! 117: avetries => '0.0',
! 118: avetries_list =>'',
! 119: difficulty =>'',
! 120: difficulty_list => '',
! 121: clear => '5',
! 122: technical => '4',
! 123: correct => '3',
! 124: helpful => '2',
! 125: depth => '5',
! 126: hostname =>'6',
! 127: },
! 128: );
! 129: foreach my $data (@TestRecords) {
! 130: my ($count,$error) = &LONCAPA::lonmetadata::store_metadata($dbh,$data);
! 131: if (! $count) {
! 132: warn $error;
! 133: return 0;
! 134: }
! 135: }
! 136: return 1;
! 137: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>