Developers' test suite

Re: Developers' test suite

by sam marshall -
Number of replies: 0
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
OK, having written the post I got curious and tried it. It does fit in directly within the existing test framework. Here's an example:
require_once('simpletest/web_tester.php');

class test_learn_website extends WebTestCase {

const USERNAME='??',PASSWORD='??',SITE='d820-06e',
BASE='http://learn.open.ac.uk/';

function setUp() {
}

function test_sams() {
$this->get(self::BASE.self::SITE);
$this->assertTitle('Sign IN');
$this->setField('username',self::USERNAME);
$this->setField('password',self::PASSWORD);
$this->clickSubmit('Sign in');
$this->assertTitle('Course: The Challenge of the Social Sciences');
}

}
Username and password changed to protect the innocent smile [It was a dummy account, not mine. Even so.]

This tries to log into a Moodle course (course/view.php) via an Apache mod_redirect, which results in getting redirected to our single sign-on page and then redirected again about 387 times [unless they've changed it - I had to manually implement something that went through the process once and it was hugely tedious]. Then I made it fill in the username and password and sign in, which ends up creating some new cookies and (eventually) redirecting back to the Moodle site, automatically logging into that via our auth method, and viewing the course page.

Not very difficult I think! And neat that it can run in the same automated framework as our other tests. So anyway it's pretty cool, although obviously it doesn't handle Javascript, or browser-specific testing.

--sam