Example #1
0
 /**
  * @dataProvider submittedData
  * @param $data
  */
 public function testPreSubmit($data)
 {
     $eventMock = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock();
     $eventMock->expects($this->once())->method('getData')->will($this->returnValue($data));
     $this->manager->expects($this->once())->method('loadOrCreateTags')->with(array(self::TEST_TAG_NAME))->will($this->returnValue(array(new Tag(self::TEST_TAG_NAME))));
     $phpUnit = $this;
     $eventMock->expects($this->once())->method('setData')->will($this->returnCallback(function ($entities) use($phpUnit) {
         $phpUnit->assertArrayHasKey('all', $entities);
         $phpUnit->assertArrayHasKey('owner', $entities);
         $phpUnit->assertContainsOnlyInstancesOf('Oro\\Bundle\\TagBundle\\Entity\\Tag', $entities['all']);
         $phpUnit->assertEmpty($entities['owner']);
     }));
     $this->subscriber->preSubmit($eventMock);
 }
 /**
  * {@inheritdoc}
  */
 public function preSet(FormEvent $event)
 {
     $mailbox = $event->getForm()->getRoot()->getData();
     if ($mailbox instanceof Mailbox) {
         $organization = $mailbox->getOrganization();
         $this->organization = $organization;
     }
     parent::preSet($event);
 }
Example #3
0
 /**
  * @dataProvider entityProvider
  */
 public function testPreSet($entity, $shouldSetData)
 {
     $eventMock = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock();
     $parentFormMock = $this->getMockForAbstractClass('Symfony\\Component\\Form\\Test\\FormInterface');
     $parentFormMock->expects($this->once())->method('getData')->will($this->returnValue($entity));
     $formMock = $this->getMockForAbstractClass('Symfony\\Component\\Form\\Test\\FormInterface');
     $formMock->expects($this->once())->method('getParent')->will($this->returnValue($parentFormMock));
     $eventMock->expects($this->once())->method('getForm')->will($this->returnValue($formMock));
     if ($shouldSetData) {
         $this->taggableHelper->expects($this->once())->method('isTaggable')->willReturn(true);
         $this->manager->expects($this->once())->method('getPreparedArray')->with($entity)->will($this->returnValue(array(array('owner' => false), array('owner' => true))));
         $eventMock->expects($this->exactly($shouldSetData))->method('setData');
     } else {
         $this->manager->expects($this->never())->method('getPreparedArray');
         $eventMock->expects($this->never())->method('setData');
     }
     $this->subscriber->preSet($eventMock);
 }