Fix blank/empty field being returned as invalid object #222
This commit is contained in:
@@ -129,6 +129,10 @@ class ImportExport
|
||||
|
||||
# No multiple values in here, just a straight value
|
||||
if (\count($split_values) === 1) {
|
||||
if(trim($split_values[0]) === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [$split_values[0]];
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,10 @@ class ImporterTest extends TestCase
|
||||
public function testConvertStringtoObjects(): void
|
||||
{
|
||||
$tests = [
|
||||
[
|
||||
'input' => '',
|
||||
'expected' => [],
|
||||
],
|
||||
[
|
||||
'input' => 'gate',
|
||||
'expected' => ['gate']
|
||||
@@ -139,6 +143,10 @@ class ImporterTest extends TestCase
|
||||
public function testConvertObjectToString(): void
|
||||
{
|
||||
$tests = [
|
||||
[
|
||||
'input' => '',
|
||||
'expected' => ''
|
||||
],
|
||||
[
|
||||
'input' => ['gate'],
|
||||
'expected' => 'gate',
|
||||
@@ -440,6 +448,36 @@ class ImporterTest extends TestCase
|
||||
$this->assertCount(1, $subfleets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the flight importer
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function testFlightImporterEmptyCustomFields(): void
|
||||
{
|
||||
[$airline, $subfleet] = $this->insertFlightsScaffoldData();
|
||||
|
||||
$file_path = base_path('tests/data/flights_empty_fields.csv');
|
||||
$status = $this->importSvc->importFlights($file_path);
|
||||
|
||||
$this->assertCount(1, $status['success']);
|
||||
$this->assertCount(0, $status['errors']);
|
||||
|
||||
// See if it imported
|
||||
$flight = \App\Models\Flight::where([
|
||||
'airline_id' => $airline->id,
|
||||
'flight_number' => '1972'
|
||||
])->first();
|
||||
|
||||
$this->assertNotNull($flight);
|
||||
|
||||
// Check the custom fields entered
|
||||
$fields = \App\Models\FlightFieldValue::where([
|
||||
'flight_id' => $flight->id,
|
||||
])->get();
|
||||
|
||||
$this->assertCount(0, $fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
|
||||
2
tests/data/flights_empty_fields.csv
Normal file
2
tests/data/flights_empty_fields.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
airline,flight_number,route_code,route_leg,dpt_airport,arr_airport,alt_airport,days,dpt_time,arr_time,level,distance,flight_time,flight_type,route,notes,active,subfleets,fares,fields
|
||||
VMS,1972,,,KAUS,KJFK,KLGA,15,0810 CST,1235 EST,350,1477,207,J,ILEXY2 ZENZI LFK ELD J29 MEM Q29 JHW J70 STENT J70 MAGIO J70 LVZ LENDY6,"Just a flight",1,A32X,Y?price=300&cost=100&capacity=130;F?price=600&cost=400;B?,
|
||||
|
Reference in New Issue
Block a user