"Fossies" - the Fresh Open Source Software Archive

Member "eprints3.4-3.4.4/tests/21_database_fields.pl" (7 Aug 2022, 2910 Bytes) of package /linux/www/eprints3.4-3.4.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "21_database_fields.pl": 3.4-3.4.3_vs_3.4-3.4.4.

    1 use strict;
    2 use Test::More tests => 17;
    3 
    4 BEGIN { use_ok( "EPrints" ); }
    5 BEGIN { use_ok( "EPrints::Test" ); }
    6 
    7 my $session = EPrints::Test::get_test_session( 0 );
    8 ok(defined $session, 'opened an EPrints::Session object (noisy, no_check_db)');
    9 
   10 # a dataset that won't mind being broken
   11 my $dataset = $session->dataset( "upload_progress" );
   12 
   13 my $db = $session->get_db;
   14 
   15 my $field;
   16 
   17 # singular add/remove
   18 $field = EPrints::MetaField->new(
   19     dataset => $dataset,
   20     type => "text",
   21     name => "unit_tests",
   22     sql_index => 1,
   23 );
   24 ok( $db->add_field( $dataset, $field ), "add field" );
   25 ok( $db->has_column( $dataset->get_sql_table_name, $field->get_sql_name ), "expected column name" );
   26 ok( $db->remove_field( $dataset, $field ), "remove field" );
   27 
   28 # single rename
   29 $field = EPrints::MetaField->new(
   30     dataset => $dataset,
   31     type => "text",
   32     name => "unit_tests",
   33 );
   34 ok( $db->add_field( $dataset, $field ), "add field" );
   35 $field->set_property( name => "unit_tests2" );
   36 ok( $db->rename_field( $dataset, $field, "unit_tests" ), "rename field" );
   37 ok( $db->has_column( $dataset->get_sql_table_name, $field->get_sql_name ), "expected column name" );
   38 ok( $db->remove_field( $dataset, $field ), "remove field" );
   39 
   40 # multiple add/remove
   41 $field = EPrints::MetaField->new(
   42     dataset => $dataset,
   43     type => "text",
   44     name => "unit_tests",
   45     multiple => 1,
   46 );
   47 ok( $db->add_field( $dataset, $field ), "add multiple field" );
   48 ok( $db->has_table( $dataset->get_sql_sub_table_name( $field ) ), "expected table name" );
   49 ok( $db->remove_field( $dataset, $field ), "remove multiple field" );
   50 
   51 # multiple rename
   52 $field = EPrints::MetaField->new(
   53     dataset => $dataset,
   54     type => "text",
   55     name => "unit_tests",
   56     multiple => 1,
   57 );
   58 ok( $db->add_field( $dataset, $field ), "add multiple field" );
   59 $field->set_property( name => "unit_tests2" );
   60 ok( $db->rename_field( $dataset, $field, "unit_tests" ), "rename multiple field" );
   61 ok( $db->has_table( $dataset->get_sql_sub_table_name( $field ) ), "expected table name" );
   62 ok( $db->remove_field( $dataset, $field ), "remove multiple field" );
   63 
   64 $session->terminate;
   65 
   66 =head1 COPYRIGHT
   67 
   68 =for COPYRIGHT BEGIN
   69 
   70 Copyright 2022 University of Southampton.
   71 EPrints 3.4 is supplied by EPrints Services.
   72 
   73 http://www.eprints.org/eprints-3.4/
   74 
   75 =for COPYRIGHT END
   76 
   77 =for LICENSE BEGIN
   78 
   79 This file is part of EPrints 3.4 L<http://www.eprints.org/>.
   80 
   81 EPrints 3.4 and this file are released under the terms of the
   82 GNU Lesser General Public License version 3 as published by
   83 the Free Software Foundation unless otherwise stated.
   84 
   85 EPrints 3.4 is distributed in the hope that it will be useful,
   86 but WITHOUT ANY WARRANTY; without even the implied warranty of
   87 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   88 See the GNU Lesser General Public License for more details.
   89 
   90 You should have received a copy of the GNU Lesser General Public
   91 License along with EPrints 3.4.
   92 If not, see L<http://www.gnu.org/licenses/>.
   93 
   94 =for LICENSE END
   95