# Copyright (c) 2007 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: CSVImportForm.bunit,v 1.7 2010/10/17 22:12:13 nagler Exp $ my($_G) = class()->use('Type.Gender'); FormModel({ class_name => 'Bivio::Biz::Model::t::CSVImportForm::T1Form', setup_request => sub { my(undef, $params) = @_; @$params = { source => file_field("CSVImportForm/$params->[0].csv"), }; return; }, comparator => 'nested_contains', }); [ simple_case(t1a => { result => [ { name => 'joe', id => 1, other => 'ok', gender => $_G->MALE, count => 1, }, { name => 'bob', id => 2, other => undef, gender => undef, count => 2, }, { name => 'mary', id => undef, other => undef, gender => undef, count => 3, }, ], }), map( error_case(shift(@$_) => { result => undef, source => shift(@$_), }), [t1b => 'EMPTY'], [t1c => qr{missing.*name}i], [t1d => qr{no.*rows}i], [t1e => qr{invalid csv file}i], [t1f => qr{Record 1: name: field may not be empty}i], [t1g => qr{no.*rows}i], ), column_info => [ name => [{field => 'RealmOwner.name'}], id => [{field => 'User.user_id'}], ], record_to_model_properties => [ [{id => 1}, 'User'] => [{user_id => 1}], [{name => 1}, 'RealmOwner'] => [{name => 1}], ], ];