Skip to content

Commit

Permalink
Issue afup#1110 tests fonctionnels Personnes physiques CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Dec 4, 2021
1 parent 8dfdedd commit 1ee0fa9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sources/AppBundle/Controller/Admin/Members/UserExportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ public function __invoke(Request $request)
{
$isActive = $request->query->getBoolean('isActive');
$isCompanyManager = $request->query->getBoolean('isCompanyManager');
$filename = tempnam(sys_get_temp_dir(), 'export_personnes_physiques_');
$file = new SplFileObject($filename, 'w');
$baseName = 'export_personnes_physiques';
if ($isActive) {
$baseName .= '_actives';
}
if ($isCompanyManager) {
$baseName .= '_managers';
}
$tmpFile = tempnam(sys_get_temp_dir(), $baseName);
$file = new SplFileObject($tmpFile, 'w');
$users = $this->userRepository->search('lastname', 'asc', null, null, null, $isActive, $isCompanyManager);
foreach ($users as $user) {
$file->fputcsv([
Expand All @@ -33,7 +40,7 @@ public function __invoke(Request $request)
]);
}
$response = new BinaryFileResponse($file);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'export_personnes_physiques.csv');
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $baseName . '.csv');

return $response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,30 @@ Feature: Administration - Partie Personnes physiques - cotisations
Then I should see "Cotisations de MyCorp"
When I follow the button of tooltip "Télécharger la facture"
Then the response header "Content-disposition" should equal 'attachment; filename="MyCorp_COTIS-2018-201_13072018.pdf"'

@reloadDbWithTestData
Scenario: On test l'export CSV des "Personnes physiques en CSV"
Given I am logged in as admin and on the Administration
And I follow "Personnes physiques"
Then I should see "Personnes physiques"
Then I should see "Exports"
And I follow "Toutes les personnes physiques en CSV"
Then the response header "Content-disposition" should equal 'attachment; filename="export_personnes_physiques.csv"'

@reloadDbWithTestData
Scenario: On test l'export CSV des "Personnes physiques actives en CSV"
Given I am logged in as admin and on the Administration
And I follow "Personnes physiques"
Then I should see "Exports"
Then I should see "Personnes physiques"
And I follow "Export des personnes physiques actives en CSV"
Then the response header "Content-disposition" should equal 'attachment; filename="export_personnes_physiques_actives.csv"'

@reloadDbWithTestData
Scenario: On test l'export CSV des "Personnes physiques actives et company managers en CSV"
Given I am logged in as admin and on the Administration
And I follow "Personnes physiques"
Then I should see "Exports"
Then I should see "Personnes physiques"
And I follow "Export des personnes physiques actives et company managers en CSV"
Then the response header "Content-disposition" should equal 'attachment; filename="export_personnes_physiques_actives_managers.csv"'

0 comments on commit 1ee0fa9

Please sign in to comment.