113 - Viewing the Update Form

Just the view, saving changes not yet implemented.
This commit is contained in:
Adam Wathan
2017-06-28 13:44:06 -04:00
parent 5157129cca
commit a8673b2036
7 changed files with 305 additions and 8 deletions

View File

@@ -0,0 +1,84 @@
<?php
namespace Tests\Feature\Backstage;
use App\User;
use App\Concert;
use Carbon\Carbon;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class EditConcertTest extends TestCase
{
use DatabaseMigrations;
/** @test */
function promoters_can_view_the_edit_form_for_their_own_unpublished_concerts()
{
$this->disableExceptionHandling();
$user = factory(User::class)->create();
$concert = factory(Concert::class)->create(['user_id' => $user->id]);
$this->assertFalse($concert->isPublished());
$response = $this->actingAs($user)->get("/backstage/concerts/{$concert->id}/edit");
$response->assertStatus(200);
$this->assertTrue($response->data('concert')->is($concert));
}
/** @test */
function promoters_cannot_view_the_edit_form_for_their_own_published_concerts()
{
$user = factory(User::class)->create();
$concert = factory(Concert::class)->states('published')->create(['user_id' => $user->id]);
$this->assertTrue($concert->isPublished());
$response = $this->actingAs($user)->get("/backstage/concerts/{$concert->id}/edit");
$response->assertStatus(403);
}
/** @test */
function promoters_cannot_view_the_edit_form_for_other_concerts()
{
$user = factory(User::class)->create();
$otherUser = factory(User::class)->create();
$concert = factory(Concert::class)->create(['user_id' => $otherUser->id]);
$response = $this->actingAs($user)->get("/backstage/concerts/{$concert->id}/edit");
$response->assertStatus(404);
}
/** @test */
function promoters_see_a_404_when_attempting_to_view_the_edit_form_for_a_concert_that_does_not_exist()
{
$user = factory(User::class)->create();
$response = $this->actingAs($user)->get("/backstage/concerts/999/edit");
$response->assertStatus(404);
}
/** @test */
function guests_are_asked_to_login_when_attempting_to_view_the_edit_form_for_any_concert()
{
$otherUser = factory(User::class)->create();
$concert = factory(Concert::class)->create(['user_id' => $otherUser->id]);
$response = $this->get("/backstage/concerts/{$concert->id}/edit");
$response->assertStatus(302);
$response->assertRedirect('/login');
}
/** @test */
function guests_are_asked_to_login_when_attempting_to_view_the_edit_form_for_a_concert_that_does_not_exist()
{
$response = $this->get("/backstage/concerts/999/edit");
$response->assertStatus(302);
$response->assertRedirect('/login');
}
}

View File

@@ -20,10 +20,6 @@ class ViewConcertListTest extends TestCase
{
parent::setUp();
TestResponse::macro('data', function ($key) {
return $this->original->getData()[$key];
});
Collection::macro('assertContains', function ($value) {
Assert::assertTrue($this->contains($value), "Failed asserting that the collection contains the specified value.");
});

View File

@@ -4,6 +4,7 @@ namespace Tests;
use Exception;
use App\Exceptions\Handler;
use Illuminate\Foundation\Testing\TestResponse;
use Illuminate\Contracts\Debug\ExceptionHandler;
abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
@@ -20,6 +21,10 @@ abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
protected function setUp()
{
parent::setUp();
TestResponse::macro('data', function ($key) {
return $this->original->getData()[$key];
});
}
protected function disableExceptionHandling()