/** * @param $entity * @param FieldMetadata $metadata * @param int $count * @param $expectedValue * * @dataProvider getValueDataProvider */ public function testGetValue($entity, FieldMetadata $metadata, $count, $expectedValue) { $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $repository = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\Repository\\ActivityListRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('getRecordsCountForTargetClassAndId')->with(ClassUtils::getClass($entity), $entity->getId(), [$metadata->get('type')])->willReturn($count); $em->expects($this->once())->method('getRepository')->willReturn($repository); $this->registry->expects($this->once())->method('getManagerForClass')->willReturn($em); $this->assertEquals($expectedValue, $this->accessor->getValue($entity, $metadata)); }
public function testValidate() { $this->repository->expects($this->once())->method('findDuplicate')->with($this->lineItem)->will($this->returnValue(true)); $this->registry->expects($this->once())->method('getRepository')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($this->repository)); $this->context->expects($this->once())->method('addViolation')->with($this->constraint->message); $validator = new LineItemValidator($this->registry); $validator->initialize($this->context); $validator->validate($this->lineItem, $this->constraint); }
/** * @test */ public function testProcess() { $this->doctrineRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->manager)); $this->manager->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder))->with($this->equalTo('a')); $this->grid->expects($this->once())->method('getParameters')->will($this->returnValue($this->parameterBag)); $this->parameterBag->expects($this->once())->method('get')->will($this->returnValue(1)); $this->grid->expects($this->once())->method('setDatasource'); $this->combinedAuditDatasource->process($this->grid, []); }
public function setUp() { $this->providerStorage = new EmailOwnerProviderStorage(); $this->entityNameResolver = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\Provider\\EntityNameResolver')->disableOriginalConstructor()->getMock(); $this->mailboxRepository = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Repository\\MailboxRepository')->disableOriginalConstructor()->getMock(); $this->doctrine = $this->getMockBuilder('Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->getMock(); $this->doctrine->expects($this->any())->method('getRepository')->with($this->equalTo('OroEmailBundle:Mailbox'))->will($this->returnValue($this->mailboxRepository)); $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock(); $this->factory = new EmailQueryFactory($this->providerStorage, $this->entityNameResolver, $this->doctrine, $this->securityFacade); }
/** * @param array $inputData * @param array $expectedData * * @dataProvider getActionsProvider */ public function testGetActions(array $inputData, array $expectedData) { $this->record->expects($this->any())->method('getValue')->with('id')->willReturn($inputData['record']['id']); $this->doctrine->expects($this->any())->method('getManagerForClass')->with($expectedData['class'])->willReturn($this->manager); $this->manager->expects($this->any())->method('getReference')->with($expectedData['class'], $expectedData['id'])->willReturn($inputData['object']); $this->securityFacade->expects($this->any())->method('isGranted')->willReturnCallback(function ($permission) use($inputData) { return $inputData['isGranted'][$permission]; }); $this->assertEquals($expectedData['actions'], $this->actionPermissionProvider->getActions($this->record, $inputData['config'])); }
public function setUp() { $this->contextAccessor = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Model\\ContextAccessor'); $this->mailboxProcessStorage = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Mailbox\\MailboxProcessStorage')->disableOriginalConstructor()->getMock(); $demoProcess = $this->getMock('Oro\\Bundle\\EmailBundle\\Mailbox\\MailboxProcessProviderInterface'); $demoProcess->expects($this->any())->method('getSettingsEntityFQCN')->will($this->returnValue('DemoProcessSettings')); $this->mailboxProcessStorage->expects($this->any())->method('getProcess')->with($this->equalTo('demo'))->will($this->returnValue($demoProcess)); $this->registry = $this->getMockBuilder('Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->getMock(); $this->repository = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Repository\\MailboxRepository')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->any())->method('getRepository')->with($this->equalTo('OroEmailBundle:Mailbox'))->will($this->returnValue($this->repository)); $this->action = new RequestMailboxes($this->contextAccessor, $this->registry, $this->mailboxProcessStorage); $this->action->setDispatcher($this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')); }
public function testProcessExistingShoppingList() { $this->shoppingList->expects($this->once())->method('getId')->willReturn(1); $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('PUT')); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); /** @var \PHPUnit_Framework_MockObject_MockObject|ObjectManager $manager */ $manager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $manager->expects($this->once())->method('persist'); $manager->expects($this->once())->method('flush'); $this->registry->expects($this->once())->method('getManagerForClass')->with(self::SHOPPING_LIST_SHORTCUT)->will($this->returnValue($manager)); $handler = new ShoppingListHandler($this->form, $this->request, $this->manager, $this->registry); $this->assertTrue($handler->process($this->shoppingList)); }
protected function initManager() { $manager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $manager->expects($this->any())->method('persist'); $manager->expects($this->any())->method('flush'); $this->registry->expects($this->any())->method('getManager')->willReturn($manager); }
protected function setUp() { MockAnnotations::init($this); $this->doctrineRegistry->expects($this->any())->method('getRepository')->will($this->returnCallback([$this, 'getRepository'])); $this->ticketService = new TicketApiServiceImpl($this->doctrineRegistry, $this->ticketBuilder, $this->attachmentManager, $this->authorizationService, $this->dispatcher, $this->tagManager, $this->securityFacade); $this->ticketService->setApiPagingService($this->apiPagingService); }
/** * @test */ public function updateBranchWithAllValues() { $this->fileMock = new UploadedFileStub(self::DUMMY_LOGO_PATH, self::DUMMY_LOGO_NAME); $uploadedFile = $this->fileMock->move(self::DUMMY_LOGO_PATH, self::DUMMY_LOGO_NAME); $this->branchRepository->expects($this->once())->method('get')->will($this->returnValue($this->branch)); $this->branch->expects($this->exactly(2))->method('getLogo')->will($this->returnValue($this->logo)); $this->branchLogoHandler->expects($this->once())->method('remove')->with($this->equalTo($this->logo)); $this->branchLogoHandler->expects($this->once())->method('upload')->with($this->equalTo($this->fileMock))->will($this->returnValue($uploadedFile)); $name = 'DUMMY_NAME_UPDT'; $description = 'DUMMY_DESC_UPDT'; $assigneeId = 1; $assignee = new User($assigneeId, User::TYPE_ORO); $defaultAssignee = new OroUser(); $tags = array('autocomplete' => array(), 'all' => array(), 'owner' => array()); $this->branch->expects($this->once())->method('update')->with($this->equalTo($name), $this->equalTo($description), $this->equalTo($defaultAssignee), $this->equalTo(new Logo($uploadedFile->getFilename(), $uploadedFile->getFilename()))); $this->branch->expects($this->once())->method('setTags')->with($this->equalTo($tags)); $this->registry->expects($this->exactly(2))->method('getManager')->will($this->returnValue($this->entityManager)); $this->entityManager->expects($this->once())->method('persist')->with($this->branch); $this->entityManager->expects($this->once())->method('flush'); $this->tagManager->expects($this->once())->method('saveTagging')->with($this->equalTo($this->branch)); $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo('Entity:DiamanteDeskBundle:Branch'))->will($this->returnValue(true)); $this->registry->expects($this->once())->method('getRepository')->with($this->equalTo('OroUserBundle:User'))->will($this->returnValue($this->userRepo)); $this->userRepo->expects($this->once())->method('find')->with($this->equalTo($assigneeId))->will($this->returnValue($defaultAssignee)); $command = new BranchCommand(); $command->name = $name; $command->description = $description; $command->defaultAssignee = $assigneeId; $command->logoFile = $this->fileMock; $command->tags = $tags; $this->branchServiceImpl->updateBranch($command); }
/** * @test */ public function deleteAttachment() { $pathname = 'some/path/file.ext'; $filename = 'file.ext'; $attachment = new Attachment(new File($pathname)); $this->fileStorageService->expects($this->once())->method('remove')->with($this->equalTo($filename)); $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->once())->method('remove')->with($this->equalTo($attachment)); $this->manager->deleteAttachment($attachment); }
/** * @dataProvider getEntityIdentifier * * @param array $ids */ public function testGetEntityIdentifier(array $ids) { $entity = new Bar(); $meta = $this->getNoConstructorMock(ClassMetadata::class); $meta->expects($this->once())->method('getIdentifierValues')->with($entity)->will($this->returnValue($ids)); $this->doctrine->expects($this->once())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->once())->method('getClassMetadata')->with(get_class($entity))->will($this->returnValue($meta)); $prefix = null; if ($ids) { $prefix = CacheKeyBuilder::IDENTIFIER_PREFIX . implode(CacheKeyBuilder::IDENTIFIER_SEPARATOR, $ids); } $this->assertEquals($prefix, $this->builder->getEntityIdentifier($entity)); }
public function testRenderTicket() { $tags = array(array('id' => 1, 'name' => 'Ticket Tag')); $renderTagResult = '<span class="tag-inline">Ticket Tag</span>'; $this->registry->expects($this->once())->method('getRepository')->will($this->returnValue($this->sharedRepository)); $this->tagManager->expects($this->once())->method('loadTagging')->will($this->returnValue($this->tagManager)); $this->twig->expects($this->once())->method('render')->will($this->returnValue($renderTagResult)); $this->sharedRepository->expects($this->once())->method('get')->will($this->returnValue($this->ticket)); $this->ticket->expects($this->once())->method('getTags')->will($this->returnValue($this->commonCollection)); $this->commonCollection->expects($this->once())->method('getValues')->will($this->returnValue($tags)); $ticketResult = $this->renderTagExtensionExtension->renderTag($this->twig, 1, 'ticket'); $this->assertEquals($renderTagResult, $ticketResult); }
/** * Test case to cover the showResignedAction with filter value as post * * @covers Skyrocket\LoginBundle\Controller\DefaultController::showResignedAction */ public function testShowResignedWithFilterAction() { $dummyResultArray = $this->getResignedDummyFilterArray(); $this->mockController->expects($this->once())->method('getRequest')->will($this->returnValue($this->mockRequest)); $this->mockRequest->expects($this->any())->method('getMethod')->will($this->returnValue('POST')); $this->mockRequest->expects($this->at(1))->method('get')->with($this->equalTo('fromDate'))->will($this->returnValue('08/04/2015')); $this->mockRequest->expects($this->at(2))->method('get')->with($this->equalTo('toDate'))->will($this->returnValue('08/06/2015')); $this->mockController->expects($this->once())->method('getDoctrine')->will($this->returnValue($this->mockRegistry)); $this->mockRegistry->expects($this->once())->method('getManager')->will($this->returnValue($this->mockEntityManager)); $this->mockEntityManager->expects($this->once())->method('getRepository')->with($this->equalTo('SkyrocketLoginBundle:Employee'))->will($this->returnValue($this->mockRepository)); $this->mockRepository->expects($this->once())->method('getFilteredEmployeesResigned')->with($this->equalTo(1), $this->equalTo('2015-08-04 00:00:00'), $this->equalTo('2015-08-06 00:00:00'))->will($this->returnValue($dummyResultArray)); $this->mockController->showResignedAction(); }
/** * @param array $activity * @param int $qbCalls * @param int $hasModelCalls * @param int $hasModelCalls * * @dataProvider getInheritanceDataProvider */ public function testApplyInheritanceActivity($activity, $qbCalls, $hasModelCalls, $getConfigCalls) { $config = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Config')->disableOriginalConstructor()->getMock(); $config->expects($this->exactly($getConfigCalls))->method('getValues')->willReturn($activity); $this->configManager->expects($this->exactly($hasModelCalls))->method('hasConfigEntityModel')->with('test')->willReturn(true); $this->configManager->expects($this->exactly($getConfigCalls))->method('getEntityConfig')->with('activity', 'test')->willReturn($config); $expr = new Expr(); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->any())->method('getExpressionBuilder')->willReturn($expr); $qb = new QueryBuilder($em); $qb->select('test')->from('test', 'ttt'); $em->expects($this->exactly($qbCalls))->method('createQueryBuilder')->willReturn($qb); $this->registry->expects($this->exactly($qbCalls))->method('getManagerForClass')->willReturn($em); $this->activityInheritanceTargetsHelper->applyInheritanceActivity($qb, 'test', 1); }
/** * @param object|null $lineItem */ protected function addRegistryExpectations(LineItem $lineItem) { /** @var \PHPUnit_Framework_MockObject_MockObject|LineItemRepository $repository */ $repository = $this->getMockBuilder('OroB2B\\Bundle\\ShoppingListBundle\\Entity\\Repository\\LineItemRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('findDuplicate')->with($this->lineItem)->will($this->returnValue($lineItem)); /** @var \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface $manager */ $manager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface'); $manager->expects($this->once())->method('beginTransaction'); $manager->expects($this->once())->method('commit'); $manager->expects($this->never())->method('rollback'); $manager->expects($this->never())->method('persist'); $manager->expects($this->once())->method('flush'); $manager->expects($this->once())->method('getRepository')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($repository)); $this->registry->expects($this->once())->method('getManagerForClass')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($manager)); }
public function testProcessNotExistingLineItem() { $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('PUT')); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $repository = $this->getMockBuilder('OroB2B\\Bundle\\ShoppingListBundle\\Entity\\Repository\\LineItemRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('findDuplicate')->with($this->lineItem)->will($this->returnValue(null)); $manager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $manager->expects($this->once())->method('getRepository')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($repository)); $manager->expects($this->once())->method('persist')->with($this->lineItem); $manager->expects($this->once())->method('flush'); $this->registry->expects($this->once())->method('getManagerForClass')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($manager)); $handler = new LineItemHandler($this->form, $this->request, $this->registry); $this->assertTrue($handler->process($this->lineItem)); $this->assertEquals([], $handler->updateSavedId([])); }
/** * @test */ public function thatAttachmentRemovesFromTicket() { $attachment = new Attachment(new File('some/path/file.ext')); $this->ticketRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_TICKET_ID))->will($this->returnValue($this->ticket)); $this->ticket->expects($this->once())->method('getAttachment')->with($this->equalTo(self::DUMMY_ATTACHMENT_ID))->will($this->returnValue($attachment)); $this->ticket->expects($this->once())->method('removeAttachment')->with($this->equalTo($attachment)); $this->attachmentManager->expects($this->once())->method('deleteAttachment')->with($this->equalTo($attachment)); $this->doctrineRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->once())->method('persist')->with($this->equalTo($this->ticket)); $this->em->expects($this->never())->method('flush'); $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo($this->ticket))->will($this->returnValue(true)); $removeTicketAttachmentCommand = new RemoveTicketAttachmentCommand(); $removeTicketAttachmentCommand->ticketId = self::DUMMY_TICKET_ID; $removeTicketAttachmentCommand->attachmentId = self::DUMMY_ATTACHMENT_ID; $this->ticketService->removeAttachmentFromTicket($removeTicketAttachmentCommand); }
public function testMailboxOrigins() { $user1 = new TestUser(); $mailbox1 = new TestMailbox(); $origin1 = new TestUserEmailOrigin(1); $origin1->setMailboxName('testName1'); $origin1->setUser($user1); $folder1 = new TestEmailFolder(1); $folder2 = new TestEmailFolder(2); $folder3 = new TestEmailFolder(3); $folder1->setFullName('Folder1'); $folder1->setSyncEnabled(true); $folder2->setFullName('Folder2'); $folder2->setSyncEnabled(true); $folder3->setFullName('Folder - disabled'); $origin1->addFolder($folder1); $origin1->addFolder($folder2); $origin1->addFolder($folder3); $mailbox1->setOrigin($origin1); $mailbox2 = new TestMailbox(); $mailbox2->setLabel('Box2'); $origin2 = new TestUserEmailOrigin(2); $origin2->setMailboxName('testName2'); $origin2->setUser($user1); $origin2->setActive(false); $folder3 = new TestEmailFolder(3); $folder3->setSyncEnabled(true); $folder3->setFullName('Folder3'); $origin2->addFolder($folder3); $mailbox2->setOrigin($origin2); $this->doctrine->expects($this->any())->method('getRepository')->will($this->returnValue($this->originRepository)); $this->originRepository->expects($this->once())->method('findBy')->willReturn([]); $this->originRepository->expects($this->once())->method('findAvailableMailboxes')->willReturn([$mailbox1, $mailbox2]); $result = $this->originFolderFilterProvider->getListTypeChoices(); $this->assertNotEmpty($result); $this->assertCount(2, $result); $this->assertEquals($origin1->isActive(), $result[$mailbox1->getLabel()]['active']); $this->assertEquals($origin2->isActive(), $result[$mailbox2->getLabel()]['active']); $this->assertCount(2, $result[$mailbox1->getLabel()]['folder']); $this->assertCount(1, $result[$mailbox2->getLabel()]['folder']); $this->assertEquals($folder2->getFullName(), $result[$mailbox1->getLabel()]['folder'][$folder2->getId()]); }
protected function setUp() { $this->emailCacheManager = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Cache\\EmailCacheManager')->disableOriginalConstructor()->getMock(); $filesystemMap = $this->getMockBuilder('Knp\\Bundle\\GaufretteBundle\\FilesystemMap')->disableOriginalConstructor()->getMock(); $this->filesystem = $this->getMockBuilder('Gaufrette\\Filesystem')->setMethods(['delete', 'write', 'has'])->disableOriginalConstructor()->getMock(); $filesystemMap->expects($this->once())->method('get')->with('attachments')->will($this->returnValue($this->filesystem)); $this->registry = $this->getMockBuilder('Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->getMock(); $this->configFileValidator = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\Validator\\ConfigFileValidator')->disableOriginalConstructor()->getMock(); $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); $this->kernel->expects($this->once())->method('getRootDir')->willReturn(''); $this->om = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->om)); $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->setMethods(['getLoggedUser'])->disableOriginalConstructor()->getMock(); $this->securityFacadeLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->setMethods(['getService'])->disableOriginalConstructor()->getMock(); $this->securityFacadeLink->expects($this->any())->method('getService')->will($this->returnValue($this->securityFacade)); $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->attachment = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\Entity\\Attachment')->setMethods(['supportTarget'])->disableOriginalConstructor()->getMock(); $this->attachmentConfig = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\EntityConfig\\AttachmentConfig')->disableOriginalConstructor()->getMock(); $this->emailAttachmentManager = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Manager\\EmailAttachmentManager')->setMethods(['getAttachmentFullPath', 'buildAttachmentInstance'])->setConstructorArgs([$filesystemMap, $this->em, $this->kernel, $this->securityFacadeLink, $this->configFileValidator, $this->attachmentConfig])->getMock(); $this->emailAttachmentManager->expects($this->any())->method('getAttachmentFullPath')->willReturn(__DIR__ . '/../Fixtures/attachment/test.txt'); }
/** * @test */ public function thatAttachmentRemovesFromComment() { $attachment = new Attachment(new File('some/path/file.ext')); $this->commentRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_COMMENT_ID))->will($this->returnValue($this->comment)); $this->comment->expects($this->once())->method('getAttachment')->with($this->equalTo(1))->will($this->returnValue($attachment)); $this->comment->expects($this->once())->method('removeAttachment')->with($this->equalTo($attachment)); $this->attachmentManager->expects($this->once())->method('deleteAttachment')->with($this->equalTo($attachment)); $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->any())->method('persist'); $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo($this->comment))->will($this->returnValue(true)); $removeCommentAttachmentCommand = new RemoveCommentAttachmentCommand(); $removeCommentAttachmentCommand->attachmentId = 1; $removeCommentAttachmentCommand->commentId = self::DUMMY_COMMENT_ID; $this->service->removeAttachmentFromComment($removeCommentAttachmentCommand); }