From aff87c4be0e51cb80cbdeb562a1ac45819bca016 Mon Sep 17 00:00:00 2001 From: Giuseppe Foti Date: Tue, 30 Jan 2024 18:06:53 +0100 Subject: [PATCH] Aggiunti test per codice fiscale Signed-off-by: Giuseppe Foti --- includes/gcmi-custom-lib.php | 14 +-- tests/test-class-gcmi-codicefiscale.php | 134 ++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 tests/test-class-gcmi-codicefiscale.php diff --git a/includes/gcmi-custom-lib.php b/includes/gcmi-custom-lib.php index 0631701..2af7aa5 100644 --- a/includes/gcmi-custom-lib.php +++ b/includes/gcmi-custom-lib.php @@ -187,17 +187,17 @@ function ( $item ) { * @param bool $var_export true to print the var_export output. */ function gcmi_error_log( $object = null, $var_export = false ): void { - $contents = "\n------------------\n"; - $contents .= "var_dump:\n"; - ob_start(); - var_dump( $object ); - $contents .= ob_get_contents(); - ob_end_clean(); - + $contents = "\n------------------\n"; if ( true === $var_export ) { $contents .= "\n"; $contents .= "var_export:\n"; $contents .= var_export( $object, true ); + } else { + $contents .= "var_dump:\n"; + ob_start(); + var_dump( $object ); + $contents .= ob_get_contents(); + ob_end_clean(); } $contents .= "\n------------------\n"; error_log( $contents ); diff --git a/tests/test-class-gcmi-codicefiscale.php b/tests/test-class-gcmi-codicefiscale.php new file mode 100644 index 0000000..3ca137d --- /dev/null +++ b/tests/test-class-gcmi-codicefiscale.php @@ -0,0 +1,134 @@ +setCF( $input ); + + $this->assertSame( $expected['valid'], $testCF->GetCodiceValido() ); + if ( true === $testCF->GetCodiceValido() ) { + $this->assertSame( $expected['giorno'], $testCF->GetGGNascita() ); + $this->assertSame( $expected['mese'], $testCF->GetMMNascita() ); + $this->assertSame( $expected['anno'], $testCF->GetAANascita() ); + $this->assertSame( $expected['sesso'], $testCF->GetSesso() ); + $this->assertSame( $expected['comune'], $testCF->GetComuneNascita() ); + } else { + $this->assertSame( $expected['errore'], $testCF->GetErrore() ); + } + } + + public function provideCodici() { + return array( + array( + 'MRARSS80H04B850Y', + array( + 'valid' => true, + 'giorno' => '04', + 'mese' => '06', + 'anno' => '80', + 'sesso' => 'M', + 'comune' => 'B850', + 'errore' => null, + ), + ), + array( + 'MRARSS80H04B85OY', + array( + 'valid' => false, + 'giorno' => '04', + 'mese' => '06', + 'anno' => '80', + 'sesso' => 'M', + 'comune' => 'B850', + 'errore' => 'Invalid character in homocode decoding', + ), + ), + array( + 'MRARSS80H04B850YA', + array( + 'valid' => false, + 'giorno' => '04', + 'mese' => '06', + 'anno' => '80', + 'sesso' => 'M', + 'comune' => 'B850', + 'errore' => 'Incorrect code length', + ), + ), + array( + 'MRARSSS0H04B850Y', + array( + 'valid' => false, + 'giorno' => '04', + 'mese' => '06', + 'anno' => '80', + 'sesso' => 'M', + 'comune' => 'B850', + 'errore' => 'Incorrect tax code', + ), + ), + array( + 'MR@RSS80H04B850Y', + array( + 'valid' => false, + 'giorno' => '04', + 'mese' => '06', + 'anno' => '80', + 'sesso' => 'M', + 'comune' => 'B850', + 'errore' => 'The code to be analyzed contains incorrect characters', + ), + ), + array( + '', + array( + 'valid' => false, + 'giorno' => '04', + 'mese' => '06', + 'anno' => '80', + 'sesso' => 'M', + 'comune' => 'B850', + 'errore' => 'No Fiscal Code to be analyzed', + ), + ), + array( + 'MRARSS80H44B850C', + array( + 'valid' => true, + 'giorno' => '04', + 'mese' => '06', + 'anno' => '80', + 'sesso' => 'F', + 'comune' => 'B850', + 'errore' => null, + ), + ), + array( + 'MRARSSU0H44B850Z', + array( + 'valid' => true, + 'giorno' => '04', + 'mese' => '06', + 'anno' => '80', + 'sesso' => 'F', + 'comune' => 'B850', + 'errore' => null, + ), + ), + ); + } +}