PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Jun 23, 2018 9:08 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Aug 08, 2005 11:40 pm 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 16, 2002 8:57 am
Posts: 1834
Location: Watertown, MA
I think I fought through all the issues with testing my test tools; but it broke a lot of my existing tests. I thought that was because I had changed the interface slightly. However its a deeper problem and I think it should be "impossible".

Here is the tests of the Web Test Tool:
Syntax: [ Download ] [ Hide ]
class WebAuthTestCaseTest extends DatabaseUnitTestCase {



  function WebAuthTestCaseTest() {

    $this->DatabaseUnitTestCase('WebAuthTestCase Tests');

  }



  function testLoginFromLoginPage() {

    $browser = new SimpleBrowser();

    $browser->get(CIB_URL."accounts/login.php");

    $browser->setField("username","siteadmin-tester");

    $browser->setField("password","XXXX");

    $browser->clickSubmit("Login");

    $this->assertPattern("/personal/",$browser->getUrl());

  }



  function testRedirectFromLoginPage() {

    $browser = new SimpleBrowser();

    $browser->get(CIB_URL."accounts/login.php");

    $browser->setField("username","siteadmin-tester");

    $browser->setField("password","XXXX");

    $browser->setField("returnTo","results/import_cib.php");

    $browser->clickSubmit("Login");

    $this->assertPattern("/import_cib/",$browser->getUrl());

  }



 

  function testLogin() {

    $web = new WebAuthTestCase("Testing Login","siteadmin-tester","/");

    $web->setBrowser($web->createBrowser()); // simulate invoke

    $web->_runner = &$web->_createRunner(new HTMLReporter()); // simulate run

    $web->setup();

    $this->assertPattern("/personal/",$web->getUrl());

  }



  function testLoginWithRedirect() {

    $web = new WebAuthTestCase("Testing Login","siteadmin-tester",

                               "results/import_cib.php");

    $web->setBrowser($web->createBrowser()); // simulate invoke

    $web->_runner = &$web->_createRunner(new HTMLReporter()); //simulate run

    $web->setup();

    $this->assertPattern("/import_cib/",$web->getUrl());

  }



}


Here is the source for the test tool:
Syntax: [ Download ] [ Hide ]
class WebAuthTestCase extends DatabaseWebTestCase {

  var $u;

  var $p;

  var $logins;



  function WebAuthTestCase($title,$user,$page="") {

    parent::DatabaseWebTestCase($title);

    $this->u=$user;

    $this->p=$page;

    $this->logins["siteadmin-tester"]="XXXX";

  }



  /** Login and Navigate to desired page */

  function setup() {

    parent::setUp();

    $postTo=CIB_URL."accounts/SCRIPTS/login.php";

    $postParam=array("returnTo"=>$this->p,

                     "username"=>$this->u,

                     "password"=>$this->logins[$this->u]);

    $temp=$this->post($postTo, $postParam);

    if (!$temp) {echo "POST FAILED--$postTo--"; print_r($postParam);}

  }

  function tearDown() {

    parent::tearDown();

  }

}  

?>


Here's a bit of a test class that uses the test tool:
Syntax: [ Download ] [ Hide ]
class TestAdminLinks extends WebAuthTestCase {

  function TestAdminLinks() {

    $this->WebAuthTestCase('Sliding Doors Admin -- Admin Links',

                       "siteadmin-tester","register/SD/admin/index.php");

  }

  function setUp() {

    parent::setUp();

  }

 

  function testInformationExportOption() {

    $this->showSource();

    $this->assertWantedText("Information Export");

  }

}


Now for the "impossible aspect" -- All of the tests of the test tool pass. However all the tests that use it fail. In all cases the post fails in the setup so there is no page loaded. (The showSource is empty).

So I added the debug "POST FAILED" strings and captured the T/F return from post. What's really confusing me is that the last test method in the test of web tools (last method of first code block) is also triggering the POST FAILED, but still passing the test!!!?? How is that possible?

Digging deeper I also find that $browser->setField() is often returning false, even though it appears to set the field...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 12:32 am 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 16, 2002 8:57 am
Posts: 1834
Location: Watertown, MA
Looking into why the $browser->setField call is returning false... It appears that hidden form elements aren't properly initialized? I'm going to try to write an isolated test case, to double check....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 12:47 am 
Offline
DevNet Resident
User avatar

Joined: Fri Aug 16, 2002 8:57 am
Posts: 1834
Location: Watertown, MA
Bingo. Hidden elements don't seem to be treated correctly:

Syntax: [ Download ] [ Hide ]
class HiddenInputTest extends WebTestCase {

  function HiddenInputTest() {

    $this->WebTestCase("Test Hidden Elements");

  }

  function testHidden() {

    $this->assertTrue($this->get(CIB_URL.'tempTestForm.html'));

    $this->assertTrue($this->setField('bar','qux'));

  }

}

Contents of tempTestForm.html
Syntax: [ Download ] [ Hide ]
<html>

<head>

<title>Foo</title>

</head>

<body>

<form action="nosuchpage.php" method="post">

<input type="hidden" name="bar" value="baz" />

<input type="submit" />

</form>

</body>

</html>


The test fails. Emailing the SimpleTest list now....


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group