WebTestCase('new email'); } function testUserlogin() { global $user; // open website $this->get('http://' . BASE_URL); $this->assertText('Login'); $this->clickLink('Normal Login'); $this->assertText('Pass Phrase:'); // login $this->setField('email', $user['1']['username']); $this->setField('pword', $user['1']['password']); $this->clickSubmit('Login'); $this->assertText('Logout', "Login failed - don't see logout button"); $this->get('http://' . BASE_URL."account.php?id=1"); $this->assertField('newemail', "", "Don't see field for newemail"); $this->setField('newemail', $user['1']['newemail']); $this->clickSubmit('Add'); $this->assertText('has been added to the system', "couldn't add new email to the system"); $this->assertNoText('is already in the system', "the email provided is already in the system"); $this->assertNoText('Not a valid email address', "string provided is not a valid email address"); sleep(5); // Check if email has been added $rawpage = $this->get('http://' . BASE_URL."account.php?id=2"); // U is for ungreedy - find smallest match // s searches in multiple lines $this->assertNoPattern('/.*Unverified.*'.$user['1']['newemail'].'/sU', "email is not yet verified"); $this->assertText($user['1']['newemail'], "Don't see our new email address"); // Don't know a better way to get all these ids to delete. Can't check the checkboxes // using simpletest. Extracting them from the site source ... if ($this->assertTrue($rawpage)) { // $hits[0] will contain what is found by the regex // $hits[1] will contain what is sselected by () in the regex == the actual id to delete $hits=array(); preg_match_all('/name=.delid... value=.([\d]+)/', $rawpage, $hits); $deleteIDs=$hits[1]; } // And now delete all these IDs if (count($deleteIDs) == 1) { $deleteIDs = $deleteIDs[0]; } $this->setFieldByName('delid[]', $deleteIDs); $this->clickSubmit('Delete'); $this->back(); $this->assertNoPattern('/delid/', "Deleted all possible email addresses but I still find at least one to delete in the page"); // logout again $this->clickLink('Logout'); // Logout $this->assertText('Login', "Logout faild - don't see login button"); } } ?>