diff --git a/src/CodiceFiscaleGenerator.php b/src/CodiceFiscaleGenerator.php index 652cd05..be2806a 100644 --- a/src/CodiceFiscaleGenerator.php +++ b/src/CodiceFiscaleGenerator.php @@ -194,7 +194,7 @@ protected function _calcolaDataNascita() $mm = $this->_mesi[$mese]; - $gg = (strtoupper($this->sesso) == config('codicefiscale.labels.male')) ? $giorno : $giorno + 40; + $gg = ($this->sesso == config('codicefiscale.labels.male')) ? $giorno : $giorno + 40; $gg = str_pad($gg, 2, '0', STR_PAD_LEFT); return $aa.$mm.$gg; diff --git a/tests/CodiceFiscaleConfigTest.php b/tests/CodiceFiscaleConfigTest.php index a10de79..7bfa0e9 100644 --- a/tests/CodiceFiscaleConfigTest.php +++ b/tests/CodiceFiscaleConfigTest.php @@ -41,4 +41,23 @@ public function configChange() ['RSSMRA95E05F205Z', 'codicefiscale.date-format', 'd/m/Y', Carbon::parse('1995-05-05'), 'birthdate'], ]; } + + /** @test */ + public function it_can_require_cf_validation_against_form_fields_with_overridded_gender_labels() + { + $rules = [ + 'cf_field' => 'codice_fiscale:first_name=first_name,last_name=last_name,birthdate=birthdate,place=place', + ]; + + $data = [ + 'cf_field' => 'RSSMRA80A01F205X', + 'first_name' => 'Mario', + 'last_name' => 'Rossi', + 'birthdate' => '1980-01-01', + 'place' => 'Milano', + ]; + + $validator = $this->app['validator']->make($data, $rules); + $this->assertEquals(false, $validator->passes()); + } }