From a8673b20369be09e0a7087b9e2fa91285c3e6634 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Wed, 28 Jun 2017 13:44:06 -0400 Subject: [PATCH] 113 - Viewing the Update Form Just the view, saving changes not yet implemented. --- .../Backstage/ConcertsController.php | 11 + .../views/backstage/concerts/edit.blade.php | 204 ++++++++++++++++++ .../views/backstage/concerts/index.blade.php | 3 - routes/web.php | 2 +- tests/Feature/Backstage/EditConcertTest.php | 84 ++++++++ .../Feature/Backstage/ViewConcertListTest.php | 4 - tests/TestCase.php | 5 + 7 files changed, 305 insertions(+), 8 deletions(-) create mode 100644 resources/views/backstage/concerts/edit.blade.php create mode 100644 tests/Feature/Backstage/EditConcertTest.php diff --git a/app/Http/Controllers/Backstage/ConcertsController.php b/app/Http/Controllers/Backstage/ConcertsController.php index 6d9be22..7030596 100644 --- a/app/Http/Controllers/Backstage/ConcertsController.php +++ b/app/Http/Controllers/Backstage/ConcertsController.php @@ -55,4 +55,15 @@ class ConcertsController extends Controller return redirect()->route('concerts.show', $concert); } + + public function edit($id) + { + $concert = Auth::user()->concerts()->findOrFail($id); + + abort_if($concert->isPublished(), 403); + + return view('backstage.concerts.edit', [ + 'concert' => $concert, + ]); + } } diff --git a/resources/views/backstage/concerts/edit.blade.php b/resources/views/backstage/concerts/edit.blade.php new file mode 100644 index 0000000..7620a3c --- /dev/null +++ b/resources/views/backstage/concerts/edit.blade.php @@ -0,0 +1,204 @@ +@extends('layouts.master') + +@section('body') +
+ +
+ +
+
+

Edit concert

+
+
+
+ {{ csrf_field() }} + {{ method_field('PATCH') }} + + @if ($errors->any()) +
+
+

+ There {{ $errors->count() == 1 ? 'is' : 'are' }} {{ $errors->count() }} {{ str_plural('error', $errors->count() )}} with this concert: +

+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+
+ @endif + +
+
+
+
+
+

Concert Details

+

Tell us who's playing! (Please be Slayer!)

+

Include the headliner in the concert name, use the subtitle section to list any opening bands, and add any important information to the description.

+
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+
+
+
+
+
+
+

Date & Time

+

True metalheads really only care about the obscure openers, so make sure they don't get there late!

+
+
+
+
+
+
+
+
+ + +
+
+
+ +
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Venue Information

+

Where's the show? Let attendees know the venue name and address so they can bring the mosh.

+
+
+
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Tickets & Pricing

+

Set your ticket price and availability, but don't forget, metalheads are cheap so keep it reasonable.

+
+
+
+
+
+
+
+
+ +
+ + $ + + +
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+ +
+
+ + + +@endsection diff --git a/resources/views/backstage/concerts/index.blade.php b/resources/views/backstage/concerts/index.blade.php index 895a0ec..74435db 100644 --- a/resources/views/backstage/concerts/index.blade.php +++ b/resources/views/backstage/concerts/index.blade.php @@ -48,9 +48,6 @@ {{ $concert->formatted_date }} @ {{ $concert->formatted_start_time }}

-
- Edit -
diff --git a/routes/web.php b/routes/web.php index 05dc605..bb49481 100644 --- a/routes/web.php +++ b/routes/web.php @@ -23,5 +23,5 @@ Route::group(['middleware' => 'auth', 'prefix' => 'backstage', 'namespace' => 'B Route::get('/concerts', 'ConcertsController@index'); Route::get('/concerts/new', 'ConcertsController@create')->name('backstage.concerts.new'); Route::post('/concerts', 'ConcertsController@store'); + Route::get('/concerts/{id}/edit', 'ConcertsController@edit')->name('backstage.concerts.edit'); }); - diff --git a/tests/Feature/Backstage/EditConcertTest.php b/tests/Feature/Backstage/EditConcertTest.php new file mode 100644 index 0000000..e193ef0 --- /dev/null +++ b/tests/Feature/Backstage/EditConcertTest.php @@ -0,0 +1,84 @@ +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'); + } +} diff --git a/tests/Feature/Backstage/ViewConcertListTest.php b/tests/Feature/Backstage/ViewConcertListTest.php index da01d9a..c5d53ba 100644 --- a/tests/Feature/Backstage/ViewConcertListTest.php +++ b/tests/Feature/Backstage/ViewConcertListTest.php @@ -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."); }); diff --git a/tests/TestCase.php b/tests/TestCase.php index 3de88c5..76387b6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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()