Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-02-02 13:13:04

udo
Administrator
From: Switzerland
Registered: 2009-08-06
Posts: 62

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:
[code=php]
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);
}[/code]
Any suggestions?

Thanks, Udo

Offline

#2 2010-02-03 04:13:17

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

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

Udo, does this work?

Offline

#3 2010-02-03 10:40:21

udo
Administrator
From: Switzerland
Registered: 2009-08-06
Posts: 62

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:
[code=php]
<?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);
    }
}[/code]

Update:
Maybe you are referring to this line:
[code=php]$this->assertQueryContentContains('a[href="/index/demo"]', 'Demo');[/code]
I think the page has to be valid(!) XHTML to work properly.

Offline

Board footer

Powered by FluxBB