#!/bin/bash

set -e

server="$1"

source "$(dirname "$0")"/webapp_validate_common.sh

PORT=8080
CONTEXT_PATH="css-validator/"

start_server "$server" "${PORT:-8080}" "$CONTEXT_PATH"

#echo "current path: $PWD"

curl -v --stderr - \
  -F file=@debian/tests/sample.css \
  -F profile=css3svg  \
  -F usermedium=all  \
  -F warning=1  \
  -F vextwarning=  \
  -F lang=en \
  -o "$tempfile" \
  "http://localhost:${PORT:-8080}/css-validator/validator"

if grep "<h3>Congratulations! No Error Found.</h3>" "$tempfile"; then
  echo "Validation of file was successful."
else
  debug_failure
  echo "-------------"
  cat "$tempfile"
  echo "-------------"
  echo "Issue validating the file. Output is above."
  exit 1
fi

rm "$tempfile"
