diff options
author | wei <> | 2006-07-07 23:18:19 +0000 |
---|---|---|
committer | wei <> | 2006-07-07 23:18:19 +0000 |
commit | b2e97539e7af7712b04dd5c2610a454d09aa0333 (patch) | |
tree | d09ae76ddc7f349a39b74b0cb1f40c8b678a352e /tests/test_tools/simpletest/docs/en/authentication_documentation.html | |
parent | fce10eed76455b7e0419f13affb4f29e73ef0375 (diff) |
Update simpletest
Diffstat (limited to 'tests/test_tools/simpletest/docs/en/authentication_documentation.html')
-rwxr-xr-x | tests/test_tools/simpletest/docs/en/authentication_documentation.html | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/tests/test_tools/simpletest/docs/en/authentication_documentation.html b/tests/test_tools/simpletest/docs/en/authentication_documentation.html index 0623023c..c90d61e5 100755 --- a/tests/test_tools/simpletest/docs/en/authentication_documentation.html +++ b/tests/test_tools/simpletest/docs/en/authentication_documentation.html @@ -21,9 +21,6 @@ <a href="group_test_documentation.html">Group tests</a> </li> <li> -<a href="server_stubs_documentation.html">Server stubs</a> -</li> -<li> <a href="mock_objects_documentation.html">Mock objects</a> </li> <li> @@ -109,6 +106,19 @@ class AuthenticationTest extends WebTestCase { on the amount of detail you want to see. </p> <p> + One theme that runs through SimpleTest is the ability to use + <span class="new_code">SimpleExpectation</span> objects wherever a simple + match is not enough. + If you want only an approximate match to the realm for + example, you can do this... +<pre> +class AuthenticationTest extends WebTestCase { + function test401Header() { + $this->get('http://www.lastcraft.com/protected/'); + $this->assertRealm(<strong>new PatternExpectation('/simpletest/i')</strong>); + } +} +</pre> Most of the time we are not interested in testing the authentication itself, but want to get past it to test the pages underneath. @@ -116,7 +126,7 @@ class AuthenticationTest extends WebTestCase { an authentication response... <pre> class AuthenticationTest extends WebTestCase { - function testAuthentication() { + function testCanAuthenticate() { $this->get('http://www.lastcraft.com/protected/');<strong> $this->authenticate('Me', 'Secret');</strong> $this->assertTitle(...); @@ -208,9 +218,15 @@ class LogInTest extends WebTestCase { </pre> All we are doing is confirming that the cookie is set. As the value is likely to be rather cryptic it's not - really worth testing this. - </p> - <p> + really worth testing this with... +<pre> +class LogInTest extends WebTestCase { + function testSessionCookieIsCorrectPattern() { + $this->get('http://www.my-site.com/login.php'); + $this->assertCookie('SID', <strong>new PatternExpectation('/[a-f0-9]{32}/i')</strong>); + } +} +</pre> The rest of the test would be the same as any other form, but we might want to confirm that we still have the same cookie after log-in as before we entered. @@ -224,8 +240,8 @@ class LogInTest extends WebTestCase { $session = $this->getCookie('SID'); $this->setField('u', 'Me'); $this->setField('p', 'Secret'); - $this->clickSubmit('Log in'); - $this->assertWantedPattern('/Welcome Me/'); + $this->click('Log in'); + $this->assertText('Welcome Me'); $this->assertCookie('SID', $session);</strong> } } @@ -243,7 +259,7 @@ class LogInTest extends WebTestCase { $this->get('http://www.my-site.com/login.php');<strong> $this->setCookie('SID', 'Some other session'); $this->get('http://www.my-site.com/restricted.php');</strong> - $this->assertWantedPattern('/Access denied/'); + $this->assertText('Access denied'); } } </pre> @@ -266,12 +282,12 @@ class LogInTest extends WebTestCase { $this->get('http://www.my-site.com/login.php'); $this->setField('u', 'Me'); $this->setField('p', 'Secret'); - $this->clickSubmit('Log in'); - $this->assertWantedPattern('/Welcome Me/');<strong> + $this->click('Log in'); + $this->assertText('Welcome Me');<strong> $this->restart(); $this->get('http://www.my-site.com/restricted.php'); - $this->assertWantedPattern('/Access denied/');</strong> + $this->assertText('Access denied');</strong> } } </pre> @@ -297,13 +313,13 @@ class LogInTest extends WebTestCase { $this->get('http://www.my-site.com/login.php'); $this->setField('u', 'Me'); $this->setField('p', 'Secret'); - $this->clickSubmit('Log in'); - $this->assertWantedPattern('/Welcome Me/'); + $this->click('Log in'); + $this->assertText('Welcome Me'); <strong> $this->ageCookies(3600);</strong> $this->restart(); $this->get('http://www.my-site.com/restricted.php'); - $this->assertWantedPattern('/Access denied/'); + $this->assertText('Access denied'); } } </pre> |