<?php
/**
 * Created by PhpStorm.
 * User: oriol
 * Date: 21/04/16
 * Time: 09:29
 */

namespace tests\controllers;

use App\Http\Controllers\ConfirmarMatriculesController;
use APP\Acces;
class ConfirmarMatriculesControllerTest extends \TestCase
{
    public function testConfirmarMatriculesControllerTest()
    {
        $ConfirmarMatriculesControllerTest = new ConfirmarMatriculesController();
    }
    public function testllistarAccessos(){
        $ConfirmarMatriculesController = new ConfirmarMatriculesController();
        $accessos = $ConfirmarMatriculesController->llistarAccessos();
        $accessos = $accessos->get();
        $this->assertEquals(count($accessos),28);
    }
    /**
     *S'envia el json corresponent amb el que es vol tetejar Acces de vehicle
     * amb lectura de matricula incorrecta per tant no autoritzat
     */
    public function testActualitzarMatricula(){
        $Acces = new Acces();
        $this->WithoutMiddleware();
        $dades = array_add(['matricula' => '9875CXP'], 'id_acces', 16);
        $this->call('POST', '/confirmar', $dades);
        $this->assertRedirectedTo('/confirmar');
        $resultat = $Acces->where('id', 16)->get();
        $this->assertEquals($resultat[0]->matricula,'9875CXP');

    }
    public function testborrarBadAcces(){
        $Acces = new Acces();
        $this->WithoutMiddleware();
        $dades = array_add(['matricula' => '9875CXP'], 'id_acces', 20);
        $this->call('POST', '/confirmar/borrar', $dades);
        $resultat = $Acces->where('id', 20)->get();
        $this->assertEquals(count($resultat),0);

    }
    public function testbonaLecturaAcces(){
        $Acces = new Acces();
        $this->WithoutMiddleware();
        $dades = array_add(['matricula' => '9875CXP'],'id_acces', 23);
        $this->call('POST', '/confirmar/matricula', $dades);
        $resultat = $Acces->where('id', 23)->get();
        $this->assertEquals($resultat[0]->lectura_matricula,1);

    }
}
