Skip to content

Commit

Permalink
Add validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
robertogallea committed Oct 25, 2021
1 parent d919710 commit 7dc1fc3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
19 changes: 19 additions & 0 deletions tests/CodiceFiscaleConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
11 changes: 8 additions & 3 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests;

use Illuminate\Support\Facades\Config;
use robertogallea\LaravelCodiceFiscale\CodiceFiscaleServiceProvider;

class ValidatorTest extends TestCase
Expand Down Expand Up @@ -55,7 +54,6 @@ public function it_doesnt_validate_if_city_code_does_not_exist()
/** @test */
public function it_can_require_cf_validation_against_form_fields_and_pass()
{
Config::set('codicefiscale.labels.male', 'maschio');
$rules = [
'cf_field' => 'codice_fiscale:first_name=first_name,last_name=last_name,birthdate=birthdate,place=place,gender=gender',
];
Expand All @@ -66,7 +64,7 @@ public function it_can_require_cf_validation_against_form_fields_and_pass()
'last_name' => 'Rossi',
'birthdate' => '1980-01-01',
'place' => 'Milano',
'gender' => 'maschio',
'gender' => 'M',
];

$validator = $this->app['validator']->make($data, $rules);
Expand Down Expand Up @@ -130,4 +128,11 @@ public function it_can_require_cf_validation_against_form_fields_and_dont_pass_i
$validator = $this->app['validator']->make($data, $rules);
$this->assertEquals(false, $validator->passes());
}

protected function getPackageProviders($app)
{
return [
CodiceFiscaleServiceProvider::class,
];
}
}

0 comments on commit 7dc1fc3

Please sign in to comment.