Exemplo n.º 1
0
 public function testOptions()
 {
     $field = new FieldDescription();
     $field->setOptions(array('template' => 'foo', 'type' => 'bar', 'misc' => 'foobar'));
     // test method shortcut
     $this->assertEquals(null, $field->getOption('template'));
     $this->assertEquals(null, $field->getOption('type'));
     $this->assertEquals('foo', $field->getTemplate());
     $this->assertEquals('bar', $field->getType());
     // test the default value option
     $this->assertEquals('default', $field->getOption('template', 'default'));
     // test the merge options
     $field->setOption('array', array('key1' => 'val1'));
     $field->mergeOption('array', array('key1' => 'key_1', 'key2' => 'key_2'));
     $this->assertEquals(array('key1' => 'key_1', 'key2' => 'key_2'), $field->getOption('array'));
     $field->mergeOption('non_existant', array('key1' => 'key_1', 'key2' => 'key_2'));
     $this->assertEquals(array('key1' => 'key_1', 'key2' => 'key_2'), $field->getOption('array'));
     $field->mergeOptions(array('array' => array('key3' => 'key_3')));
     $this->assertEquals(array('key1' => 'key_1', 'key2' => 'key_2', 'key3' => 'key_3'), $field->getOption('array'));
     $field->setOption('integer', 1);
     try {
         $field->mergeOption('integer', array());
         $this->fail('no exception raised !!');
     } catch (\RuntimeException $e) {
     }
     $field->mergeOptions(array('final' => 'test'));
     $expected = array('misc' => 'foobar', 'array' => array('key1' => 'key_1', 'key2' => 'key_2', 'key3' => 'key_3'), 'non_existant' => array('key1' => 'key_1', 'key2' => 'key_2'), 'integer' => 1, 'final' => 'test', 'placeholder' => 'short_object_description_placeholder', 'link_parameters' => array());
     $this->assertEquals($expected, $field->getOptions());
 }