Reputation: 4668
I need to add a value to $_POST, specifically 'port' so I can tell my test submission to go through fakemail.
The fakemail documentation shows how to insert a value to $_POST with SimpleTest:
$this->clickSubmit('Send', array('port' => 10025));
In PHPUnit, this doesn't work:
$this->click("//input[@value='Send']", array('port' => 10025));
I'm very unfamiliar with all the concepts behind testing, so this may be simpler than I'm making it. How would you get the job done using PHPUnit/Selenium?
Upvotes: 1
Views: 1090
Reputation: 1464
Haven't tested this in phpunit, but in Selenium IDE you are able to change hidden fields using javascript.
Test page:
<html><head></head><body>
<?php print_r($_POST); ?>
<br/><br/>
<form action="test.php" method="POST">
<input type="hidden" id="hhh" name="hhh" value="orig"/>
<input type="text" name="ttt"/>
<input type="submit" name="sss"/>
</form>
</body></html>
Script (generated from firefox IDE, so haven't tested it):
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser("*chrome");
$this->setBrowserUrl("http://localhost/test.php");
}
public function testMyTestCase()
{
$this->type("ttt", "bbb");
$this->runScript("javascript{ this.browserbot.getCurrentWindow().document.getElementById('hhh').value = 'new2'; }");
$this->click("sss");
}
}
?>
So just add the port
variable as a hidden field and set the value with javascript.
Upvotes: 1