#!/bin/sh
##
## Script to check WCAG 1.0 Checklist on openacs
## ---------------------------------------------
## Copyright (C) 2008 Hector Romojaro
##
##-------------------------------------------------------------------------------##
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
##-------------------------------------------------------------------------------##

# Check parameters
if [ $# -lt 2 ]; then
        echo "Usage: `basename $0` [-v] priority directory"
        exit 1
fi

# Variables
if [ "$1" == "-v" ]; then
	PRIORITY="$2"
	DIR="$3"
	VERBOSE="true"
else
	PRIORITY="$1"
	DIR="$2"
	VERBOSE="false"
fi
FUNCTIONS="waitest-functions"
DESCRIPTIONS="waitest-descriptions"
EXCEPTIONS_LIST="waitest-exceptions"
EXCEPTIONS_DIR="exceptions"

# grep
GREP="grep -RiIn --color=always"

# Import test descriptions
. $DESCRIPTIONS
# Import test exceptions list
. $EXCEPTIONS_LIST
# Import functions
. $FUNCTIONS

## Tests to be performed ##
function performTests() {

	# Priority 1
	if [ "$PRIORITY" -eq "1" ]; then

		# [1.1] Provide a text equivalent for every non-text element.
		test1dot1	
		# [2.1] Ensure that all information conveyed with color is also available without color.
		#test2dot1
		# [4.1] Clearly identify changes in the natural language of a document text and any text equivalents (e.g., captions).
		#test4dot1
		# [6.1] Organize documents so they may be read without style sheets.
		#test6dot1
		# [6.2] Ensure that equivalents for dynamic content are updated when the dynamic content changes.
		#test6dot2
		# [7.1] Until user agents allow users to control flickering, avoid causing the screen to flicker.
		#test7dot1
		# [14.1] Use the clearest and simplest language appropriate for a site content.
		#test14dot1
		# [1.2] Provide redundant text links for each active region of a server-side image map.
		#test1dot2
		# [9.1] Provide client-side image maps instead of server-side image maps except where the regions cannot be defined with an available geometric shape.
		#test9dot1
		# [5.1] For data tables, identify row and column headers.
		test5dot1
		# [5.2] For data tables that have two or more logical levels of row or column headers, use markup to associate data cells and header cells.
		test5dot2
		# [12.1] Title each frame to facilitate frame identification and navigation. 
		test12dot1
		# [6.3] Ensure that pages are usable when scripts, applets, or other programmatic objects are turned off or not supported.
		#test6dot3
		# [1.3] Until user agents can automatically read aloud the text equivalent of a visual track, provide an auditory description of the important information of the visual track of a multimedia presentation.
		#test1dot3
		# [1.4] For any time-based multimedia presentation, synchronize equivalent alternatives with the presentation.
		#test1dot4
		# [11.4] If, after best efforts, you cannot create an accessible page, provide a link to an alternative page that uses W3C technologies, is accessible, has equivalent information (or functionality), and is updated as often as the inaccessible (original) page. 
		#test11dot4

	# Priority 2
	elif [ "$PRIORITY" -eq "2" ]; then

		# [2.2] Ensure that foreground and background color combinations provide sufficient contrast when viewed by someone having color deficits or when viewed on a black and white screen. [Priority 2 for images, Priority 3 for text].
		test2dot2
		# [3.1] When an appropriate markup language exists, use markup rather than images to convey information. 
		#test3dot1
		# [3.2] Create documents that validate to published formal grammars. 
		#test3dot2
		# [3.3] Use style sheets to control layout and presentation. 
		test3dot3
		# [3.4] Use relative rather than absolute units in markup language attribute values and style sheet property values. 
		test3dot4
		# [3.5] Use header elements to convey document structure and use them according to specification. 
		#test3dot5
		# [3.6] Mark up lists and list items properly. 
		#test3dot6
		# [3.7] Mark up quotations. Do not use quotation markup for formatting effects such as indentation. 
		test3dot7
		# [6.5] Ensure that dynamic content is accessible or provide an alternative presentation or page. 
		#test6dot5
		# [7.2] Until user agents allow users to control blinking, avoid causing content to blink (i.e., change presentation at a regular rate, such as turning on and off).
		test7dot2
		# [7.4] Until user agents provide the ability to stop the refresh, do not create periodically auto-refreshing pages.
		test7dot4
		# [7.5] Until user agents provide the ability to stop auto-redirect, do not use markup to redirect pages automatically. Instead, configure the server to perform redirects.
		test7dot5
		# [10.1] Until user agents allow users to turn off spawned windows, do not cause pop-ups or other windows to appear and do not change the current window without informing the user.
		#test10dot1
		# [11.1] Use W3C technologies when they are available and appropriate for a task and use the latest versions when supported. 
		#test11dot1
		# [11.2] Avoid deprecated features of W3C technologies 
		test11dot2
		# [12.3] Divide large blocks of information into more manageable groups where natural and appropriate. 
		#test12dot3
		# [13.1] Clearly identify the target of each link. 
		test13dot1
		# [13.2] Provide metadata to add semantic information to pages and sites. 
		#test13dot2
		# [13.3] Provide information about the general layout of a site (e.g., a site map or table of contents). 
		#test13dot3
		# [13.4] Use navigation mechanisms in a consistent manner. 	  	 
		#test13dot4
		# [5.3] Do not use tables for layout unless the table makes sense when linearized. Otherwise, if the table does not make sense, provide an alternative equivalent (which may be a linearized version).
		#test5dot3
		# [5.4] If a table is used for layout, do not use any structural markup for the purpose of visual formatting. 
		#test5dot4
		# [12.2] Describe the purpose of frames and how frames relate to each other if it is not obvious by frame titles alone. 
		#test12dot2
		# [10.2] Until user agents support explicit associations between labels and form controls, for all form controls with implicitly associated labels, ensure that the label is properly positioned.
		#test10dot2
		# [12.4] Associate labels explicitly with their controls. 
		#test12dot4
		# [6.4] For scripts and applets, ensure that event handlers are input device-independent. 
		#test6dot4
		# [7.3] Until user agents allow users to freeze moving content, avoid movement in pages. 
		#test7dot3
		# [8.1] Make programmatic elements such as scripts and applets directly accessible or compatible with assistive technologies [Priority 1 if functionality is important and not presented elsewhere, otherwise Priority 2.]
		#test8dot1
		# [9.2] Ensure that any element that has its own interface can be operated in a device-independent manner.
		#test9dot2
		# [9.3] For scripts, specify logical event handlers rather than device-dependent event handlers. 
		#test9dot3

	# Priority 3
	elif [ "$PRIORITY" -eq "3" ]; then
		echo "* Priority 3 not implemented :)"

	# Whatever is not priority 1-3
	else
		echo "Error: priority must be a number between 1 and 3."
		exit 1
	fi

        # Done!
        exit 0
}

# Go Go Go!!!
echo "* Performing checks for Web Content Accesibility guidelines 1.0, priority $PRIORITY"
echo -e "---------------------------------------------------------------------------\n"
performTests

