Zend_Test_PHPUnit_ControllerTestCase: asserting a checkbox is checked

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend_Test_PHPUnit_ControllerTestCase: asserting a checkbox is checked

David Mintz-3
I am having some trouble figuring out the magic words. My response body contains this:

<input type="checkbox" name="person[active]" id="person_active" value="1" checked="checked" />

In the controller test, I when I say

     $this->assertQuery('#person_active');

the assertion succeeds, but

     $this->assertQuery('#person_active[checked="checked"]');

fails with 'Failed asserting node DENOTED BY #person_active[checked="checked"] EXISTS.'

After diddling around with several variations, the only thing that works for me is to assert that the containing element contains a checkbox whose "checked" attribute is "checked:"

 $this->assertQuery('#person_active-element input[checked="checked"]') ;

It might be worth noting that the jQuery snippet

         $('#person_active[checked="checked"]').length == 1

typed into the Firebug console evaluates to true. So it looks like my CSS is kosher.

Any ideas? Thanks.

--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Reply | Threaded
Open this post in threaded view
|

Re: Zend_Test_PHPUnit_ControllerTestCase: asserting a checkbox is checked

nuqqsa
I'm afraid this is a bug. CSS selectors are converted to XPath queries before the evaluation, and apparently there is something wrong with that conversion.

In this case, the expression:

    #person_active[@checked="checked"]

is transformed to the XPath query:

    //*[@id='person_active'][checked="checked"]

The problem here is that the @ before the attribute checked is missing, therefore it fails to match any element.

This workaround will get the job done (although it's not a valid selector):

    $this->assertQuery('#person_active[@checked="checked"]');

or you can use the assertXpath() method instead.

--

Núria

2010/4/27 David Mintz <[hidden email]>
I am having some trouble figuring out the magic words. My response body contains this:

<input type="checkbox" name="person[active]" id="person_active" value="1" checked="checked" />

In the controller test, I when I say

     $this->assertQuery('#person_active');

the assertion succeeds, but

     $this->assertQuery('#person_active[checked="checked"]');

fails with 'Failed asserting node DENOTED BY #person_active[checked="checked"] EXISTS.'

After diddling around with several variations, the only thing that works for me is to assert that the containing element contains a checkbox whose "checked" attribute is "checked:"

 $this->assertQuery('#person_active-element input[checked="checked"]') ;

It might be worth noting that the jQuery snippet

         $('#person_active[checked="checked"]').length == 1

typed into the Firebug console evaluates to true. So it looks like my CSS is kosher.

Any ideas? Thanks.

--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/



Reply | Threaded
Open this post in threaded view
|

Re: Zend_Test_PHPUnit_ControllerTestCase: asserting a checkbox is checked

Marian Meres-2
I confirm I had similar problems with css selectors. I didn't discover
it deeply though, but used xpath assertion instead which worked as
expected.

m.

On Tue, Apr 27, 2010 at 11:04 PM, Núria <[hidden email]> wrote:

> I'm afraid this is a bug. CSS selectors are converted to XPath queries
> before the evaluation, and apparently there is something wrong with that
> conversion.
>
> In this case, the expression:
>
>     #person_active[@checked="checked"]
>
> is transformed to the XPath query:
>
>     //*[@id='person_active'][checked="checked"]
>
> The problem here is that the @ before the attribute checked is missing,
> therefore it fails to match any element.
>
> This workaround will get the job done (although it's not a valid selector):
>
>     $this->assertQuery('#person_active[@checked="checked"]');
>
> or you can use the assertXpath() method instead.
>
> --
>
> Núria
>
> 2010/4/27 David Mintz <[hidden email]>
>>
>> I am having some trouble figuring out the magic words. My response body
>> contains this:
>>
>> <input type="checkbox" name="person[active]" id="person_active" value="1"
>> checked="checked" />
>>
>> In the controller test, I when I say
>>
>>      $this->assertQuery('#person_active');
>>
>> the assertion succeeds, but
>>
>>      $this->assertQuery('#person_active[checked="checked"]');
>>
>> fails with 'Failed asserting node DENOTED BY
>> #person_active[checked="checked"] EXISTS.'
>>
>> After diddling around with several variations, the only thing that works
>> for me is to assert that the containing element contains a checkbox whose
>> "checked" attribute is "checked:"
>>
>>  $this->assertQuery('#person_active-element input[checked="checked"]') ;
>>
>> It might be worth noting that the jQuery snippet
>>
>>          $('#person_active[checked="checked"]').length == 1
>>
>> typed into the Firebug console evaluates to true. So it looks like my CSS
>> is kosher.
>>
>> Any ideas? Thanks.
>>
>> --
>> Support real health care reform:
>> http://phimg.org/
>>
>> --
>> David Mintz
>> http://davidmintz.org/
>>
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Test_PHPUnit_ControllerTestCase: asserting a checkbox is checked

nuqqsa
Yesterday I reported the issue: http://framework.zend.com/issues/browse/ZF-9764 and Matthew resolved it at the speed of light (many thanks!), so the fix will be included in the next mini release.

--

Núria

2010/4/28 Marian Meres <[hidden email]>
I confirm I had similar problems with css selectors. I didn't discover
it deeply though, but used xpath assertion instead which worked as
expected.

m.

On Tue, Apr 27, 2010 at 11:04 PM, Núria <[hidden email]> wrote:
> I'm afraid this is a bug. CSS selectors are converted to XPath queries
> before the evaluation, and apparently there is something wrong with that
> conversion.
>
> In this case, the expression:
>
>     #person_active[@checked="checked"]
>
> is transformed to the XPath query:
>
>     //*[@id='person_active'][checked="checked"]
>
> The problem here is that the @ before the attribute checked is missing,
> therefore it fails to match any element.
>
> This workaround will get the job done (although it's not a valid selector):
>
>     $this->assertQuery('#person_active[@checked="checked"]');
>
> or you can use the assertXpath() method instead.
>
> --
>
> Núria
>
> 2010/4/27 David Mintz <[hidden email]>
>>
>> I am having some trouble figuring out the magic words. My response body
>> contains this:
>>
>> <input type="checkbox" name="person[active]" id="person_active" value="1"
>> checked="checked" />
>>
>> In the controller test, I when I say
>>
>>      $this->assertQuery('#person_active');
>>
>> the assertion succeeds, but
>>
>>      $this->assertQuery('#person_active[checked="checked"]');
>>
>> fails with 'Failed asserting node DENOTED BY
>> #person_active[checked="checked"] EXISTS.'
>>
>> After diddling around with several variations, the only thing that works
>> for me is to assert that the containing element contains a checkbox whose
>> "checked" attribute is "checked:"
>>
>>  $this->assertQuery('#person_active-element input[checked="checked"]') ;
>>
>> It might be worth noting that the jQuery snippet
>>
>>          $('#person_active[checked="checked"]').length == 1
>>
>> typed into the Firebug console evaluates to true. So it looks like my CSS
>> is kosher.
>>
>> Any ideas? Thanks.
>>
>> --
>> Support real health care reform:
>> http://phimg.org/
>>
>> --
>> David Mintz
>> http://davidmintz.org/
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Zend_Test_PHPUnit_ControllerTestCase: asserting a checkbox is checked

David Mintz-3


On Thu, Apr 29, 2010 at 3:24 AM, Núria <[hidden email]> wrote:
Yesterday I reported the issue: http://framework.zend.com/issues/browse/ZF-9764 and Matthew resolved it at the speed of light (many thanks!), so the fix will be included in the next mini release.


I guess I won't be demanding a refund just yet (-:
 
--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/