From a3aaa98ce06af463c0d2f3a3a8864569ecac986e Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Fri, 19 May 2017 14:19:07 -0400 Subject: [PATCH] 105 - Validation and Redirects --- .../Backstage/ConcertsController.php | 4 +++ tests/Feature/Backstage/AddConcertTest.php | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/app/Http/Controllers/Backstage/ConcertsController.php b/app/Http/Controllers/Backstage/ConcertsController.php index 855ac28..e480c06 100644 --- a/app/Http/Controllers/Backstage/ConcertsController.php +++ b/app/Http/Controllers/Backstage/ConcertsController.php @@ -16,6 +16,10 @@ class ConcertsController extends Controller public function store() { + $this->validate(request(), [ + 'title' => ['required'], + ]); + $concert = Concert::create([ 'title' => request('title'), 'subtitle' => request('subtitle'), diff --git a/tests/Feature/Backstage/AddConcertTest.php b/tests/Feature/Backstage/AddConcertTest.php index 7076494..0483a80 100644 --- a/tests/Feature/Backstage/AddConcertTest.php +++ b/tests/Feature/Backstage/AddConcertTest.php @@ -12,6 +12,12 @@ class AddConcertTest extends TestCase { use DatabaseMigrations; + private function from($url) + { + session()->setPreviousUrl(url($url)); + return $this; + } + /** @test */ function promoters_can_view_the_add_concert_form() { @@ -93,4 +99,30 @@ class AddConcertTest extends TestCase $response->assertRedirect('/login'); $this->assertEquals(0, Concert::count()); } + + /** @test */ + function title_is_required() + { + $user = factory(User::class)->create(); + + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ + 'title' => '', + 'subtitle' => 'with Cruel Hand and Backtrack', + 'additional_information' => "You must be 19 years of age to attend this concert.", + 'date' => '2017-11-18', + 'time' => '8:00pm', + 'venue' => 'The Mosh Pit', + 'venue_address' => '123 Fake St.', + 'city' => 'Laraville', + 'state' => 'ON', + 'zip' => '12345', + 'ticket_price' => '32.50', + 'ticket_quantity' => '75', + ]); + + $response->assertStatus(302); + $response->assertRedirect('/backstage/concerts/new'); + $response->assertSessionHasErrors('title'); + $this->assertEquals(0, Concert::count()); + } }