Welcome! Log In Create A New Profile

Advanced

[PHP] Problem with AssertTag: children count wrong

Posted by Michael Otteneder 
Michael Otteneder
[PHP] Problem with AssertTag: children count wrong
May 02, 2012 08:00PM
Hi List!

I'm trying to use phpUnit's AssertTag function to make sure that some html
code contains an ul element with exactly li items in it.

My test looks like this:


function testUnconfiguredFilter() {
$matcher = array(
'tag' => 'ul',
'children' => array(
'count' => 3,
'only' => array('tag' => 'li')
)
);
$this->assertTag($matcher, $this->html, $message, $isHtml = FALSE);
}

the value of $html is:

<div class="flFilterbox" id="flFilterunconfiguredFilter">
<h3>unconfiguredFilter</h3>

<ul class="flFilterboxInner">
<li><a href=""> FilterValue1</a> ()</li>
<li><a href=""> FilterValue2</a> ()</li>
<li><a href=""> FilterValue3</a> ()</li>
</ul>
</div>

So I think the assertion SHOULD work - but it does not, no matter what I
use for count! Sadly PHPUnit's output ist not very helpful, all it gives me
is:

1) GeneratedFiltersTest::testUnconfiguredFilter
Failed asserting that false is true.


Has someone got an idea whats going on? This is really freakin me out,
could not find anything about it anywhere on the web.

Kind regards,
Michael
On 05/02/2012 10:55 AM, Michael Otteneder wrote:
> Hi List!
>
> I'm trying to use phpUnit's AssertTag function to make sure that some html
> code contains an ul element with exactly li items in it.
>
> My test looks like this:
>
>
> function testUnconfiguredFilter() {
> $matcher = array(
> 'tag' => 'ul',
> 'children' => array(
> 'count' => 3,
> 'only' => array('tag' => 'li')
> )
> );
> $this->assertTag($matcher, $this->html, $message, $isHtml = FALSE);
> }
>
> the value of $html is:
>
> <div class="flFilterbox" id="flFilterunconfiguredFilter">
> <h3>unconfiguredFilter</h3>
>
> <ul class="flFilterboxInner">
> <li><a href=""> FilterValue1</a> ()</li>
> <li><a href=""> FilterValue2</a> ()</li>
> <li><a href=""> FilterValue3</a> ()</li>
> </ul>
> </div>
>
> So I think the assertion SHOULD work - but it does not, no matter what I
> use for count! Sadly PHPUnit's output ist not very helpful, all it gives me
> is:
>
> 1) GeneratedFiltersTest::testUnconfiguredFilter
> Failed asserting that false is true.

When dealing with classes, and specifically calling a static method
within a class, the variable $this does not exist. You must use 'self'
instead.

You would need to do this instead if you wanted to use the $this way of
things

$test = new GeneratedFiltersTest;
$test->testUnconfiguredFilter();

Plus, I am going to assume (since I don't see your code), that the
method "assertTag()" is in a parent class that is inherited by the class
GeneratedFiltersTest and again, since you are calling it via a static
method, the inheritance would not have taken place.

>
>
> Has someone got an idea whats going on? This is really freakin me out,
> could not find anything about it anywhere on the web.
>
> Kind regards,
> Michael
>


--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Michael Otteneder
Re: [PHP] Problem with AssertTag: children count wrong
May 02, 2012 10:30PM
Hi, sorry, I forgot to include the class definition:

class GeneratedFiltersTest extends PHPUnit_Framework_Testcase {

function testUnconfiguredFilter() {
$matcher = array(
'tag' => 'ul',
'children' => array(
'count' => 3,
'only' => array('tag' => 'li')
)
);
$this->assertTag($matcher, $this->html, $message, $isHtml = FALSE);
}
}

I dont think that the problem is that $this does not exist. Other examples
of assertTag() and other assert* functions work perfectly well.
The only problem I have is when I use the 'children' option with assertTag,
because the count never hast the value it should have.

kind regards,
Michael
On Wed, May 2, 2012 at 9:22 PM, Jim Lucas <[email protected]> wrote:

> On 05/02/2012 10:55 AM, Michael Otteneder wrote:
>
>> Hi List!
>>
>> I'm trying to use phpUnit's AssertTag function to make sure that some html
>> code contains an ul element with exactly li items in it.
>>
>> My test looks like this:
>>
>>
>> function testUnconfiguredFilter() {
>> $matcher = array(
>> 'tag' => 'ul',
>> 'children' => array(
>> 'count' => 3,
>> 'only' => array('tag' => 'li')
>> )
>> );
>> $this->assertTag($matcher, $this->html, $message, $isHtml = FALSE);
>> }
>>
>> the value of $html is:
>>
>> <div class="flFilterbox" id="**flFilterunconfiguredFilter">
>> <h3>unconfiguredFilter</h3>
>>
>> <ul class="flFilterboxInner">
>> <li><a href=""> FilterValue1</a> ()</li>
>> <li><a href=""> FilterValue2</a> ()</li>
>> <li><a href=""> FilterValue3</a> ()</li>
>> </ul>
>> </div>
>>
>> So I think the assertion SHOULD work - but it does not, no matter what I
>> use for count! Sadly PHPUnit's output ist not very helpful, all it gives
>> me
>> is:
>>
>> 1) GeneratedFiltersTest::**testUnconfiguredFilter
>> Failed asserting that false is true.
>>
>
> When dealing with classes, and specifically calling a static method within
> a class, the variable $this does not exist. You must use 'self' instead.
>
> You would need to do this instead if you wanted to use the $this way of
> things
>
> $test = new GeneratedFiltersTest;
> $test->testUnconfiguredFilter(**);
>
> Plus, I am going to assume (since I don't see your code), that the method
> "assertTag()" is in a parent class that is inherited by the class
> GeneratedFiltersTest and again, since you are calling it via a static
> method, the inheritance would not have taken place.
>
>
>
>>
>> Has someone got an idea whats going on? This is really freakin me out,
>> could not find anything about it anywhere on the web.
>>
>> Kind regards,
>> Michael
>>
>>
>
> --
> Jim Lucas
>
> http://www.cmsws.com/
> http://www.cmsws.com/examples/
> http://www.bendsource.com/
>
Sorry, only registered users may post in this forum.

Click here to login