1

Topic: PHPUnit - Select link elements and check if the pages are reachable

Hello,

How would you approach this challenge:

  • make PHPUnit select a link from a web page
    e.g.: <a title="Demo Title" href="/index/demo">Demo</a>

  • then use the result to check if the page is reachable
    e.g.: $this->dispatch("/index/demo");

At the moment I'm doing this:

PHP Code:
 
public function testPageIndexReachable()
{
    $this->dispatch("/");
    // check if link on currently loaded page exist
    $this->assertQueryContentContains('a[href="/index/demo"]', 'Demo');
    $this->assertModule("default");
    $this->assertController("index");
    $this->assertAction("index");
    $this->assertResponseCode(200);
}

Any suggestions?

Thanks, Udo

2

Re: PHPUnit - Select link elements and check if the pages are reachable

Udo, does this work?

3

Re: PHPUnit - Select link elements and check if the pages are reachable

yes, sometimes I wonder myself... wink

Or are you referring to a specific line?

Complete code looks similar to this:

PHP Code:
 
<?php
/**
 * Module Default: IndexControllerTest class
 */
class IndexControllerTest extends ControllerTestCase
{
    
    /* some other tests ... */
    
    
    public function testPageIndexReachable()
    {
        $this->dispatch("/");
        // check if link on currently loaded page exist
        $this->assertQueryContentContains('a[href="/index/demo"]', 'Demo');
        $this->assertModule("default");
        $this->assertController("index");
        $this->assertAction("index");
        $this->assertResponseCode(200);
    }
}

Update:
Maybe you are referring to this line:

PHP Code:
$this->assertQueryContentContains('a[href="/index/demo"]', 'Demo');

I think the page has to be valid(!) XHTML to work properly.