public function testInitWithoutPersistence() { $this->setExpectedException('Balance\\InputFilter\\InputFilterException', 'Invalid Model'); $inputFilter = new Postings(); $serviceLocator = new ServiceManager(); $serviceLocator->setService('Balance\\Model\\Persistence\\Accounts', $this->getMock('Balance\\Model\\Persistence\\PersistenceInterface')); $inputFilterPluginManager = new InputFilterPluginManager(); $inputFilterPluginManager->setServiceLocator($serviceLocator); $inputFilter->setServiceLocator($inputFilterPluginManager); $inputFilter->init(); }
/** * Get the input filter, and validate the incoming data * * @TODO: when we have the new input filter, we should use named validation group and context * * @param string $inputFilterName * @param array $validationGroup * @param mixed $context * @return array * @throws UnprocessableEntityException */ public function __invoke($inputFilterName, array $validationGroup = [], $context = null) { /** @var \Zend\InputFilter\InputFilterInterface $inputFilter */ $inputFilter = $this->inputFilterPluginManager->get($inputFilterName); if (!empty($validationGroup)) { $inputFilter->setValidationGroup($validationGroup); } $data = array_merge(json_decode($this->controller->getRequest()->getContent(), true) ?: [], $this->controller->getRequest()->getPost()->toArray()); $inputFilter->setData($data); if ($inputFilter->isValid($context)) { return $inputFilter->getValues(); } throw new UnprocessableEntityException('Validation error', $inputFilter->getMessages()); }
public function setUp() { $services = $this->services = new ServiceManager(); $elements = new FormElementManager(); $filters = new FilterPluginManager(); $hydrators = new HydratorPluginManager(); $inputFilters = new InputFilterPluginManager(); $validators = new ValidatorPluginManager(); $elements->setServiceLocator($services); $filters->setServiceLocator($services); $hydrators->setServiceLocator($services); $inputFilters->setServiceLocator($services); $validators->setServiceLocator($services); $services->setService('FilterManager', $filters); $services->setService('FormElementManager', $elements); $services->setService('HydratorManager', $hydrators); $services->setService('InputFilterManager', $inputFilters); $services->setService('ValidatorManager', $validators); $inputFilters->setInvokableClass('FooInputFilter', 'Zend\\InputFilter\\InputFilter'); $forms = $this->forms = new FormAbstractServiceFactory(); $services->addAbstractFactory($forms); }
/** * @param InputFilterPluginManager $inputFilterManager * @return self */ public function setInputFilterManager(InputFilterPluginManager $inputFilterManager) { $this->inputFilterManager = $inputFilterManager; $serviceLocator = $this->inputFilterManager->getServiceLocator(); if ($serviceLocator && $serviceLocator instanceof ServiceLocatorInterface) { if ($serviceLocator->has('ValidatorManager')) { $this->getDefaultValidatorChain()->setPluginManager($serviceLocator->get('ValidatorManager')); } if ($serviceLocator->has('FilterManager')) { $this->getDefaultFilterChain()->setPluginManager($serviceLocator->get('FilterManager')); } } return $this; }
public function testSetInputFilterManagerWithServiceManager() { $inputFilterManager = new InputFilterPluginManager(); $serviceManager = new ServiceManager\ServiceManager(); $serviceManager->setService('ValidatorManager', new Validator\ValidatorPluginManager()); $serviceManager->setService('FilterManager', new Filter\FilterPluginManager()); $inputFilterManager->setServiceLocator($serviceManager); $factory = new Factory(); $factory->setInputFilterManager($inputFilterManager); $this->assertInstanceOf('Zend\\Validator\\ValidatorPluginManager', $factory->getDefaultValidatorChain()->getPluginManager()); $this->assertInstanceOf('Zend\\Filter\\FilterPluginManager', $factory->getDefaultFilterChain()->getPluginManager()); }
/** * @covers Zend\InputFilter\InputFilterPluginManager::validatePlugin */ public function testAllowLoadingInstancesOfInputInterface() { $input = $this->getMock('Zend\\InputFilter\\InputInterface'); $this->assertNull($this->manager->validatePlugin($input)); }
/** * @param InputFilterPluginManager $inputFilterManager * @return self */ public function setInputFilterManager(InputFilterPluginManager $inputFilterManager) { $this->inputFilterManager = $inputFilterManager; $inputFilterManager->populateFactoryPluginManagers($this); return $this; }
/** * @depends testCanCreateService * @return void */ public function testCreateServiceWithOptionalManagers() { $serviceLocator = $this->serviceManager; //Test with optional managers $hydrator = new ObjectProperty(); $hydratorManager = new HydratorPluginManager(); $hydratorManager->setService('Zend\\Stdlib\\Hydrator\\ObjectProperty', $hydrator); $serviceLocator->setService('HydratorManager', $hydratorManager); $inputFilter = new InputFilter(); $inputFilterManager = new InputFilterPluginManager(); $inputFilterManager->setService('Zend\\InputFilter\\InputFilter', $inputFilter); $serviceLocator->setService('InputFilterManager', $inputFilterManager); $objectFull = $serviceLocator->get('MyObject\\Full'); $this->assertSame($hydrator, $objectFull->getHydrator()); $this->assertSame($inputFilter, $objectFull->getInputFilter()); }
/** * @depends testCanCreateService * @return void */ public function testCreateServiceWithOptionalManagers() { $serviceLocator = $this->serviceManager; //Test with optional managers $hydrator = new ObjectProperty(); $hydratorManager = new HydratorPluginManager(); $hydratorManager->setService('Zend\\Stdlib\\Hydrator\\ObjectProperty', $hydrator); $serviceLocator->setService('HydratorManager', $hydratorManager); $inputFilter = new InputFilter(); $inputFilterManager = new InputFilterPluginManager(); $inputFilterManager->setService('Zend\\InputFilter\\InputFilter', $inputFilter); $serviceLocator->setService('InputFilterManager', $inputFilterManager); $domainObject = new DomainObject(); $objectManager = new ObjectManager(); $objectManager->setService('DomainObject', $domainObject); $serviceLocator->setService('Matryoshka\\Model\\Object\\ObjectManager', $objectManager); $modelFull = $serviceLocator->get('MyModel\\Full'); $this->assertSame($hydrator, $modelFull->getHydrator()); $this->assertSame($inputFilter, $modelFull->getInputFilter()); $this->assertSame($domainObject, $modelFull->getObjectPrototype()); $listenerAggregate = $this->getMockForAbstractClass('Zend\\EventManager\\ListenerAggregateInterface', ['attach']); $listenerAggregate = $serviceLocator->get('ListenerAggregateMockedAsset'); $listenerAggregate->expects($this->atLeastOnce())->method('attach')->with($this->isInstanceOf('Zend\\EventManager\\EventManagerInterface')); $listenerManager = new ListenerManager(); $listenerManager->setService('ListenerAggregateMockedAsset', $listenerAggregate); $serviceLocator->setService('Matryoshka\\Model\\Listener\\ListenerManager', $listenerManager); /* @var $myModelOL \Matryoshka\Model\ObservableModel */ $myModelOL = $serviceLocator->get('MyModel\\OL'); }
public function testLoadingInvalidElementRaisesException() { $this->manager->setInvokableClass('test', get_class($this)); $this->setExpectedException('Zend\\InputFilter\\Exception\\RuntimeException'); $this->manager->get('test'); }