"Fossies" - the Fresh Open Source Software Archive

Member "eprints3.4-3.4.4/tests/03_set_value.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 "03_set_value.pl": 3.4-3.4.3_vs_3.4-3.4.4.

    1 #!/usr/bin/perl
    2 
    3 use Test::More tests => 11;
    4 
    5 BEGIN { use_ok( "EPrints" ); }
    6 BEGIN { use_ok( "EPrints::Test" ); }
    7 
    8 my $repository = EPrints::Test::get_test_repository();
    9 my $dataset = $repository->dataset( "archive" );
   10 
   11 my $eprint = EPrints::DataObj::EPrint->new_from_data( $repository, {
   12     eprint_status => "archive",
   13 }, $dataset );
   14 
   15 $eprint->set_value( "creators", [
   16 { name => { family => 'family_value1', given => 'given_value1' } },
   17 { name => { family => 'family_value2', given => 'given_value2' } },
   18 ]);
   19 
   20 my $creators = $eprint->get_value( "creators_name" );
   21 
   22 is( $creators->[0]->{family}, "family_value1" );
   23 is( $creators->[1]->{family}, "family_value2" );
   24 
   25 $eprint->set_value( "corp_creators", [
   26  "first",
   27  "second",
   28 ]);
   29 
   30 my $corp_creators = $eprint->get_value( "corp_creators" );
   31 
   32 is( $corp_creators->[1], "second" );
   33 
   34 my $field;
   35 for($dataset->fields)
   36 {
   37     next if $_->get_property( "sub_name" ); # compounds aren't de-duped
   38     $field = $_, last if $_->get_property( "multiple" ) && $_->isa( "EPrints::MetaField::Set" );
   39 }
   40 
   41 SKIP: {
   42     skip "Missing multiple MetaField::Set", 1 unless defined $field;
   43 
   44     $field->set_value( $eprint, [qw( one two three two five)] );
   45 
   46     is_deeply( $field->get_value( $eprint ), [qw( one two three five )], "set field removes duplicates");
   47 };
   48 
   49 my $tf = EPrints::MetaField->new(
   50     type => "time",
   51     name => "xxx_time",
   52     repository => $repository );
   53 $dataset->register_field( $tf );
   54 
   55 $tf->set_value( $eprint, "1234-12-31 23:59:59" );
   56 is( $tf->get_value( $eprint ), "1234-12-31 23:59:59", "set time value default" );
   57 $tf->set_value( $eprint, "1234-12-31T23:59:59Z" );
   58 is( $tf->get_value( $eprint ), "1234-12-31 23:59:59", "set time value ISO" );
   59 $tf->set_value( $eprint, "1234-12-31 23" );
   60 is( $tf->get_value( $eprint ), "1234-12-31 23", "set partial time value" );
   61 $tf->set_value( $eprint, undef );
   62 is( $tf->get_value( $eprint ), undef, "set undef time value" );
   63 
   64 $tf->set_property( multiple => 1 );
   65 $tf->set_value( $eprint, ["1234-12-31 23:59:59"] );
   66 is( $tf->get_value( $eprint )->[0], "1234-12-31 23:59:59", "set multiple time value" );
   67 
   68 =head1 COPYRIGHT
   69 
   70 =for COPYRIGHT BEGIN
   71 
   72 Copyright 2022 University of Southampton.
   73 EPrints 3.4 is supplied by EPrints Services.
   74 
   75 http://www.eprints.org/eprints-3.4/
   76 
   77 =for COPYRIGHT END
   78 
   79 =for LICENSE BEGIN
   80 
   81 This file is part of EPrints 3.4 L<http://www.eprints.org/>.
   82 
   83 EPrints 3.4 and this file are released under the terms of the
   84 GNU Lesser General Public License version 3 as published by
   85 the Free Software Foundation unless otherwise stated.
   86 
   87 EPrints 3.4 is distributed in the hope that it will be useful,
   88 but WITHOUT ANY WARRANTY; without even the implied warranty of
   89 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   90 See the GNU Lesser General Public License for more details.
   91 
   92 You should have received a copy of the GNU Lesser General Public
   93 License along with EPrints 3.4.
   94 If not, see L<http://www.gnu.org/licenses/>.
   95 
   96 =for LICENSE END
   97