Merged revisions 52618 via svnmerge from

http://svn.silverstripe.com/open/modules/sapphire/branches/govtsecurity

........
  r52618 | sminnee | 2008-04-13 16:58:15 +1200 (Sun, 13 Apr 2008) | 1 line
  
  Updated tests to make better use of TestViewer
........


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@53470 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-04-26 06:32:52 +00:00
parent efd1cf63e2
commit 834da4640d
2 changed files with 20 additions and 14 deletions

View File

@ -1,24 +1,30 @@
<?php <?php
class ObjectTest extends SapphireTest { class ObjectTest extends SapphireTest {
function testHasMethod() {
function testHasmethodBehaviour() {
/* SiteTree should have all of the methods that Versioned has, because Versioned is listed in SiteTree's
* extensions */
$st = new SiteTree(); $st = new SiteTree();
$cc = new ContentController($st); $cc = new ContentController($st);
// Check that Versiond methods exist on SiteTree
$this->assertTrue($st->hasMethod('publish'), "Test SiteTree has publish"); $this->assertTrue($st->hasMethod('publish'), "Test SiteTree has publish");
$this->assertTrue($st->hasMethod('migrateVersion'), "Test SiteTree has migrateVersion"); $this->assertTrue($st->hasMethod('migrateVersion'), "Test SiteTree has migrateVersion");
// Check for different casing /* This relationship should be case-insensitive, too */
$this->assertTrue($st->hasMethod('PuBliSh'), "Test SiteTree has PuBliSh"); $this->assertTrue($st->hasMethod('PuBliSh'), "Test SiteTree has PuBliSh");
$this->assertTrue($st->hasMethod('MiGratEVersIOn'), "Test SiteTree has MiGratEVersIOn"); $this->assertTrue($st->hasMethod('MiGratEVersIOn'), "Test SiteTree has MiGratEVersIOn");
// Check that SiteTree methods exist on ContentController (test failover) /* In a similar manner, all of SiteTree's methods should be available on ContentController, because $failover is set */
$this->assertTrue($cc->hasMethod('canView'), "Test ContentController has canView"); $this->assertTrue($cc->hasMethod('canView'), "Test ContentController has canView");
$this->assertTrue($cc->hasMethod('linkorcurrent'), "Test ContentController has linkorcurrent"); $this->assertTrue($cc->hasMethod('linkorcurrent'), "Test ContentController has linkorcurrent");
/* This 'method copying' is transitive, so all of Versioned's methods should be available on ContentControler.
* Once again, this is case-insensitive */
$this->assertTrue($cc->hasMethod('MiGratEVersIOn'), "Test ContentController has MiGratEVersIOn"); $this->assertTrue($cc->hasMethod('MiGratEVersIOn'), "Test ContentController has MiGratEVersIOn");
// Make use of the test object below. 1st instantiation is different from subsequent, so create a few /* The above examples make use of SiteTree, Versioned and ContentController. Let's test defineMethods() more
* directly, with some sample objects */
$objs = array(); $objs = array();
$objs[] = new ObjectTest_T2(); $objs[] = new ObjectTest_T2();
$objs[] = new ObjectTest_T2(); $objs[] = new ObjectTest_T2();

View File

@ -11,7 +11,7 @@ class SecurityTest extends SapphireTest {
* Test that the login form redirects to the change password form after logging in with an expired password * Test that the login form redirects to the change password form after logging in with an expired password
*/ */
function testExpiredPassword() { function testExpiredPassword() {
// BAD PASSWORDS ARE LOCKED OUT /* BAD PASSWORDS ARE LOCKED OUT */
$session = new Session(array()); $session = new Session(array());
$badResponse = $this->doTestLoginForm('sam@silverstripe.com' , 'badpassword', $session); $badResponse = $this->doTestLoginForm('sam@silverstripe.com' , 'badpassword', $session);
@ -19,7 +19,7 @@ class SecurityTest extends SapphireTest {
$this->assertRegExp('/Security\/login/', $badResponse->getHeader('Location')); $this->assertRegExp('/Security\/login/', $badResponse->getHeader('Location'));
$this->assertNull($session->inst_get('loggedInAs')); $this->assertNull($session->inst_get('loggedInAs'));
// UNEXPIRED PASSWORD GO THROUGH WITHOUT A HITCH /* UNEXPIRED PASSWORD GO THROUGH WITHOUT A HITCH */
$session = new Session(array()); $session = new Session(array());
$goodResponse = $this->doTestLoginForm('sam@silverstripe.com' , '1nitialPassword', $session); $goodResponse = $this->doTestLoginForm('sam@silverstripe.com' , '1nitialPassword', $session);
@ -27,7 +27,7 @@ class SecurityTest extends SapphireTest {
$this->assertEquals(Director::baseURL() . 'test/link', $goodResponse->getHeader('Location')); $this->assertEquals(Director::baseURL() . 'test/link', $goodResponse->getHeader('Location'));
$this->assertEquals($this->idFromFixture('Member', 'test'), $session->inst_get('loggedInAs')); $this->assertEquals($this->idFromFixture('Member', 'test'), $session->inst_get('loggedInAs'));
// EXPIRED PASSWORDS ARE SENT TO THE CHANGE PASSWORD FORM /* EXPIRED PASSWORDS ARE SENT TO THE CHANGE PASSWORD FORM */
$session = new Session(array()); $session = new Session(array());
$expiredResponse = $this->doTestLoginForm('expired@silverstripe.com' , '1nitialPassword', $session); $expiredResponse = $this->doTestLoginForm('expired@silverstripe.com' , '1nitialPassword', $session);
@ -41,19 +41,19 @@ class SecurityTest extends SapphireTest {
Member::lock_out_after_incorrect_logins(5); Member::lock_out_after_incorrect_logins(5);
// LOG IN WITH A BAD PASSWORD 7 TIMES /* LOG IN WITH A BAD PASSWORD 7 TIMES */
for($i=1;$i<=7;$i++) { for($i=1;$i<=7;$i++) {
$this->doTestLoginForm('sam@silverstripe.com' , 'incorrectpassword', $session); $this->doTestLoginForm('sam@silverstripe.com' , 'incorrectpassword', $session);
$member = DataObject::get_by_id("Member", $this->idFromFixture('Member', 'test')); $member = DataObject::get_by_id("Member", $this->idFromFixture('Member', 'test'));
// THE FIRST 4 TIMES, THE MEMBER SHOULDN'T BE LOCKED OUT /* THE FIRST 4 TIMES, THE MEMBER SHOULDN'T BE LOCKED OUT */
if($i < 5) { if($i < 5) {
$this->assertNull($member->LockedOutUntil); $this->assertNull($member->LockedOutUntil);
$this->assertTrue(false !== stripos($this->loginErrorMessage($session), "That doesn't seem to be the right e-mail address or password")); $this->assertTrue(false !== stripos($this->loginErrorMessage($session), "That doesn't seem to be the right e-mail address or password"));
} }
// AFTER THAT THE USER IS LOCKED OUT FOR 15 MINUTES /* AFTER THAT THE USER IS LOCKED OUT FOR 15 MINUTES */
//(we check for at least 14 minutes because we don't want a slow running test to report a failure.) //(we check for at least 14 minutes because we don't want a slow running test to report a failure.)
else { else {
@ -65,12 +65,12 @@ class SecurityTest extends SapphireTest {
} }
} }
// THE USER CAN'T LOG IN NOW, EVEN IF THEY GET THE RIGHT PASSWORD /* THE USER CAN'T LOG IN NOW, EVEN IF THEY GET THE RIGHT PASSWORD */
$this->doTestLoginForm('sam@silverstripe.com' , '1nitialPassword', $session); $this->doTestLoginForm('sam@silverstripe.com' , '1nitialPassword', $session);
$this->assertNull($session->inst_get('loggedInAs')); $this->assertNull($session->inst_get('loggedInAs'));
// BUT, IF TIME PASSES, THEY CAN LOG IN /* BUT, IF TIME PASSES, THEY CAN LOG IN */
// (We fake this by re-setting LockedOutUntil) // (We fake this by re-setting LockedOutUntil)
$member = DataObject::get_by_id("Member", $this->idFromFixture('Member', 'test')); $member = DataObject::get_by_id("Member", $this->idFromFixture('Member', 'test'));
@ -83,7 +83,7 @@ class SecurityTest extends SapphireTest {
// Log the user out // Log the user out
$session->inst_set('loggedInAs', null); $session->inst_set('loggedInAs', null);
// NOW THAT THE LOCK-OUT HAS EXPIRED, CHECK THAT WE ARE ALLOWED 4 FAILED ATTEMPTS BEFORE LOGGING IN /* NOW THAT THE LOCK-OUT HAS EXPIRED, CHECK THAT WE ARE ALLOWED 4 FAILED ATTEMPTS BEFORE LOGGING IN */
$this->doTestLoginForm('sam@silverstripe.com' , 'incorrectpassword', $session); $this->doTestLoginForm('sam@silverstripe.com' , 'incorrectpassword', $session);
$this->doTestLoginForm('sam@silverstripe.com' , 'incorrectpassword', $session); $this->doTestLoginForm('sam@silverstripe.com' , 'incorrectpassword', $session);