You are here

public function BrazilianIdsServiceTest::testValidateCpf in Brazilian IDs 8

Tests CPF validation.

File

tests/src/Unit/BrazilianIdsServiceTest.php, line 42

Class

BrazilianIdsServiceTest
@coversDefaultClass \Drupal\brazilian_ids\BrazilianIdsService @group brazilian_ids

Namespace

Drupal\Tests\brazilian_ids\Unit

Code

public function testValidateCpf() {

  // Valid CPF numbers.
  $this
    ->assertTrue($this->service
    ->validateCpf('29979245883'));
  $this
    ->assertTrue($this->service
    ->validateCpf('81684990009'));
  $this
    ->assertTrue($this->service
    ->validateCpf('82523167000'));
  $this
    ->assertTrue($this->service
    ->validateCpf('08219249072'));

  // Invalid varification digits.
  $this
    ->assertFalse($this->service
    ->validateCpf('29979245873'));
  $this
    ->assertFalse($this->service
    ->validateCpf('29979245881'));
  $this
    ->assertFalse($this->service
    ->validateCpf('29979245803'));
  $this
    ->assertFalse($this->service
    ->validateCpf('29979245880'));
  $this
    ->assertFalse($this->service
    ->validateCpf('29979245800'));

  // Less than 11 digits.
  $this
    ->assertFalse($this->service
    ->validateCpf('2997924588'));

  // More than 11 digits.
  $this
    ->assertFalse($this->service
    ->validateCpf('299792458833'));

  // CPF numbers using just one digit must be false.
  $this
    ->assertFalse($this->service
    ->validateCpf('00000000000'));
  $this
    ->assertFalse($this->service
    ->validateCpf('11111111111'));
  $this
    ->assertFalse($this->service
    ->validateCpf('22222222222'));
  $this
    ->assertFalse($this->service
    ->validateCpf('33333333333'));
  $this
    ->assertFalse($this->service
    ->validateCpf('44444444444'));
  $this
    ->assertFalse($this->service
    ->validateCpf('55555555555'));
  $this
    ->assertFalse($this->service
    ->validateCpf('66666666666'));
  $this
    ->assertFalse($this->service
    ->validateCpf('77777777777'));
  $this
    ->assertFalse($this->service
    ->validateCpf('88888888888'));
  $this
    ->assertFalse($this->service
    ->validateCpf('99999999999'));
}