i new in testing.i want test function.i have installed phpunit. check many tutorials on internet.but not proper information regarding testing. here function code:
public function loginaction(request $request) { $session = $this->getrequest()->getsession(); if( $session->get('userid') && $session->get('userid') != '' && $session->get('type') == '2') { //if user login redirect login page return $this->redirect($this->generateurl('registrargeneral_dashboard')); } $em = $this->getdoctrine()->getentitymanager(); $repository = $em->getrepository('drpadminbundle:user'); if ($request->getmethod() == 'post') { $session->clear(); $username = $request->get('username'); $password = md5($request->get('password')); //find email, password type , status of user $user = $repository->findoneby(array('username' => $username, 'password' => $password,'type'=>2,'status'=>1 )); $useremail = $repository->findoneby(array('email' => $username, 'password' => $password,'type'=>2,'status'=>1 )); if ($user) { //set session of user login $session->set('userid', $user->getid()); $session->set('type', 2); $session->set('nameregistrar', $user->getfirstname()); $session->set('pictureregistrar', $user->getpicture()); //echo "<pre>";print_r($session->get('picture'));die; return $this->redirect($this->generateurl('registrargeneral_dashboard')); } if ($useremail) { $session->set('type', 2); $session->set('userid', $useremail->getid()); $session->set('nameregistrar', $useremail->getfirstname()); $session->set('pictureregistrar', $useremail->getpicture()); //echo "<pre>";print_r($session->get('picture'));die; return $this->redirect($this->generateurl('registrargeneral_dashboard')); } else { return $this->render('drpregistrargeneralbundle:pages:login.html.twig', array('name' => 'invalid email/password')); } } return $this->render('drpregistrargeneralbundle:pages:login.html.twig'); } how test function? please help
i don't know want test here exemple of can test user fonctionnalities :
public function testuserpagedown() { $client = static::createclient(); $client->request('get', '/user/login'); $this->asserttrue($client->getresponse()->issuccessful()); $client->request('get', '/user/register'); $this->asserttrue($client->getresponse()->issuccessful()); } public function testuserfirewall() { $client = static::createclient(); //trying go user routes without being logged $client->request('get', '/user/profile'); $this->asserttrue($client->getresponse()->isredirect()); $client->request('get', '/user/profile/edit'); $this->asserttrue($client->getresponse()->isredirect()); $client->request('get', '/user/profile/editpassword'); $this->asserttrue($client->getresponse()->isredirect()); } public function testuserformregister() { $client = static::createclient(); $crawler = $client->request('get', '/user/register'); $buttoncrawlernode = $crawler->selectbutton('submit_user_register'); $form = $buttoncrawlernode->form(); $testform = array( 'wineot_databundle_user[username]' => 'test', 'wineot_databundle_user[firstname]' => 'test', 'wineot_databundle_user[lastname]' => 'test', 'wineot_databundle_user[mail]' => 'test@mail.fr', 'wineot_databundle_user[plain_password][first]' => 'blabla321', 'wineot_databundle_user[plain_password][second]' => 'blabla321' ); $response = $client->getresponse(); $client->submit($form, $testform); //if submit true mean register ok $this->asserttrue($response->issuccessful()); } i hope undestand how test.
Comments
Post a Comment