You are here

public function BrazilianIdsServiceTest::testValidateCnpj in Brazilian IDs 8

Tests CNPJ validation.

File

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

Class

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

Namespace

Drupal\Tests\brazilian_ids\Unit

Code

public function testValidateCnpj() {

  // Valid CNPJ numbers.
  $this
    ->assertTrue($this->service
    ->validateCnpj('45598438000151'));
  $this
    ->assertTrue($this->service
    ->validateCnpj('46264168000105'));
  $this
    ->assertTrue($this->service
    ->validateCnpj('50232337000100'));
  $this
    ->assertTrue($this->service
    ->validateCnpj('09753778000146'));

  // Invalid varification digits.
  $this
    ->assertFalse($this->service
    ->validateCnpj('45598438000161'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('45598438000152'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('45598438000101'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('45598438000150'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('45598438000100'));

  // Less than 14 digits.
  $this
    ->assertFalse($this->service
    ->validateCnpj('4559843800015'));

  // More than 14 digits.
  $this
    ->assertFalse($this->service
    ->validateCnpj('455984380001511'));

  // CNPJ numbers using just one digit must be false.
  $this
    ->assertFalse($this->service
    ->validateCnpj('00000000000000'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('11111111111111'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('22222222222222'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('33333333333333'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('44444444444444'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('55555555555555'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('66666666666666'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('77777777777777'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('88888888888888'));
  $this
    ->assertFalse($this->service
    ->validateCnpj('99999999999999'));
}