Getting more and more stumped

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Getting more and more stumped

Post by nielsene »

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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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...
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

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....
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Bingo. Hidden elements don't seem to be treated correctly:

Code: Select all

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

Code: Select all

<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....
Post Reply