#!/bin/bash
# file: DirectMarkUP_
#
# Test driver for DirectMarkUP.cgi
#
# Input:  The input to the CGI script must be urlencoded name value pairs
#	  of the form:
#	'name1=value1&name2=value2...'
#
# Note: this script assumes METHOD=POST and non-multipart forms
#
# History:
# 30Jul98 MGiguere Updated for version 2.0 testing
# 30Mar98 MGiguere Created.

# setup CGI environment variables

export CONTENT_LENGTH=${#args1}
export CONTENT_TYPE='application/x-www-form-urlencoded'
export REQUEST_METHOD=POST
export SERVER_ADMIN='meg@dexa.com'

if [ -e "event.log" ]; then
    /bin/rm event.log
fi

# Test 1: One field undefined in input
echo Test1:
cp Sample.html Target.html
args='regPrice=.98&superPrice=1.20'
export CONTENT_LENGTH=${#args}
echo "$args" | ./DirectMarkUP.cgi Target.html >Test1.out
diff Test1.out std/Test1.out

# Test2 : All args missing test (no input test)
echo Test2:
export CONTENT_LENGTH=0
cp Sample.html Target.html
./DirectMarkUP.cgi Target.html >Test2.out
diff Test2.out std/Test2.out

# Test 3: All args defined one missing value
echo Test3:
cp Sample.html Target.html
args='regPrice=&superPrice=1.20&specials='
export CONTENT_LENGTH=${#args}
echo "$args" | ./DirectMarkUP.cgi Target.html >Test3.out
diff Test3.out std/Test3.out

# Test 4: Change all text fields
echo Test4:
cp Sample.html Target.html
args='regPrice=.98&superPrice=1.20&specials=Elephant+muffins+$1.00+ea.'
export CONTENT_LENGTH=${#args}
echo "$args" | ./DirectMarkUP.cgi Target.html >Test4.out
diff Test4.out std/Test4.out

# Test 5: Embedded html tags in DIRECT block
echo Test5:
cp Sample1.html Target.html
args='regPrice=.98&superPrice=1.20&specials=Got rid of embedded HTML Tags?'
export CONTENT_LENGTH=${#args}
echo "$args" | ./DirectMarkUP.cgi Target.html >Test5.out
diff Test5.out std/Test5.out

# Test 6: No target file specified test
echo Test6:
args='regPrice=.98&superPrice=1.20&specials=Got rid of embedded HTML Tags?'
export CONTENT_LENGTH=${#args}
echo "$args" | ./DirectMarkUP.cgi >Test6.out
diff Test6.out std/Test6.out

# Test 7: test MakeDirectForm
echo Test7:
./MakeDirectForm.pl Sample.html >Test7.out
diff Test7.out std/Test7.out

# Test 8: MakeDirectForm tags broken by \n
echo Test8:
./MakeDirectForm.pl Sampleb.html >Test8.out
diff Test8.out std/Test8.out
