Ejemplo n.º 1
0
 function it_creates_a_project_passing_the_image(UserInterface $user, ParticipantFactory $participantFactory, ParticipantInterface $participant, WorkflowInterface $workflow, MediaUploaderInterface $uploader, MediaFactory $mediaFactory, MediaInterface $media)
 {
     $image = new UploadedFile('', '', null, null, 99, true);
     // Avoids file not found exception
     $participantFactory->create(Argument::type('Kreta\\Component\\Project\\Model\\Project'), $user, 'ROLE_ADMIN')->shouldBeCalled()->willReturn($participant);
     $mediaFactory->create($image)->shouldBeCalled()->willReturn($media);
     $uploader->upload($media)->shouldBeCalled();
     $this->create($user, $workflow, false, $image)->shouldReturnAnInstanceOf('Kreta\\Component\\Project\\Model\\Project');
 }
Ejemplo n.º 2
0
 /**
  * Creates an instance of a project.
  *
  * @param \Kreta\Component\User\Model\Interfaces\UserInterface              $user     The project creator
  * @param \Kreta\Component\Workflow\Model\Interfaces\WorkflowInterface|null $workflow The workflow
  * @param boolean                                                           $load     Load boolean, by default true
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile               $image    The image, can be null
  *
  * @return \Kreta\Component\Project\Model\Interfaces\ProjectInterface
  */
 public function create(UserInterface $user, WorkflowInterface $workflow = null, $load = true, UploadedFile $image = null)
 {
     $project = new $this->className();
     $participant = $this->participantFactory->create($project, $user, 'ROLE_ADMIN');
     if (!$workflow instanceof WorkflowInterface) {
         $workflow = $this->workflowFactory->create(self::DEFAULT_WORKFLOW_NAME, $user, true);
     }
     if ($load) {
         $project = $this->loadPrioritiesAndTypes($project);
     }
     if ($image instanceof UploadedFile) {
         $media = $this->mediaFactory->create($image);
         $this->uploader->upload($media);
         $project->setImage($media);
     }
     return $project->addParticipant($participant)->setWorkflow($workflow);
 }