mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
106 - Converting Empty Strings to Null
This commit is contained in:
@@ -15,6 +15,9 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $middleware = [
|
||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
18
app/Http/Middleware/TrimStrings.php
Normal file
18
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as BaseTrimmer;
|
||||
|
||||
class TrimStrings extends BaseTrimmer
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class CreateConcertsTable extends Migration
|
||||
Schema::create('concerts', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('title');
|
||||
$table->string('subtitle');
|
||||
$table->string('subtitle')->nullable();
|
||||
$table->datetime('date');
|
||||
$table->integer('ticket_price');
|
||||
$table->string('venue');
|
||||
|
||||
@@ -125,4 +125,44 @@ class AddConcertTest extends TestCase
|
||||
$response->assertSessionHasErrors('title');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function subtitle_is_optional()
|
||||
{
|
||||
$this->disableExceptionHandling();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
$response = $this->actingAs($user)->post('/backstage/concerts', [
|
||||
'title' => 'No Warning',
|
||||
'subtitle' => '',
|
||||
'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',
|
||||
]);
|
||||
|
||||
tap(Concert::first(), function ($concert) use ($response) {
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect("/concerts/{$concert->id}");
|
||||
|
||||
$this->assertEquals('No Warning', $concert->title);
|
||||
$this->assertNull($concert->subtitle);
|
||||
$this->assertEquals("You must be 19 years of age to attend this concert.", $concert->additional_information);
|
||||
$this->assertEquals(Carbon::parse('2017-11-18 8:00pm'), $concert->date);
|
||||
$this->assertEquals('The Mosh Pit', $concert->venue);
|
||||
$this->assertEquals('123 Fake St.', $concert->venue_address);
|
||||
$this->assertEquals('Laraville', $concert->city);
|
||||
$this->assertEquals('ON', $concert->state);
|
||||
$this->assertEquals('12345', $concert->zip);
|
||||
$this->assertEquals(3250, $concert->ticket_price);
|
||||
$this->assertEquals(75, $concert->ticketsRemaining());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user