# Copyright (c) 2009 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: RemoteCopyListForm.bunit,v 1.1 2009/03/07 02:48:20 nagler Exp $ FormModel(); my($map_path); $map_path = sub { my($op) = shift; return FilePathArray([$map_path->(sub {shift}, $op, @_)]) unless ref($op); return map($op->("/RemoteCopyBunit/file$_", $_), @_); }; [ req_state({ task => 'REMOTE_COPY_FORM', user => 'remote_copy_user', realm => 'remote_copy_bunit', }), empty_case({ realm_0 => 'remote_copy_bunit', want_realm_0 => 1, }), simple_case({ want_realm_0 => 1, }, { to_delete_0 => FilePathArray([]), to_create_0 => FilePathArray([]), to_update_0 => FilePathArray([]), }), inline_case(sub { req()->set_realm('remote_copy_bunit'); req()->initialize_fully('REMOTE_COPY_FORM'); $map_path->( sub {model('RealmFile', {path => shift})->delete}, 1, 3); $map_path->(sub { my($p, $n) = @_; return model('RealmFile', {path => $p})->update_with_content( {path => uc($p)}, \("new content $n"), ); }, 2, 4); $map_path->(sub { my($p, $n) = @_; return model('RealmFile')->create_with_content({ path => $p, user_id => realm_id('remote_copy_user'), }, \("new file $n")); }, 5, 6); return; }), simple_case({ want_realm_0 => 1, }, { want_realm_0 => 1, to_create_0 => $map_path->(1, 3), to_update_0 => $map_path->(2, 4), to_delete_0 => $map_path->(5, 6), }), [{ prepare_ok => 1, want_realm_0 => 1, to_create_0 => $map_path->(1, 3), to_update_0 => $map_path->(2, 4), to_delete_0 => $map_path->(5, 6), }] => sub { $map_path->(sub {model(RealmFile => {path => shift})}, 1, 3); $map_path->(sub { my($p, $n) = @_; my($rf) = model(RealmFile => {path => $p}); assert_equals("file$n", $rf->get_content); assert_equals($p, $rf->get('path')); return; }); $map_path->(sub { my($p, $n) = @_; return assert_equals( 0, model('RealmFile')->unsafe_load(path => $p)); }); return 1; }, ];