# 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: ImageUploadForm.bunit,v 1.5 2007/10/23 17:45:21 nagler Exp $ FormModel({ setup_request => sub { my(undef, $params) = @_; class('Type.FormMode')->from_name( $params->[1] ? pop(@$params) : 'create' )->execute(req()); return; }, }); require 'RealmFile.PL'; [ [{ image_file => file_field('ImageUploadForm/t1.gif'), }] => [{ 'Model.RealmFile' => { path => sub { my($a) = req()->get('Model.RealmFile')->get_content_length; my($e) = length( ${file_field('ImageUploadForm/t1.gif')->{content}}); Bivio::Die->die("$a: actual not equal expected ($e)") unless abs($a - $e) < 10; return '/Image/t1.gif'; }, }, }], [{ image_file => file_field('ImageUploadForm/t2.png'), }] => [{ 'Model.RealmFile' => { path => sub { my($f) = req()->get('Model.RealmFile')->get_os_path; chomp(my $a = `imgsize $f`); assert_equals(qr/width.*640.* height.*240/i, $a); return '/Image/t2.png'; }, }, }], [{ image_file => file_field('ImageUploadForm/t2.png'), }, 'edit'] => [{ 'Model.RealmFile' => { # Update touches /Image last path => '/Image/t2.png', }, }], map( error_case({ image_file => file_field("ImageUploadForm/$_->[0]"), } => { image_file => $_->[1], }), [qw(t2.png EXISTS)], [qw(t3.tif SYNTAX_ERROR)], [qw(t4m.gif TOO_MANY)], ), ];