예제 #1
0
    /**
     * Tests resetting a select box including option groups.
     */
    public function testReset()
    {
        $tag = new SelectBoxTag();
        $tag->setContent('<select:option value="1" selected="selected">One</select:option>
<select:group label="foo">
   <group:option value="2" selected="selected">Two</group:option>
   <group:option value="3" selected="selected">Three</group:option>
</select:group>
<select:option value="4" selected="selected">Four</select:option>');
        $tag->onParseTime();
        $tag->onAfterAppend();
        // test whether all items are selected
        foreach ($tag->getChildren() as &$child) {
            if ($child instanceof SelectBoxGroupTag) {
                foreach ($child->getChildren() as &$optionChild) {
                    $this->assertEquals('selected', $optionChild->getAttribute('selected'));
                }
            } else {
                $this->assertEquals('selected', $child->getAttribute('selected'));
            }
        }
        $tag->reset();
        // test whether all items are un-selected
        foreach ($tag->getChildren() as &$child) {
            if ($child instanceof SelectBoxGroupTag) {
                foreach ($child->getChildren() as &$optionChild) {
                    $this->assertNull($optionChild->getAttribute('selected'));
                }
            } else {
                $this->assertNull($child->getAttribute('selected'));
            }
        }
    }