1<?php 2 // $Id: acceptance_test.php,v 1.1 2005/11/09 23:41:18 gsmet Exp $ 3 require_once(dirname(__FILE__) . '/../options.php'); 4 require_once(dirname(__FILE__) . '/../browser.php'); 5 require_once(dirname(__FILE__) . '/../web_tester.php'); 6 require_once(dirname(__FILE__) . '/../unit_tester.php'); 7 8 class TestOfLiveBrowser extends UnitTestCase { 9 10 function testGet() { 11 $browser = &new SimpleBrowser(); 12 $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 13 14 $this->assertTrue($browser->get('http://www.lastcraft.com/test/network_confirm.php')); 15 $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); 16 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/', $browser->getContent()); 17 $this->assertEqual($browser->getTitle(), 'Simple test target file'); 18 $this->assertEqual($browser->getResponseCode(), 200); 19 $this->assertEqual($browser->getMimeType(), 'text/html'); 20 } 21 22 function testPost() { 23 $browser = &new SimpleBrowser(); 24 $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 25 $this->assertTrue($browser->post('http://www.lastcraft.com/test/network_confirm.php')); 26 $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); 27 $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/', $browser->getContent()); 28 } 29 30 function testAbsoluteLinkFollowing() { 31 $browser = &new SimpleBrowser(); 32 $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 33 $browser->get('http://www.lastcraft.com/test/link_confirm.php'); 34 $this->assertTrue($browser->clickLink('Absolute')); 35 $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); 36 } 37 38 function testRelativeLinkFollowing() { 39 $browser = &new SimpleBrowser(); 40 $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 41 $browser->get('http://www.lastcraft.com/test/link_confirm.php'); 42 $this->assertTrue($browser->clickLink('Relative')); 43 $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); 44 } 45 46 function testIdLinkFollowing() { 47 $browser = &new SimpleBrowser(); 48 $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 49 $browser->get('http://www.lastcraft.com/test/link_confirm.php'); 50 $this->assertTrue($browser->clickLinkById(1)); 51 $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); 52 } 53 54 function testCookieReading() { 55 $browser = &new SimpleBrowser(); 56 $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 57 $browser->get('http://www.lastcraft.com/test/set_cookies.php'); 58 $this->assertEqual($browser->getCurrentCookieValue('session_cookie'), 'A'); 59 $this->assertEqual($browser->getCurrentCookieValue('short_cookie'), 'B'); 60 $this->assertEqual($browser->getCurrentCookieValue('day_cookie'), 'C'); 61 } 62 63 function testSimpleSubmit() { 64 $browser = &new SimpleBrowser(); 65 $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 66 $browser->get('http://www.lastcraft.com/test/form.html'); 67 $this->assertTrue($browser->clickSubmit('Go!')); 68 $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/', $browser->getContent()); 69 $this->assertWantedPattern('/go=\[Go!\]/', $browser->getContent()); 70 } 71 } 72 73 class TestOfLiveFetching extends WebTestCase { 74 75 function setUp() { 76 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 77 } 78 79 function testGet() { 80 $this->assertTrue($this->get('http://www.lastcraft.com/test/network_confirm.php')); 81 $this->assertTrue($this->getUrl() == 'http://www.lastcraft.com/test/network_confirm.php'); 82 $this->assertWantedPattern('/target for the SimpleTest/'); 83 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/'); 84 $this->assertTitle('Simple test target file'); 85 $this->assertResponse(200); 86 $this->assertMime('text/html'); 87 } 88 89 function testSlowGet() { 90 $this->assertTrue($this->get('http://www.lastcraft.com/test/slow_page.php')); 91 } 92 93 function testTimedOutGet() { 94 $this->setConnectionTimeout(1); 95 $this->assertFalse($this->get('http://www.lastcraft.com/test/slow_page.php')); 96 } 97 98 function testPost() { 99 $this->assertTrue($this->post('http://www.lastcraft.com/test/network_confirm.php')); 100 $this->assertWantedText('target for the SimpleTest'); 101 $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/'); 102 } 103 104 function testGetWithData() { 105 $this->get('http://www.lastcraft.com/test/network_confirm.php', array("a" => "aaa")); 106 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/'); 107 $this->assertWantedText('a=[aaa]'); 108 } 109 110 function testPostWithData() { 111 $this->post('http://www.lastcraft.com/test/network_confirm.php', array("a" => "aaa")); 112 $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/'); 113 $this->assertWantedText('a=[aaa]'); 114 } 115 116 function testRelativeGet() { 117 $this->get('http://www.lastcraft.com/test/link_confirm.php'); 118 $this->assertTrue($this->get('network_confirm.php')); 119 $this->assertWantedText('target for the SimpleTest'); 120 } 121 122 function testRelativePost() { 123 $this->post('http://www.lastcraft.com/test/link_confirm.php'); 124 $this->assertTrue($this->post('network_confirm.php')); 125 $this->assertWantedText('target for the SimpleTest'); 126 } 127 128 function testAbsoluteLinkFollowing() { 129 $this->get('http://www.lastcraft.com/test/link_confirm.php'); 130 $this->assertLink('Absolute'); 131 $this->assertTrue($this->clickLink('Absolute')); 132 $this->assertWantedText('target for the SimpleTest'); 133 } 134 135 function testRelativeLinkFollowing() { 136 $this->get('http://www.lastcraft.com/test/link_confirm.php'); 137 $this->assertTrue($this->clickLink('Relative')); 138 $this->assertWantedText('target for the SimpleTest'); 139 } 140 141 function testLinkIdFollowing() { 142 $this->get('http://www.lastcraft.com/test/link_confirm.php'); 143 $this->assertLinkById(1); 144 $this->assertTrue($this->clickLinkById(1)); 145 $this->assertWantedText('target for the SimpleTest'); 146 } 147 148 function testAbsoluteUrlBehavesAbsolutely() { 149 $this->get('http://www.lastcraft.com/test/link_confirm.php'); 150 $this->get('http://www.lastcraft.com'); 151 $this->assertWantedText('No guarantee of quality is given or even intended'); 152 } 153 } 154 155 class TestOfLivePageLinkingWithMinimalLinks extends WebTestCase { 156 157 function setUp() { 158 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 159 } 160 161 function testClickToExplicitelyNamedSelfReturns() { 162 $this->get('http://www.lastcraft.com/test/front_controller_style/a_page.php'); 163 $this->assertTrue($this->getUrl() == 'http://www.lastcraft.com/test/front_controller_style/a_page.php'); 164 $this->assertTitle('Simple test page with links'); 165 $this->clickLink('Self'); 166 $this->assertTitle('Simple test page with links'); 167 } 168 169 function testClickToMissingPageReturnsToSamePage() { 170 $this->get('http://www.lastcraft.com/test/front_controller_style/a_page.php'); 171 $this->clickLink('No page'); 172 $this->assertTitle('Simple test page with links'); 173 $this->assertWantedText('[action=no_page]'); 174 } 175 176 function testClickToBareActionReturnsToSamePage() { 177 $this->get('http://www.lastcraft.com/test/front_controller_style/a_page.php'); 178 $this->clickLink('Bare action'); 179 $this->assertTitle('Simple test page with links'); 180 $this->assertWantedText('[action=]'); 181 } 182 183 function testClickToSingleQuestionMarkReturnsToSamePage() { 184 $this->get('http://www.lastcraft.com/test/front_controller_style/a_page.php'); 185 $this->clickLink('Empty query'); 186 $this->assertTitle('Simple test page with links'); 187 } 188 189 function testClickToEmptyStringReturnsToSamePage() { 190 $this->get('http://www.lastcraft.com/test/front_controller_style/a_page.php'); 191 $this->clickLink('Empty link'); 192 $this->assertTitle('Simple test page with links'); 193 } 194 195 function testClickToSingleDotGoesToCurrentDirectory() { 196 $this->get('http://www.lastcraft.com/test/front_controller_style/a_page.php'); 197 $this->clickLink('Current directory'); 198 $this->assertTitle('Simple test front controller'); 199 } 200 201 function testClickBackADirectoryLevel() { 202 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 203 $this->clickLink('Down one'); 204 $this->assertWantedText('Index of /test'); 205 } 206 } 207 208 class TestOfLiveFrontControllerEmulation extends WebTestCase { 209 210 function setUp() { 211 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 212 } 213 214 function testJumpToNamedPage() { 215 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 216 $this->assertWantedText('Simple test front controller'); 217 $this->clickLink('Index'); 218 $this->assertResponse(200); 219 $this->assertWantedText('[action=index]'); 220 } 221 222 function testJumpToUnnamedPage() { 223 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 224 $this->clickLink('No page'); 225 $this->assertResponse(200); 226 $this->assertWantedText('Simple test front controller'); 227 $this->assertWantedText('[action=no_page]'); 228 } 229 230 function testJumpToUnnamedPageWithBareParameter() { 231 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 232 $this->clickLink('Bare action'); 233 $this->assertResponse(200); 234 $this->assertWantedText('Simple test front controller'); 235 $this->assertWantedText('[action=]'); 236 } 237 238 function testJumpToUnnamedPageWithEmptyQuery() { 239 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 240 $this->clickLink('Empty query'); 241 $this->assertResponse(200); 242 $this->assertWantedPattern('/Simple test front controller/'); 243 $this->assertWantedPattern('/raw get data.*?\[\].*?get data/si'); 244 } 245 246 function testJumpToUnnamedPageWithEmptyLink() { 247 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 248 $this->clickLink('Empty link'); 249 $this->assertResponse(200); 250 $this->assertWantedPattern('/Simple test front controller/'); 251 $this->assertWantedPattern('/raw get data.*?\[\].*?get data/si'); 252 } 253 254 function testJumpBackADirectoryLevel() { 255 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 256 $this->clickLink('Down one'); 257 $this->assertWantedText('Index of /test'); 258 } 259 260 function testSubmitToNamedPage() { 261 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 262 $this->assertWantedText('Simple test front controller'); 263 $this->clickSubmit('Index'); 264 $this->assertResponse(200); 265 $this->assertWantedText('[action=Index]'); 266 } 267 268 function testSubmitToSameDirectory() { 269 $this->get('http://www.lastcraft.com/test/front_controller_style/index.php'); 270 $this->clickSubmit('Same directory'); 271 $this->assertResponse(200); 272 $this->assertWantedText('[action=Same+directory]'); 273 } 274 275 function testSubmitToEmptyAction() { 276 $this->get('http://www.lastcraft.com/test/front_controller_style/index.php'); 277 $this->clickSubmit('Empty action'); 278 $this->assertResponse(200); 279 $this->assertWantedText('[action=Empty+action]'); 280 } 281 282 function testSubmitToNoAction() { 283 $this->get('http://www.lastcraft.com/test/front_controller_style/index.php'); 284 $this->clickSubmit('No action'); 285 $this->assertResponse(200); 286 $this->assertWantedText('[action=No+action]'); 287 } 288 289 function testSubmitBackADirectoryLevel() { 290 $this->get('http://www.lastcraft.com/test/front_controller_style/'); 291 $this->clickSubmit('Down one'); 292 $this->assertWantedText('Index of /test'); 293 } 294 } 295 296 class TestOfLiveHeaders extends WebTestCase { 297 298 function setUp() { 299 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 300 } 301 302 function testConfirmingHeaderExistence() { 303 $this->get('http://www.lastcraft.com/'); 304 $this->assertHeader('content-type'); 305 $this->assertHeader('content-type', 'text/html'); 306 $this->assertHeaderPattern('content-type', '/HTML/i'); 307 $this->assertNoUnwantedHeader('WWW-Authenticate'); 308 } 309 } 310 311 class TestOfLiveRedirects extends WebTestCase { 312 313 function setUp() { 314 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 315 } 316 317 function testNoRedirects() { 318 $this->setMaximumRedirects(0); 319 $this->get('http://www.lastcraft.com/test/redirect.php'); 320 $this->assertTitle('Redirection test'); 321 } 322 323 function testRedirects() { 324 $this->setMaximumRedirects(1); 325 $this->get('http://www.lastcraft.com/test/redirect.php'); 326 $this->assertTitle('Simple test target file'); 327 } 328 329 function testRedirectLosesGetData() { 330 $this->get('http://www.lastcraft.com/test/redirect.php', array('a' => 'aaa')); 331 $this->assertNoUnwantedText('a=[aaa]'); 332 } 333 334 function testRedirectKeepsExtraRequestDataOfItsOwn() { 335 $this->get('http://www.lastcraft.com/test/redirect.php'); 336 $this->assertWantedText('r=[rrr]'); 337 } 338 339 function testRedirectLosesPostData() { 340 $this->post('http://www.lastcraft.com/test/redirect.php', array('a' => 'aaa')); 341 $this->assertTitle('Simple test target file'); 342 $this->assertNoUnwantedText('a=[aaa]'); 343 } 344 345 function testRedirectWithBaseUrlChange() { 346 $this->get('http://www.lastcraft.com/test/base_change_redirect.php'); 347 $this->assertTitle('Simple test target file in folder'); 348 $this->get('http://www.lastcraft.com/test/path/base_change_redirect.php'); 349 $this->assertTitle('Simple test target file'); 350 } 351 352 function testRedirectWithDoubleBaseUrlChange() { 353 $this->get('http://www.lastcraft.com/test/double_base_change_redirect.php'); 354 $this->assertTitle('Simple test target file'); 355 } 356 } 357 358 class TestOfLiveCookies extends WebTestCase { 359 360 function setUp() { 361 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 362 } 363 364 function testCookieSetting() { 365 $this->setCookie('a', 'Test cookie a', 'www.lastcraft.com'); 366 $this->setCookie('b', 'Test cookie b', 'www.lastcraft.com', 'test'); 367 $this->get('http://www.lastcraft.com/test/network_confirm.php'); 368 $this->assertWantedPattern('/Test cookie a/'); 369 $this->assertWantedPattern('/Test cookie b/'); 370 $this->assertCookie('a'); 371 $this->assertCookie('b', 'Test cookie b'); 372 $this->assertTrue($this->getCookie('a') == 'Test cookie a'); 373 $this->assertTrue($this->getCookie('b') == 'Test cookie b'); 374 } 375 376 function testCookieReading() { 377 $this->get('http://www.lastcraft.com/test/set_cookies.php'); 378 $this->assertCookie('session_cookie', 'A'); 379 $this->assertCookie('short_cookie', ''); 380 $this->assertCookie('day_cookie', 'C'); 381 } 382 383 function testTemporaryCookieExpiry() { 384 $this->get('http://www.lastcraft.com/test/set_cookies.php'); 385 $this->restart(); 386 $this->assertNoCookie('session_cookie'); 387 $this->assertCookie('day_cookie', 'C'); 388 } 389 390 function testTimedCookieExpiry() { 391 $this->get('http://www.lastcraft.com/test/set_cookies.php'); 392 $this->ageCookies(3600); 393 $this->restart(time() + 60); // Includes a 60 sec. clock drift margin. 394 $this->assertNoCookie('session_cookie'); 395 $this->assertNoCookie('hour_cookie'); 396 $this->assertCookie('day_cookie', 'C'); 397 } 398 399 function testOfClockOverDrift() { 400 $this->get('http://www.lastcraft.com/test/set_cookies.php'); 401 $this->restart(time() + 160); // Allows sixty second drift. 402 $this->assertNoCookie( 403 'short_cookie', 404 '%s->Please check your computer clock setting if you are not using NTP'); 405 } 406 407 function testOfClockUnderDrift() { 408 $this->get('http://www.lastcraft.com/test/set_cookies.php'); 409 $this->restart(time() + 40); // Allows sixty second drift. 410 $this->assertCookie( 411 'short_cookie', 412 '', 413 '%s->Please check your computer clock setting if you are not using NTP'); 414 } 415 416 function testCookiePath() { 417 $this->get('http://www.lastcraft.com/test/set_cookies.php'); 418 $this->assertNoCookie("path_cookie", "D"); 419 $this->get('./path/show_cookies.php'); 420 $this->assertWantedPattern('/path_cookie/'); 421 $this->assertCookie("path_cookie", "D"); 422 } 423 } 424 425 class TestOfLiveForms extends WebTestCase { 426 427 function setUp() { 428 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 429 } 430 431 function testSimpleSubmit() { 432 $this->get('http://www.lastcraft.com/test/form.html'); 433 $this->assertTrue($this->clickSubmit('Go!')); 434 $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/'); 435 $this->assertWantedText('go=[Go!]'); 436 } 437 438 function testDefaultFormValues() { 439 $this->get('http://www.lastcraft.com/test/form.html'); 440 $this->assertField('a', ''); 441 $this->assertField('b', 'Default text'); 442 $this->assertField('c', ''); 443 $this->assertField('d', 'd1'); 444 $this->assertField('e', false); 445 $this->assertField('f', 'on'); 446 $this->assertField('g', 'g3'); 447 $this->assertField('h', 2); 448 $this->assertField('go', 'Go!'); 449 $this->assertTrue($this->clickSubmit('Go!')); 450 $this->assertWantedText('go=[Go!]'); 451 $this->assertWantedText('a=[]'); 452 $this->assertWantedText('b=[Default text]'); 453 $this->assertWantedText('c=[]'); 454 $this->assertWantedText('d=[d1]'); 455 $this->assertNoUnwantedText('e=['); 456 $this->assertWantedText('f=[on]'); 457 $this->assertWantedText('g=[g3]'); 458 } 459 460 function testFormSubmissionByLabel() { 461 $this->get('http://www.lastcraft.com/test/form.html'); 462 $this->setField('a', 'aaa'); 463 $this->setField('b', 'bbb'); 464 $this->setField('c', 'ccc'); 465 $this->setField('d', 'D2'); 466 $this->setField('e', 'on'); 467 $this->setField('f', false); 468 $this->setField('g', 'g2'); 469 $this->setField('h', 1); 470 $this->assertTrue($this->clickSubmit('Go!')); 471 $this->assertWantedText('a=[aaa]'); 472 $this->assertWantedText('b=[bbb]'); 473 $this->assertWantedText('c=[ccc]'); 474 $this->assertWantedText('d=[d2]'); 475 $this->assertWantedText('e=[on]'); 476 $this->assertNoUnwantedText('f=['); 477 $this->assertWantedText('g=[g2]'); 478 } 479 480 function testAdditionalFormValues() { 481 $this->get('http://www.lastcraft.com/test/form.html'); 482 $this->assertTrue($this->clickSubmit('Go!', array('add' => 'A'))); 483 $this->assertWantedText('go=[Go!]'); 484 $this->assertWantedText('add=[A]'); 485 } 486 487 function testFormSubmissionByName() { 488 $this->get('http://www.lastcraft.com/test/form.html'); 489 $this->assertTrue($this->clickSubmitByName('go')); 490 $this->assertWantedText('go=[Go!]'); 491 } 492 493 function testFormSubmissionByNameAndadditionalParameters() { 494 $this->get('http://www.lastcraft.com/test/form.html'); 495 $this->assertTrue($this->clickSubmitByName('go', array('add' => 'A'))); 496 $this->assertWantedText('go=[Go!]'); 497 $this->assertWantedText('add=[A]'); 498 } 499 500 function testFormSubmissionBySubmitButtonLabeledSubmit() { 501 $this->get('http://www.lastcraft.com/test/form.html'); 502 $this->assertTrue($this->clickSubmitByName('test')); 503 $this->assertWantedText('test=[Submit]'); 504 } 505 506 function testFormSubmissionWithIds() { 507 $this->get('http://www.lastcraft.com/test/form.html'); 508 $this->assertFieldById(1, ''); 509 $this->assertFieldById(2, 'Default text'); 510 $this->assertFieldById(3, ''); 511 $this->assertFieldById(4, 'd1'); 512 $this->assertFieldById(5, false); 513 $this->setFieldById(1, 'aaa'); 514 $this->setFieldById(2, 'bbb'); 515 $this->setFieldById(3, 'ccc'); 516 $this->setFieldById(4, 'D2'); 517 $this->setFieldById(5, 'on'); 518 $this->assertTrue($this->clickSubmitById(99)); 519 $this->assertWantedText('a=[aaa]'); 520 $this->assertWantedText('b=[bbb]'); 521 $this->assertWantedText('c=[ccc]'); 522 $this->assertWantedText('d=[d2]'); 523 $this->assertWantedText('e=[on]'); 524 $this->assertWantedText('go=[Go!]'); 525 } 526 527 function testImageSubmissionByLabel() { 528 $this->get('http://www.lastcraft.com/test/form.html'); 529 $this->assertTrue($this->clickImage('Image go!', 10, 12)); 530 $this->assertWantedText('go_x=[10]'); 531 $this->assertWantedText('go_y=[12]'); 532 } 533 534 function testImageSubmissionByLabelWithAdditionalParameters() { 535 $this->get('http://www.lastcraft.com/test/form.html'); 536 $this->assertTrue($this->clickImage('Image go!', 10, 12, array('add' => 'A'))); 537 $this->assertWantedText('add=[A]'); 538 } 539 540 function testImageSubmissionByName() { 541 $this->get('http://www.lastcraft.com/test/form.html'); 542 $this->assertTrue($this->clickImageByName('go', 10, 12)); 543 $this->assertWantedText('go_x=[10]'); 544 $this->assertWantedText('go_y=[12]'); 545 } 546 547 function testImageSubmissionById() { 548 $this->get('http://www.lastcraft.com/test/form.html'); 549 $this->assertTrue($this->clickImageById(97, 10, 12)); 550 $this->assertWantedText('go_x=[10]'); 551 $this->assertWantedText('go_y=[12]'); 552 } 553 554 function testButtonSubmissionByLabel() { 555 $this->get('http://www.lastcraft.com/test/form.html'); 556 $this->assertTrue($this->clickSubmit('Button go!', 10, 12)); 557 $this->assertWantedPattern('/go=\[ButtonGo\]/s'); 558 } 559 560 function testSelfSubmit() { 561 $this->get('http://www.lastcraft.com/test/self_form.php'); 562 $this->assertNoUnwantedPattern('/<p>submitted<\/p>/i'); 563 $this->assertNoUnwantedPattern('/<p>wrong form<\/p>/i'); 564 $this->assertTitle('Test of form self submission'); 565 $this->assertTrue($this->clickSubmit()); 566 $this->assertWantedPattern('/<p>submitted<\/p>/i'); 567 $this->assertNoUnwantedPattern('/<p>wrong form<\/p>/i'); 568 $this->assertTitle('Test of form self submission'); 569 } 570 571 function testSettingOfBlankOption() { 572 $this->get('http://www.lastcraft.com/test/form.html'); 573 $this->assertTrue($this->setField('d', '')); 574 $this->clickSubmit('Go!'); 575 $this->assertWantedText('d=[]'); 576 } 577 } 578 579 class TestOfLiveMultiValueWidgets extends WebTestCase { 580 581 function setUp() { 582 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 583 } 584 585 function testDefaultFormValueSubmission() { 586 $this->get('http://www.lastcraft.com/test/multiple_widget_form.html'); 587 $this->assertField('a', array('a2', 'a3')); 588 $this->assertField('b', array('b2', 'b3')); 589 $this->assertField('c[]', array('c2', 'c3')); 590 $this->assertTrue($this->clickSubmit('Go!')); 591 $this->assertWantedText('a=[a2, a3]'); 592 $this->assertWantedText('b=[b2, b3]'); 593 $this->assertWantedText('c=[c2, c3]'); 594 } 595 596 function testSubmittingMultipleValues() { 597 $this->get('http://www.lastcraft.com/test/multiple_widget_form.html'); 598 $this->setField('a', array('a1', 'a4')); 599 $this->assertField('a', array('a1', 'a4')); 600 $this->assertField('a', array('a4', 'a1')); 601 $this->setField('b', array('b1', 'b4')); 602 $this->assertField('b', array('b1', 'b4')); 603 $this->setField('c[]', array('c1', 'c4')); 604 $this->assertField('c[]', array('c1', 'c4')); 605 $this->assertTrue($this->clickSubmit('Go!')); 606 $this->assertWantedText('a=[a1, a4]'); 607 $this->assertWantedText('b=[b1, b4]'); 608 $this->assertWantedText('c=[c1, c4]'); 609 } 610 611 function testSavantStyleHiddenFieldDefaults() { 612 $this->get('http://www.lastcraft.com/test/savant_style_form.html'); 613 $this->assertField('a', array('a0')); 614 $this->assertField('b', array('b0')); 615 $this->assertTrue($this->clickSubmit('Go!')); 616 $this->assertWantedText('a=[a0]'); 617 $this->assertWantedText('b=[b0]'); 618 } 619 620 function testSavantStyleHiddenDefaultsAreOverridden() { 621 $this->get('http://www.lastcraft.com/test/savant_style_form.html'); 622 $this->assertTrue($this->setField('a', array('a1'))); 623 $this->assertTrue($this->setField('b', 'b1')); 624 $this->assertTrue($this->clickSubmit('Go!')); 625 $this->assertWantedText('a=[a1]'); 626 $this->assertWantedText('b=[b1]'); 627 } 628 629 function testSavantStyleFormSettingById() { 630 $this->get('http://www.lastcraft.com/test/savant_style_form.html'); 631 $this->assertFieldById(1, array('a0')); 632 $this->assertFieldById(4, array('b0')); 633 $this->assertTrue($this->setFieldById(2, 'a1')); 634 $this->assertTrue($this->setFieldById(5, 'b1')); 635 $this->assertTrue($this->clickSubmitById(99)); 636 $this->assertWantedText('a=[a1]'); 637 $this->assertWantedText('b=[b1]'); 638 } 639 } 640 641 class TestOfLiveHistoryNavigation extends WebTestCase { 642 643 function setUp() { 644 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 645 } 646 647 function testRetry() { 648 $this->get('http://www.lastcraft.com/test/cookie_based_counter.php'); 649 $this->assertWantedPattern('/count: 1/i'); 650 $this->retry(); 651 $this->assertWantedPattern('/count: 2/i'); 652 $this->retry(); 653 $this->assertWantedPattern('/count: 3/i'); 654 } 655 656 function testOfBackButton() { 657 $this->get('http://www.lastcraft.com/test/1.html'); 658 $this->clickLink('2'); 659 $this->assertTitle('2'); 660 $this->assertTrue($this->back()); 661 $this->assertTitle('1'); 662 $this->assertTrue($this->forward()); 663 $this->assertTitle('2'); 664 $this->assertFalse($this->forward()); 665 } 666 667 function testGetRetryResubmitsData() { 668 $this->assertTrue($this->get( 669 'http://www.lastcraft.com/test/network_confirm.php?a=aaa')); 670 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/'); 671 $this->assertWantedText('a=[aaa]'); 672 $this->retry(); 673 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/'); 674 $this->assertWantedText('a=[aaa]'); 675 } 676 677 function testGetRetryResubmitsExtraData() { 678 $this->assertTrue($this->get( 679 'http://www.lastcraft.com/test/network_confirm.php', 680 array('a' => 'aaa'))); 681 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/'); 682 $this->assertWantedText('a=[aaa]'); 683 $this->retry(); 684 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/'); 685 $this->assertWantedText('a=[aaa]'); 686 } 687 688 function testPostRetryResubmitsData() { 689 $this->assertTrue($this->post( 690 'http://www.lastcraft.com/test/network_confirm.php', 691 array('a' => 'aaa'))); 692 $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/'); 693 $this->assertWantedText('a=[aaa]'); 694 $this->retry(); 695 $this->assertWantedPattern('/Request method.*?<dd>POST<\/dd>/'); 696 $this->assertWantedText('a=[aaa]'); 697 } 698 699 function testGetRetryResubmitsRepeatedData() { 700 $this->assertTrue($this->get( 701 'http://www.lastcraft.com/test/network_confirm.php?a=1&a=2')); 702 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/'); 703 $this->assertWantedText('a=[1, 2]'); 704 $this->retry(); 705 $this->assertWantedPattern('/Request method.*?<dd>GET<\/dd>/'); 706 $this->assertWantedText('a=[1, 2]'); 707 } 708 } 709 710 class TestOfLiveAuthentication extends WebTestCase { 711 712 function setUp() { 713 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 714 } 715 716 function testChallengeFromProtectedPage() { 717 $this->get('http://www.lastcraft.com/test/protected/'); 718 $this->assertResponse(401); 719 $this->assertAuthentication('Basic'); 720 $this->assertRealm('SimpleTest basic authentication'); 721 $this->authenticate('test', 'secret'); 722 $this->assertResponse(200); 723 $this->retry(); 724 $this->assertResponse(200); 725 } 726 727 function testEncodedAuthenticationFetchesPage() { 728 $this->get('http://test:secret@www.lastcraft.com/test/protected/'); 729 $this->assertResponse(200); 730 } 731 732 function testRealmExtendsToWholeDirectory() { 733 $this->get('http://www.lastcraft.com/test/protected/1.html'); 734 $this->authenticate('test', 'secret'); 735 $this->clickLink('2'); 736 $this->assertResponse(200); 737 $this->clickLink('3'); 738 $this->assertResponse(200); 739 } 740 741 function testRedirectKeepsAuthentication() { 742 $this->get('http://www.lastcraft.com/test/protected/local_redirect.php'); 743 $this->authenticate('test', 'secret'); 744 $this->assertTitle('Simple test target file'); 745 } 746 747 function testSessionRestartLosesAuthentication() { 748 $this->get('http://www.lastcraft.com/test/protected/'); 749 $this->authenticate('test', 'secret'); 750 $this->assertResponse(200); 751 $this->restart(); 752 $this->get('http://www.lastcraft.com/test/protected/'); 753 $this->assertResponse(401); 754 } 755 } 756 757 class TestOfLoadingFrames extends WebTestCase { 758 759 function setUp() { 760 $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); 761 } 762 763 function testNoFramesContentWhenFramesDisabled() { 764 $this->ignoreFrames(); 765 $this->get('http://www.lastcraft.com/test/one_page_frameset.html'); 766 $this->assertTitle('Frameset for testing of SimpleTest'); 767 $this->assertWantedText('This content is for no frames only'); 768 } 769 770 function testPatternMatchCanReadTheOnlyFrame() { 771 $this->get('http://www.lastcraft.com/test/one_page_frameset.html'); 772 $this->assertWantedText('A target for the SimpleTest test suite'); 773 $this->assertNoUnwantedText('This content is for no frames only'); 774 } 775 776 function testMessyFramesetResponsesByName() { 777 $this->assertTrue($this->get( 778 'http://www.lastcraft.com/test/messy_frameset.html')); 779 $this->assertTitle('Frameset for testing of SimpleTest'); 780 781 $this->assertTrue($this->setFrameFocus('Front controller')); 782 $this->assertResponse(200); 783 $this->assertWantedText('Simple test front controller'); 784 785 $this->assertTrue($this->setFrameFocus('One')); 786 $this->assertResponse(200); 787 $this->assertLink('2'); 788 789 $this->assertTrue($this->setFrameFocus('Frame links')); 790 $this->assertResponse(200); 791 $this->assertLink('Set one to 2'); 792 793 $this->assertTrue($this->setFrameFocus('Counter')); 794 $this->assertResponse(200); 795 $this->assertWantedText('Count: 1'); 796 797 $this->assertTrue($this->setFrameFocus('Redirected')); 798 $this->assertResponse(200); 799 $this->assertWantedText('r=rrr'); 800 801 $this->assertTrue($this->setFrameFocus('Protected')); 802 $this->assertResponse(401); 803 804 $this->assertTrue($this->setFrameFocus('Protected redirect')); 805 $this->assertResponse(401); 806 807 $this->assertTrue($this->setFrameFocusByIndex(1)); 808 $this->assertResponse(200); 809 $this->assertWantedText('Simple test front controller'); 810 811 $this->assertTrue($this->setFrameFocusByIndex(2)); 812 $this->assertResponse(200); 813 $this->assertLink('2'); 814 815 $this->assertTrue($this->setFrameFocusByIndex(3)); 816 $this->assertResponse(200); 817 $this->assertLink('Set one to 2'); 818 819 $this->assertTrue($this->setFrameFocusByIndex(4)); 820 $this->assertResponse(200); 821 $this->assertWantedTExt('Count: 1'); 822 823 $this->assertTrue($this->setFrameFocusByIndex(5)); 824 $this->assertResponse(200); 825 $this->assertWantedText('r=rrr'); 826 827 $this->assertTrue($this->setFrameFocusByIndex(6)); 828 $this->assertResponse(401); 829 830 $this->assertTrue($this->setFrameFocusByIndex(7)); 831 } 832 833 function testReloadingFramesetPage() { 834 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 835 $this->assertWantedText('Count: 1'); 836 $this->retry(); 837 $this->assertWantedText('Count: 2'); 838 $this->retry(); 839 $this->assertWantedText('Count: 3'); 840 } 841 842 function testReloadingSingleFrameWithCookieCounter() { 843 $this->get('http://www.lastcraft.com/test/counting_frameset.html'); 844 $this->setFrameFocus('a'); 845 $this->assertWantedText('Count: 1'); 846 $this->setFrameFocus('b'); 847 $this->assertWantedText('Count: 2'); 848 849 $this->setFrameFocus('a'); 850 $this->retry(); 851 $this->assertWantedText('Count: 3'); 852 $this->retry(); 853 $this->assertWantedText('Count: 4'); 854 $this->setFrameFocus('b'); 855 $this->assertWantedText('Count: 2'); 856 } 857 858 function testReloadingFrameWhenUnfocusedReloadsWholeFrameset() { 859 $this->get('http://www.lastcraft.com/test/counting_frameset.html'); 860 $this->setFrameFocus('a'); 861 $this->assertWantedText('Count: 1'); 862 $this->setFrameFocus('b'); 863 $this->assertWantedText('Count: 2'); 864 865 $this->clearFrameFocus('a'); 866 $this->retry(); 867 868 $this->assertTitle('Frameset for testing of SimpleTest'); 869 $this->setFrameFocus('a'); 870 $this->assertWantedText('Count: 3'); 871 $this->setFrameFocus('b'); 872 $this->assertWantedText('Count: 4'); 873 } 874 875 function testClickingNormalLinkReplacesJustThatFrame() { 876 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 877 $this->clickLink('2'); 878 $this->assertLink('3'); 879 $this->assertWantedText('Simple test front controller'); 880 } 881 882 function testJumpToNamedPageReplacesJustThatFrame() { 883 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 884 $this->assertWantedPattern('/Simple test front controller/'); 885 $this->clickLink('Index'); 886 $this->assertResponse(200); 887 $this->assertWantedText('[action=index]'); 888 $this->assertWantedText('Count: 1'); 889 } 890 891 function testJumpToUnnamedPageReplacesJustThatFrame() { 892 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 893 $this->clickLink('No page'); 894 $this->assertResponse(200); 895 $this->assertWantedText('Simple test front controller'); 896 $this->assertWantedText('[action=no_page]'); 897 $this->assertWantedText('Count: 1'); 898 } 899 900 function testJumpToUnnamedPageWithBareParameterReplacesJustThatFrame() { 901 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 902 $this->clickLink('Bare action'); 903 $this->assertResponse(200); 904 $this->assertWantedText('Simple test front controller'); 905 $this->assertWantedText('[action=]'); 906 $this->assertWantedText('Count: 1'); 907 } 908 909 function testJumpToUnnamedPageWithEmptyQueryReplacesJustThatFrame() { 910 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 911 $this->clickLink('Empty query'); 912 $this->assertResponse(200); 913 $this->assertWantedPattern('/Simple test front controller/'); 914 $this->assertWantedPattern('/raw get data.*?\[\].*?get data/si'); 915 $this->assertWantedPattern('/Count: 1/'); 916 } 917 918 function testJumpToUnnamedPageWithEmptyLinkReplacesJustThatFrame() { 919 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 920 $this->clickLink('Empty link'); 921 $this->assertResponse(200); 922 $this->assertWantedPattern('/Simple test front controller/'); 923 $this->assertWantedPattern('/raw get data.*?\[\].*?get data/si'); 924 $this->assertWantedPattern('/Count: 1/'); 925 } 926 927 function testJumpBackADirectoryLevelReplacesJustThatFrame() { 928 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 929 $this->clickLink('Down one'); 930 $this->assertWantedPattern('/index of \/test/i'); 931 $this->assertWantedPattern('/Count: 1/'); 932 } 933 934 function testSubmitToNamedPageReplacesJustThatFrame() { 935 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 936 $this->assertWantedPattern('/Simple test front controller/'); 937 $this->clickSubmit('Index'); 938 $this->assertResponse(200); 939 $this->assertWantedText('[action=Index]'); 940 $this->assertWantedText('Count: 1'); 941 } 942 943 function testSubmitToSameDirectoryReplacesJustThatFrame() { 944 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 945 $this->clickSubmit('Same directory'); 946 $this->assertResponse(200); 947 $this->assertWantedText('[action=Same+directory]'); 948 $this->assertWantedText('Count: 1'); 949 } 950 951 function testSubmitToEmptyActionReplacesJustThatFrame() { 952 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 953 $this->clickSubmit('Empty action'); 954 $this->assertResponse(200); 955 $this->assertWantedText('[action=Empty+action]'); 956 $this->assertWantedText('Count: 1'); 957 } 958 959 function testSubmitToNoActionReplacesJustThatFrame() { 960 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 961 $this->clickSubmit('No action'); 962 $this->assertResponse(200); 963 $this->assertWantedText('[action=No+action]'); 964 $this->assertWantedText('Count: 1'); 965 } 966 967 function testSubmitBackADirectoryLevelReplacesJustThatFrame() { 968 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 969 $this->clickSubmit('Down one'); 970 $this->assertWantedPattern('/index of \/test/i'); 971 $this->assertWantedPattern('/Count: 1/'); 972 } 973 974 function testTopLinkExitsFrameset() { 975 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 976 $this->clickLink('Exit the frameset'); 977 $this->assertTitle('Simple test target file'); 978 } 979 980 function testLinkInOnePageCanLoadAnother() { 981 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 982 $this->assertNoLink('3'); 983 $this->clickLink('Set one to 2'); 984 $this->assertLink('3'); 985 $this->assertNoLink('2'); 986 $this->assertTitle('Frameset for testing of SimpleTest'); 987 } 988 } 989 990 class TestOfFrameAuthentication extends WebTestCase { 991 992 function testUnauthenticatedFrameSendsChallenge() { 993 $this->get('http://www.lastcraft.com/test/protected/'); 994 $this->setFrameFocus('Protected'); 995 $this->assertAuthentication('Basic'); 996 $this->assertRealm('SimpleTest basic authentication'); 997 $this->assertResponse(401); 998 } 999 1000 function testCanReadFrameFromAlreadyAuthenticatedRealm() { 1001 $this->get('http://www.lastcraft.com/test/protected/'); 1002 $this->authenticate('test', 'secret'); 1003 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 1004 $this->setFrameFocus('Protected'); 1005 $this->assertResponse(200); 1006 $this->assertWantedText('A target for the SimpleTest test suite'); 1007 } 1008 1009 function testCanAuthenticateFrame() { 1010 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 1011 $this->setFrameFocus('Protected'); 1012 $this->authenticate('test', 'secret'); 1013 $this->assertResponse(200); 1014 $this->assertWantedText('A target for the SimpleTest test suite'); 1015 $this->clearFrameFocus(); 1016 $this->assertWantedText('Count: 1'); 1017 } 1018 1019 function testCanAuthenticateRedirectedFrame() { 1020 $this->get('http://www.lastcraft.com/test/messy_frameset.html'); 1021 $this->setFrameFocus('Protected redirect'); 1022 $this->assertResponse(401); 1023 $this->authenticate('test', 'secret'); 1024 $this->assertResponse(200); 1025 $this->assertWantedText('A target for the SimpleTest test suite'); 1026 $this->clearFrameFocus(); 1027 $this->assertWantedText('Count: 1'); 1028 } 1029 } 1030 1031 class TestOfNestedFrames extends WebTestCase { 1032 1033 function testCanNavigateToSpecificContent() { 1034 $this->get('http://www.lastcraft.com/test/nested_frameset.html'); 1035 $this->assertTitle('Nested frameset for testing of SimpleTest'); 1036 1037 $this->assertWantedPattern('/This is frame A/'); 1038 $this->assertWantedPattern('/This is frame B/'); 1039 $this->assertWantedPattern('/Simple test front controller/'); 1040 $this->assertLink('2'); 1041 $this->assertLink('Set one to 2'); 1042 $this->assertWantedPattern('/Count: 1/'); 1043 $this->assertWantedPattern('/r=rrr/'); 1044 1045 $this->setFrameFocus('pair'); 1046 $this->assertWantedPattern('/This is frame A/'); 1047 $this->assertWantedPattern('/This is frame B/'); 1048 $this->assertNoUnwantedPattern('/Simple test front controller/'); 1049 $this->assertNoLink('2'); 1050 1051 $this->setFrameFocus('aaa'); 1052 $this->assertWantedPattern('/This is frame A/'); 1053 $this->assertNoUnwantedPattern('/This is frame B/'); 1054 1055 $this->clearFrameFocus(); 1056 $this->assertResponse(200); 1057 $this->setFrameFocus('messy'); 1058 $this->assertResponse(200); 1059 $this->setFrameFocus('Front controller'); 1060 $this->assertResponse(200); 1061 $this->assertWantedPattern('/Simple test front controller/'); 1062 $this->assertNoLink('2'); 1063 } 1064 1065 function testReloadingFramesetPage() { 1066 $this->get('http://www.lastcraft.com/test/nested_frameset.html'); 1067 $this->assertWantedPattern('/Count: 1/'); 1068 $this->retry(); 1069 $this->assertWantedPattern('/Count: 2/'); 1070 $this->retry(); 1071 $this->assertWantedPattern('/Count: 3/'); 1072 } 1073 1074 function testRetryingNestedPageOnlyRetriesThatSet() { 1075 $this->get('http://www.lastcraft.com/test/nested_frameset.html'); 1076 $this->assertWantedPattern('/Count: 1/'); 1077 $this->setFrameFocus('messy'); 1078 $this->retry(); 1079 $this->assertWantedPattern('/Count: 2/'); 1080 $this->setFrameFocus('Counter'); 1081 $this->retry(); 1082 $this->assertWantedPattern('/Count: 3/'); 1083 1084 $this->clearFrameFocus(); 1085 $this->setFrameFocus('messy'); 1086 $this->setFrameFocus('Front controller'); 1087 $this->retry(); 1088 1089 $this->clearFrameFocus(); 1090 $this->assertWantedPattern('/Count: 3/'); 1091 } 1092 1093 function testAuthenticatingNestedPage() { 1094 $this->get('http://www.lastcraft.com/test/nested_frameset.html'); 1095 $this->setFrameFocus('messy'); 1096 $this->setFrameFocus('Protected'); 1097 $this->assertAuthentication('Basic'); 1098 $this->assertRealm('SimpleTest basic authentication'); 1099 $this->assertResponse(401); 1100 1101 $this->authenticate('test', 'secret'); 1102 $this->assertResponse(200); 1103 $this->assertWantedPattern('/A target for the SimpleTest test suite/'); 1104 } 1105 } 1106?>