Created
June 22, 2017 14:11
-
-
Save anonymous/a5faf217e88c9b3bc5763ae0cec6d896 to your computer and use it in GitHub Desktop.
Test no Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Support\Facades\DB; | |
use App\User; | |
use Illuminate\Foundation\Testing\WithoutMiddleware; | |
use Illuminate\Foundation\Testing\DatabaseMigrations; | |
use Illuminate\Foundation\Testing\DatabaseTransactions; | |
class CategoryControllerTest extends TestCase | |
{ | |
// use WithoutMiddleware; | |
use DatabaseTransactions; | |
/** | |
* A basic test example. | |
* | |
* @return void | |
*/ | |
public function testIndex() | |
{ | |
Auth::attempt(['email' => 'elton.nicolau@teste.com.br', 'password' => 'password']); | |
$response = $this->action('GET', 'Admin\CategoryController@index'); | |
$this->see('Categorias'); | |
} | |
public function testView() | |
{ | |
Auth::attempt(['email' => 'elton.nicolau@teste.com.br', 'password' => 'password']); | |
$response = $this->action('GET', 'Admin\CategoryController@view', 1); | |
$this->assertViewHas('category'); | |
} | |
public function testGetCategories() | |
{ | |
Auth::attempt(['email' => 'elton.nicolau@teste.com.br', 'password' => 'password']); | |
$this->post('/admin/category/getCategories'); | |
$this->seeJson(['draw' => 1]); | |
} | |
public function testAdd() | |
{ | |
Auth::attempt(['email' => 'elton.nicolau@teste.com.br', 'password' => 'password']); | |
$this->visit('/admin/category/add') | |
->see('Nova Categoria') | |
->type('Direção Teste', 'name') | |
->press('Salvar'); | |
$this->seeInDatabase('categories', ['name' => 'Direção Teste']); | |
} | |
public function testEdit() | |
{ | |
Auth::attempt(['email' => 'elton.nicolau@teste.com.br', 'password' => 'password']); | |
$this->visit('/admin/category/edit/1') | |
->see('Editar Categoria') | |
->type('Teste', 'name') | |
->press('Salvar'); | |
$this->seeInDatabase('categories', ['id' => 1,'name'=>'Teste']); | |
} | |
public function testDelete() | |
{ | |
Auth::attempt(['email' => 'elton.nicolau@teste.com.br', 'password' => 'password']); | |
$this->call('POST', '/admin/category/delete', ['id' => 1]); | |
$this->notSeeInDatabase('categories', ['id' => 1,'name'=>'Teste']); | |
} | |
public function testDeleteFail() | |
{ | |
Auth::attempt(['email' => 'elton.nicolau@teste.com.br', 'password' => 'password']); | |
$response = $this->call('POST', '/admin/category/delete', ['id' => 99999]); | |
$this->seeJson(['type' => 'error']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment