public
Description: PHP5 Unit Testing Framework
Home | Edit | New

SnapTest Web Interface

Setting Up the Web Interface

In the SnapTest root directory, there is a file snaptest_web.dist which contains everything you need to get public web tests up and running. For reference, we’ve included the file below, and will go through each step of the configuration.

VERSION < 1.2.1


// snaptest web interface

// STEP 1: Define the absolute path to where snaptest.php is
// Include the ending slash
define(‘SNAP_WI_PATH’, ‘/path/to/snaptest/directory/’);

// STEP 2: Define the absolute path to your top level test directory
// Include the ending slash
define(‘SNAP_WI_TEST_PATH’, ‘/path/to/my/tests/’);

// STEP 3: Define the URL of this file. This way, we can find it
// once more without weird script url hackery
define(‘SNAP_WI_URL_PATH’, ‘http://www.example.com/path/to/snaptest_web.dist.php’);

// STEP 4: Set a key. You only need this if you are putting your
// tests on a publicly accessible server. This also offers very minimal
// protection. If you’re actually going this far in the protecting bit,
// it is probably time to read up on .htaccess and possibly write your own
// web stub to do security.
// A blank string means no key will be used.
define(‘SNAP_WI_KEY’, ’’);

// STEP 5: set the matching path Files matching this pattern will be testable
define(‘SNAP_WI_TEST_MATCH’, ‘^.*\.stest\.php$’);

// STEP 6: Relax, you’re done.
// Go to http://www.example.com/path/to/snaptest_web.dist.php

// -———————————————————————————————————-

// include the snaptest web core, which will handle the request, components
// etc. All the heavy lifting should happen well out of sight.
require_once SNAP_WI_PATH . ‘snaptest_webcore.php’;

VERSION >= 1.2.1


// STEP 4: Obfuscation. If this is defined to TRUE then full path obfuscation
// will be on and the path informaton will be ommitted from the display side
// of everything. It is strongly encouraged to leave this on unless you are in
// a secure environment and don't mind your entire path being exposed.
define('SNAP_WI_CRYPT', TRUE);

Step 1: Absolute path to snatest.php’s directory

The absolute path is used for includes and the bootstrap to get into snaptest_webcore.php (the main entry point). Usually this information is provided by your system administrator, and may be accessible from the path information of your FTP / SFTP client. The ending slash (/ or \) is required.

Step 2: Absolute path to test directory

This is the directory where your tests reside. They do not (and probably should not) be in the same location as SnapTest. This way you can easily update SnapTest independent of any tests you write. The ending slash (/ or \) is required.

Step 3: URL of this file

You had to put the snaptest_web.dist.php file into a publicly accessible location, and you might have even renamed it. This URL defines the path to that file and is used for all subsequent URL requests the script generates.

Step 4: Key protection (VERSION 1.2.1)

This is added more as a safety precaution than anything else. If you provide anything other than "" as the web interface key, calls to http://example.com/snaptest_web.dist.php will fail until you add ?key= to the URL string. This is done in the cases where you have a semi-sensitive deployment of code, and do not want to expose your tests to the rest of the world. For most people, an empty string is fine. For the select few, it is definitely a better idea to implement stronger security and control list structures.

Step 4: Mask File Paths (VERSION 1.2.2)

By setting this define value to TRUE, full file paths will be omitted from the web runner output. This was deemed a bit more realistic of a security measure than trying to protect calls with a key (which was cleartext anyway).

Step 5: Setting the test pattern

For most people, the test pattern will be fine. This is the standard test pattern used by the command line interface as well. Files matching this pattern will be included in the test.

Web Interface Options

Adding special URL parameters can add additional functionality to the SnapTest web interface. Parameters are specified by adding a ?, followed by the options you want to enable:

  • debug=true turns on the JS debugger
  • autorun=true auto runs the tests as soon as all tests have been gathered
  • key=<yourkey> required if you enabled the SNAP_WI_KEY option

An example of a URL with some of these parameters would look something like http://www.example.com/snaptest_web.dist.php?debug=true&key=mykeyhere

Last edited by Jakobo, Sun Jul 19 17:15:38 -0700 2009
Home | Edit | New
Versions: