コード例 #1
0
 public function testToArray()
 {
     $object = $this->getMockForAbstractClass('\\Foundation\\Form\\Element\\ListElement', array($this->field));
     for ($i = 0; $i < 3; $i++) {
         $item = new \Foundation\Form\Element\ListItem();
         $item->setValue($i . 'value');
         $item->setLabel($i . 'label');
         $object->addItem($item);
     }
     $values = array('name' => 'test' . uniqid(), 'class' => 'test' . uniqid(), 'value' => 'test' . uniqid(), 'instructions' => 'test' . uniqid(), 'format' => 'test' . uniqid(), 'label' => 'test' . uniqid());
     $object->setName($values['name']);
     $object->setValue($values['value']);
     $object->setClass($values['class']);
     $object->setInstructions($values['instructions']);
     $object->setFormat($values['format']);
     $object->setLabel($values['label']);
     $arr = $object->toArray();
     $this->assertArrayHasKey('items', $arr);
     for ($i = 0; $i < 3; $i++) {
         $this->assertArrayHasKey($i, $arr['items']);
         $this->assertSame($i . 'label', $arr['items'][$i]['label']);
         $this->assertSame($i . 'value', $arr['items'][$i]['value']);
     }
     unset($arr['items']);
     foreach ($arr as $key => $value) {
         $this->assertArrayHasKey($key, $values);
         $this->assertSame($values[$key], $value);
     }
 }
コード例 #2
0
 public function testSetProperties()
 {
     $object = new \Foundation\Form\Element\ListItem($this->field);
     $value = uniqid();
     $attributes = array('class', 'dir', 'id', 'lang', 'style', 'title', 'xmlLang', 'disabled', 'value');
     foreach ($attributes as $memberName) {
         $set = 'set' . ucfirst($memberName);
         $object->{$set}($value);
     }
     foreach ($attributes as $memberName) {
         $get = 'get' . ucfirst($memberName);
         $this->assertEquals($value, $object->{$get}(), "Wrong value for {$memberName}");
     }
     $object->setLabel($value);
     $this->assertEquals($value, $object->getLabel());
     $this->assertEmpty($object->getMetadataString());
     $object->addMetadata($value);
     $this->assertContains($value, $object->getMetadataString());
 }