SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Location
    N. California
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Simpletest logouts/session timeouts after login

    Hello,

    New to browsers, sessions, etc... I writing tests in simpletest to test our website. For many of the tests to work, the test first has to login into the site. When the login occurs, our web software creates a name for the session with session_name and then does a session_start.

    If I get the content of the page before login, it's correct, if I login the page returned is correct. The login test is a separate method in the WebTestCase that I extend. The login method is passed a browser object ref to use to login. (e.g. $browser = & new SimpleBrowser; this->mylogin($browser)).

    So each test calls the login method. In the login method, the correct page is returned after the login.

    In the test code, after the return from the login method, any get to the site returns the page asking you to login?! What is going on here? e.g. after return from login a call like:
    $page = $browser->getContent(); Gets the wrong page?

    e.g.

    test
    login
    get a page, looks good! logged in.
    <back in test code>
    get a page: opps, wrong page, asking you to login!?
    endtest

    Thanks for any help or pointers.

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's been a while since I used Simpletest's browser so view my comment with some skepticism.

    Shouldn't you just use the SimpleBrowser to go to the URL of the login page, fill in the fields of the login form, and get the resulting page?

    As for the site returning only the login page, you should be aware that Simpletest clears any sessions you might have (I think ... memory is shaky). Therefore, it's better to test this sort of thing with the browser going to the URL.
    Zealotry is contingent upon 100 posts and addiction 200?

  3. #3
    SitePoint Member
    Join Date
    Jul 2008
    Location
    N. California
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    OK, So now I'm getting and setting the cookie, but still getting logged out even though the request header shows the cookie...

    Does anyone know what simpletest really does with sessions, I've been trying to go through the simpletest code itself, but there is a lot there... my head hurts.

    One thing I find strange is that after I set the cookie with
    $browser->setCookie, and then wait for the next set of headers, after that I print_r($_COOKIE) and it's empty? This makes no sense to me...

    Thanks for any help you can provide.

  4. #4
    SitePoint Member
    Join Date
    Jul 2008
    Location
    N. California
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by auricle View Post
    It's been a while since I used Simpletest's browser so view my comment with some skepticism.

    Shouldn't you just use the SimpleBrowser to go to the URL of the login page, fill in the fields of the login form, and get the resulting page?

    As for the site returning only the login page, you should be aware that Simpletest clears any sessions you might have (I think ... memory is shaky). Therefore, it's better to test this sort of thing with the browser going to the URL.
    That is what I am doing... using simpletest's browser, going to the url and filling the fields, the resulting page is what I expect. This issue is that the next get to that domain (slightly different url) results in a page being returned that indicates the session 'might' have timed out... funny how writing about this makes me want to ask a co-worker some important questions about what he is returning to me.

    Even so, I still would like to know more about what simpletest does with sessions and cookies.

    Thanks for your reply.

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Location
    N. California
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    The issue here turned out to be my use of the retry method. That was casing the session to get logged out. Removed the call and just visit the home page after login and all is good.

    Still wish I could understand why I don't see things in $_COOKE after setting a cookie. Anywho, onward and upward.

  6. #6
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    You can see the cookie the browser has got by using SimpleBrowser->getCookie(). The $_COOKIES variable is the the cookies set in your browser that is running the test script. Not the same browser at all. The browser used for testing is an independent entity.

    The retry() method is the equivalent of hitting the page refresh in a browser. The restart() method is equivalent of closing a browser and opening it again. That is - temporary cookies will disappear, and any HTTP authentications will be lost.

    SimpleTest does nothing with sessions, but then neither does a web browser. Sessions are stored on your web server by your web application (to a temp file by default). The browser only keeps track of the cookie holding the session key. It represents this cookie on each request so that PHP can pull out the correct session carried from the last request.

    Does this help?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  7. #7
    SitePoint Member
    Join Date
    Jul 2008
    Location
    N. California
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Marcus,

    Thanks for the reply. It helped at lot! Thanks for the great framework.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •