<?php
/**
 * Created by PhpStorm.
 * User: oriol
 * Date: 24/04/16
 * Time: 22:18
 */

namespace tests\controllers;
use App\Http\Controllers\SancioController;
use App\Sancio;
use App\Acces;

class SancioControllerTest extends \TestCase
{
    public function testSancioControllerCanBeCreated()
    {
        $SancioController = new SancioController();
    }
    public function testPostSancionar(){
        $sancio = new Sancio();
        $Acces = new Acces();
        $this->WithoutMiddleware();
        $dades = (['id' => 33]);
        //echo $SancioController->postSancionar($dades);
        $this->call('POST', '/sancions', $dades);
        $resultat = $sancio->where('id_acces', 33)->get();
        $this->assertEquals($resultat[0]->matricula,"9436FZP");
        $this->assertEquals($resultat->count(),1);
        $resultat = $Acces->where('id',33)->get();
        $this->assertEquals($resultat[0]->sancionat,1);
    }
    public function testmarcarErrorLectura(){
        $Acces = new Acces();
        $this->WithoutMiddleware();
        $request = (['id' => 33]);
        $this->call('POST', '/sancions/errorlectura', $request);
        $this->assertRedirectedTo('/sancions', $with = []);
        $resultat = $Acces->where('id', 33)->get();
        $this->assertEquals($resultat[0]->lectura_matricula,0);
    }
    public function testautoritzarAcces(){
        $Acces = new Acces();
        $this->WithoutMiddleware();
        $request = (['id' => 33]);
        $this->call('POST', '/sancions/autoritzar', $request);
        $this->assertRedirectedTo('/sancions', $with = []);
        $resultat = $Acces->where('id', 33)->get();
        $this->assertEquals($resultat[0]->acces_autoritzat,True);
    }
}
