You are here

public function TelephoneItemTest::testInvalidTelephoneNumber in Telephone Validation 8.2

Test invalid number.

File

tests/src/Kernel/TelephoneItemTest.php, line 53

Class

TelephoneItemTest
Test entity validation.

Namespace

Drupal\Tests\telephone_validation\Kernel

Code

public function testInvalidTelephoneNumber() {

  // Invalid Canadian number.
  $value = '999999';

  // Verify entity creation.
  $entity = EntityTest::create();
  $entity->field_test = $value;
  $entity->name->value = $this
    ->randomMachineName();
  $violations = $entity
    ->validate();
  $this
    ->assertEquals(count($violations), 1);
  $this
    ->assertEquals($violations[0]
    ->getMessage(), '999999 is not a valid phone number.');
}