Exemple #1
0
    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');
    }
Exemple #2
0
 /**
  * @expectedException DomainException
  */
 public function testCreate()
 {
     $factory = new Factory();
     $element = $factory->create(array('type' => 'App\\Form\\Element', 'name' => 'test', 'options' => array('option' => 'option_value'), 'attributes' => array('attr' => 'attr_value')));
     $this->assertInstanceOf('App\\Form\\Element', $element);
     $this->assertEquals('test', $element->getName());
     $this->assertEquals('option_value', $element->getOption('option'));
     $this->assertEquals('attr_value', $element->getAttribute('attr'));
     $element = $factory->create(array('type' => 'App\\Form\\Fieldset', 'name' => 'test', 'options' => array('option' => 'option_value'), 'attributes' => array('attr' => 'attr_value')));
     $this->assertInstanceOf('App\\Form\\Fieldset', $element);
     $this->assertEquals('test', $element->getName());
     $this->assertEquals('option_value', $element->getOption('option'));
     $this->assertEquals('attr_value', $element->getAttribute('attr'));
     $element = $factory->createFieldset(array('name' => 'test', 'options' => array('option' => 'option_value'), 'attributes' => array('attr' => 'attr_value')));
     $this->assertInstanceOf('App\\Form\\Fieldset', $element);
     $this->assertEquals('test', $element->getName());
     $this->assertEquals('option_value', $element->getOption('option'));
     $this->assertEquals('attr_value', $element->getAttribute('attr'));
     $element = $factory->createElement(array('name' => 'test', 'options' => array('option' => 'option_value'), 'attributes' => array('attr' => 'attr_value')));
     $this->assertInstanceOf('App\\Form\\Element', $element);
     $this->assertEquals('test', $element->getName());
     $this->assertEquals('option_value', $element->getOption('option'));
     $this->assertEquals('attr_value', $element->getAttribute('attr'));
     $element = $factory->createForm(array('name' => 'test', 'options' => array('option' => 'option_value'), 'attributes' => array('attr' => 'attr_value')));
     $this->assertInstanceOf('App\\Form\\Form', $element);
     $this->assertEquals('test', $element->getName());
     $this->assertEquals('option_value', $element->getOption('option'));
     $this->assertEquals('attr_value', $element->getAttribute('attr'));
     $element = $factory->create(array('type' => 'App\\Form\\Form', 'name' => 'test', 'options' => array('option' => 'option_value'), 'attributes' => array('attr' => 'attr_value')));
     $this->assertInstanceOf('App\\Form\\Form', $element);
     $this->assertEquals('test', $element->getName());
     $this->assertEquals('option_value', $element->getOption('option'));
     $this->assertEquals('attr_value', $element->getAttribute('attr'));
     // Exception
     $factory->create(array('type' => 'App\\Form\\Forms'));
 }
Exemple #3
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testFilters()
 {
     $elementArray = array('type' => 'App\\Form\\Element', 'options' => array('model_link' => 'Model\\TestModel', 'filters' => array('App\\Filter\\Name')));
     $factory = new Factory();
     $element = $factory->create($elementArray);
     $element->setValue(' test');
     $this->assertEquals(array('test'), $element->getValue());
     $element->setValue('    ');
     $this->assertEquals(array(''), $element->getValue());
     $element->setFilters(array('type' => 'Zend\\Filter\\Digits'));
     $element->setValue(0);
     $this->assertEquals(array('0'), $element->getValue());
     $element->setValue('Тест69');
     $this->assertEquals(array('69'), $element->getValue());
     $elementArray = array('type' => 'App\\Form\\Element', 'options' => array('model_link' => 'Model\\TestModel', 'filters' => array(array('type' => 'Zend\\Filter\\Digits'), array('Zend\\Filter\\Int'))));
     $factory = new Factory();
     $element = $factory->create($elementArray);
     $this->assertEquals(array('69 тест'), $element->setValue('69 тест')->getRawValue());
     $this->assertEquals(array('69'), $element->setValue('69 тест')->getValue());
     $this->assertEquals(array('69 тест'), $element->getRawValue());
     $this->assertEquals(array('69'), $element->setValue('тест 69')->getValue());
     $this->assertEquals(array(''), $element->setValue('тест с очень длинным префиксом')->getValue());
     $filter = Filter::getFilterInstance('Zend\\Filter\\Int');
     $this->assertTrue($element->hasFilter($filter));
     $this->assertFalse($element->hasFilter('Zend\\Filter\\Float'));
     $this->assertEquals($filter, $element->getFilter($filter));
     $this->assertNull($element->getFilter('Zend\\Filter\\Float'));
     $this->assertInternalType('array', $element->getFilter());
     // exception
     $elementArray = array('type' => 'App\\Form\\Element', 'options' => array('filters' => array(array())));
     $element = $factory->create($elementArray);
 }