require_once('simpletest/web_tester.php');Username and password changed to protect the innocent [It was a dummy account, not mine. Even so.]
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');
}
}
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