Commit 6bf4720243b9115741ad652f2f46e767960a594e

Authored by Gabriela Mayoli
Committed by gabrielamayoli
1 parent 64e36f3f
Exists in master and in 1 other branch 3.1

Atualização de primeiros testes do primeiro controller da nova coleta.

src/Cacic/WSBundle/Controller/NeoController.php
@@ -19,7 +19,8 @@ use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; @@ -19,7 +19,8 @@ use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
19 19
20 use Cacic\CommonBundle\Entity\Computador; 20 use Cacic\CommonBundle\Entity\Computador;
21 use Cacic\CommonBundle\Entity\LogAcesso; 21 use Cacic\CommonBundle\Entity\LogAcesso;
22 -use Cacic\CommonBundle\Entity\SoRepository; 22 +use Cacic\CommonBundle\Entity\So;
  23 +
23 24
24 class NeoController extends Controller { 25 class NeoController extends Controller {
25 26
@@ -61,18 +62,25 @@ class NeoController extends Controller { @@ -61,18 +62,25 @@ class NeoController extends Controller {
61 // JSON Serialization 62 // JSON Serialization
62 //$usuario = $serializer->deserialize($data, 'Usuario', 'json'); 63 //$usuario = $serializer->deserialize($data, 'Usuario', 'json');
63 $usuario = json_decode($data); 64 $usuario = json_decode($data);
64 - $logger->debug("JSON login received data".print_r($usuario, true)); 65 + $logger->debug("JSON login received data".print_r($usuario, true)); //user e password
65 $_SERVER['SERVER_ADDR'] = $this->getRequest()->getUri(); 66 $_SERVER['SERVER_ADDR'] = $this->getRequest()->getUri();
66 67
67 $auth = $this->forward('CacicCommonBundle:Security:login', array( 68 $auth = $this->forward('CacicCommonBundle:Security:login', array(
68 - 'username' => $usuario->user,  
69 - 'password' => $usuario->password, 69 + "username" => $usuario->user,
  70 + "password" => $usuario->password,
70 )); 71 ));
  72 + $logger->debug("JSON login received data".print_r($auth, true)); //dados .twig
  73 +
71 74
72 $session = $request->getSession(); 75 $session = $request->getSession();
73 76
  77 + //Gera chave criptografada
  78 + $chave = "123456";
  79 + $chavecrip = md5($chave);
  80 +
74 $auth->setContent(json_encode(array( 81 $auth->setContent(json_encode(array(
75 - 'session' => $session->getId() 82 + 'session' => $session->getId(),
  83 + 'chavecrip' => $chavecrip
76 ))); 84 )));
77 85
78 return $auth; 86 return $auth;
src/Cacic/WSBundle/Tests/Controller/NeoControllerTest.php
@@ -12,7 +12,8 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -12,7 +12,8 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
12 use Symfony\Component\HttpFoundation\Session; 12 use Symfony\Component\HttpFoundation\Session;
13 use Symfony\Component\Serializer\Serializer; 13 use Symfony\Component\Serializer\Serializer;
14 use Symfony\Component\Serializer\Encoder\JsonEncoder; 14 use Symfony\Component\Serializer\Encoder\JsonEncoder;
15 -use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; 15 +
  16 +
16 17
17 class NeoControllerTest extends WebTestCase 18 class NeoControllerTest extends WebTestCase
18 { 19 {
@@ -69,17 +70,22 @@ class NeoControllerTest extends WebTestCase @@ -69,17 +70,22 @@ class NeoControllerTest extends WebTestCase
69 "password": "123456" 70 "password": "123456"
70 }' 71 }'
71 ); 72 );
72 - $logger->debug("Dados JSON de login enviados \n".$this->client->getRequest()->getcontent()); 73 + $logger->debug("Dados JSON de login enviados\n".$this->client->getRequest()->getcontent());//user e password
73 74
74 $response = $this->client->getResponse(); 75 $response = $this->client->getResponse();
  76 + $logger->debug("Response:\n".print_r($response,true)); // arrays session e chavecrip
75 $data = $response->getContent(); 77 $data = $response->getContent();
76 - $logger->debug("Response data: \n".print_r($data,true)); 78 + $logger->debug("Response data:\n".print_r($data,true)); //session e chavecrip
77 // JSON Serialization 79 // JSON Serialization
78 $json = json_decode($data, true); 80 $json = json_decode($data, true);
  81 + $logger->debug("Response json: \n".print_r($json,true)); //session e chavecrip
79 $session = $json['session']; 82 $session = $json['session'];
  83 + $chavecrip= $json['chavecrip'];
80 84
81 $this->assertTrue(is_string($session)); 85 $this->assertTrue(is_string($session));
82 86
  87 + $this->assertTrue(is_string($chavecrip));
  88 +
83 89
84 } 90 }
85 91
@@ -105,7 +111,7 @@ class NeoControllerTest extends WebTestCase @@ -105,7 +111,7 @@ class NeoControllerTest extends WebTestCase
105 111
106 $response = $this->client->getResponse(); 112 $response = $this->client->getResponse();
107 $data = $response->getContent(); 113 $data = $response->getContent();
108 - $logger->debug("Response data: \n".print_r($data,true)); 114 +
109 // JSON Serialization 115 // JSON Serialization
110 $json = json_decode($data, true); 116 $json = json_decode($data, true);
111 $session = $json['session']; 117 $session = $json['session'];
@@ -162,7 +168,7 @@ class NeoControllerTest extends WebTestCase @@ -162,7 +168,7 @@ class NeoControllerTest extends WebTestCase
162 168
163 $response = $this->client->getResponse(); 169 $response = $this->client->getResponse();
164 $status = $response->getStatusCode(); 170 $status = $response->getStatusCode();
165 - $logger->debug("Response status: $status"); 171 + $logger->debug("Response status AAAAAAAAAAAAAAAAAAAAAAAAAAAA: $status");
166 172
167 $this->assertEquals($status, 200); 173 $this->assertEquals($status, 200);
168 174