BrazilianIdsServiceTest.php in Brazilian IDs 8
File
tests/src/Unit/BrazilianIdsServiceTest.php
View source
<?php
namespace Drupal\Tests\brazilian_ids\Unit;
use Drupal\brazilian_ids\BrazilianIdsService;
use Drupal\Tests\UnitTestCase;
class BrazilianIdsServiceTest extends UnitTestCase {
private $service;
public function testCleanCpf() {
$this
->assertEquals('29979245883', $this->service
->clean('299.792.458-83'));
}
public function testCleanCnpj() {
$this
->assertEquals('27491687000161', $this->service
->clean('27.491.687/0001-61'));
}
public function testCleanRg() {
$this
->assertEquals('275353369', $this->service
->clean('27.535.336-9'));
$this
->assertEquals('27535336X', $this->service
->clean('27.535.336-X'));
$this
->assertEquals('27535336x', $this->service
->clean('27.535.336-x'));
}
public function testValidateCpf() {
$this
->assertTrue($this->service
->validateCpf('29979245883'));
$this
->assertTrue($this->service
->validateCpf('81684990009'));
$this
->assertTrue($this->service
->validateCpf('82523167000'));
$this
->assertTrue($this->service
->validateCpf('08219249072'));
$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'));
$this
->assertFalse($this->service
->validateCpf('2997924588'));
$this
->assertFalse($this->service
->validateCpf('299792458833'));
$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'));
}
public function testValidateCnpj() {
$this
->assertTrue($this->service
->validateCnpj('45598438000151'));
$this
->assertTrue($this->service
->validateCnpj('46264168000105'));
$this
->assertTrue($this->service
->validateCnpj('50232337000100'));
$this
->assertTrue($this->service
->validateCnpj('09753778000146'));
$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'));
$this
->assertFalse($this->service
->validateCnpj('4559843800015'));
$this
->assertFalse($this->service
->validateCnpj('455984380001511'));
$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'));
}
public function testValidateCpfCnpj() {
$this
->assertTrue($this->service
->validateCpfCnpj('29979245883'));
$this
->assertTrue($this->service
->validateCpfCnpj('45598438000151'));
$this
->assertFalse($this->service
->validateCpfCnpj('29979245881'));
$this
->assertFalse($this->service
->validateCpfCnpj('45598438000150'));
$this
->assertFalse($this->service
->validateCpfCnpj('2997924588'));
$this
->assertFalse($this->service
->validateCpfCnpj('299792458833'));
$this
->assertFalse($this->service
->validateCpfCnpj('455984380001512'));
}
public function setUp() {
$this->service = new BrazilianIdsService();
$string_translation = $this
->getStringTranslationStub();
$this->service
->setStringTranslation($string_translation);
}
}