public function testProcessInvalid() { $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(false)); $this->assertFalse($this->handler->process($this->entity)); }
/** * @dataProvider supportedMethods * * @param string $method */ public function testProcessSupportedRequest($method) { $this->form->expects($this->once())->method('setData')->with($this->entity); $this->request->setMethod($method); $this->form->expects($this->once())->method('submit')->with($this->request); $this->assertFalse($this->handler->process($this->entity)); }
/** * @dataProvider eventDataProvider * * @param Integration $entity * @param null|User $newOwner * @param Integration|null $oldIntegration * @param bool $expectOwnerSetEvent * @param bool $expectIntegrationUpdateEvent */ public function testEventDispatching($entity, $newOwner, $oldIntegration, $expectOwnerSetEvent, $expectIntegrationUpdateEvent) { $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($entity)->will($this->returnCallback(function ($entity) use($newOwner) { $entity->setDefaultUserOwner($newOwner); })); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->em->expects($this->once())->method('persist')->with($entity); $this->em->expects($this->once())->method('flush'); if ($entity->getId()) { $this->em->expects($this->once())->method('find')->with('OroIntegrationBundle:Channel', $entity->getId())->will($this->returnValue($oldIntegration)); } $dispatchCallIndex = 0; if ($expectOwnerSetEvent) { $this->eventDispatcher->expects($this->at($dispatchCallIndex++))->method('dispatch')->with($this->equalTo(DefaultOwnerSetEvent::NAME), $this->isInstanceOf('Oro\\Bundle\\IntegrationBundle\\Event\\DefaultOwnerSetEvent')); } if ($expectIntegrationUpdateEvent) { $this->eventDispatcher->expects($this->at($dispatchCallIndex++))->method('dispatch')->with($this->equalTo(IntegrationUpdateEvent::NAME), $this->callback(function ($event) use($entity, $oldIntegration) { $this->assertInstanceOf('Oro\\Bundle\\IntegrationBundle\\Event\\IntegrationUpdateEvent', $event); $this->assertSame($entity, $event->getIntegration()); $this->assertEquals($oldIntegration, $event->getOldState()); return true; })); } elseif (!$expectOwnerSetEvent) { $this->eventDispatcher->expects($this->never())->method('dispatch'); } $this->assertTrue($this->handler->process($entity)); }
/** * @dataProvider processValidDataProvider * * @param bool $isDataChanged */ public function testProcessValidData($isDataChanged) { $appendedAccount = new Account(); $appendedAccount->setId(1); $removedAccount = new Account(); $removedAccount->setId(2); $this->entity->addAccount($removedAccount); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedAccount))); $this->form->expects($this->at(3))->method('get')->with('appendAccounts')->will($this->returnValue($appendForm)); $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedAccount))); $this->form->expects($this->at(4))->method('get')->with('removeAccounts')->will($this->returnValue($removeForm)); if ($isDataChanged) { $this->manager->expects($this->once())->method('persist')->with($this->entity); } else { $this->manager->expects($this->exactly(2))->method('persist')->with($this->entity); } $this->manager->expects($this->once())->method('flush'); $this->configureUnitOfWork($isDataChanged); $this->assertTrue($this->handler->process($this->entity)); $actualAccounts = $this->entity->getAccounts()->toArray(); $this->assertCount(1, $actualAccounts); $this->assertEquals($appendedAccount, current($actualAccounts)); }
/** * @dataProvider supportedMethods * * @param string $method */ public function testProcessSupportedRequest($method) { $this->request->setMethod($method); $this->form->expects($this->any())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->assertTrue($this->handler->process($this->entity)); }
public function testProcessWithoutContactViewPermission() { $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->form->expects($this->never())->method('get'); $this->assertTrue($this->handler->process($this->entity)); }
public function testAddingErrorToNonEditableSystemEntity() { $this->entity->setIsSystem(true); $this->entity->setIsEditable(false); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('addError'); $this->request->setMethod('POST'); $this->translator->expects($this->once())->method('trans'); $this->assertFalse($this->handler->process($this->entity)); }
/** * @dataProvider supportedMethods */ public function testProcessValidData($method) { $this->request->setMethod($method); $this->form->expects($this->once())->method('setData')->with($this->identicalTo($this->entity)); $this->form->expects($this->once())->method('submit')->with($this->identicalTo($this->request)); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->om->expects($this->once())->method('persist'); $this->om->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); }
public function testProcessValidData() { $this->form->expects($this->once())->method('setData')->with($this->attribute); $this->request->request->set(UpdateAttributeType::NAME, []); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->manager->expects($this->once())->method('persist')->with($this->attribute); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->attribute)); }
/** * @dataProvider submittedDataProvider * * @param string $requestType * @param array $requestData * @param array $expectedResult * @param null $expectedException */ public function testGetFormSubmittedData($requestType, $requestData, $expectedResult, $expectedException = null) { $this->request->setMethod($requestType); foreach ($requestData as $key => $value) { $this->request->request->set($key, $value); } if (null !== $expectedException) { $this->setExpectedException($expectedException); } $this->form->expects($this->any())->method('getName')->will($this->returnValue(self::TEST_NAME)); $this->assertSame($expectedResult, $this->handler->getFormSubmittedData()); }
public function testProcessValidData() { $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->once())->method('persist')->with($this->entity); $this->em->expects($this->once())->method('flush'); $this->dispatcher->expects($this->once())->method('dispatch')->with($this->equalTo(ChannelSaveEvent::EVENT_NAME), $this->isInstanceOf('OroCRM\\Bundle\\ChannelBundle\\Event\\ChannelSaveEvent')); $this->assertTrue($this->handler->process($this->entity)); }
/** * @param string $method * @param bool $formValid * @param bool $isFlushCalled * * @dataProvider processProvider */ public function testProcess($method, $isFormValid, $isFlushCalled) { $entity = new TrackingWebsite(); $this->request->setMethod($method); $this->form->expects($this->any())->method('submit')->with($this->request); $this->form->expects($this->any())->method('isValid')->will($this->returnValue($isFormValid)); if ($isFlushCalled) { $this->manager->expects($this->once())->method('persist')->with($this->equalTo($entity))->will($this->returnValue(true)); $this->manager->expects($this->once())->method('flush'); } $handler = new TrackingWebsiteHandler($this->form, $this->request, $this->manager); $handler->process($entity); }
public function testProcess() { $data = $this->getMockBuilder('OroCRM\\Bundle\\CampaignBundle\\Entity\\EmailCampaign')->disableOriginalConstructor()->getMock(); $this->form->expects($this->once())->method('setData')->with($data); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('submit')->with($this->request); $manager = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock(); $manager->expects($this->once())->method('persist')->with($data); $manager->expects($this->once())->method('flush'); $this->registry->expects($this->once())->method('getManagerForClass')->with('OroCRMCampaignBundle:EmailCampaign')->will($this->returnValue($manager)); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->assertTrue($this->handler->process($data)); }
public function testProcessValidPost() { $offerData = ['offer', 'data']; $quote = new Quote(); $order = new Order(); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->willReturn(true); $this->form->expects($this->once())->method('getData')->willReturn($offerData); $this->converter->expects($this->once())->method('convert')->with($quote, $this->accountUser, $offerData)->willReturn($order); $this->manager->expects($this->once())->method('persist')->with($order); $this->manager->expects($this->once())->method('flush'); $this->assertEquals($order, $this->handler->process($quote)); }
/** * @param string $method * * @dataProvider methodsData */ public function testProcessException($method) { $this->request->setMethod($method); $this->model->setFrom('*****@*****.**')->setTo(['*****@*****.**'])->setSubject('testSubject')->setBody('testBody'); $this->form->expects($this->once())->method('setData')->with($this->model); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $exception = new \Exception('TEST'); $this->emailProcessor->expects($this->once())->method('process')->with($this->model)->will($this->returnCallback(function () use($exception) { throw $exception; })); $this->logger->expects($this->once())->method('error')->with('Email sending failed.', ['exception' => $exception]); $this->form->expects($this->once())->method('addError')->with($this->isInstanceOf('Symfony\\Component\\Form\\FormError')); $this->assertFalse($this->handler->process($this->model)); }
/** * @param $entityClass * @param $entityId * @param $from * @param $subject * @param $parentEmail * @param $helperDecodeClassNameCalls * @param $emGetRepositoryCalls * @param $helperPreciseFullEmailAddressCalls * @param $helperGetUserCalls * @param $helperBuildFullEmailAddress * * @dataProvider createEmailModelProvider * * @SuppressWarnings(PHPMD) */ public function testCreateEmailModel($entityClass, $entityId, $from, $subject, $parentEmail, $helperDecodeClassNameCalls, $emGetRepositoryCalls, $helperPreciseFullEmailAddressCalls, $helperGetUserCalls, $helperBuildFullEmailAddress) { $emailModel = new EmailModel(); $this->request = new Request(); $this->request->setMethod('GET'); if ($entityClass) { $this->request->query->set('entityClass', $entityClass); } if ($entityId) { $this->request->query->set('entityId', $entityId); } if ($from) { $this->request->query->set('from', $from); } if ($subject) { $this->request->query->set('subject', $subject); } $this->emailModelBuilder = new EmailModelBuilder($this->helper, $this->entityManager, $this->configManager, $this->activityListProvider, $this->emailAttachmentProvider, $this->factory); $this->emailModelBuilder->setRequest($this->request); $this->helper->expects($this->exactly($helperDecodeClassNameCalls))->method('decodeClassName')->willReturn($entityClass); $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $this->entityManager->expects($this->exactly($emGetRepositoryCalls))->method('getRepository')->willReturn($repository); $this->helper->expects($this->exactly($helperPreciseFullEmailAddressCalls))->method('preciseFullEmailAddress'); $this->helper->expects($this->exactly($helperGetUserCalls))->method('getUser')->willReturn($this->getMock('Oro\\Bundle\\UserBundle\\Entity\\User')); $this->helper->expects($this->exactly($helperBuildFullEmailAddress))->method('buildFullEmailAddress'); $this->configManager->expects($this->once())->method('get')->with('oro_email.signature'); $result = $this->emailModelBuilder->createEmailModel($emailModel); $this->assertEquals($emailModel, $result); $this->assertEquals($entityClass, $result->getEntityClass()); $this->assertEquals($entityId, $result->getEntityId()); $this->assertEquals($subject, $result->getSubject()); $this->assertEquals($from, $result->getFrom()); }
/** * @dataProvider supportedMethods */ public function testProcessValidDataWithTargetEntityActivity($method) { $targetEntity = new User(); ReflectionUtil::setId($targetEntity, 123); $organization = new Organization(); ReflectionUtil::setId($organization, 1); $targetEntity->setOrganization($organization); $defaultCalendar = $this->getMockBuilder('Oro\\Bundle\\CalendarBundle\\Entity\\Calendar')->disableOriginalConstructor()->getMock(); $this->entity->setCalendar($defaultCalendar); $this->entityRoutingHelper->expects($this->once())->method('getEntityClassName')->will($this->returnValue(get_class($targetEntity))); $this->entityRoutingHelper->expects($this->once())->method('getEntityId')->will($this->returnValue($targetEntity->getId())); $this->entityRoutingHelper->expects($this->once())->method('getAction')->will($this->returnValue('activity')); $this->request->setMethod($method); $this->form->expects($this->once())->method('setData')->with($this->identicalTo($this->entity)); $this->form->expects($this->once())->method('submit')->with($this->identicalTo($this->request)); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->entityRoutingHelper->expects($this->once())->method('getEntityReference')->with(get_class($targetEntity), $targetEntity->getId())->will($this->returnValue($targetEntity)); $this->activityManager->expects($this->once())->method('addActivityTarget')->with($this->identicalTo($this->entity), $this->identicalTo($targetEntity)); $this->form->expects($this->once())->method('get')->will($this->returnValue($this->form)); $this->form->expects($this->once())->method('getData'); $this->om->expects($this->once())->method('persist')->with($this->identicalTo($this->entity)); $this->om->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $this->assertSame($defaultCalendar, $this->entity->getCalendar()); }
public function uploadConfigAction(Request $request) { $config = $this->normalizeLineBreaks($request->get('config')); /** @var Session $session */ $session = $this->get('session'); $yaml = new Yaml(); try { $parsed = $yaml::parse($config); } catch (\Exception $e) { $session->getFlashBag()->add('error', ['title' => 'There was a problem parsing your config file', 'content' => $e->getMessage()]); $request->setMethod('GET'); return $this->indexAction($request); } if (empty($parsed)) { $session->getFlashBag()->add('error', ['title' => 'The config file provided was empty', 'content' => 'Check your config file, or manually recreate it in the GUI.']); $request->setMethod('GET'); return $this->indexAction($request); } $manager = $this->get('puphpet.extension.manager'); $manager->setCustomDataAll($parsed); try { $session->getFlashBag()->add('success', ['title' => 'Success!', 'content' => 'Your previously generated config file was successfully loaded!']); $rendered = $this->render('PuphpetBundle:front:template.html.twig', ['extensions' => $manager->getExtensions(), 'messages' => $session->getFlashBag()->all()]); return $rendered; } catch (\Exception $e) { $session->getFlashBag()->clear(); $session->getFlashBag()->add('error', ['title' => 'There was a problem parsing your config file', 'content' => sprintf('<p> Please recreate your manifest manually below.</p>' . '<p>Error message:</p><p>%s</p>', $e->getMessage())]); return new RedirectResponse($this->generateUrl('puphpet.main.homepage')); } }
/** * Change user password * * @View(serializerEnableMaxDepthChecks=true) * * @Put("/profile/change-password", name="_change_password_profile") * * @param Request $request * @param $entity * * @return Response */ public function putAction(Request $request) { $request->request->set('current_password', $request->request->get('currentPassword')); $entity = $this->getUser(); if (!is_object($entity) || !$entity instanceof UserInterface) { throw new AccessDeniedException('This user does not have access to this section.'); } /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ $dispatcher = $this->get('event_dispatcher'); $event = new GetResponseUserEvent($entity, $request); $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event); if (null !== $event->getResponse()) { return $event->getResponse(); } $changePasswordType = $this->get('app.change_password.form.type'); try { $request->setMethod('PATCH'); //Treat all PUTs as PATCH $form = $this->createForm($changePasswordType, $entity, array('method' => $request->getMethod(), 'validation_groups' => array('ChangePassword', 'Default'))); $this->removeExtraFields($request, $form); $form->handleRequest($request); if ($form->isValid()) { /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ $userManager = $this->get('fos_user.user_manager'); $userManager->updateUser($entity); return $entity; } return FOSView::create(array('errors' => $form->getErrors()), Codes::HTTP_INTERNAL_SERVER_ERROR); } catch (\Exception $e) { return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR); } }
/** * @covers ::processPlaceholders * * @dataProvider placeholdersProvider */ public function testProcessPlaceholders(array $placeholders, $method, $route_match_has_no_big_pipe_option, $request_has_session, $request_has_big_pipe_nojs_cookie, array $expected_big_pipe_placeholders) { $request = new Request(); $request->setMethod($method); if ($request_has_big_pipe_nojs_cookie) { $request->cookies->set(BigPipeStrategy::NOJS_COOKIE, 1); } $request_stack = $this->prophesize(RequestStack::class); $request_stack->getCurrentRequest()->willReturn($request); $session_configuration = $this->prophesize(SessionConfigurationInterface::class); $session_configuration->hasSession(Argument::type(Request::class))->willReturn($request_has_session); $route = $this->prophesize(Route::class); $route->getOption('_no_big_pipe')->willReturn($route_match_has_no_big_pipe_option); $route_match = $this->prophesize(RouteMatchInterface::class); $route_match->getRouteObject()->willReturn($route); $big_pipe_strategy = new BigPipeStrategy($session_configuration->reveal(), $request_stack->reveal(), $route_match->reveal()); $processed_placeholders = $big_pipe_strategy->processPlaceholders($placeholders); if ($request->isMethodSafe() && !$route_match_has_no_big_pipe_option && $request_has_session) { $this->assertSameSize($expected_big_pipe_placeholders, $processed_placeholders, 'BigPipe is able to deliver all placeholders.'); foreach (array_keys($placeholders) as $placeholder) { $this->assertSame($expected_big_pipe_placeholders[$placeholder], $processed_placeholders[$placeholder], "Verifying how BigPipeStrategy handles the placeholder '{$placeholder}'"); } } else { $this->assertSame(0, count($processed_placeholders)); } }
public function test_receive_authn_request() { $expectedRelayState = 'relayState'; $request = new Request(); $request->setMethod('POST'); $request->request->add(array('SAMLRequ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9xQ3J5VE90bVJhQzM5MWlHQXFiejF3dFp0Vjk1Ym9HZHVyOFNDaEs5TEtjUHJiQ0R4cG82NEJNZ3RQazJIa1JnRTdoNVlXa0xIeG14d1pyWWkzRUFmUzZJdWNibFkzd3dZNEdFaXg4RFFoMWxZZ3B2NVRPRDhJTVZmK29VV2RwODFVbi9JcUhxTGhuU3Vwd2s2ckJZYlVGaE4vQ2xLNVVjb0RxV0hjajI3dEdLRDZhTmx4VGRTd2NZQmwzVHM9PC9kczpYNTA5Q2VydGlmaWNhdGU+PC9kczpYNTA5RGF0YT48L2RzOktleUluZm8+PC9kczpTaWduYXR1cmU+PC9BdXRoblJlcXVlc3Q+Cg==', 'RelayState' => $expectedRelayState)); $binding = new HttpPostBinding(); $eventDispatcherMock = $this->getEventDispatcherMock(); $eventDispatcherMock->expects($this->once())->method('dispatch')->willReturnCallback(function ($name, GenericEvent $event) { $this->assertEquals(Events::BINDING_MESSAGE_RECEIVED, $name); $this->assertNotEmpty($event->getSubject()); $doc = new \DOMDocument(); $doc->loadXML($event->getSubject()); $this->assertEquals('AuthnRequest', $doc->firstChild->localName); }); $binding->setEventDispatcher($eventDispatcherMock); $this->assertSame($eventDispatcherMock, $binding->getEventDispatcher()); $messageContext = new MessageContext(); $binding->receive($request, $messageContext); /** @var \LightSaml\Model\Protocol\AuthnRequest $message */ $message = $messageContext->getMessage(); $this->assertInstanceOf('LightSaml\\Model\\Protocol\\AuthnRequest', $message); $this->assertEquals($expectedRelayState, $message->getRelayState()); $this->assertNotNull($message->getSignature()); $this->assertInstanceOf('LightSaml\\Model\\XmlDSig\\AbstractSignatureReader', $message->getSignature()); $this->assertInstanceOf('LightSaml\\Model\\XmlDSig\\SignatureXmlReader', $message->getSignature()); }
/** * @expectedException Synapse\Controller\BadRequestException */ public function testGetContentAsArrayThrowsBadRequestExceptionIfContentInvalid() { $invalidJson = 'This is not JSON.'; $request = new Request([], [], [], [], [], [], $invalidJson); $request->setMethod('delete'); $response = $this->controller->execute($request); }
/** * @dataProvider supportedMethods */ public function testProcessValidData($method) { $this->request->setMethod($method); $this->model->setFrom('*****@*****.**')->setTo(array('*****@*****.**'))->setSubject('testSubject')->setBody('testBody'); $this->form->expects($this->once())->method('setData')->with($this->model); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $message = new \Swift_Message(); $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); $this->mailer->expects($this->once())->method('send')->will($this->returnValue(1)); $origin = new InternalEmailOrigin(); $folder = new EmailFolder(); $folder->setType(EmailFolder::SENT); $origin->addFolder($folder); $emailOriginRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $emailOriginRepo->expects($this->once())->method('findOneBy')->with(array('name' => InternalEmailOrigin::BAP))->will($this->returnValue($origin)); $this->em->expects($this->once())->method('getRepository')->with('OroEmailBundle:InternalEmailOrigin')->will($this->returnValue($emailOriginRepo)); $this->emailEntityBuilder->expects($this->once())->method('setOrigin')->with($this->identicalTo($origin)); $email = new EmailEntity(); $this->emailEntityBuilder->expects($this->once())->method('email')->with('testSubject', '*****@*****.**', array('*****@*****.**'))->will($this->returnValue($email)); $body = new EmailBody(); $this->emailEntityBuilder->expects($this->once())->method('body')->with('testBody', false, true)->will($this->returnValue($body)); $batch = $this->getMock('Oro\\Bundle\\EmailBundle\\Builder\\EmailEntityBatchInterface'); $this->emailEntityBuilder->expects($this->once())->method('getBatch')->will($this->returnValue($batch)); $batch->expects($this->once())->method('persist')->with($this->identicalTo($this->em)); $this->em->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->model)); $this->assertNotNull($message); $this->assertEquals(array('*****@*****.**' => null), $message->getFrom()); $this->assertEquals(array('*****@*****.**' => null), $message->getTo()); $this->assertEquals('testSubject', $message->getSubject()); $this->assertEquals('testBody', $message->getBody()); $this->assertTrue($folder === $email->getFolder()); $this->assertTrue($body === $email->getEmailBody()); }
public function testJoinAction() { $name = "GrupDeneme"; $domain = "denemegrup"; $groupResponse = $this->createGroup($this->container->get('pheetup.controller.user.group'), $name, $domain); $request = new Request(); $request->setMethod('GET'); $groupRepository = $this->em->getRepository('PheetupUserBundle:Group'); $group = $groupRepository->findOneBy(['name' => $name]); $this->assertNotEmpty($group->getId()); $userManager = $this->container->get('fos_user.user_manager'); $user = $userManager->createUser(); $user->setUsername('ahmet'); $user->setEmail('*****@*****.**'); $user->setPlainPassword('deneme'); $user->setEnabled(true); $userManager->updateUser($user); $user = $userManager->findUserBy(array('username' => 'ahmet')); $loginManager = $this->container->get('fos_user.security.login_manager'); $firewallName = $this->container->getParameter('fos_user.firewall_name'); $loginManager->logInUser($firewallName, $user); $this->assertTrue($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')); $controller = new DefaultController(); $controller->setContainer($this->container); $response = $controller->joinAction($group); $this->assertEquals($response->getContent(), "You successfully joined group"); }
private function createValidPreflightRequest() { $request = new Request(); $request->headers->set('Origin', 'localhost'); $request->headers->set('Access-Control-Request-Method', 'get'); $request->setMethod('OPTIONS'); return $request; }
/** * @param string $method * @return Request */ protected function getMockRequest($method = '') { $request = new Request(); if (!empty($method)) { $request->setMethod($method); } return $request; }
public function testHandle() { $httpKernel = $this->getKernelFromController(["AppController", "homeAction"]); $request = new Request(); $request->setMethod('GET'); $response = $httpKernel->handle($request); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); $this->assertEquals('AppController::home', $response->getContent()); }
public function testProcessValidData() { $subtotal = new Subtotal(); $amount = 42; $subtotal->setType(Subtotal::TYPE_SUBTOTAL); $subtotal->setAmount($amount); $subtotals = new ArrayCollection([$subtotal]); $this->subtotalsProvider->expects($this->any())->method('getSubtotals')->willReturn($subtotals); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->manager->expects($this->once())->method('persist')->with($this->entity); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($subtotals as $subtotal) { $this->assertEquals($amount, $propertyAccessor->getValue($this->entity, $subtotal->getType())); } }
/** * @dataProvider getMethodsProvider * @param string $method */ public function testNonSuccess($method) { $listener = $this->getListener(); $request = new Request(); $request->setMethod($method); $content = 'foobar'; $response = new Response($content, 400); $event = $this->getEvent($request, $response); $listener->onKernelResponse($event); $this->assertNull($response->getEtag()); }
/** * @param Channel $entity * @param mixed $requestValue * @param string $expectedType * * @dataProvider handleRequestDataProvider */ public function testHandleRequestChannelType(Channel $entity, $requestValue, $expectedType) { $this->request->setMethod('GET'); $expectedEntity = clone $entity; $expectedEntity->setChannelType($expectedType); $this->form->expects($this->once())->method('setData')->with($expectedEntity); $this->form->expects($this->never())->method('submit'); $this->dispatcher->expects($this->never())->method('dispatch'); $this->request->request->set('orocrm_channel_form', ['channelType' => $requestValue]); $this->handler->process($entity); }