/** * @Route("/login", name="login_route") * * @return string */ public function loginAction() { $authenticationUtils = $this->get('security.authentication_utils'); $error = $authenticationUtils->getLastAuthenticationError(); // last username entered by the user $lastUsername = $authenticationUtils->getLastUsername(); $user = new User(); $user->setEmail($lastUsername); $form = $this->createFormBuilder($user)->setAction($this->generateUrl('login_check'))->add('_username', 'email', array('label' => 'Email'))->add('password', 'password', array('label' => 'Passwort'))->add('save', 'submit', array('label' => 'Einloggen', 'attr' => array('class' => 'btn btn-primary')))->getForm(); return $this->render('user/login.html.twig', array('error' => $error, 'form' => $form->createView())); }
/** * tests setLicenseeId() */ public function testGetLicenseeIdShouldBeEqualSetLicenseeId() { $this->user->setLicenseeId('test'); $this->assertEquals('test', $this->user->getLicenseeId()); }
/** * tests the formdelAction with an existing user */ public function testFormdelActionExistingUser() { $user = new User(); $user->setId('someId'); $user->setEmail('*****@*****.**'); $user->setRoles('ROLE_USER'); $this->loadMongoContainer(); $request = $this->getMockBuilder("Symfony\\Component\\HttpFoundation\\Request")->disableOriginalConstructor()->getMock(); $postMock = $this->getMockBuilder("Symfony\\Component\\HttpFoundation\\ParameterBag")->disableOriginalConstructor()->getMock(); $postArray = array('formtype' => 'user', 'id' => $user->getId()); $postMock->expects($this->once())->method("all")->will($this->returnValue($postArray)); $request->request = $postMock; $this->repository->expects($this->once())->method('find')->with($user->getId())->will($this->returnValue($user)); $dm = $this->getMockBuilder('Doctrine\\ODM\\MongoDB\\DocumentManager')->disableOriginalConstructor()->getMock(); $this->service->expects($this->once())->method('getManager')->will($this->returnValue($dm)); $dm->expects($this->once())->method('remove')->with($user); $dm->expects($this->once())->method('flush'); $controller = new DefaultController(); $controller->setContainer($this->container); /* @var $response \Symfony\Component\HttpFoundation\Response */ $response = $controller->formdelAction($request); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); $json = $response->getContent(); $this->assertJson($json); $json = json_decode($json); $this->assertFalse($json->error); }
private function installUsers(array $users, ManagerRegistry $mongo, DocumentManager $dm) { $repository = $mongo->getRepository('DembeloMain:User'); $encoder = $this->getContainer()->get('security.password_encoder'); if (!isset($this->dummyData['users'])) { $this->dummyData['users'] = array(); } foreach ($users as $userData) { $user = $repository->findOneByEmail($userData['email']); if (is_null($user)) { $user = new User(); $user->setEmail($userData['email']); $password = $encoder->encodePassword($user, $userData['password']); $user->setPassword($password); $user->setRoles($userData['roles']); if (in_array('ROLE_LICENSEE', $userData['roles'])) { $user->setLicenseeId($this->dummyData['licensees'][0]->getId()); } $dm->persist($user); } $this->dummyData['users'][] = $user; } }