Exemplo n.º 1
0
 public function testPreSubmit()
 {
     $this->mockConfigs(array('is_granted' => true, 'owner_type' => OwnershipType::OWNER_TYPE_USER));
     $businessUnit = $this->getMockBuilder('Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit')->disableOriginalConstructor()->getMock();
     $businessUnit->expects($this->any())->method('getId')->will($this->returnValue(2));
     $this->user->expects($this->any())->method('getId')->will($this->returnValue(1));
     $newUser = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\User')->disableOriginalConstructor()->getMock();
     $newUser->expects($this->any())->method('getId')->will($this->returnValue(2));
     $this->user->expects($this->any())->method('getOwner')->will($this->returnValue($newUser));
     $ownerForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $form->expects($this->any())->method('get')->will($this->returnValue($ownerForm));
     $ownerForm->expects($this->any())->method('getData')->will($this->returnValue($this->user));
     $form->expects($this->any())->method('has')->will($this->returnValue(true));
     $form->expects($this->any())->method('getParent')->will($this->returnValue(false));
     $form->expects($this->once())->method('getNormData')->will($this->returnValue($this->entityClassName));
     $this->businessUnitManager->expects($this->once())->method('canUserBeSetAsOwner')->will($this->returnValue(false));
     $event = new FormEvent($form, $this->user);
     $this->extension->preSubmit($event);
     $ownerForm->expects($this->once())->method('addError')->with(new FormError('You have no permission to set this owner'));
     $this->extension->postSubmit($event);
 }