Skip to content

Commit

Permalink
Aggiunti test per codice fiscale
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Foti <foti.giuseppe@gmail.com>
  • Loading branch information
MocioF committed Jan 30, 2024
1 parent 854a67d commit aff87c4
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 7 deletions.
14 changes: 7 additions & 7 deletions includes/gcmi-custom-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
134 changes: 134 additions & 0 deletions tests/test-class-gcmi-codicefiscale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

final class GCMI_CodiceFiscaleTest extends WP_UnitTestCase {

public function set_up() {
parent::set_up();
require_once 'modules/cf/class-gcmi-codicefiscale.php';
}

public function tear_down() {
parent::tear_down();
}

/**
* @dataProvider provideCodici
* @group codicefiscale
*/
public function test_GetCodiceValido( $input, $expected ) {
$testCF = new GCMI_CODICEFISCALE();
$testCF->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,
),
),
);
}
}

0 comments on commit aff87c4

Please # to comment.