Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,104 @@
<?php
/**
* @file
* Contains \Drupal\telephone\Tests\TelephoneFieldTest.
*/
namespace Drupal\telephone\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the creation of telephone fields.
*
* @group telephone
*/
class TelephoneFieldTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'field',
'node',
'telephone'
);
/**
* A user with permission to create articles.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(array('type' => 'article'));
$this->webUser = $this->drupalCreateUser(array('create article content', 'edit own article content'));
$this->drupalLogin($this->webUser);
}
// Test fields.
/**
* Helper function for testTelephoneField().
*/
function testTelephoneField() {
// Add the telephone field to the article content type.
entity_create('field_storage_config', array(
'field_name' => 'field_telephone',
'entity_type' => 'node',
'type' => 'telephone',
))->save();
entity_create('field_config', array(
'field_name' => 'field_telephone',
'label' => 'Telephone Number',
'entity_type' => 'node',
'bundle' => 'article',
))->save();
entity_get_form_display('node', 'article', 'default')
->setComponent('field_telephone', array(
'type' => 'telephone_default',
'settings' => array(
'placeholder' => '123-456-7890',
),
))
->save();
entity_get_display('node', 'article', 'default')
->setComponent('field_telephone', array(
'type' => 'telephone_link',
'weight' => 1,
))
->save();
// Display creation form.
$this->drupalGet('node/add/article');
$this->assertFieldByName("field_telephone[0][value]", '', 'Widget found.');
$this->assertRaw('placeholder="123-456-7890"');
// Test basic entry of telephone field.
$edit = array(
'title[0][value]' => $this->randomMachineName(),
'field_telephone[0][value]' => "123456789",
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw('<a href="tel:123456789">', 'A telephone link is provided on the article node page.');
// Add number with a space in it. Need to ensure it is stripped on output.
$edit = array(
'title[0][value]' => $this->randomMachineName(),
'field_telephone[0][value]' => "1234 56789",
);
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$this->assertRaw('<a href="tel:123456789">', 'Telephone link is output with whitespace removed.');
}
}

View file

@ -0,0 +1,79 @@
<?php
/**
* @file
* Contains \Drupal\telephone\Tests\TelephoneItemTest.
*/
namespace Drupal\telephone\Tests;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\field\Tests\FieldUnitTestBase;
/**
* Tests the new entity API for the telephone field type.
*
* @group telephone
*/
class TelephoneItemTest extends FieldUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('telephone');
protected function setUp() {
parent::setUp();
// Create a telephone field storage and field for validation.
entity_create('field_storage_config', array(
'field_name' => 'field_test',
'entity_type' => 'entity_test',
'type' => 'telephone',
))->save();
entity_create('field_config', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'bundle' => 'entity_test',
))->save();
}
/**
* Tests using entity fields of the telephone field type.
*/
public function testTestItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$value = '+0123456789';
$entity->field_test = $value;
$entity->name->value = $this->randomMachineName();
$entity->save();
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$this->assertTrue($entity->field_test instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test->value, $value);
$this->assertEqual($entity->field_test[0]->value, $value);
// Verify changing the field value.
$new_value = '+41' . rand(1000000, 9999999);
$entity->field_test->value = $new_value;
$this->assertEqual($entity->field_test->value, $new_value);
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$this->assertEqual($entity->field_test->value, $new_value);
// Test sample item generation.
$entity = entity_create('entity_test');
$entity->field_test->generateSampleItems();
$this->entityValidateAndSave($entity);
}
}