SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    London
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SimpleTest howto test for a pattern within a Link

    Hi,

    Currently using SimpleTest simpletest_1.0.1beta

    How can i assert for a pattern within a link, example below.
    PHP Code:
    <class="action" href="/index.php/AdStyles/create" title="Create a new ad style">
    <
    img width="16" height="16" src="/images/newArticle_ico16.png" alt="New Ad Style"/>
    New 
    Ad Style
    </a
    Basically i want to assert that the links exists and can be clicked eg
    But there is an image within the link, and the link has no id.

    This assertion does not work.
    PHP Code:
     $this->assertLink('<img alt="New Ad Style" src="/images/newArticle_ico16.png" height="16" width="16" />New Ad Style'); 
    PHP Code:
    var_dump($this->_browser->_page->_links);


      
    object(SimpleAnchorTag)#696 (3) {
        
    ["_name"]=>
        
    string(1"a"
        
    ["_attributes"]=>
        array(
    3) {
          [
    "title"]=>
          
    string(21"Create a new ad style"
          
    ["class"]=>
          
    string(6"action"
          
    ["href"]=>
          
    string(26"/index.php/AdStyles/create"
        
    }
        [
    "_content"]=>
        
    string(96"<img alt="New Ad Style" src="/images/newArticle_ico16.png" height="16" width="16" />New Ad Style"
      


    Is this link untestable ?

    .
    Last edited by davro; Jun 1, 2007 at 15:03.
    David Stevens, create-inspire
    PHP London, www.phplondon.org

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe try assertWantedPattern

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    London
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi skinny monkey,
    assertWantedPattern works fine, personally i prefer using assertPattern as the assertWantedPattern is marked as @deprecated but hey ho.

    The problem really is that i cannot find anyway to click the link with the SimpleTest web tester, i know its quite a messy link with an image inside and no id, but it is a valid link that could be clicked by a user in there browser ?
    David Stevens, create-inspire
    PHP London, www.phplondon.org

  4. #4
    SitePoint Guru dagfinn's Avatar
    Join Date
    Jan 2004
    Location
    Oslo, Norway
    Posts
    894
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by davro View Post
    Hi skinny monkey,
    assertWantedPattern works fine, personally i prefer using assertPattern as the assertWantedPattern is marked as @deprecated but hey ho.

    The problem really is that i cannot find anyway to click the link with the SimpleTest web tester, i know its quite a messy link with an image inside and no id, but it is a valid link that could be clicked by a user in there browser ?
    The best way is to get an ID added to the link. Presumably, you're not in control of the web page, but if whoever is can be made to understand the demands of testing, that would be the best.

    The second best way is to get the entire HTML text of the web page ($this->getBrowser->getContent(), I think), extract the URL using regular expressions and do $this->get($url);
    Dagfinn Reiersøl
    PHP in Action / Blog / Twitter
    "Making the impossible possible, the possible easy,
    and the easy elegant"
    -- Moshe Feldenkrais

  5. #5
    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 dagfinn View Post
    The second best way is to get the entire HTML text of the web page ($this->getBrowser->getContent(), I think), extract the URL using regular expressions and do $this->get($url);
    why not just
    PHP Code:
     $this->click('New Ad Style'); 
    ?
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    London
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, sweatje

    I have tryed this but it fails with my test case
    PHP Code:
    $this->assertLink('New Ad Style'); 
    HTML Code:
    1) Link [New Ad Style] should exist at [/sites/personaldev/dstevens/cms/test/functional/cms/TestOfAdStyles.php line 33]
    I had a little chat to Marcus about it last night at http://www.phplondon.org/, so i added a test case with the img alt text as well and it passes.
    PHP Code:
    $this->assertLink('New Ad Style New Ad Style'); 
    David Stevens, create-inspire
    PHP London, www.phplondon.org


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
  •