# Copyright (c) 2006 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: EasyForm.bunit,v 1.7 2008/09/10 21:49:09 nagler Exp $ Request('initialize_fully'); set_realm_and_user(qw(fourem root)); my($dir) = '/Forms/bunit'; my($csv) = "$dir.csv"; my($rf) = Bivio::Biz::Model->new(req(), 'RealmFile'); $rf->delete({path => $csv}); $rf->unauth_delete_deep({ realm_id => req('auth_id'), path => $dir, }); $rf->create_folder({path => $dir}); $rf->create_with_content({ path => $csv, }, \(<<'EOF')); &date,&client_addr,&email,a,b,C EOF commit(); ignore_redirects(1); [ class() => [ { method => 'execute', compute_params => sub { my(undef, $params) = @_; req()->put_durable( form => $params->[0], path_info => $params->[1] || 'bunit', task_id => Bivio::Agent::TaskId->from_name( $params->[2] || 'FORUM_EASY_FORM'), query => {goto => 'http://www.bivio.biz'}, ); req()->get('r')->method($params->[3] || 'POST'); return [req()]; }, compute_return => sub { assert_equals( qr{Subject: /Forms/bunit.csv submission.*\&email: .*root}s, req()->unsafe_get_captured_mail, ); commit(); return [$rf->load({path => $csv})->get_content]; }, } => [ [ {a => '1'}, ] => qr{\n[\d/]+ [\d:]+ GMT,127.0.0.1,[^,]+root\@[^,]+,1,,\n}, [ {a => 1, B => 2, c => 3}, ] => qr{\n[\d/]+ [\d:]+ GMT,127.0.0.1,[^,]+root\@[^,]+,1,2,3\n}, [{a => 1, not_found => 3}] => qr{,not_found\n.*,3$}s, [{}] => qr{\n[\d/]+ [\d:]+ GMT,127.0.0.1,[^,]+root\@[^,]+,,,,\n}, [{a => 'a', b => 'b', c => {filename => '', content => 'bla'}}] => qr{\n[\d/]+ [\d:]+ GMT,127.0.0.1,[^,]+root\@[^,]+,a,b,http:.*c.dat,\n}, [{a => 1, c => { filename => 'x.txt', content_type => 'text/plain', content => \("some text\n"), }}] => sub { my($case, $actual) = @_; my($file) = reverse( split(/,/, (reverse(split(/\n/, ${$actual->[0]})))[0])); Bivio::Die->die($file, ': file name wrong') unless $file =~ m{(/Forms/bunit/\w+-c.txt)$}; Bivio::Die->die($rf->get_content, ': wrong content for ', $file) unless "some text\n" eq ${$rf->load({path => $1})->get_content}; return 1; }, [{a => 1}, undef, undef, 'GET'] => INVALID_OP(), [{a => '1'}] => qr{,1,,,$}s, ], ], ];