From 301c015424c224c8d38807d3b341564de04cbacd Mon Sep 17 00:00:00 2001 From: Adrien Gallou Date: Sun, 25 Feb 2024 14:28:18 +0100 Subject: [PATCH] ajout de tests fonctionnels sur l'import de fichier dans le cadre de l'issue #1428 on ajoute un cas de test sur l'import de fichier. --- db/seeds/ComptaCategorie.php | 5 +++ tests/behat/bootstrap/FeatureContext.php | 36 ++++++++++++++++ .../Admin/Tresorerie/JournalImport.feature | 43 +++++++++++++++++++ tests/behat/files/test_credit_mutuel.csv | 3 ++ 4 files changed, 87 insertions(+) create mode 100644 tests/behat/features/Admin/Tresorerie/JournalImport.feature create mode 100644 tests/behat/files/test_credit_mutuel.csv diff --git a/db/seeds/ComptaCategorie.php b/db/seeds/ComptaCategorie.php index 53fe15930..96860c944 100644 --- a/db/seeds/ComptaCategorie.php +++ b/db/seeds/ComptaCategorie.php @@ -198,6 +198,11 @@ public function run() 'idevenement'=>0, 'categorie'=>'Seminaire', ], + [ + 'id'=>48, + 'idevenement'=>0, + 'categorie'=>'Outils', + ], ]; $table = $this->table('compta_categorie'); diff --git a/tests/behat/bootstrap/FeatureContext.php b/tests/behat/bootstrap/FeatureContext.php index 03eedfb98..7a9eeb6ce 100644 --- a/tests/behat/bootstrap/FeatureContext.php +++ b/tests/behat/bootstrap/FeatureContext.php @@ -188,6 +188,29 @@ public function selectHasForCurrentSelectedValue($field, $expectedValue) } } + /** + * @Then The :field field should has the following selected text :expectedValue + */ + public function selectHasForCurrentSelectedText($field, $expectedValue) + { + $node = $this->minkContext->assertSession()->fieldExists($field); + $options = $node->findAll('css', 'option'); + + $selectedValue = null; + foreach ($options as $option) { + if ($option->isSelected()) { + $selectedValue = $option->getText(); + break; + } + } + + if ($selectedValue != $expectedValue) { + throw new \Exception( + sprintf('The select has the following text "%s" (expected "%s")', $selectedValue, $expectedValue) + ); + } + } + /** * @Then the response header :arg1 should equal :arg2 @@ -205,6 +228,19 @@ public function assertResponseHeaderMatch($headerName, $regExpExpectedValue) $this->minkContext->assertSession()->responseHeaderMatches($headerName, $regExpExpectedValue); } + /** + * @Then the current URL should match :arg1 + */ + public function assertCurrentUrlContains($regex) + { + $currentUrl = $this->minkContext->getSession()->getCurrentUrl(); + + if (!preg_match($regex, $currentUrl)) { + throw new \Exception(sprintf('The current URL "%s" does not matches "%s"', $currentUrl, $regex)); + } + + } + /** * @When I follow the button of tooltip :arg1 */ diff --git a/tests/behat/features/Admin/Tresorerie/JournalImport.feature b/tests/behat/features/Admin/Tresorerie/JournalImport.feature new file mode 100644 index 000000000..6c9d850c2 --- /dev/null +++ b/tests/behat/features/Admin/Tresorerie/JournalImport.feature @@ -0,0 +1,43 @@ +Feature: Administration - Trésorerie - Journal import + + @reloadDbWithTestData + Scenario: Test d'import du fichier + Given I am logged in as admin and on the Administration + When I follow "Journal" + Then the ".content h2" element should contain "Journal" + # On vérifie qu'on a aucune entrée pour la période + When I select "2019-01-01 - 2019-12-31" from "id_periode" + And I submit the form with name "forum" + Then the current URL should match "/id_periode=13/" + When I check "also_display_classifed_entries" + And I press "Filtrer" + Then the current URL should match "/id_periode=13/" + And the current URL should match "/also_display_classifed_entries=on/" + And I should see " Aucune ecriture" + # On importe le fichier sur le crédit mutuel + When I follow "Importer un fichier CSV" + Then I should see "Import CSV" + When I select "CMUT" from "banque" + And I attach the file "test_credit_mutuel.csv" to "fichiercsv" + And I press "Soumettre" + Then I should see "Le fichier a été importé" + # On vérifie que l'import s'est bien passé + When I select "2019-01-01 - 2019-12-31" from "id_periode" + And I submit the form with name "forum" + Then the current URL should match "/id_periode=13/" + When I check "also_display_classifed_entries" + And I press "Filtrer" + Then the current URL should match "/id_periode=13/" + And the current URL should match "/also_display_classifed_entries=on/" + And I should not see " Aucune ecriture" + # Test meetup + When I follow the button of tooltip "Modifier la ligne CB MEETUP ORG SUB FACT 190323 DONT FRAIS DE COMM. 1,89 EUR" + Then I should see "Modifier une écriture" + Then The "idevenement" field should has the following selected text "Association AFUP" + Then The "idcategorie" field should has the following selected text "Meetup" + # Test Twilio + When I move backward one page + When I follow the button of tooltip "Modifier la ligne CB Twilio SZ5KZ54M FACT 090223 DONT FRAIS DE COMM. 0,26 EUR" + Then I should see "Modifier une écriture" + Then The "idevenement" field should has the following selected text "Association AFUP" + Then The "idcategorie" field should has the following selected text "Outils" diff --git a/tests/behat/files/test_credit_mutuel.csv b/tests/behat/files/test_credit_mutuel.csv new file mode 100644 index 000000000..aee36cf40 --- /dev/null +++ b/tests/behat/files/test_credit_mutuel.csv @@ -0,0 +1,3 @@ +Date;Date de valeur;Débit;Crédit;Libellé;Solde +31/01/2019;02/02/2019;-69,73;;CB MEETUP ORG SUB FACT 190323 DONT FRAIS DE COMM. 1,89 EUR ;23147,48 +31/01/2019;02/02/2019;-9,88;;CB Twilio SZ5KZ54M FACT 090223 DONT FRAIS DE COMM. 0,26 EUR ;23136,32