TelephoneFormatterFunctionalTest.test in Telephone Formatter 7
File
tests/TelephoneFormatterFunctionalTest.test
View source
<?php
use libphonenumber\PhoneNumberFormat;
class TelephoneFormatterFunctionalTest extends DrupalWebTestCase {
protected $privilegedUser;
public static function getInfo() {
return array(
'name' => 'Telephone Formatter Functional Tests',
'description' => 'Tests the creation of telephone fields.',
'group' => 'Telephone Formatter',
);
}
public function setUp() {
parent::setUp('telephone_formatter');
$this->privilegedUser = $this
->drupalCreateUser(array(
'create page content',
'edit own page content',
));
$this
->drupalLogin($this->privilegedUser);
}
public function testTelephoneFieldFallback() {
$this
->generateTelephoneField();
$node = $this
->drupalCreateNode([
'field_telephone' => [
'98765432',
],
]);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText(98765432, 'Telephone number was found on the created node.');
}
protected function generateTelephoneField($settings = array()) {
$field_name = 'field_telephone';
$field = array(
'field_name' => $field_name,
'type' => 'telephone',
);
field_create_field($field);
$instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'Telephone Number',
);
field_create_instance($instance);
$instance_info = field_info_instance('node', 'field_telephone', 'page');
$instance_info['display']['default'] = $settings + array(
'format' => PhoneNumberFormat::INTERNATIONAL,
'link' => TRUE,
'default_country' => NULL,
);
field_update_instance($instance_info);
}
}