<?php
namespace Drupal\field_ui\Tests;
use Drupal\simpletest\WebTestBase;
class AlterTest extends WebTestBase {
public static $modules = array(
'field_ui',
'field_test',
'text',
'options',
);
public static function getInfo() {
return array(
'name' => 'Widget customization',
'description' => 'Test custom field widget hooks and callbacks on field administration pages.',
'group' => 'Field UI',
);
}
function setUp() {
parent::setUp();
$this
->drupalCreateContentType(array(
'type' => 'page',
'name' => 'Basic page',
));
$this
->drupalCreateContentType(array(
'type' => 'article',
'name' => 'Article',
));
$admin_user = $this
->drupalCreateUser(array(
'access content',
'administer content types',
'administer users',
));
$this
->drupalLogin($admin_user);
}
function testDefaultWidgetPropertiesAlter() {
field_create_field(array(
'field_name' => 'alter_test_text',
'type' => 'text',
));
$instance = array(
'field_name' => 'alter_test_text',
'entity_type' => 'node',
'bundle' => 'article',
'widget' => array(
'type' => 'text_textfield',
'size' => 60,
),
);
field_create_instance($instance);
$this
->drupalGet('admin/structure/types/manage/article/fields/alter_test_text');
$this
->assertText('Field size: 42', 'Altered field size is found in hook_field_widget_form_alter().');
$this
->assertText('From hook_field_widget_form_alter(): Default form is true.', 'Default value form detected in hook_field_widget_form_alter().');
field_create_field(array(
'field_name' => 'alter_test_options',
'type' => 'list_text',
));
$instance = array(
'field_name' => 'alter_test_options',
'entity_type' => 'user',
'bundle' => 'user',
'widget' => array(
'type' => 'options_select',
),
);
field_create_instance($instance);
$instance = array(
'field_name' => 'alter_test_options',
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_select',
),
);
field_create_instance($instance);
$this
->drupalGet('admin/config/people/accounts/fields/alter_test_options');
$this
->assertText('Widget type: options_buttons', 'Widget type is altered for users in hook_field_widget_form_alter().');
$this
->drupalGet('admin/structure/types/manage/page/fields/alter_test_options');
$this
->assertText('Widget type: options_select', 'Widget type is not altered for pages in hook_field_widget_form_alter().');
}
}