public function testPreSubmitData()
 {
     $eventMock = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock();
     $configMock = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $configMock->expects($this->once())->method('getOptions')->will($this->returnValue(array('auto_initialize' => true)));
     $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('template'))->will($this->returnValue($fieldMock));
     $formMock->expects($this->once())->method('add');
     $newFieldMock = $this->getMockBuilder('Symfony\\Component\\Form\\Test\\FormInterface')->disableOriginalConstructor()->getMock();
     $phpUnit = $this;
     $this->formBuilder->expects($this->once())->method('createNamed')->will($this->returnCallback(function ($name, $type, $data, $config) use($phpUnit, $newFieldMock) {
         $phpUnit->assertEquals('template', $name);
         $phpUnit->assertEquals('oro_email_template_list', $type);
         $phpUnit->assertNull($data);
         $phpUnit->assertArrayHasKey('query_builder', $config);
         $phpUnit->assertArrayHasKey('selectedEntity', $config);
         $phpUnit->assertArrayHasKey('auto_initialize', $config);
         return $newFieldMock;
     }));
     $eventMock->expects($this->once())->method('getData')->will($this->returnValue(array('entityName' => 'testEntityName')));
     $eventMock->expects($this->once())->method('getForm')->will($this->returnValue($formMock));
     $this->listener->preSubmit($eventMock);
 }
 public function testPreSubmitData()
 {
     $organization = $this->getMock('Oro\\Bundle\\OrganizationBundle\\Entity\\Organization');
     $token = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\UsernamePasswordOrganizationToken')->disableOriginalConstructor()->getMock();
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $token->expects($this->once())->method('getOrganizationContext')->will($this->returnValue($organization));
     $eventMock = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock();
     $configMock = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $configMock->expects($this->once())->method('getOptions')->will($this->returnValue(array('auto_initialize' => true)));
     $formType = $this->getMock('Symfony\\Component\\Form\\ResolvedFormTypeInterface');
     $formType->expects($this->once())->method('getName')->will($this->returnValue('template'));
     $configMock->expects($this->once())->method('getType')->will($this->returnValue($formType));
     $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('template'))->will($this->returnValue($fieldMock));
     $formMock->expects($this->once())->method('add');
     $eventMock->expects($this->once())->method('getData')->will($this->returnValue(array('entityName' => 'testEntityName')));
     $eventMock->expects($this->once())->method('getForm')->will($this->returnValue($formMock));
     $this->listener->preSubmit($eventMock);
 }