protected function setUp() { $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->factory = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface'); $this->builder = new TestFormBuilder('name', null, $this->dispatcher, $this->factory); $this->factory->expects($this->any())->method('createNamedBuilder')->willReturn($this->builder); }
/** * @param bool $expectedSubmit * @param mixed $expectedException */ private function initializeMocks($expectedSubmit, $expectedException) { if ($expectedSubmit) { $formMock = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $data = null; $this->formFactory->expects($this->once())->method('create')->with($this->equalTo('oro_integration_channel_form'), $this->isInstanceOf('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel'), $this->equalTo(['csrf_protection' => false, 'disable_customer_datasource_types' => false]))->will($this->returnCallback(function ($type, $formData) use(&$data, $formMock) { // capture form data $data = $formData; return $formMock; })); $formMock->expects($this->once())->method('submit')->will($this->returnCallback(function ($submitted) use(&$data) { // emulate submit $accessor = PropertyAccess::createPropertyAccessor(); foreach ($submitted as $key => $value) { $accessor->setValue($data, $key, $value); } })); $invalid = null != $expectedException; $formMock->expects($this->once())->method('isValid')->will($this->returnValue(!$invalid)); if ($invalid) { $formMock->expects($this->once())->method('getErrors')->will($this->returnValue([new FormError('message')])); } } else { $this->formFactory->expects($this->never())->method('create'); } }
public function setUp() { $this->form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $this->formBuilder = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface'); $this->formBuilder->expects($this->any())->method('createNamed')->will($this->returnValue($this->form)); $this->request = Request::create(''); $this->entity = new Integration(); $this->handler = new ChannelIntegrationHandler($this->request, $this->formBuilder); }
public function setUp() { $this->form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $this->formFactory = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface'); $this->formFactory->expects($this->any())->method('create')->will($this->returnValue($this->form)); $this->filterUtility = $this->getMockBuilder('Oro\\Bundle\\FilterBundle\\Filter\\FilterUtility')->disableOriginalConstructor()->getMock(); $this->filterUtility->expects($this->any())->method('getExcludeParams')->willReturn([]); $this->formatter = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Formatter\\ProductUnitLabelFormatter')->disableOriginalConstructor()->getMock(); $this->productPriceFilter = new ProductPriceFilter($this->formFactory, $this->filterUtility, $this->formatter); }
public function testRender() { $this->urlGenerator->expects($this->once())->method('generate')->with($this->identicalTo($route = 'route_value'), $this->identicalTo([$routeParameter = 'route_parameter' => $routeParameterValue = 'route_parameter_value']), $this->identicalTo($routeReferenceType = UrlGeneratorInterface::ABSOLUTE_PATH))->will($this->returnValue($url = 'url_value')); $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($routeParameter))->will($this->returnValue($routeParameterValue)); $action = $this->createActionMock(); $action->expects($this->once())->method('getLabel')->will($this->returnValue($actionLabel = 'action_label')); $action->expects($this->once())->method('getOption')->with($this->identicalTo('trans_domain'))->will($this->returnValue($actionTransDomain = 'action_trans_domain')); $this->formFactory->expects($this->once())->method('create')->with($this->identicalTo(CsrfProtectionType::class), $this->isNull(), $this->identicalTo(['method' => $method = Request::METHOD_DELETE, 'action' => $url, 'label' => $actionLabel, 'translation_domain' => $actionTransDomain]))->will($this->returnValue($form = $this->createFormMock())); $form->expects($this->once())->method('createView')->will($this->returnValue($view = $this->createFormViewMock())); $this->assertSame($view, $this->type->render($data, ['action' => $action, 'method' => strtolower($method), 'route' => $route, 'route_parameters' => [$routeParameter], 'route_reference_type' => $routeReferenceType])); }
/** * @param bool $isFieldForm */ protected function configureFormMock($isFieldForm) { $this->containerMock->expects($this->at(1))->method('get')->with('form.factory')->willReturn($this->formFactoryMock); $formMock = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $invocationMocker = $this->formFactoryMock->expects($this->once())->method('createNamed')->willReturn($formMock); if ($isFieldForm) { $invocationMocker->with('', 'guess_field_type', null, ['data_class' => 'Test\\Entity', 'field_name' => 'someField', 'dynamic_fields_disabled' => true, 'ownership_disabled' => true]); } else { $invocationMocker->with('mass_edit_field', 'update_field_choice', null, ['entity' => 'Test\\Entity', 'with_relations' => true]); } $formMock->expects($this->once())->method('createView')->willReturn($this->getMock('Symfony\\Component\\Form\\FormView')); }
public function testProcessValidDataWithResponse() { $request = Request::create('/post/valid-with-response', 'POST'); $request->request->set(QuickAddType::NAME, [QuickAddType::COMPONENT_FIELD_NAME => self::COMPONENT_NAME]); $response = new RedirectResponse('/processor-redirect'); $products = [['sku' => '111', 'qty' => 123], ['sku' => '222', 'qty' => 234]]; $productsForm = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $productsForm->expects($this->once())->method('getData')->willReturn($products); $form = $this->getMock('Symfony\\Component\\Form\\FormInterface'); $form->expects($this->once())->method('submit')->with($request); $form->expects($this->once())->method('isValid')->willReturn(true); $form->expects($this->once())->method('get')->with(QuickAddType::PRODUCTS_FIELD_NAME)->willReturn($productsForm); $this->formFactory->expects($this->once())->method('create')->with(QuickAddType::NAME, null, ['validation_required' => true])->willReturn($form); $processor = $this->getProcessor(); $processor->expects($this->once())->method('process')->with([ProductDataStorage::ENTITY_ITEMS_DATA_KEY => $products], $request)->willReturn($response); $this->assertEquals(['form' => $form, 'response' => $response], $this->handler->process($request)); }
public function testPreSubmitData() { $eventMock = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock(); $countryMock = $this->getMockBuilder('Oro\\Bundle\\AddressBundle\\Entity\\Country')->disableOriginalConstructor()->getMock(); $countryMock->expects($this->once())->method('hasRegions')->will($this->returnValue(true)); $repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $repository->expects($this->any())->method('find')->with(self::TEST_COUNTRY_NAME)->will($this->returnValue($countryMock)); $this->om->expects($this->once())->method('getRepository')->with($this->equalTo('OroAddressBundle:Country'))->will($this->returnValue($repository)); $configMock = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface'); $configMock->expects($this->once())->method('getOptions')->will($this->returnValue(array())); $fieldMock = $this->getMockBuilder('Symfony\\Component\\Form\\Test\\FormInterface')->disableOriginalConstructor()->getMock(); $fieldMock->expects($this->once())->method('getConfig')->will($this->returnValue($configMock)); $formMock = $this->getMockBuilder('Symfony\\Component\\Form\\Test\\FormInterface')->disableOriginalConstructor()->getMock(); $formMock->expects($this->once())->method('get')->with($this->equalTo('region'))->will($this->returnValue($fieldMock)); $formMock->expects($this->once())->method('add'); $newFieldMock = $this->getMockBuilder('Symfony\\Component\\Form\\Test\\FormInterface')->disableOriginalConstructor()->getMock(); $this->formBuilder->expects($this->once())->method('createNamed')->will($this->returnValue($newFieldMock)); $startData = array('region_text' => 'regionText', 'country' => self::TEST_COUNTRY_NAME); $eventMock->expects($this->once())->method('getData')->will($this->returnValue($startData)); $eventMock->expects($this->once())->method('getForm')->will($this->returnValue($formMock)); $eventMock->expects($this->once())->method('setData')->with(array_intersect_key($startData, array('country' => self::TEST_COUNTRY_NAME))); $this->subscriber->preSubmit($eventMock); }
public function testCreateWithApi() { $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true)); $this->symfonyFormFactory->expects($this->once())->method('create')->with($this->identicalTo($type = 'type'), $this->identicalTo($data = 'data'), $this->identicalTo(array_merge($options = ['option'], ['csrf_protection' => false])))->will($this->returnValue($form = 'form')); $this->assertSame($form, $this->formFactory->create($type, $data, $options)); }