コード例 #1
0
ファイル: FilterTest.php プロジェクト: slkxmail/App
 /**
  * @expectedException \App\Exception\InvalidElementException
  * @group mm1
  */
 public function testInstance()
 {
     $filter = Filter::getFilterInstance('StringTrim', array(), array('\\App\\Filter'));
     $this->assertInstanceOf('App\\Filter\\StringTrim', $filter);
     $this->assertEquals('', $filter->filter("\r\n "));
     $filter = Filter::getFilterInstance('StringTrim', array('charlist' => "\r\n"), array('\\App\\Filter'));
     $this->assertInstanceOf('App\\Filter\\StringTrim', $filter);
     $this->assertEquals(' ', $filter->filter("\r\n "));
     Filter::getFilterInstance('Element', array(), array('\\App\\Form'));
     Filter::getFilterInstance('Unknown', array(), array('\\App\\Filter'));
 }
コード例 #2
0
ファイル: ElementTest.php プロジェクト: slkxmail/App
 /**
  * @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);
 }
コード例 #3
0
ファイル: Element.php プロジェクト: slkxmail/App
 /**
  * Получить список фильтров
  *
  * @return array|AbstractFilter[]
  */
 public function getFilters()
 {
     if ($this->dirtyFilters && ($filters = $this->getOption('filters'))) {
         foreach ($filters as $k => $filter) {
             if (is_array($filter)) {
                 $filters[$k] = Filter::getFilterInstance($filter['type'], $filter['params']);
             }
         }
         $this->setOption('filters', $filters);
         $this->dirtyFilters = false;
     }
     return $this->getOption('filters');
 }