Page 1 of 1
How to handle session between two windows in
Posted: Wed Sep 01, 2010 5:29 am
by indiavitus
I am using phpunit to test my php application.
In my application, one main window opens a new window for search, and after search when I click on any record, Record details appears in the main window.
How can i handle this scenario in phpunit.
Thanks,
Manoj
Re: How to handle session between two windows in
Posted: Fri Sep 03, 2010 6:11 am
by josh
Code: Select all
function testOne()
{
$_SESSION['foo'] = 'bar';
$this->assertEquals( 'bar', $_SESSION['foo'] );
}
There is an option to destroy the super globals on each test run, make sure you use it or reset the super globals manually in your setUp() tearDown() methods, as you don't want state crossing from one test to the next, creates "erratic test runs" which will lead you down a painful path of "high test test maintenance".
So basically just set the session as if the user had had it set. Then run your assertions like a regular test. And clean up the $_SESSION as part of the tearDown()
If you are lucky enough to have a nice architecture you could look into using an object wrapper, so you can insert mock objects. Here in my example I would call a "mock array", for lack of a term. Using the mock object is better, because then you are creating a software where it is easy to alter the session behavior. If you don't have to use globals in your test, you don't have to use globals in the production code - and that's an ideal goal. Although PHP does have procedural callbacks for that in place (for example if you wanted the session data to come from a database, or other custom function).
Re: How to handle session between two windows in
Posted: Fri Sep 03, 2010 6:26 am
by indiavitus
Thanks josh for your reply.
I have different problem with which i am struggling.
I have written a test case which is testing a web application. In my application, one search page get opens from a main page. upon entering some search criteria in the search page, it fetches all the related records on the search page itself.
But once I click over any record in the search page, details for that record in get displayed in the main page which invoked the search page.
In my test case, I am able to open the search page, search the data and click on any of the data. After clicking, how can i take the control of the main page.
This is where I got stuck.
Please suggest.
Thanks,
Manoj