Advertisement
Guest User

Untitled

a guest
May 13th, 2017
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tests\AppBundle\Controller;
  4.  
  5. use Tests\ApiTestCaseBase;
  6.  
  7. class AuthControllerTest extends ApiTestCaseBase
  8. {
  9.     public function testPostRegsiterNewUser()
  10.     {
  11.         $data = [
  12.             'username' => 'test_login',
  13.             'email' => 'test@gmail.com',
  14.             'plainPassword' => [
  15.                 'first' => 'test123', 'second' => 'test123'
  16.             ]
  17.         ];
  18.        
  19.         $this->makePOSTRequest($data);
  20.  
  21.         $this->assertEquals(201, $this->client->getResponse()->getStatusCode());
  22.     }
  23.  
  24.     public function testPostRegsiterNewUserWithInvalidEmail()
  25.     {
  26.         $data = [
  27.             'username' => 'test_login',
  28.             'email' => 'testgmail.com',
  29.             'plainPassword' => [
  30.                 'first' => 'test123', 'second' => 'test123'
  31.             ]
  32.         ];
  33.  
  34.         $this->makePOSTRequest($data);
  35.  
  36.         $this->assertEquals(400, $this->client->getResponse()->getStatusCode());
  37.     }
  38.    
  39.     public function testPOSTLoginUser()
  40.     {
  41.         $userName = "test_login";
  42.         $password = "test_login_2017";
  43.  
  44.         $user = $this->createUser($userName, $password);
  45.  
  46.         $this->client->request(
  47.             'POST', '/auth/login', [], [], [
  48.             'CONTENT_TYPE' => 'application/json',
  49.             'PHP_AUTH_USER' => $userName,
  50.             'PHP_AUTH_PW' => $password,
  51.             ]
  52.         );
  53.        
  54.         $responseArr = json_decode($this->client->getResponse()->getContent(), true);
  55.  
  56.         $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
  57.         $this->assertArrayHasKey('token', $responseArr);
  58.     }
  59.  
  60.     private function makePOSTRequest($data)
  61.     {
  62.         $this->client->request(
  63.             'POST',
  64.             '/auth/register',
  65.             [],
  66.             [],
  67.             ['CONTENT_TYPE' => 'application/json'],
  68.             json_encode($data)
  69.         );
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement