123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653 |
- <?php
- // $Id: acceptance_test.php 1808 2008-09-11 19:18:02Z pp11 $
- require_once(dirname(__FILE__) . '/../autorun.php');
- require_once(dirname(__FILE__) . '/../compatibility.php');
- require_once(dirname(__FILE__) . '/../browser.php');
- require_once(dirname(__FILE__) . '/../web_tester.php');
- require_once(dirname(__FILE__) . '/../unit_tester.php');
-
- class SimpleTestAcceptanceTest extends WebTestCase {
- static function samples() {
- return 'http://www.lastcraft.com/test/';
- }
- }
-
- class TestOfLiveBrowser extends UnitTestCase {
- function samples() {
- return SimpleTestAcceptanceTest::samples();
- }
-
- function testGet() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $this->assertTrue($browser->get($this->samples() . 'network_confirm.php'));
- $this->assertPattern('/target for the SimpleTest/', $browser->getContent());
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/', $browser->getContent());
- $this->assertEqual($browser->getTitle(), 'Simple test target file');
- $this->assertEqual($browser->getResponseCode(), 200);
- $this->assertEqual($browser->getMimeType(), 'text/html');
- }
-
- function testPost() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $this->assertTrue($browser->post($this->samples() . 'network_confirm.php'));
- $this->assertPattern('/target for the SimpleTest/', $browser->getContent());
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/', $browser->getContent());
- }
-
- function testAbsoluteLinkFollowing() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $browser->get($this->samples() . 'link_confirm.php');
- $this->assertTrue($browser->clickLink('Absolute'));
- $this->assertPattern('/target for the SimpleTest/', $browser->getContent());
- }
-
- function testRelativeEncodedeLinkFollowing() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $browser->get($this->samples() . 'link_confirm.php');
- $this->assertTrue($browser->clickLink("m�rc�l kiek'eboe"));
- $this->assertPattern('/target for the SimpleTest/', $browser->getContent());
- }
-
- function testRelativeLinkFollowing() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $browser->get($this->samples() . 'link_confirm.php');
- $this->assertTrue($browser->clickLink('Relative'));
- $this->assertPattern('/target for the SimpleTest/', $browser->getContent());
- }
-
- function testUnifiedClickLinkClicking() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $browser->get($this->samples() . 'link_confirm.php');
- $this->assertTrue($browser->click('Relative'));
- $this->assertPattern('/target for the SimpleTest/', $browser->getContent());
- }
-
- function testIdLinkFollowing() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $browser->get($this->samples() . 'link_confirm.php');
- $this->assertTrue($browser->clickLinkById(1));
- $this->assertPattern('/target for the SimpleTest/', $browser->getContent());
- }
-
- function testCookieReading() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $browser->get($this->samples() . 'set_cookies.php');
- $this->assertEqual($browser->getCurrentCookieValue('session_cookie'), 'A');
- $this->assertEqual($browser->getCurrentCookieValue('short_cookie'), 'B');
- $this->assertEqual($browser->getCurrentCookieValue('day_cookie'), 'C');
- }
-
- function testSimpleSubmit() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $browser->get($this->samples() . 'form.html');
- $this->assertTrue($browser->clickSubmit('Go!'));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/', $browser->getContent());
- $this->assertPattern('/go=\[Go!\]/', $browser->getContent());
- }
-
- function testUnifiedClickCanSubmit() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $browser->get($this->samples() . 'form.html');
- $this->assertTrue($browser->click('Go!'));
- $this->assertPattern('/go=\[Go!\]/', $browser->getContent());
- }
- }
-
- class TestOfLocalFileBrowser extends UnitTestCase {
- function samples() {
- return 'file://'.dirname(__FILE__).'/site/';
- }
-
- function testGet() {
- $browser = new SimpleBrowser();
- $browser->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- $this->assertTrue($browser->get($this->samples() . 'file.html'));
- $this->assertPattern('/Link to SimpleTest/', $browser->getContent());
- $this->assertEqual($browser->getTitle(), 'Link to SimpleTest');
- $this->assertFalse($browser->getResponseCode());
- $this->assertEqual($browser->getMimeType(), '');
- }
- }
-
- class TestRadioFields extends SimpleTestAcceptanceTest {
- function testSetFieldAsInteger() {
- $this->get($this->samples() . 'form_with_radio_buttons.html');
- $this->assertTrue($this->setField('tested_field', 2));
- $this->clickSubmitByName('send');
- $this->assertEqual($this->getUrl(), $this->samples() . 'form_with_radio_buttons.html?tested_field=2&send=click+me');
- }
-
- function testSetFieldAsString() {
- $this->get($this->samples() . 'form_with_radio_buttons.html');
- $this->assertTrue($this->setField('tested_field', '2'));
- $this->clickSubmitByName('send');
- $this->assertEqual($this->getUrl(), $this->samples() . 'form_with_radio_buttons.html?tested_field=2&send=click+me');
- }
- }
-
- class TestOfLiveFetching extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testFormWithArrayBasedInputs() {
- $this->get($this->samples() . 'form_with_array_based_inputs.php');
- $this->setField('value[]', '3', '1');
- $this->setField('value[]', '4', '2');
- $this->clickSubmit('Go');
- $this->assertPattern('/QUERY_STRING : value%5B%5D=3&value%5B%5D=4&submit=Go/');
- }
-
- function testFormWithQuotedValues() {
- $this->get($this->samples() . 'form_with_quoted_values.php');
- $this->assertField('a', 'default');
- $this->assertFieldById('text_field', 'default');
- $this->clickSubmit('Go');
- $this->assertPattern('/a=default&submit=Go/');
- }
-
- function testGet() {
- $this->assertTrue($this->get($this->samples() . 'network_confirm.php'));
- $this->assertEqual($this->getUrl(), $this->samples() . 'network_confirm.php');
- $this->assertText('target for the SimpleTest');
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/');
- $this->assertTitle('Simple test target file');
- $this->assertTitle(new PatternExpectation('/target file/'));
- $this->assertResponse(200);
- $this->assertMime('text/html');
- $this->assertHeader('connection', 'close');
- $this->assertHeader('connection', new PatternExpectation('/los/'));
- }
-
- function testSlowGet() {
- $this->assertTrue($this->get($this->samples() . 'slow_page.php'));
- }
-
- function testTimedOutGet() {
- $this->setConnectionTimeout(1);
- $this->ignoreErrors();
- $this->assertFalse($this->get($this->samples() . 'slow_page.php'));
- }
-
- function testPost() {
- $this->assertTrue($this->post($this->samples() . 'network_confirm.php'));
- $this->assertText('target for the SimpleTest');
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- }
-
- function testGetWithData() {
- $this->get($this->samples() . 'network_confirm.php', array("a" => "aaa"));
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/');
- $this->assertText('a=[aaa]');
- }
-
- function testPostWithData() {
- $this->post($this->samples() . 'network_confirm.php', array("a" => "aaa"));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('a=[aaa]');
- }
-
- function testPostWithRecursiveData() {
- $this->post($this->samples() . 'network_confirm.php', array("a" => "aaa"));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('a=[aaa]');
-
- $this->post($this->samples() . 'network_confirm.php', array("a[aa]" => "aaa"));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('a=[aa=[aaa]]');
-
- $this->post($this->samples() . 'network_confirm.php', array("a[aa][aaa]" => "aaaa"));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('a=[aa=[aaa=[aaaa]]]');
-
- $this->post($this->samples() . 'network_confirm.php', array("a" => array("aa" => "aaa")));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('a=[aa=[aaa]]');
-
- $this->post($this->samples() . 'network_confirm.php', array("a" => array("aa" => array("aaa" => "aaaa"))));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('a=[aa=[aaa=[aaaa]]]');
- }
-
- function testRelativeGet() {
- $this->get($this->samples() . 'link_confirm.php');
- $this->assertTrue($this->get('network_confirm.php'));
- $this->assertText('target for the SimpleTest');
- }
-
- function testRelativePost() {
- $this->post($this->samples() . 'link_confirm.php');
- $this->assertTrue($this->post('network_confirm.php'));
- $this->assertText('target for the SimpleTest');
- }
- }
-
- class TestOfLinkFollowing extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testLinkAssertions() {
- $this->get($this->samples() . 'link_confirm.php');
- $this->assertLink('Absolute', $this->samples() . 'network_confirm.php');
- $this->assertLink('Absolute', new PatternExpectation('/confirm/'));
- $this->assertClickable('Absolute');
- }
-
- function testAbsoluteLinkFollowing() {
- $this->get($this->samples() . 'link_confirm.php');
- $this->assertTrue($this->clickLink('Absolute'));
- $this->assertText('target for the SimpleTest');
- }
-
- function testRelativeLinkFollowing() {
- $this->get($this->samples() . 'link_confirm.php');
- $this->assertTrue($this->clickLink('Relative'));
- $this->assertText('target for the SimpleTest');
- }
-
- function testLinkIdFollowing() {
- $this->get($this->samples() . 'link_confirm.php');
- $this->assertLinkById(1);
- $this->assertTrue($this->clickLinkById(1));
- $this->assertText('target for the SimpleTest');
- }
-
- function testAbsoluteUrlBehavesAbsolutely() {
- $this->get($this->samples() . 'link_confirm.php');
- $this->get('http://www.lastcraft.com');
- $this->assertText('No guarantee of quality is given or even intended');
- }
-
- function testRelativeUrlRespectsBaseTag() {
- $this->get($this->samples() . 'base_tag/base_link.html');
- $this->click('Back to test pages');
- $this->assertTitle('Simple test target file');
- }
- }
-
- class TestOfLivePageLinkingWithMinimalLinks extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testClickToExplicitelyNamedSelfReturns() {
- $this->get($this->samples() . 'front_controller_style/a_page.php');
- $this->assertEqual($this->getUrl(), $this->samples() . 'front_controller_style/a_page.php');
- $this->assertTitle('Simple test page with links');
- $this->assertLink('Self');
- $this->clickLink('Self');
- $this->assertTitle('Simple test page with links');
- }
-
- function testClickToMissingPageReturnsToSamePage() {
- $this->get($this->samples() . 'front_controller_style/a_page.php');
- $this->clickLink('No page');
- $this->assertTitle('Simple test page with links');
- $this->assertText('[action=no_page]');
- }
-
- function testClickToBareActionReturnsToSamePage() {
- $this->get($this->samples() . 'front_controller_style/a_page.php');
- $this->clickLink('Bare action');
- $this->assertTitle('Simple test page with links');
- $this->assertText('[action=]');
- }
-
- function testClickToSingleQuestionMarkReturnsToSamePage() {
- $this->get($this->samples() . 'front_controller_style/a_page.php');
- $this->clickLink('Empty query');
- $this->assertTitle('Simple test page with links');
- }
-
- function testClickToEmptyStringReturnsToSamePage() {
- $this->get($this->samples() . 'front_controller_style/a_page.php');
- $this->clickLink('Empty link');
- $this->assertTitle('Simple test page with links');
- }
-
- function testClickToSingleDotGoesToCurrentDirectory() {
- $this->get($this->samples() . 'front_controller_style/a_page.php');
- $this->clickLink('Current directory');
- $this->assertTitle(
- 'Simple test front controller',
- '%s -> index.php needs to be set as a default web server home page');
- }
-
- function testClickBackADirectoryLevel() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->clickLink('Down one');
- $this->assertPattern('|Index of .*?/test|i');
- }
- }
-
- class TestOfLiveFrontControllerEmulation extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testJumpToNamedPage() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->assertText('Simple test front controller');
- $this->clickLink('Index');
- $this->assertResponse(200);
- $this->assertText('[action=index]');
- }
-
- function testJumpToUnnamedPage() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->clickLink('No page');
- $this->assertResponse(200);
- $this->assertText('Simple test front controller');
- $this->assertText('[action=no_page]');
- }
-
- function testJumpToUnnamedPageWithBareParameter() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->clickLink('Bare action');
- $this->assertResponse(200);
- $this->assertText('Simple test front controller');
- $this->assertText('[action=]');
- }
-
- function testJumpToUnnamedPageWithEmptyQuery() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->clickLink('Empty query');
- $this->assertResponse(200);
- $this->assertPattern('/Simple test front controller/');
- $this->assertPattern('/raw get data.*?\[\].*?get data/si');
- }
-
- function testJumpToUnnamedPageWithEmptyLink() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->clickLink('Empty link');
- $this->assertResponse(200);
- $this->assertPattern('/Simple test front controller/');
- $this->assertPattern('/raw get data.*?\[\].*?get data/si');
- }
-
- function testJumpBackADirectoryLevel() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->clickLink('Down one');
- $this->assertPattern('|Index of .*?/test|');
- }
-
- function testSubmitToNamedPage() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->assertText('Simple test front controller');
- $this->clickSubmit('Index');
- $this->assertResponse(200);
- $this->assertText('[action=Index]');
- }
-
- function testSubmitToSameDirectory() {
- $this->get($this->samples() . 'front_controller_style/index.php');
- $this->clickSubmit('Same directory');
- $this->assertResponse(200);
- $this->assertText('[action=Same+directory]');
- }
-
- function testSubmitToEmptyAction() {
- $this->get($this->samples() . 'front_controller_style/index.php');
- $this->clickSubmit('Empty action');
- $this->assertResponse(200);
- $this->assertText('[action=Empty+action]');
- }
-
- function testSubmitToNoAction() {
- $this->get($this->samples() . 'front_controller_style/index.php');
- $this->clickSubmit('No action');
- $this->assertResponse(200);
- $this->assertText('[action=No+action]');
- }
-
- function testSubmitBackADirectoryLevel() {
- $this->get($this->samples() . 'front_controller_style/');
- $this->clickSubmit('Down one');
- $this->assertPattern('|Index of .*?/test|');
- }
-
- function testSubmitToNamedPageWithMixedPostAndGet() {
- $this->get($this->samples() . 'front_controller_style/?a=A');
- $this->assertText('Simple test front controller');
- $this->clickSubmit('Index post');
- $this->assertText('action=[Index post]');
- $this->assertNoText('[a=A]');
- }
-
- function testSubmitToSameDirectoryMixedPostAndGet() {
- $this->get($this->samples() . 'front_controller_style/index.php?a=A');
- $this->clickSubmit('Same directory post');
- $this->assertText('action=[Same directory post]');
- $this->assertNoText('[a=A]');
- }
-
- function testSubmitToEmptyActionMixedPostAndGet() {
- $this->get($this->samples() . 'front_controller_style/index.php?a=A');
- $this->clickSubmit('Empty action post');
- $this->assertText('action=[Empty action post]');
- $this->assertText('[a=A]');
- }
-
- function testSubmitToNoActionMixedPostAndGet() {
- $this->get($this->samples() . 'front_controller_style/index.php?a=A');
- $this->clickSubmit('No action post');
- $this->assertText('action=[No action post]');
- $this->assertText('[a=A]');
- }
- }
-
- class TestOfLiveHeaders extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testConfirmingHeaderExistence() {
- $this->get('http://www.lastcraft.com/');
- $this->assertHeader('content-type');
- $this->assertHeader('content-type', 'text/html');
- $this->assertHeader('content-type', new PatternExpectation('/HTML/i'));
- $this->assertNoHeader('WWW-Authenticate');
- }
- }
-
- class TestOfLiveRedirects extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testNoRedirects() {
- $this->setMaximumRedirects(0);
- $this->get($this->samples() . 'redirect.php');
- $this->assertTitle('Redirection test');
- }
-
- function testRedirects() {
- $this->setMaximumRedirects(1);
- $this->get($this->samples() . 'redirect.php');
- $this->assertTitle('Simple test target file');
- }
-
- function testRedirectLosesGetData() {
- $this->get($this->samples() . 'redirect.php', array('a' => 'aaa'));
- $this->assertNoText('a=[aaa]');
- }
-
- function testRedirectKeepsExtraRequestDataOfItsOwn() {
- $this->get($this->samples() . 'redirect.php');
- $this->assertText('r=[rrr]');
- }
-
- function testRedirectLosesPostData() {
- $this->post($this->samples() . 'redirect.php', array('a' => 'aaa'));
- $this->assertTitle('Simple test target file');
- $this->assertNoText('a=[aaa]');
- }
-
- function testRedirectWithBaseUrlChange() {
- $this->get($this->samples() . 'base_change_redirect.php');
- $this->assertTitle('Simple test target file in folder');
- $this->get($this->samples() . 'path/base_change_redirect.php');
- $this->assertTitle('Simple test target file');
- }
-
- function testRedirectWithDoubleBaseUrlChange() {
- $this->get($this->samples() . 'double_base_change_redirect.php');
- $this->assertTitle('Simple test target file');
- }
- }
-
- class TestOfLiveCookies extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function here() {
- return new SimpleUrl($this->samples());
- }
-
- function thisHost() {
- $here = $this->here();
- return $here->getHost();
- }
-
- function thisPath() {
- $here = $this->here();
- return $here->getPath();
- }
-
- function testCookieSettingAndAssertions() {
- $this->setCookie('a', 'Test cookie a');
- $this->setCookie('b', 'Test cookie b', $this->thisHost());
- $this->setCookie('c', 'Test cookie c', $this->thisHost(), $this->thisPath());
- $this->get($this->samples() . 'network_confirm.php');
- $this->assertText('Test cookie a');
- $this->assertText('Test cookie b');
- $this->assertText('Test cookie c');
- $this->assertCookie('a');
- $this->assertCookie('b', 'Test cookie b');
- $this->assertTrue($this->getCookie('c') == 'Test cookie c');
- }
-
- function testNoCookieSetWhenCookiesDisabled() {
- $this->setCookie('a', 'Test cookie a');
- $this->ignoreCookies();
- $this->get($this->samples() . 'network_confirm.php');
- $this->assertNoText('Test cookie a');
- }
-
- function testCookieReading() {
- $this->get($this->samples() . 'set_cookies.php');
- $this->assertCookie('session_cookie', 'A');
- $this->assertCookie('short_cookie', 'B');
- $this->assertCookie('day_cookie', 'C');
- }
-
- function testNoCookie() {
- $this->assertNoCookie('aRandomCookie');
- }
-
- function testNoCookieReadingWhenCookiesDisabled() {
- $this->ignoreCookies();
- $this->get($this->samples() . 'set_cookies.php');
- $this->assertNoCookie('session_cookie');
- $this->assertNoCookie('short_cookie');
- $this->assertNoCookie('day_cookie');
- }
-
- function testCookiePatternAssertions() {
- $this->get($this->samples() . 'set_cookies.php');
- $this->assertCookie('session_cookie', new PatternExpectation('/a/i'));
- }
-
- function testTemporaryCookieExpiry() {
- $this->get($this->samples() . 'set_cookies.php');
- $this->restart();
- $this->assertNoCookie('session_cookie');
- $this->assertCookie('day_cookie', 'C');
- }
-
- function testTimedCookieExpiryWith100SecondMargin() {
- $this->get($this->samples() . 'set_cookies.php');
- $this->ageCookies(3600);
- $this->restart(time() + 100);
- $this->assertNoCookie('session_cookie');
- $this->assertNoCookie('hour_cookie');
- $this->assertCookie('day_cookie', 'C');
- }
-
- function testNoClockOverDriftBy100Seconds() {
- $this->get($this->samples() . 'set_cookies.php');
- $this->restart(time() + 200);
- $this->assertNoCookie(
- 'short_cookie',
- '%s -> Please check your computer clock setting if you are not using NTP');
- }
-
- function testNoClockUnderDriftBy100Seconds() {
- $this->get($this->samples() . 'set_cookies.php');
- $this->restart(time() + 0);
- $this->assertCookie(
- 'short_cookie',
- 'B',
- '%s -> Please check your computer clock setting if you are not using NTP');
- }
-
- function testCookiePath() {
- $this->get($this->samples() . 'set_cookies.php');
- $this->assertNoCookie('path_cookie', 'D');
- $this->get('./path/show_cookies.php');
- $this->assertPattern('/path_cookie/');
- $this->assertCookie('path_cookie', 'D');
- }
- }
-
- class LiveTestOfForms extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testSimpleSubmit() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('go=[Go!]');
- }
-
- function testDefaultFormValues() {
- $this->get($this->samples() . 'form.html');
- $this->assertFieldByName('a', '');
- $this->assertFieldByName('b', 'Default text');
- $this->assertFieldByName('c', '');
- $this->assertFieldByName('d', 'd1');
- $this->assertFieldByName('e', false);
- $this->assertFieldByName('f', 'on');
- $this->assertFieldByName('g', 'g3');
- $this->assertFieldByName('h', 2);
- $this->assertFieldByName('go', 'Go!');
- $this->assertClickable('Go!');
- $this->assertSubmit('Go!');
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('go=[Go!]');
- $this->assertText('a=[]');
- $this->assertText('b=[Default text]');
- $this->assertText('c=[]');
- $this->assertText('d=[d1]');
- $this->assertNoText('e=[');
- $this->assertText('f=[on]');
- $this->assertText('g=[g3]');
- }
-
- function testFormSubmissionByButtonLabel() {
- $this->get($this->samples() . 'form.html');
- $this->setFieldByName('a', 'aaa');
- $this->setFieldByName('b', 'bbb');
- $this->setFieldByName('c', 'ccc');
- $this->setFieldByName('d', 'D2');
- $this->setFieldByName('e', 'on');
- $this->setFieldByName('f', false);
- $this->setFieldByName('g', 'g2');
- $this->setFieldByName('h', 1);
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('a=[aaa]');
- $this->assertText('b=[bbb]');
- $this->assertText('c=[ccc]');
- $this->assertText('d=[d2]');
- $this->assertText('e=[on]');
- $this->assertNoText('f=[');
- $this->assertText('g=[g2]');
- }
-
- function testAdditionalFormValues() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->clickSubmit('Go!', array('add' => 'A')));
- $this->assertText('go=[Go!]');
- $this->assertText('add=[A]');
- }
-
- function testFormSubmissionByName() {
- $this->get($this->samples() . 'form.html');
- $this->setFieldByName('a', 'A');
- $this->assertTrue($this->clickSubmitByName('go'));
- $this->assertText('a=[A]');
- }
-
- function testFormSubmissionByNameAndAdditionalParameters() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->clickSubmitByName('go', array('add' => 'A')));
- $this->assertText('go=[Go!]');
- $this->assertText('add=[A]');
- }
-
- function testFormSubmissionBySubmitButtonLabeledSubmit() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->clickSubmitByName('test'));
- $this->assertText('test=[Submit]');
- }
-
- function testFormSubmissionWithIds() {
- $this->get($this->samples() . 'form.html');
- $this->assertFieldById(1, '');
- $this->assertFieldById(2, 'Default text');
- $this->assertFieldById(3, '');
- $this->assertFieldById(4, 'd1');
- $this->assertFieldById(5, false);
- $this->assertFieldById(6, 'on');
- $this->assertFieldById(8, 'g3');
- $this->assertFieldById(11, 2);
- $this->setFieldById(1, 'aaa');
- $this->setFieldById(2, 'bbb');
- $this->setFieldById(3, 'ccc');
- $this->setFieldById(4, 'D2');
- $this->setFieldById(5, 'on');
- $this->setFieldById(6, false);
- $this->setFieldById(8, 'g2');
- $this->setFieldById(11, 'H1');
- $this->assertTrue($this->clickSubmitById(99));
- $this->assertText('a=[aaa]');
- $this->assertText('b=[bbb]');
- $this->assertText('c=[ccc]');
- $this->assertText('d=[d2]');
- $this->assertText('e=[on]');
- $this->assertNoText('f=[');
- $this->assertText('g=[g2]');
- $this->assertText('h=[1]');
- $this->assertText('go=[Go!]');
- }
-
- function testFormSubmissionWithLabels() {
- $this->get($this->samples() . 'form.html');
- $this->assertField('Text A', '');
- $this->assertField('Text B', 'Default text');
- $this->assertField('Text area C', '');
- $this->assertField('Selection D', 'd1');
- $this->assertField('Checkbox E', false);
- $this->assertField('Checkbox F', 'on');
- $this->assertField('3', 'g3');
- $this->assertField('Selection H', 2);
- $this->setField('Text A', 'aaa');
- $this->setField('Text B', 'bbb');
- $this->setField('Text area C', 'ccc');
- $this->setField('Selection D', 'D2');
- $this->setField('Checkbox E', 'on');
- $this->setField('Checkbox F', false);
- $this->setField('2', 'g2');
- $this->setField('Selection H', 'H1');
- $this->clickSubmit('Go!');
- $this->assertText('a=[aaa]');
- $this->assertText('b=[bbb]');
- $this->assertText('c=[ccc]');
- $this->assertText('d=[d2]');
- $this->assertText('e=[on]');
- $this->assertNoText('f=[');
- $this->assertText('g=[g2]');
- $this->assertText('h=[1]');
- $this->assertText('go=[Go!]');
- }
-
- function testSettingCheckboxWithBooleanTrueSetsUnderlyingValue() {
- $this->get($this->samples() . 'form.html');
- $this->setField('Checkbox E', true);
- $this->assertField('Checkbox E', 'on');
- $this->clickSubmit('Go!');
- $this->assertText('e=[on]');
- }
-
- function testFormSubmissionWithMixedPostAndGet() {
- $this->get($this->samples() . 'form_with_mixed_post_and_get.html');
- $this->setField('Text A', 'Hello');
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('a=[Hello]');
- $this->assertText('x=[X]');
- $this->assertText('y=[Y]');
- }
-
- function testFormSubmissionWithMixedPostAndEncodedGet() {
- $this->get($this->samples() . 'form_with_mixed_post_and_get.html');
- $this->setField('Text B', 'Hello');
- $this->assertTrue($this->clickSubmit('Go encoded!'));
- $this->assertText('b=[Hello]');
- $this->assertText('x=[X]');
- $this->assertText('y=[Y]');
- }
-
- function testFormSubmissionWithoutAction() {
- $this->get($this->samples() . 'form_without_action.php?test=test');
- $this->assertText('_GET : [test]');
- $this->assertTrue($this->clickSubmit('Submit Post With Empty Action'));
- $this->assertText('_GET : [test]');
- $this->assertText('_POST : [test]');
- }
-
- function testImageSubmissionByLabel() {
- $this->get($this->samples() . 'form.html');
- $this->assertImage('Image go!');
- $this->assertTrue($this->clickImage('Image go!', 10, 12));
- $this->assertText('go_x=[10]');
- $this->assertText('go_y=[12]');
- }
-
- function testImageSubmissionByLabelWithAdditionalParameters() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->clickImage('Image go!', 10, 12, array('add' => 'A')));
- $this->assertText('add=[A]');
- }
-
- function testImageSubmissionByName() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->clickImageByName('go', 10, 12));
- $this->assertText('go_x=[10]');
- $this->assertText('go_y=[12]');
- }
-
- function testImageSubmissionById() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->clickImageById(97, 10, 12));
- $this->assertText('go_x=[10]');
- $this->assertText('go_y=[12]');
- }
-
- function testButtonSubmissionByLabel() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->clickSubmit('Button go!', 10, 12));
- $this->assertPattern('/go=\[ButtonGo\]/s');
- }
-
- function testNamelessSubmitSendsNoValue() {
- $this->get($this->samples() . 'form_with_unnamed_submit.html');
- $this->click('Go!');
- $this->assertNoText('Go!');
- $this->assertNoText('submit');
- }
-
- function testNamelessImageSendsXAndYValues() {
- $this->get($this->samples() . 'form_with_unnamed_submit.html');
- $this->clickImage('Image go!', 4, 5);
- $this->assertNoText('ImageGo');
- $this->assertText('x=[4]');
- $this->assertText('y=[5]');
- }
-
- function testNamelessButtonSendsNoValue() {
- $this->get($this->samples() . 'form_with_unnamed_submit.html');
- $this->click('Button Go!');
- $this->assertNoText('ButtonGo');
- }
-
- function testSelfSubmit() {
- $this->get($this->samples() . 'self_form.php');
- $this->assertNoText('[Submitted]');
- $this->assertNoText('[Wrong form]');
- $this->assertTrue($this->clickSubmit());
- $this->assertText('[Submitted]');
- $this->assertNoText('[Wrong form]');
- $this->assertTitle('Test of form self submission');
- }
-
- function testSelfSubmitWithParameters() {
- $this->get($this->samples() . 'self_form.php');
- $this->setFieldByName('visible', 'Resent');
- $this->assertTrue($this->clickSubmit());
- $this->assertText('[Resent]');
- }
-
- function testSettingOfBlankOption() {
- $this->get($this->samples() . 'form.html');
- $this->assertTrue($this->setFieldByName('d', ''));
- $this->clickSubmit('Go!');
- $this->assertText('d=[]');
- }
-
- function testAssertingFieldValueWithPattern() {
- $this->get($this->samples() . 'form.html');
- $this->setField('c', 'A very long string');
- $this->assertField('c', new PatternExpectation('/very long/'));
- }
-
- function testSendingMultipartFormDataEncodedForm() {
- $this->get($this->samples() . 'form_data_encoded_form.html');
- $this->assertField('Text A', '');
- $this->assertField('Text B', 'Default text');
- $this->assertField('Text area C', '');
- $this->assertField('Selection D', 'd1');
- $this->assertField('Checkbox E', false);
- $this->assertField('Checkbox F', 'on');
- $this->assertField('3', 'g3');
- $this->assertField('Selection H', 2);
- $this->setField('Text A', 'aaa');
- $this->setField('Text B', 'bbb');
- $this->setField('Text area C', 'ccc');
- $this->setField('Selection D', 'D2');
- $this->setField('Checkbox E', 'on');
- $this->setField('Checkbox F', false);
- $this->setField('2', 'g2');
- $this->setField('Selection H', 'H1');
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('a=[aaa]');
- $this->assertText('b=[bbb]');
- $this->assertText('c=[ccc]');
- $this->assertText('d=[d2]');
- $this->assertText('e=[on]');
- $this->assertNoText('f=[');
- $this->assertText('g=[g2]');
- $this->assertText('h=[1]');
- $this->assertText('go=[Go!]');
- }
-
- function testSettingVariousBlanksInFields() {
- $this->get($this->samples() . 'form_with_false_defaults.html');
- $this->assertField('Text A', '');
- $this->setField('Text A', '0');
- $this->assertField('Text A', '0');
- $this->assertField('Text area B', '');
- $this->setField('Text area B', '0');
- $this->assertField('Text area B', '0');
- $this->assertField('Text area C', " ");
- $this->assertField('Selection D', '');
- $this->setField('Selection D', 'D2');
- $this->assertField('Selection D', 'D2');
- $this->setField('Selection D', 'D3');
- $this->assertField('Selection D', '0');
- $this->setField('Selection D', 'D4');
- $this->assertField('Selection D', '?');
- $this->assertField('Checkbox E', '');
- $this->assertField('Checkbox F', 'on');
- $this->assertField('Checkbox G', '0');
- $this->assertField('Checkbox H', '?');
- $this->assertFieldByName('i', 'on');
- $this->setFieldByName('i', '');
- $this->assertFieldByName('i', '');
- $this->setFieldByName('i', '0');
- $this->assertFieldByName('i', '0');
- $this->setFieldByName('i', '?');
- $this->assertFieldByName('i', '?');
- }
-
- function testSubmissionOfBlankFields() {
- $this->get($this->samples() . 'form_with_false_defaults.html');
- $this->setField('Text A', '');
- $this->setField('Text area B', '');
- $this->setFieldByName('i', '');
- $this->click('Go!');
- $this->assertText('a=[]');
- $this->assertText('b=[]');
- $this->assertPattern('/c=\[ \]/');
- $this->assertText('d=[]');
- $this->assertText('e=[]');
- $this->assertText('i=[]');
- }
-
- function testSubmissionOfEmptyValues() {
- $this->get($this->samples() . 'form_with_false_defaults.html');
- $this->setField('Selection D', 'D2');
- $this->click('Go!');
- $this->assertText('a=[]');
- $this->assertText('b=[]');
- $this->assertText('d=[D2]');
- $this->assertText('f=[on]');
- $this->assertText('i=[on]');
- }
-
- function testSubmissionOfZeroes() {
- $this->get($this->samples() . 'form_with_false_defaults.html');
- $this->setField('Text A', '0');
- $this->setField('Text area B', '0');
- $this->setField('Selection D', 'D3');
- $this->setFieldByName('i', '0');
- $this->click('Go!');
- $this->assertText('a=[0]');
- $this->assertText('b=[0]');
- $this->assertText('d=[0]');
- $this->assertText('g=[0]');
- $this->assertText('i=[0]');
- }
-
- function testSubmissionOfQuestionMarks() {
- $this->get($this->samples() . 'form_with_false_defaults.html');
- $this->setField('Text A', '?');
- $this->setField('Text area B', '?');
- $this->setField('Selection D', 'D4');
- $this->setFieldByName('i', '?');
- $this->click('Go!');
- $this->assertText('a=[?]');
- $this->assertText('b=[?]');
- $this->assertText('d=[?]');
- $this->assertText('h=[?]');
- $this->assertText('i=[?]');
- }
-
- function testSubmissionOfHtmlEncodedValues() {
- $this->get($this->samples() . 'form_with_tricky_defaults.html');
- $this->assertField('Text A', '&\'"<>');
- $this->assertField('Text B', '"');
- $this->assertField('Text area C', '&\'"<>');
- $this->assertField('Selection D', "'");
- $this->assertField('Checkbox E', '&\'"<>');
- $this->assertField('Checkbox F', false);
- $this->assertFieldByname('i', "'");
- $this->click('Go!');
- $this->assertText('a=[&\'"<>, "]');
- $this->assertText('c=[&\'"<>]');
- $this->assertText("d=[']");
- $this->assertText('e=[&\'"<>]');
- $this->assertText("i=[']");
- }
-
- function testFormActionRespectsBaseTag() {
- $this->get($this->samples() . 'base_tag/form.html');
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('go=[Go!]');
- $this->assertText('a=[]');
- }
- }
-
- class TestOfLiveMultiValueWidgets extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testDefaultFormValueSubmission() {
- $this->get($this->samples() . 'multiple_widget_form.html');
- $this->assertFieldByName('a', array('a2', 'a3'));
- $this->assertFieldByName('b', array('b2', 'b3'));
- $this->assertFieldByName('c[]', array('c2', 'c3'));
- $this->assertFieldByName('d', array('2', '3'));
- $this->assertFieldByName('e', array('2', '3'));
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('a=[a2, a3]');
- $this->assertText('b=[b2, b3]');
- $this->assertText('c=[c2, c3]');
- $this->assertText('d=[2, 3]');
- $this->assertText('e=[2, 3]');
- }
-
- function testSubmittingMultipleValues() {
- $this->get($this->samples() . 'multiple_widget_form.html');
- $this->setFieldByName('a', array('a1', 'a4'));
- $this->assertFieldByName('a', array('a1', 'a4'));
- $this->assertFieldByName('a', array('a4', 'a1'));
- $this->setFieldByName('b', array('b1', 'b4'));
- $this->assertFieldByName('b', array('b1', 'b4'));
- $this->setFieldByName('c[]', array('c1', 'c4'));
- $this->assertField('c[]', array('c1', 'c4'));
- $this->setFieldByName('d', array('1', '4'));
- $this->assertField('d', array('1', '4'));
- $this->setFieldByName('e', array('e1', 'e4'));
- $this->assertField('e', array('1', '4'));
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('a=[a1, a4]');
- $this->assertText('b=[b1, b4]');
- $this->assertText('c=[c1, c4]');
- $this->assertText('d=[1, 4]');
- $this->assertText('e=[1, 4]');
- }
-
- function testSettingByOptionValue() {
- $this->get($this->samples() . 'multiple_widget_form.html');
- $this->setFieldByName('d', array('1', '4'));
- $this->assertField('d', array('1', '4'));
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('d=[1, 4]');
- }
-
- function testSubmittingMultipleValuesByLabel() {
- $this->get($this->samples() . 'multiple_widget_form.html');
- $this->setField('Multiple selection A', array('a1', 'a4'));
- $this->assertField('Multiple selection A', array('a1', 'a4'));
- $this->assertField('Multiple selection A', array('a4', 'a1'));
- $this->setField('multiple selection C', array('c1', 'c4'));
- $this->assertField('multiple selection C', array('c1', 'c4'));
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('a=[a1, a4]');
- $this->assertText('c=[c1, c4]');
- }
-
- function testSavantStyleHiddenFieldDefaults() {
- $this->get($this->samples() . 'savant_style_form.html');
- $this->assertFieldByName('a', array('a0'));
- $this->assertFieldByName('b', array('b0'));
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('a=[a0]');
- $this->assertText('b=[b0]');
- }
-
- function testSavantStyleHiddenDefaultsAreOverridden() {
- $this->get($this->samples() . 'savant_style_form.html');
- $this->assertTrue($this->setFieldByName('a', array('a1')));
- $this->assertTrue($this->setFieldByName('b', 'b1'));
- $this->assertTrue($this->clickSubmit('Go!'));
- $this->assertText('a=[a1]');
- $this->assertText('b=[b1]');
- }
-
- function testSavantStyleFormSettingById() {
- $this->get($this->samples() . 'savant_style_form.html');
- $this->assertFieldById(1, array('a0'));
- $this->assertFieldById(4, array('b0'));
- $this->assertTrue($this->setFieldById(2, 'a1'));
- $this->assertTrue($this->setFieldById(5, 'b1'));
- $this->assertTrue($this->clickSubmitById(99));
- $this->assertText('a=[a1]');
- $this->assertText('b=[b1]');
- }
- }
-
- class TestOfFileUploads extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testSingleFileUpload() {
- $this->get($this->samples() . 'upload_form.html');
- $this->assertTrue($this->setField('Content:',
- dirname(__FILE__) . '/support/upload_sample.txt'));
- $this->assertField('Content:', dirname(__FILE__) . '/support/upload_sample.txt');
- $this->click('Go!');
- $this->assertText('Sample for testing file upload');
- }
-
- function testMultipleFileUpload() {
- $this->get($this->samples() . 'upload_form.html');
- $this->assertTrue($this->setField('Content:',
- dirname(__FILE__) . '/support/upload_sample.txt'));
- $this->assertTrue($this->setField('Supplemental:',
- dirname(__FILE__) . '/support/supplementary_upload_sample.txt'));
- $this->assertField('Supplemental:',
- dirname(__FILE__) . '/support/supplementary_upload_sample.txt');
- $this->click('Go!');
- $this->assertText('Sample for testing file upload');
- $this->assertText('Some more text content');
- }
-
- function testBinaryFileUpload() {
- $this->get($this->samples() . 'upload_form.html');
- $this->assertTrue($this->setField('Content:',
- dirname(__FILE__) . '/support/latin1_sample'));
- $this->click('Go!');
- $this->assertText(
- implode('', file(dirname(__FILE__) . '/support/latin1_sample')));
- }
- }
-
- class TestOfLiveHistoryNavigation extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testRetry() {
- $this->get($this->samples() . 'cookie_based_counter.php');
- $this->assertPattern('/count: 1/i');
- $this->retry();
- $this->assertPattern('/count: 2/i');
- $this->retry();
- $this->assertPattern('/count: 3/i');
- }
-
- function testOfBackButton() {
- $this->get($this->samples() . '1.html');
- $this->clickLink('2');
- $this->assertTitle('2');
- $this->assertTrue($this->back());
- $this->assertTitle('1');
- $this->assertTrue($this->forward());
- $this->assertTitle('2');
- $this->assertFalse($this->forward());
- }
-
- function testGetRetryResubmitsData() {
- $this->assertTrue($this->get(
- $this->samples() . 'network_confirm.php?a=aaa'));
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/');
- $this->assertText('a=[aaa]');
- $this->retry();
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/');
- $this->assertText('a=[aaa]');
- }
-
- function testGetRetryResubmitsExtraData() {
- $this->assertTrue($this->get(
- $this->samples() . 'network_confirm.php',
- array('a' => 'aaa')));
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/');
- $this->assertText('a=[aaa]');
- $this->retry();
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/');
- $this->assertText('a=[aaa]');
- }
-
- function testPostRetryResubmitsData() {
- $this->assertTrue($this->post(
- $this->samples() . 'network_confirm.php',
- array('a' => 'aaa')));
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('a=[aaa]');
- $this->retry();
- $this->assertPattern('/Request method.*?<dd>POST<\/dd>/');
- $this->assertText('a=[aaa]');
- }
-
- function testGetRetryResubmitsRepeatedData() {
- $this->assertTrue($this->get(
- $this->samples() . 'network_confirm.php?a=1&a=2'));
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/');
- $this->assertText('a=[1, 2]');
- $this->retry();
- $this->assertPattern('/Request method.*?<dd>GET<\/dd>/');
- $this->assertText('a=[1, 2]');
- }
- }
-
- class TestOfLiveAuthentication extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testChallengeFromProtectedPage() {
- $this->get($this->samples() . 'protected/');
- $this->assertResponse(401);
- $this->assertAuthentication('Basic');
- $this->assertRealm('SimpleTest basic authentication');
- $this->assertRealm(new PatternExpectation('/simpletest/i'));
- $this->authenticate('test', 'secret');
- $this->assertResponse(200);
- $this->retry();
- $this->assertResponse(200);
- }
-
- function testTrailingSlashImpliedWithinRealm() {
- $this->get($this->samples() . 'protected/');
- $this->authenticate('test', 'secret');
- $this->assertResponse(200);
- $this->get($this->samples() . 'protected');
- $this->assertResponse(200);
- }
-
- function testTrailingSlashImpliedSettingRealm() {
- $this->get($this->samples() . 'protected');
- $this->authenticate('test', 'secret');
- $this->assertResponse(200);
- $this->get($this->samples() . 'protected/');
- $this->assertResponse(200);
- }
-
- function testEncodedAuthenticationFetchesPage() {
- $this->get('http://test:secret@www.lastcraft.com/test/protected/');
- $this->assertResponse(200);
- }
-
- function testEncodedAuthenticationFetchesPageAfterTrailingSlashRedirect() {
- $this->get('http://test:secret@www.lastcraft.com/test/protected');
- $this->assertResponse(200);
- }
-
- function testRealmExtendsToWholeDirectory() {
- $this->get($this->samples() . 'protected/1.html');
- $this->authenticate('test', 'secret');
- $this->clickLink('2');
- $this->assertResponse(200);
- $this->clickLink('3');
- $this->assertResponse(200);
- }
-
- function testRedirectKeepsAuthentication() {
- $this->get($this->samples() . 'protected/local_redirect.php');
- $this->authenticate('test', 'secret');
- $this->assertTitle('Simple test target file');
- }
-
- function testRedirectKeepsEncodedAuthentication() {
- $this->get('http://test:secret@www.lastcraft.com/test/protected/local_redirect.php');
- $this->assertResponse(200);
- $this->assertTitle('Simple test target file');
- }
-
- function testSessionRestartLosesAuthentication() {
- $this->get($this->samples() . 'protected/');
- $this->authenticate('test', 'secret');
- $this->assertResponse(200);
- $this->restart();
- $this->get($this->samples() . 'protected/');
- $this->assertResponse(401);
- }
- }
-
- class TestOfLoadingFrames extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testNoFramesContentWhenFramesDisabled() {
- $this->ignoreFrames();
- $this->get($this->samples() . 'one_page_frameset.html');
- $this->assertTitle('Frameset for testing of SimpleTest');
- $this->assertText('This content is for no frames only');
- }
-
- function testPatternMatchCanReadTheOnlyFrame() {
- $this->get($this->samples() . 'one_page_frameset.html');
- $this->assertText('A target for the SimpleTest test suite');
- $this->assertNoText('This content is for no frames only');
- }
-
- function testMessyFramesetResponsesByName() {
- $this->assertTrue($this->get(
- $this->samples() . 'messy_frameset.html'));
- $this->assertTitle('Frameset for testing of SimpleTest');
-
- $this->assertTrue($this->setFrameFocus('Front controller'));
- $this->assertResponse(200);
- $this->assertText('Simple test front controller');
-
- $this->assertTrue($this->setFrameFocus('One'));
- $this->assertResponse(200);
- $this->assertLink('2');
-
- $this->assertTrue($this->setFrameFocus('Frame links'));
- $this->assertResponse(200);
- $this->assertLink('Set one to 2');
-
- $this->assertTrue($this->setFrameFocus('Counter'));
- $this->assertResponse(200);
- $this->assertText('Count: 1');
-
- $this->assertTrue($this->setFrameFocus('Redirected'));
- $this->assertResponse(200);
- $this->assertText('r=rrr');
-
- $this->assertTrue($this->setFrameFocus('Protected'));
- $this->assertResponse(401);
-
- $this->assertTrue($this->setFrameFocus('Protected redirect'));
- $this->assertResponse(401);
-
- $this->assertTrue($this->setFrameFocusByIndex(1));
- $this->assertResponse(200);
- $this->assertText('Simple test front controller');
-
- $this->assertTrue($this->setFrameFocusByIndex(2));
- $this->assertResponse(200);
- $this->assertLink('2');
-
- $this->assertTrue($this->setFrameFocusByIndex(3));
- $this->assertResponse(200);
- $this->assertLink('Set one to 2');
-
- $this->assertTrue($this->setFrameFocusByIndex(4));
- $this->assertResponse(200);
- $this->assertText('Count: 1');
-
- $this->assertTrue($this->setFrameFocusByIndex(5));
- $this->assertResponse(200);
- $this->assertText('r=rrr');
-
- $this->assertTrue($this->setFrameFocusByIndex(6));
- $this->assertResponse(401);
-
- $this->assertTrue($this->setFrameFocusByIndex(7));
- }
-
- function testReloadingFramesetPage() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->assertText('Count: 1');
- $this->retry();
- $this->assertText('Count: 2');
- $this->retry();
- $this->assertText('Count: 3');
- }
-
- function testReloadingSingleFrameWithCookieCounter() {
- $this->get($this->samples() . 'counting_frameset.html');
- $this->setFrameFocus('a');
- $this->assertText('Count: 1');
- $this->setFrameFocus('b');
- $this->assertText('Count: 2');
-
- $this->setFrameFocus('a');
- $this->retry();
- $this->assertText('Count: 3');
- $this->retry();
- $this->assertText('Count: 4');
- $this->setFrameFocus('b');
- $this->assertText('Count: 2');
- }
-
- function testReloadingFrameWhenUnfocusedReloadsWholeFrameset() {
- $this->get($this->samples() . 'counting_frameset.html');
- $this->setFrameFocus('a');
- $this->assertText('Count: 1');
- $this->setFrameFocus('b');
- $this->assertText('Count: 2');
-
- $this->clearFrameFocus('a');
- $this->retry();
-
- $this->assertTitle('Frameset for testing of SimpleTest');
- $this->setFrameFocus('a');
- $this->assertText('Count: 3');
- $this->setFrameFocus('b');
- $this->assertText('Count: 4');
- }
-
- function testClickingNormalLinkReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickLink('2');
- $this->assertLink('3');
- $this->assertText('Simple test front controller');
- }
-
- function testJumpToNamedPageReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->assertPattern('/Simple test front controller/');
- $this->clickLink('Index');
- $this->assertResponse(200);
- $this->assertText('[action=index]');
- $this->assertText('Count: 1');
- }
-
- function testJumpToUnnamedPageReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickLink('No page');
- $this->assertResponse(200);
- $this->assertText('Simple test front controller');
- $this->assertText('[action=no_page]');
- $this->assertText('Count: 1');
- }
-
- function testJumpToUnnamedPageWithBareParameterReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickLink('Bare action');
- $this->assertResponse(200);
- $this->assertText('Simple test front controller');
- $this->assertText('[action=]');
- $this->assertText('Count: 1');
- }
-
- function testJumpToUnnamedPageWithEmptyQueryReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickLink('Empty query');
- $this->assertResponse(200);
- $this->assertPattern('/Simple test front controller/');
- $this->assertPattern('/raw get data.*?\[\].*?get data/si');
- $this->assertPattern('/Count: 1/');
- }
-
- function testJumpToUnnamedPageWithEmptyLinkReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickLink('Empty link');
- $this->assertResponse(200);
- $this->assertPattern('/Simple test front controller/');
- $this->assertPattern('/raw get data.*?\[\].*?get data/si');
- $this->assertPattern('/Count: 1/');
- }
-
- function testJumpBackADirectoryLevelReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickLink('Down one');
- $this->assertPattern('/index of .*\/test/i');
- $this->assertPattern('/Count: 1/');
- }
-
- function testSubmitToNamedPageReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->assertPattern('/Simple test front controller/');
- $this->clickSubmit('Index');
- $this->assertResponse(200);
- $this->assertText('[action=Index]');
- $this->assertText('Count: 1');
- }
-
- function testSubmitToSameDirectoryReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickSubmit('Same directory');
- $this->assertResponse(200);
- $this->assertText('[action=Same+directory]');
- $this->assertText('Count: 1');
- }
-
- function testSubmitToEmptyActionReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickSubmit('Empty action');
- $this->assertResponse(200);
- $this->assertText('[action=Empty+action]');
- $this->assertText('Count: 1');
- }
-
- function testSubmitToNoActionReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickSubmit('No action');
- $this->assertResponse(200);
- $this->assertText('[action=No+action]');
- $this->assertText('Count: 1');
- }
-
- function testSubmitBackADirectoryLevelReplacesJustThatFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickSubmit('Down one');
- $this->assertPattern('/index of .*\/test/i');
- $this->assertPattern('/Count: 1/');
- }
-
- function testTopLinkExitsFrameset() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->clickLink('Exit the frameset');
- $this->assertTitle('Simple test target file');
- }
-
- function testLinkInOnePageCanLoadAnother() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->assertNoLink('3');
- $this->clickLink('Set one to 2');
- $this->assertLink('3');
- $this->assertNoLink('2');
- $this->assertTitle('Frameset for testing of SimpleTest');
- }
-
- function testFrameWithRelativeLinksRespectsBaseTagForThatPage() {
- $this->get($this->samples() . 'base_tag/frameset.html');
- $this->click('Back to test pages');
- $this->assertTitle('Frameset for testing of SimpleTest');
- $this->assertText('A target for the SimpleTest test suite');
- }
-
- function testRelativeLinkInFrameIsNotAffectedByFramesetBaseTag() {
- $this->get($this->samples() . 'base_tag/frameset_with_base_tag.html');
- $this->assertText('This is page 1');
- $this->click('To page 2');
- $this->assertTitle('Frameset for testing of SimpleTest');
- $this->assertText('This is page 2');
- }
- }
-
- class TestOfFrameAuthentication extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testUnauthenticatedFrameSendsChallenge() {
- $this->get($this->samples() . 'protected/');
- $this->setFrameFocus('Protected');
- $this->assertAuthentication('Basic');
- $this->assertRealm('SimpleTest basic authentication');
- $this->assertResponse(401);
- }
-
- function testCanReadFrameFromAlreadyAuthenticatedRealm() {
- $this->get($this->samples() . 'protected/');
- $this->authenticate('test', 'secret');
- $this->get($this->samples() . 'messy_frameset.html');
- $this->setFrameFocus('Protected');
- $this->assertResponse(200);
- $this->assertText('A target for the SimpleTest test suite');
- }
-
- function testCanAuthenticateFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->setFrameFocus('Protected');
- $this->authenticate('test', 'secret');
- $this->assertResponse(200);
- $this->assertText('A target for the SimpleTest test suite');
- $this->clearFrameFocus();
- $this->assertText('Count: 1');
- }
-
- function testCanAuthenticateRedirectedFrame() {
- $this->get($this->samples() . 'messy_frameset.html');
- $this->setFrameFocus('Protected redirect');
- $this->assertResponse(401);
- $this->authenticate('test', 'secret');
- $this->assertResponse(200);
- $this->assertText('A target for the SimpleTest test suite');
- $this->clearFrameFocus();
- $this->assertText('Count: 1');
- }
- }
-
- class TestOfNestedFrames extends SimpleTestAcceptanceTest {
- function setUp() {
- $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
- }
-
- function testCanNavigateToSpecificContent() {
- $this->get($this->samples() . 'nested_frameset.html');
- $this->assertTitle('Nested frameset for testing of SimpleTest');
-
- $this->assertPattern('/This is frame A/');
- $this->assertPattern('/This is frame B/');
- $this->assertPattern('/Simple test front controller/');
- $this->assertLink('2');
- $this->assertLink('Set one to 2');
- $this->assertPattern('/Count: 1/');
- $this->assertPattern('/r=rrr/');
-
- $this->setFrameFocus('pair');
- $this->assertPattern('/This is frame A/');
- $this->assertPattern('/This is frame B/');
- $this->assertNoPattern('/Simple test front controller/');
- $this->assertNoLink('2');
-
- $this->setFrameFocus('aaa');
- $this->assertPattern('/This is frame A/');
- $this->assertNoPattern('/This is frame B/');
-
- $this->clearFrameFocus();
- $this->assertResponse(200);
- $this->setFrameFocus('messy');
- $this->assertResponse(200);
- $this->setFrameFocus('Front controller');
- $this->assertResponse(200);
- $this->assertPattern('/Simple test front controller/');
- $this->assertNoLink('2');
- }
-
- function testReloadingFramesetPage() {
- $this->get($this->samples() . 'nested_frameset.html');
- $this->assertPattern('/Count: 1/');
- $this->retry();
- $this->assertPattern('/Count: 2/');
- $this->retry();
- $this->assertPattern('/Count: 3/');
- }
-
- function testRetryingNestedPageOnlyRetriesThatSet() {
- $this->get($this->samples() . 'nested_frameset.html');
- $this->assertPattern('/Count: 1/');
- $this->setFrameFocus('messy');
- $this->retry();
- $this->assertPattern('/Count: 2/');
- $this->setFrameFocus('Counter');
- $this->retry();
- $this->assertPattern('/Count: 3/');
-
- $this->clearFrameFocus();
- $this->setFrameFocus('messy');
- $this->setFrameFocus('Front controller');
- $this->retry();
-
- $this->clearFrameFocus();
- $this->assertPattern('/Count: 3/');
- }
-
- function testAuthenticatingNestedPage() {
- $this->get($this->samples() . 'nested_frameset.html');
- $this->setFrameFocus('messy');
- $this->setFrameFocus('Protected');
- $this->assertAuthentication('Basic');
- $this->assertRealm('SimpleTest basic authentication');
- $this->assertResponse(401);
-
- $this->authenticate('test', 'secret');
- $this->assertResponse(200);
- $this->assertPattern('/A target for the SimpleTest test suite/');
- }
- }
- ?>
|