예제 #1
0
 /**
  * Tests transformation of a complex multi-select box.
  */
 public function testTransformation()
 {
     $select = $this->getSelectBox();
     $group = new SelectBoxGroupTag();
     $group->setAttribute('label', 'foo');
     $option1 = new SelectBoxOptionTag();
     $option1->setAttribute('value', '1');
     $option1->setContent('1');
     $option1->setAttribute('selected', 'selected');
     $option2 = new SelectBoxOptionTag();
     $option2->setAttribute('value', '2');
     $option2->setContent('2');
     $option3 = new SelectBoxOptionTag();
     $option3->setAttribute('value', '3');
     $option3->setContent('3');
     $option3->setAttribute('selected', 'selected');
     $option4 = new SelectBoxOptionTag();
     $option4->setAttribute('value', '4');
     $option4->setContent('4');
     $option4->setAttribute('selected', 'selected');
     $group->addOptionTag($option1);
     $group->addOptionTag($option2);
     $group->addOptionTag($option3);
     $select->addGroupTag($group);
     $select->addOptionTag($option4);
     $actual = $select->transform();
     // general structure
     $this->assertContains('<select multiple="multiple" name="' . self::SELECT_BOX_NAME . '[]"', $actual);
     $this->assertContains('</select>', $actual);
     $this->assertContains('<optgroup label="foo">', $actual);
     $this->assertContains('</optgroup>', $actual);
     // selected items
     $this->assertContains('<option value="1" selected="selected">1</option>', $actual);
     $this->assertContains('<option value="2"', $actual);
     $this->assertContains('<option value="3" selected="selected">3</option>', $actual);
     $this->assertContains('<option value="4" selected="selected">4</option>', $actual);
 }
예제 #2
0
    /**
     * Tests selecting entries via API (e.g from within controllers).
     */
    public function testSetOption2Selected()
    {
        $tag = new SelectBoxGroupTag();
        $tag->setContent('<group:option value="1">One</group:option>
<group:option value="2">Two</group:option>
<group:option value="3">Three</group:option>');
        $tag->onParseTime();
        $tag->onAfterAppend();
        $this->assertNull($tag->getSelectedOption());
        $this->assertEmpty($tag->getSelectedOptions());
        $tag->setOption2Selected('One');
        $this->assertNotNull($tag->getSelectedOption());
        $this->assertCount(1, $tag->getSelectedOptions());
        $tag->setOption2Selected('3');
        $this->assertCount(2, $tag->getSelectedOptions());
    }
예제 #3
0
 /**
  * Returns - or lazily creates - a desired option group.
  *
  * @param string $groupLabel The name of the group.
  *
  * @return SelectBoxGroupTag The option group.
  *
  * @author Ralf Schubert
  * @version
  * Version 0.1, 07.01.2014<br />
  */
 protected function &getOrCreateGroup($groupLabel)
 {
     $group = $this->getGroup($groupLabel);
     // lazily create group for convenience reason
     if ($group === null) {
         $tag = new SelectBoxGroupTag();
         $tag->setAttribute('label', $groupLabel);
         $group = $this->addEntry($tag);
     }
     return $group;
 }