Class: AppTest extends PHPUnit_Framework_TestCase

Extends PHPUnit to provide testing capabilities for handlers. Creates the necessary environment that a handler expects. Note that you will have to set up any $_GET or $_POST values that your handlers expect.

Also includes the following convenience functions:

  • get() Aliases Controller::run() but catches header() exceptions so you can test for them.
  • userAdmin() Makes you an admin user for subsequent requests.
  • userAnon() Makes you an anonymous user for subsequent requests.
  • userMember() Makes you a member user for subsequent requests.



require_once ('lib/Autoloader.php');

class MyappAppTest extends AppTest {
    public function test_myhandler () {
        // Perform a handler request and test its output
        $res = $this->get ('myapp/myhandler', array ('one' => 'two');
        $this->assertContains ('Expected output', $res);

    public function test_admin () {
        // This should redirect to /admin
        $res = $this->get ('myapp/admin');
        $this->assertContains ('headers already sent', $res);

        // Become the admin and try again
        $this->userAdmin ();
        $res = $this->get ('myapp/admin');
        $this->assertContains ('My admin output', $res);

        // Become anonymous user again
        $this->userAnon ();

        // Continue...



protected static $c

The Controller object.

protected $backupGlobalsBlacklist = array ()

Prevent these from being reset between tests.


public userAdmin ()

Make the current user an admin.

public userMember ()

Make the current user a member.

public userAnon ()

Make the current user anonymous.

public get ($uri, $data = array ())

Alias for Controller's run() method.

public static setUpBeforeClass ()

Initializes the $i18n, $cache, $page, and $tpl objects for use with the controller in testing handlers.

public static tearDownAfterClass ()

Unset the $i18n, $cache, $page, and $tpl objects upon completion.