php - How to test update action? -
i trying test updateaction allows update users in database don't know how can test it... have succed test createaction add user in database. user id have created udpdate this.
this function testcreate :
public function testcreate() { $crawler = $this->client->request('get', '/admin/user/new'); $buttoncrawlernode = $crawler->selectbutton('submit'); $form = $buttoncrawlernode->form(array( 'myapp_usertype[email]' => 'testadd@gmail.fr', 'myapp_usertype[role]' => 'role_user', 'myapp_usertype[password][first]' => 'test', 'myapp_usertype[password][second]' => 'test', )); $this->client->submit($form); }
not dry, can try:
public function testupdate() { $user = static::$kernel->getcontainer()->get('doctrine')->getrepository('youruserbundle:user')->findonebyemail('testadd@gmail.fr'); $crawler = $client->request('get', '/admin/user/edit/'.$user->getid()); $form = $crawler->selectbutton('submit')->form(); $form = $buttoncrawlernode->form(array( 'myapp_usertype[email]' => 'another@gmail.fr', 'myapp_usertype[role]' => 'role_another', 'myapp_usertype[password][first]' => 'test', 'myapp_usertype[password][second]' => 'test', )); $crawler = $client->submit($form); $user = static::$kernel->getcontainer()->get('doctrine')->getrepository('youruserbundle:user')->find($user->getid()); $this->assertequals( 'another@gmail.fr', $user->getemail() ); $this->assertequals( 'role_another', $user->getrole() ); }
Comments
Post a Comment