示例#1
0
文件: FormTest.php 项目: slkxmail/App
    public function testRender()
    {
        $factory = new Factory();
        $expected = <<<EOS
<form name="test" action="/action/" method="POST">
<input name="test"/>

</form>

EOS;
        $form = $factory->create(array('name' => 'test', 'type' => 'App\\Form\\Form', 'options' => array('view_path' => FIXTURES_PATH . '/Form/decorators/')));
        $form->setAction('/action/');
        $this->assertEquals(array(FIXTURES_PATH . '/Form/decorators'), $form->getViewPath());
        $element = new Element('test');
        $element->setType('input')->setDecorator('input');
        $form->add($element);
        //        $this->assertEquals($expected, $form->render('test_form'));
        // exception
        //        $form->render('unknown');
    }
示例#2
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testMessages()
 {
     $element = new Element('some_field');
     $element->setModelLink('Model\\TestModel');
     $element->setValue('Значение которое не пройдет валидацию');
     $this->assertFalse($element->isValid());
     $this->assertEquals(array(array('stringLengthTooLong' => 'The input is more than 10 characters long')), $element->getMessages());
     $element->removeModelLink()->clearMessages()->addValidator('Zend\\Validator\\StringLength', array('min' => 1, 'max' => 5))->isValid();
     $this->assertEquals(array(array('stringLengthTooLong' => 'The input is more than 5 characters long')), $element->getMessages());
     $this->assertEquals(array('stringLengthTooLong' => 'The input is more than 5 characters long'), $element->getMessages(0));
     $this->assertEquals(array(), $element->getMessages(1));
     $element->setMessages(new \stdClass());
 }
示例#3
0
文件: Fieldset.php 项目: slkxmail/App
 /**
  * @param  null|int|string  $name    Optional name for the element
  * @param array             $attributes
  * @param  array            $options Optional options for the element
  */
 public function __construct($name = null, $attributes = array(), $options = array())
 {
     $this->iterator = new PriorityQueue();
     parent::__construct($name, $attributes, $options);
 }
示例#4
0
文件: Factory.php 项目: slkxmail/App
 /**
  * Configure an element based on the provided specification
  *
  * Specification can contain any of the following:
  * - type: the Element class to use; defaults to \Zend\Form\Element
  * - name: what name to provide the element, if any
  * - options: an array, Traversable, or ArrayAccess object of element options
  * - attributes: an array, Traversable, or ArrayAccess object of element
  *   attributes to assign
  *
  * @param \App\Form\Element|\App\Form\Element $element
  * @param  array|Traversable|ArrayAccess               $spec
  * @return Element
  */
 public function configureElement(Element $element, $spec)
 {
     $spec = $this->validateSpecification($spec, __METHOD__);
     $name = isset($spec['name']) ? $spec['name'] : null;
     $options = isset($spec['options']) ? $spec['options'] : null;
     $attributes = isset($spec['attributes']) ? $spec['attributes'] : null;
     if ($name !== null && $name !== '') {
         $element->setName($name);
     }
     if (is_array($options) || $options instanceof Traversable || $options instanceof ArrayAccess) {
         $element->setOptions($options);
     }
     if (is_array($attributes) || $attributes instanceof Traversable || $attributes instanceof ArrayAccess) {
         $element->setAttributes($attributes);
     }
     return $element;
 }