# Copyright (c) 2008 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: CRMForm.bunit,v 1.13 2010/11/17 22:36:18 schellj Exp $ my($ctid, $who); FormModel({ setup_request => sub { my(undef, $params) = @_; req()->put(query => { $ctid ? (this => $ctid) : (), $who ? (to => $who) : (), }); return; }, }); req()->set_realm_and_user(qw(crm_forum crm_tech1)) ->initialize_fully('FORUM_CRM_FORM'); my($crm_alias) = EmailArray(remote_email('crm')); my($cal) = model('CRMActionList')->load_all; my($board) = remote_email('board.crm_forum'); my($demo) = EmailArray(email('demo')); [ empty_case({ action_id => $cal->id_to_name(-CRMThreadStatus('OPEN')->as_int), to => undef, cc => $crm_alias, }), [{ to => $demo, cc => $crm_alias, subject => 's1', body => 'b1', action_id => $cal->id_to_name(-CRMThreadStatus('NEW')->as_int), }] => [{ 'Model.CRMThread' => { thread_root_id => sub { return $ctid = req(qw(Model.CRMThread thread_root_id)); }, crm_thread_status => CRMThreadStatus('NEW'), }, 'Model.RealmMail' => { from_email => email('crm_tech1'), }, }], inline_case(sub {$who = 'ALL'}), empty_case({ to => $demo, cc => $crm_alias, action_id => $cal->id_to_name(-CRMThreadStatus('CLOSED')->as_int), }), inline_case(sub {$who = 'REALM'}), empty_case({ to => $crm_alias, cc => EmailArray([]), action_id => $cal->id_to_name(-CRMThreadStatus('LOCKED')->as_int), }), [{ action_id => $cal->id_to_name(-CRMThreadStatus('CLOSED')->as_int), to => EmailArray([$board]), subject => 's2', body => 'b1', }] => [{ 'Model.CRMThread' => { crm_thread_status => CRMThreadStatus('CLOSED'), modified_by_user_id => realm_id('crm_tech1'), }, 'Model.RealmMail' => { from_email => sub { assert_equals( qr{\QTo: $board\E}, model(RealmFile => { realm_file_id => req(qw(Model.RealmMail realm_file_id)), })->get_content, ); return $crm_alias->get_element(0); }, }, }], empty_case({ to => $crm_alias, action_id => $cal->id_to_name(-CRMThreadStatus('CLOSED')->as_int), }), [{ action_id => $cal->id_to_name(-CRMThreadStatus('OPEN')->as_int), cc => [''], subject => 'new subj1', update_only => 1, }] => [{ 'Model.CRMThread' => { crm_thread_status => CRMThreadStatus('OPEN'), subject => 'new subj1', modified_by_user_id => realm_id('crm_tech1'), }, }], inline_case(sub {$who = 'ALL'}), empty_case({ to => $demo, cc => $crm_alias, action_id => $cal->id_to_name(-CRMThreadStatus('CLOSED')->as_int), }), inline_case(sub {$ctid = $who = undef}), [{ to => $crm_alias, subject => 's2', body => 'b2', action_id => $cal->id_to_name(req('auth_user_id')), }] => [{ 'Model.CRMThread' => { owner_user_id => req('auth_user_id'), crm_thread_status => CRMThreadStatus('OPEN'), thread_root_id => sub {$ctid = req(qw(Model.CRMThread thread_root_id))}, }, }], empty_case({ action_id => $cal->id_to_name(req('auth_user_id')), }), ];