SitePoint Sponsor

User Tag List

Page 3 of 4 FirstFirst 1234 LastLast
Results 51 to 75 of 80
  1. #51
    SitePoint Zealot
    Join Date
    Sep 2004
    Location
    Boston
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For a long time I didn't quite "get it" with testing. I realized the importance and the basics but I didn't see how it worked in a real world application. Here's an article that helped open my eyes.

    http://www.php-mag.net/itr/online_ar...odeid,114.html

    Coding a Login Box Shouldn't Hurt (International PHP Magazine)
    by Marcus Baker

    A login box is a couple of text fields and a button. A ten-minute job, right? Well, coding the first version probably is, but does it work? Easy - fire up the browser, enter a username and password and click Submit - Success!! Really? Did it set the cookie or was it set from my last test? OK, try again. Clear my cookies, log in again, and ... it fails! Oh! I'm already logged in - OK, clear the cookies, clear the database session, log in, and check the cookies. I had better test a wrong password as well - clear the cookies, clear the database session, log in, check the cookies...There has to be a better way!
    Your mileage may vary,
    --Mark

  2. #52
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try telling that to Amazon, TicketMaster, etc. :-)
    I would. I suppose I'm veering into the OOP v procedural debate here but the point I wanted to make was that testing is a more powerful tool in OOP. If someone held a gun to my head and forced me to work with procedural code sure I'd still want to test it as best I can.

  3. #53
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wei
    Is it possible or how to do a unit testing that combines javascript and php? Say with XMLHTTPRequest? There is a javascript unit tester, but how can that be synced with say SimpleTest?

    Wei.
    There is another tool I am investigating called Selinium (developed at ThoughtWorks, home of Martin Fowler). This web tested is essentially a javascript library where you can write up simple javascript commands to drive the page in an iframe.

    What makes a little bit of a stumbling block is you have to host the selenium code in the same web space as the tested code, otherwise browsers XSS protections will kick in and not allow js to run.

    Here is a demo

    HTH
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  4. #54
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually this looks quite intersting, since you get a lot more information a lot faster.

  5. #55
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Documentation is sorely lacking with selenium, in the process of trying to figure it out (never figured it out), i found this other web tester

    http://wtr.rubyforge.org/

    Watir can drive a web browser the way an end user would. It can click on links, fill in forms, press buttons etc. Watir also lets you check results. For example, you can check whether certain text appears on the page, so you can take the appropriate action.

    Currently only Internet Explorer is supported, but work is underway to support other browsers.
    At least there are some documentation with this application.

    Tried it for a couple of hours, seems to work, need to try a page with javascripts calling xmlhttp.

    Wei.

  6. #56
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No matter how busy you are drop everything and get stuck in. It will save you time in the long run.
    Having too much to do was an excuse I used too, though before I start my next project I will be putting more time into learning to use Lastcraft's Simple Test.

    For example, I spend an hour looking over this PDF on mocks, and then reading the on line documentation later I've learnt the basics of Mocks

    Wasn't too difficult, and the 2 odd hours I spent was well worth it, as McGruff has pointed out. Unit Testing rocks basically, now it's time to put it into practice

  7. #57
    SitePoint Zealot swiftone's Avatar
    Join Date
    Mar 2005
    Location
    Sunny Florida
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to all in this thread. Some very good tips.
    Happy Coding,
    Swiftone

    Unique Web Sites

  8. #58
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, once used SimpleTest, but the effort involved for me at that time was quite too much, since I was not used to OOP and always had a complete imperative approach. Thus, my test code was sometimes as long as the normal application code.
    No, no, that is the beauty of it. The testing has nothing to do with OOP or procedural. By beginning with the testing of all the cases you come up with you almost automatically figure out if the code for this specifc part of your application should be OOP or not.

    The "fail fast" method is the base of the "test" method. You write the test which will fail first. Then add code to make it not fail. Move on to step 2. Rinse and repeat. After you've done all this, either as pure test code only, procedural or OOP, you can take a step back, look at you test as say; "what does this look/smell like? a class? a standalone script? a function? a function library?".

    Whatever "it" "is" you can now program it virtually by copy and paste. And the last tests on that copy and paste are true because the individual steps on that step were true.

    If I sound like an addict, a believer, I'm sorry... I just got introduced to SimpleTest a couple of hours ago. And simply by starting my next program by going through this article I cut out what I know are hours of my design AND debugging time.

    If you has asked me a couple of hours ago the one thing a newcomer to PHP should learn/read about is OOP. Then design patterns. Now I say: test driven development. If the person has a mind, all good things will come from there.

  9. #59
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello im tryin to use the simpletest, im using this to try and login:
    PHP Code:
    <?php
    require_once('simpletest/web_tester.php');
    require_once(
    'simpletest/reporter.php');
    class 
    TestOfLogIn extends WebTestCase {
        function 
    testValidLogin() {
            
    $this->get('http://localhost/login.php');
            
    $this->setField('user''user');
            
    $this->setField('pass','password');
            
    $this->clickSubmit('submit');
            
    $this->assertWantedText('valid');
        }
        function 
    testInvalidLogin() {
            
    $this->get('http://localhost/login.php');
            
    $this->setField('user''blah');
            
    $this->setField('pass''blah');
            
    $this->clickSubmit('submit');
            
    $this->assertWantedText('invalid');
        }
    }
        
    $test = &new TestOfLogIn();
        
    $test->run(new HtmlReporter());
    ?>
    but its giving me two errors (this is one of them, both the same type of error)
    Code:
     Fail: testValidLogin -> Text [valid] not detected in [String: contact settings help Search: Login Welcome to the Log...] at line [12]
    i tried changing the php script to output valid if successful, and invalid if unsuccessful, but they dont seem to be workin, advice is appreciated.

  10. #60
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by random
    i tried changing the php script to output valid if successful, and invalid if unsuccessful, but they dont seem to be workin, advice is appreciated.
    Does it work when you browse to it normally? i.e. if you do the steps you requested in the script, do you see "valid" and "invalid" in the pages returned by the submitted forms?
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  11. #61
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Methods like showSource() - and showHeaders - can also be useful to debug a test.

    By chance, I've been using the WebTester tonight for the first time in anger to help test a chairty website. Deja vu time: reminds me of the pure delight I felt on my first experiments with the unit tester.

    Thanks again Marcus, Jason and the rest of the team.

  12. #62
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    Does it work when you browse to it normally? i.e. if you do the steps you requested in the script, do you see "valid" and "invalid" in the pages returned by the submitted forms?
    yeap a blank page with only one of those words appearing, i dont have a login class or anything, but that shouldnt matter id of thought.

    edit: does it work with php5 ok? cause thats what im using.

  13. #63
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    naperville
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've had odd issues with PHP5 and ST before. Try it in 4.

  14. #64
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by random
    edit: does it work with php5 ok? cause thats what im using.
    I use SimpleTest WebTestCases with PHP5 every day, no problems. I would tend to agree with McGruff and do a little ShowSource and ShowHeaders. Could it have something to do with localhost and cookies? Sometimes I have problems (with browsers, not with SimpleTest) if I do not have two periods in the domain name with PHP cookies.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  15. #65
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Super Phil
    I've had odd issues with PHP5 and ST before. Try it in 4.
    then it wouldnt run the code i have done for php5

    Quote Originally Posted by sweatje
    I use SimpleTest WebTestCases with PHP5 every day, no problems. I would tend to agree with McGruff and do a little ShowSource and ShowHeaders. Could it have something to do with localhost and cookies? Sometimes I have problems (with browsers, not with SimpleTest) if I do not have two periods in the domain name with PHP cookies.
    im only using sessions, not sure what ya mean by the localhost tho.
    just tried it in IE and same thing (using FF now).

    here is the showheaders:
    Code:
     
    HTTP/1.1 200 OK
    Date: Mon, 18 Apr 2005 00:22:11 GMT
    Server: Apache/2.0.52 (Win32) PHP/5.0.3
    X-Powered-By: PHP/5.0.3
    Set-Cookie: PHPSESSID=etmtgglohlqio98bh226uncf06; path=/
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    Content-Length: 7853
    Connection: close
    Content-Type: text/html; charset=ISO-8859-1
    Not sure what im looking for though.

  16. #66
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by random
    then it wouldnt run the code i have done for php5
    Of course the WebTestCase is completely independant of your php5 code (essentially BlackBox testing), so you could run it from a php4 install on another box with no problems...

    Not that it should be nescesary, see my comments above regarding php5 and WebTestCase.

    What version of SimpleTest are you using?

  17. #67
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    Of course the WebTestCase is completely independant of your php5 code (essentially BlackBox testing), so you could run it from a php4 install on another box with no problems...

    Not that it should be nescesary, see my comments above regarding php5 and WebTestCase.

    What version of SimpleTest are you using?
    I downloaded the latest one at sourceforge, 1.0 (i replied to your above post by edit). ^^

    also here is the showsource (theres a lot to the login, here is the main part):
    Code:
    <form action="/login.php" method="post" name="login">
    <tr>
    <td style="vertical-align: middle" align="left">Username:</td>
    <td align="right"><input type="text" name="user" size="18" class="textbox"></td>
    </tr>
    <tr>
    <td style="vertical-align: middle" align="left">Password:</td>
    <td align="right"><input type="password" name="pass" size="18" class="textbox"></td>
    </tr>
    </table>
    <table border="0" cellspacing="1" cellpadding="0" width="188">
    <tr>
    <td align="left"><a href="/forgot.php">Forgot Password?</a></td>
    <td align="right"><input type="submit" value="Login" class="cmdbtn" name="submit"></td>
    </tr>
    </form>

  18. #68
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    naperville
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My problems involved cookies and headers. In PHP4, script + tests wroked fine. In PHP5, cookies worked in script, but when the test was introduced they failed. When they were set in a test (as a test), they failed (headers already sent). Didn't actually investigate all that much, so I could be spreading misinformation.

  19. #69
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The localhost I was refering to was in your test case where you do:
    PHP Code:
    $this->get('http://localhost/login.php'); 
    might be better as something like
    PHP Code:
    $this->get('http://development.web.example.com/login.php'); 
    I think I would capture the value of the cookie PHPSESSID before and after the submit and assert they are equal. Seems like perhaps somehow the session is being dropped and you are getting a fresh login page instead of your result?

  20. #70
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    I think I would capture the value of the cookie PHPSESSID before and after the submit and assert they are equal. Seems like perhaps somehow the session is being dropped and you are getting a fresh login page instead of your result?
    looks like the same session, that would mean the same page surely?
    n946e78f4fgbc8d23352sbd46 (before)
    n946e78f4fgbc8d23352sbd46 (after)

    cause i was just worried it might have seen it as a different page when recalling error msgs

    edit:
    if i put in the two values (invalid and valid) before the submit, simpletest passes them, otherwise when i have them in after submit and all the checks i receive fails.

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

    clickSubmit() works off of the visible button label...
    PHP Code:
    $this->clickSubmit('Login'); 
    ...should dispatch the form. Is this the problem? A useful debugging measure is the showRequest() method which dumps the outgoing HTTP request.

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

  22. #72
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    Hi.

    clickSubmit() works off of the visible button label...
    PHP Code:
    $this->clickSubmit('Login'); 
    ...should dispatch the form. Is this the problem? A useful debugging measure is the showRequest() method which dumps the outgoing HTTP request.

    yours, Marcus
    that was the problem hehe, ooooh yeaaa green is my favourite colour!

    thnx for the help guys, appreciate it

  23. #73
    SitePoint Addict
    Join Date
    Oct 2001
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do i check the valid uploaded file, I'm not sure if this is it or not?

    PHP Code:
    $this->setField('upload''C:\admin.pdf'); 
    Last edited by random; Apr 18, 2005 at 18:39.

  24. #74
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Norway - Oslo
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use SimpleTest aswell now.
    Just used it for some weeks, but i have no problems with it, altho im just using it at a basic level.

    I cant see how you can write test cases ten times as fast. You could just wrap up those testcases to fit simpletest. For small classes the tests become about the same size since there are no complex behaviour in the class i test. But the tests tend to be of quite equal length if i should add complexity to the original class.
    And after all thats how you should write the code and tests, adding more and more for each iteration, and thats how i end up doing it.

    I agree that writing tests before code is hard, in most cases i know so well what i want to do so when i set up the class-skeleton i just finish almost the entire case, then i write the tests.

  25. #75
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Findus
    But the tests tend to be of quite equal length if i should add complexity to the original class.
    I agree, but tend to find I write more code in tests than any other part of the system. Here is a count of lines of code in a recent project of mine as a typical example:

    Code:
    SLOC    Directory       SLOC-by-Language (Sorted)
    2550    tests           php=2542,sh=8
    2315    sql             sql=2315
    1404    models          php=1404
    299     views           php=299
    251     actions         php=251
    225     top_dir         php=225
    So of ~4700 lines of PHP, more than 2500 are in the tests directory, over half of the entire project.


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
  •