Skip to content
Permalink
Browse files

Add phpunit feature test for page

  • Loading branch information...
dignityinside committed Jun 19, 2019
1 parent 13ec110 commit d8f3df9c03c0da3b421b769268cd697f51d05561
Showing with 96 additions and 0 deletions.
  1. +96 −0 tests/Feature/Page/PageTest.php
@@ -0,0 +1,96 @@
<?php
namespace Tests\Page\Feature;
use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
/**
* Class PageTest
*
* @package Tests\Page\Feature
*
* @author Alexander Schilling <dignityinside@protonmail.com>
*/
class PageTest extends TestCase
{
use RefreshDatabase;
/** @var array */
public $data = [
'material_id' => 'blog',
'category_id' => 1,
'title' => 'Hallo World',
'slug' => 'hello-world',
'content' => 'test',
'status_id' => 'public',
'allow_comments' => 1,
'mainstream' => 1
];
/** @test */
public function a_guest_can_view_index_page()
{
$this->get(route('page.index'))->assertStatus(200);
}
/** @test */
public function a_user_can_view_index_page()
{
$this->actingAs(factory(User::class)->create())->get(route('page.index'))->assertStatus(200);
}
/** @test */
public function a_guest_may_not_create_page()
{
$this->get(route('page.create'))->assertStatus(403);
}
/** @test */
public function a_user_can_create_page()
{
// we are signed in
$this->actingAs(factory(User::class)->create());
// we are on create page
$this->get(route('page.create'))->assertStatus(200);
// we submit the form with data
$this->post(route('page.store'), $this->data)
->assertStatus(302)
->assertRedirect(route('page.create'))
->assertSessionHas('message', 'Страница добавлена!');
}
/** @test */
public function a_user_can_edit_page()
{
// create a page as user
$this->a_user_can_create_page();
// we are on update page
$this->get(route('page.edit', ['slug' => $this->data['slug']]))->assertStatus(200);
// we change the title
$this->data['title'] = "Hello World 2";
// we submit the form with new title
$this->patch(route('page.update', ['slug' => $this->data['slug']]), $this->data)
->assertStatus(302)
->assertRedirect(route('page.edit', ['slug' => $this->data['slug']]))
->assertSessionHas('message', 'Страница сохранена!');
}
/** @test */
public function a_guest_can_view_single_page()
{
// create a page as user
$this->a_user_can_create_page();
// we are on update page
$this->get(route('page.show', ['slug' => $this->data['slug']]))->assertStatus(200);
}
}

0 comments on commit d8f3df9

Please sign in to comment.
You can’t perform that action at this time.