views:

207

answers:

2

I wish to test a function that will generate lorem ipsum text, but it does so within html tags. So I cant know in advance the textual content, but i know the html structure. That is what I want to test. And maybe that the length of the texts are within certain limits. So what I am wondering is if the assertTags can do this in a way paraphrased bellow:

Result = "<p>Some text</p>";
Expected = array( 
'<p' ,
'regex',
'/p'
);
assertTags(resutl, expected)

I am using SimpleTest with cakephp, but i think it should be a general question.

A: 

Extend the SimpleExpectation class and then use your new Expectation class in the assert statement

see: http://www.lastcraft.com/expectation_documentation.php#extending

the example given is for validating an IP address but should be applicable to your problem:

class ValidIp extends SimpleExpectation {

  function test($ip) {
    return (ip2long($ip) != -1);
  }

  function testMessage($ip) {
    return "Address [$ip] should be a valid IP address";
  }
}

then in your test

$this->assert(new ValidIp(),$server->getIp());
Ken
+2  A: 
$expected = array(
    '<p',
    'preg:/[A-Za-z\.\s\,]+/',
    '/p'
);
Alexander Morland
cant i accept my own answer anymore?
Alexander Morland