public function testPreSetDataHasTemplates() { $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(); $notificationMock = $this->getMock('Oro\\Bundle\\NotificationBundle\\Entity\\EmailNotification'); $notificationMock->expects($this->exactly(2))->method('getEntityName')->will($this->returnValue('testEntity')); $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(); $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'); $fieldMock->expects($this->once())->method('getConfig')->will($this->returnValue($configMock)); $eventMock->expects($this->once())->method('getData')->will($this->returnValue($notificationMock)); $eventMock->expects($this->once())->method('getForm')->will($this->returnValue($formMock)); $this->listener->preSetData($eventMock); }
public function testPreSetDataNoTemplates() { $eventMock = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock(); $notificationMock = $this->getMock('Oro\\Bundle\\NotificationBundle\\Entity\\EmailNotification'); $notificationMock->expects($this->once())->method('getEntityName')->will($this->returnValue('testEntity')); $formMock = $this->getMockBuilder('Symfony\\Component\\Form\\Test\\FormInterface')->disableOriginalConstructor()->getMock(); $formMock->expects($this->once())->method('has')->with($this->equalTo('template'))->will($this->returnValue(false)); $formMock->expects($this->never())->method('get'); $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)); $eventMock->expects($this->once())->method('getData')->will($this->returnValue($notificationMock)); $eventMock->expects($this->once())->method('getForm')->will($this->returnValue($formMock)); $this->listener->preSetData($eventMock); }