Skip to content

Commit 5d18d5e

Browse files
authored
Merge pull request #30 from intraordinaire/feature/phpspreadsheet
🐛 Fixing date format if contain slashes
2 parents c2310db + ede7301 commit 5d18d5e

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/Distilleries/Expendable/States/ExportStateTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function postExport(Request $request)
5353
$dateStart = !empty($data['range']) && !empty($data['range']['start']) ? $data['range']['start'] : Carbon::now()->format('Y-m-d');
5454
$dateEnd = !empty($data['range']) && !empty($data['range']['end']) ? $data['range']['end'] : Carbon::now()->format('Y-m-d');
5555
$type = !empty($data['type']) ? $data['type'] : 'csv';
56-
$filename = $dateStart . ' ' . $dateEnd . '.' . $type;
56+
$filename = str_replace('/', '-', $dateStart . '_' . $dateEnd) . '.' . mb_strtolower($type);
5757

5858
return (new BaseExport($this->model, $data))->export($filename);
5959
}

tests/Http/Controllers/Backend/LanguageControllerTest.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function testExportCsv()
276276
]);
277277

278278
$this->assertContains('HTTP/1.1 200 OK', (string)$response);
279-
$this->assertContains('filename="'.$dateBegin.' '.$dateEnd.'.csv"', (string)$response);
279+
$this->assertContains('filename='.$dateBegin.'_'.$dateEnd.'.csv', (string)$response);
280280
}
281281

282282
public function testExportXls()
@@ -305,7 +305,37 @@ public function testExportXls()
305305

306306

307307
$this->assertContains('HTTP/1.1 200 OK', (string)$response);
308-
$this->assertContains('filename="'.$dateBegin.' '.$dateEnd.'.xls"', (string)$response);
308+
$this->assertContains('filename='.$dateBegin.'_'.$dateEnd.'.xls', (string)$response);
309+
310+
}
311+
312+
public function testExportDateFormat()
313+
{
314+
315+
$faker = Faker\Factory::create();
316+
$data = [
317+
'libelle' => str_replace('\'', '', $faker->country),
318+
'iso' => $faker->countryCode,
319+
'not_visible' => 0,
320+
'is_default' => 1,
321+
'status' => 1,
322+
];
323+
\Distilleries\Expendable\Models\Language::create($data);
324+
325+
$dateBegin = date('d/m/Y', time() - (24 * 60 * 60));
326+
$dateEnd = date('d/m/Y', time() + (24 * 60 * 60));
327+
\File::delete(storage_path('exports'));
328+
$response = $this->call('POST', action('Backend\LanguageController@postExport'), [
329+
'range' => [
330+
'start' => $dateBegin,
331+
'end' => $dateEnd
332+
],
333+
'type' => 'xls'
334+
]);
335+
336+
337+
$this->assertContains('HTTP/1.1 200 OK', (string)$response);
338+
$this->assertContains('filename='.str_replace('/', '-', $dateBegin . '_' . $dateEnd).'.xls', (string)$response);
309339

310340
}
311341

0 commit comments

Comments
 (0)