Ejemplo n.º 1
0
 /**
  * Checks block edit functionality.
  */
 public function testBlockFields()
 {
     $this->drupalLogin($this->adminUser);
     $this->blockType = $this->createBlockContentType('link');
     // Create a field with settings to validate.
     $this->fieldStorage = entity_create('field_storage_config', array('name' => drupal_strtolower($this->randomName()), 'entity_type' => 'block_content', 'type' => 'link', 'cardinality' => 2));
     $this->fieldStorage->save();
     $this->instance = entity_create('field_instance_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'link', 'settings' => array('title' => DRUPAL_OPTIONAL)));
     $this->instance->save();
     entity_get_form_display('block_content', 'link', 'default')->setComponent($this->fieldStorage->getName(), array('type' => 'link_default'))->save();
     entity_get_display('block_content', 'link', 'default')->setComponent($this->fieldStorage->getName(), array('type' => 'link', 'label' => 'hidden'))->save();
     // Create a block.
     $this->drupalGet('block/add/link');
     $edit = array('info[0][value]' => $this->randomName(8), $this->fieldStorage->getName() . '[0][url]' => 'http://example.com', $this->fieldStorage->getName() . '[0][title]' => 'Example.com');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $block = entity_load('block_content', 1);
     $url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default');
     // Place the block.
     $instance = array('id' => drupal_strtolower($edit['info[0][value]']), 'settings[label]' => $edit['info[0][value]'], 'region' => 'sidebar_first');
     $this->drupalPostForm($url, $instance, t('Save block'));
     // Navigate to home page.
     $this->drupalGet('<front>');
     $this->assertLinkByHref('http://example.com');
     $this->assertText('Example.com');
 }
Ejemplo n.º 2
0
 /**
  * Helper function for testTextfieldWidgets().
  */
 function _testTextfieldWidgets($field_type, $widget_type)
 {
     // Create a field.
     $field_name = Unicode::strtolower($this->randomMachineName());
     $field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => $field_type));
     $field_storage->save();
     FieldConfig::create(['field_storage' => $field_storage, 'bundle' => 'entity_test', 'label' => $this->randomMachineName() . '_label'])->save();
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => $widget_type, 'settings' => array('placeholder' => 'A placeholder on ' . $widget_type)))->save();
     entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name)->save();
     // Display creation form.
     $this->drupalGet('entity_test/add');
     $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed');
     $this->assertNoFieldByName("{$field_name}[0][format]", '1', 'Format selector is not displayed');
     $this->assertRaw(format_string('placeholder="A placeholder on @widget_type"', array('@widget_type' => $widget_type)));
     // Submit with some value.
     $value = $this->randomMachineName();
     $edit = array("{$field_name}[0][value]" => $value);
     $this->drupalPostForm(NULL, $edit, t('Save'));
     preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
     $id = $match[1];
     $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
     // Display the entity.
     $entity = EntityTest::load($id);
     $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
     $content = $display->build($entity);
     $this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
     $this->assertText($value, 'Filtered tags are not displayed');
 }
Ejemplo n.º 3
0
 /**
  * Returns the in-place editor that Edit selects.
  */
 protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default')
 {
     $entity = entity_load('entity_test', $entity_id, TRUE);
     $items = $entity->getTranslation(LanguageInterface::LANGCODE_NOT_SPECIFIED)->get($field_name);
     $options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name);
     return $this->editorSelector->getEditor($options['type'], $items);
 }
 /**
  * Test subscription output visibility for different users.
  */
 public function testSubscriptionVisiblity()
 {
     // Enable the extra field.
     entity_get_display('user', 'user', 'default')->setComponent('simplenews', array('label' => 'hidden', 'type' => 'simplenews'))->save();
     // Create admin user.
     $admin_user = $this->drupalCreateUser(array('administer users'));
     // Create user that can view user profiles.
     $user = $this->drupalCreateUser(array('access user profiles', 'subscribe to newsletters', 'access content'));
     $this->drupalLogin($admin_user);
     // Tests extra fields for admin user.
     $this->drupalGet('user/' . $admin_user->id());
     $this->assertLink('Manage subscriptions');
     $this->drupalLogout();
     // Tests extra fields for user.
     $this->drupalLogin($user);
     $this->drupalGet('user/' . $admin_user->id());
     $this->assertNoLink('Manage subscriptions');
     $this->drupalGet('user/' . $user->id());
     $this->assertLink('Manage subscriptions');
     $this->drupalLogout();
     // Tests extra fields for anonymous users.
     $this->drupalGet('user/' . $admin_user->id());
     $this->assertNoLink('Manage subscriptions');
     $this->drupalGet('user/' . $user->id());
     $this->assertNoLink('Manage subscriptions');
 }
 /**
  * Tests the Drupal 7 user picture to Drupal 8 entity display migration.
  */
 public function testUserPictureEntityDisplay()
 {
     $component = entity_get_display('user', 'user', 'default')->getComponent('user_picture');
     $this->assertIdentical('image', $component['type']);
     $this->assertIdentical('', $component['settings']['image_style']);
     $this->assertIdentical('content', $component['settings']['image_link']);
 }
Ejemplo n.º 6
0
 /**
  * Tests email field.
  */
 function testEmailField()
 {
     // Create a field with settings to validate.
     $field_name = Unicode::strtolower($this->randomMachineName());
     $this->fieldStorage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'email'));
     $this->fieldStorage->save();
     $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'entity_test']);
     $this->field->save();
     // Create a form display for the default form mode.
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'email_default', 'settings' => array('placeholder' => '*****@*****.**')))->save();
     // Create a display for the full view mode.
     entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name, array('type' => 'email_mailto'))->save();
     // Display creation form.
     $this->drupalGet('entity_test/add');
     $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget found.');
     $this->assertRaw('placeholder="*****@*****.**"');
     // Submit a valid email address and ensure it is accepted.
     $value = '*****@*****.**';
     $edit = array("{$field_name}[0][value]" => $value);
     $this->drupalPostForm(NULL, $edit, t('Save'));
     preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
     $id = $match[1];
     $this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
     $this->assertRaw($value);
     // Verify that a mailto link is displayed.
     $entity = EntityTest::load($id);
     $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
     $content = $display->build($entity);
     $this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
     $this->assertLinkByHref('mailto:test@example.com');
 }
Ejemplo n.º 7
0
 function testVideo()
 {
     $field_name = Unicode::strtolower($this->randomMachineName());
     // Create a field.
     $field_storage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'node', 'translatable' => FALSE, 'type' => 'youtube', 'cardinality' => '1'));
     $field_storage->save();
     $field = entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => 'article', 'title' => DRUPAL_DISABLED));
     $field->save();
     entity_get_form_display('node', 'article', 'default')->setComponent($field_name, array('type' => 'youtube', 'settings' => array()))->save();
     entity_get_display('node', 'article', 'full')->setComponent($field_name, array('type' => 'youtube_video'))->save();
     // Display creation form.
     $this->drupalGet('node/add/article');
     $this->assertFieldByName("{$field_name}[0][input]", '', t('Video input field is displayed'));
     // Verify that a valid URL can be submitted.
     $video_id = 'T5y3dJYHb_A';
     $value = 'http://www.youtube.com/watch?v=' . $video_id;
     $embed_value = 'http://www.youtube.com/embed/' . $video_id;
     $edit = array("title[0][value]" => 'Test', "{$field_name}[0][input]" => $value);
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
     preg_match('|/node/(\\d+)|', $this->url, $match);
     $this->assertText(t('Article Test has been created.'));
     $this->assertRaw($embed_value);
     // Verify thta the video is displayed.
     $pattern = '<iframe.*src="' . $embed_value;
     $pattern = str_replace('/', '\\/', $pattern);
     $pattern = '/' . $pattern . '/s';
     $this->assertPattern($pattern);
     // Verify that invalid URLs cannot be submitted.
     $this->drupalGet('node/add/article');
     $value = 'not-a-url';
     $edit = array("title[0][value]" => 'Test1', "{$field_name}[0][input]" => $value);
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
     $this->assertText(t('Please provide a valid YouTube URL.'));
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(['system']);
     $this->installConfig(['field']);
     $this->installConfig(['text']);
     $this->installConfig(['address']);
     $this->installEntitySchema('entity_test');
     ConfigurableLanguage::createFromLangcode('zh-hant')->save();
     // The address module is never installed, so the importer doesn't run
     // automatically. Instead, we manually import the address formats we need.
     $country_codes = ['AD', 'SV', 'TW', 'US', 'ZZ'];
     $importer = \Drupal::service('address.address_format_importer');
     $importer->importEntities($country_codes);
     $importer->importTranslations(['zh-hant']);
     $this->entityType = 'entity_test';
     $this->bundle = $this->entityType;
     $this->fieldName = Unicode::strtolower($this->randomMachineName());
     $field_storage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'address']);
     $field_storage->save();
     $field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName()]);
     $field->save();
     $this->display = entity_get_display($this->entityType, $this->bundle, 'default');
     $this->display->setComponent($this->fieldName, ['type' => 'address_plain', 'settings' => []]);
     $this->display->save();
 }
Ejemplo n.º 9
0
 /**
  * Tests field item attributes.
  */
 public function testFieldItemAttributes()
 {
     // Make sure the test field will be rendered.
     entity_get_display('entity_test', 'entity_test', 'default')->setComponent('field_test_text', array('type' => 'text_default'))->save();
     // Create an entity and save test value in field_test_text.
     $test_value = $this->randomMachineName();
     $entity = entity_create('entity_test');
     $entity->field_test_text = $test_value;
     $entity->save();
     // Browse to the entity and verify that the attribute is rendered in the
     // field item HTML markup.
     $this->drupalGet('entity_test/' . $entity->id());
     $xpath = $this->xpath('//div[@data-field-item-attr="foobar"]/p[text()=:value]', array(':value' => $test_value));
     $this->assertTrue($xpath, 'The field item attribute has been found in the rendered output of the field.');
     // Enable the RDF module to ensure that two modules can add attributes to
     // the same field item.
     \Drupal::service('module_installer')->install(array('rdf'));
     $this->resetAll();
     // Set an RDF mapping for the field_test_text field. This RDF mapping will
     // be turned into RDFa attributes in the field item output.
     $mapping = rdf_get_mapping('entity_test', 'entity_test');
     $mapping->setFieldMapping('field_test_text', array('properties' => array('schema:text')))->save();
     // Browse to the entity and verify that the attributes from both modules
     // are rendered in the field item HTML markup.
     $this->drupalGet('entity_test/' . $entity->id());
     $xpath = $this->xpath('//div[@data-field-item-attr="foobar" and @property="schema:text"]/p[text()=:value]', array(':value' => $test_value));
     $this->assertTrue($xpath, 'The field item attributes from both modules have been found in the rendered output of the field.');
 }
Ejemplo n.º 10
0
 /**
  * Returns the in-place editor that Quick Edit selects.
  */
 protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default')
 {
     $entity = entity_load('entity_test', $entity_id, TRUE);
     $items = $entity->get($field_name);
     $options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name);
     return $this->editorSelector->getEditor($options['type'], $items);
 }
 /**
  * Tests boolean field.
  */
 function testBooleanField()
 {
     $on = $this->randomMachineName();
     $off = $this->randomMachineName();
     $label = $this->randomMachineName();
     // Create a field with settings to validate.
     $field_name = drupal_strtolower($this->randomMachineName());
     $this->field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'boolean', 'settings' => array('on_label' => $on, 'off_label' => $off)));
     $this->field_storage->save();
     $this->field = FieldConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $label, 'required' => TRUE));
     $this->field->save();
     // Create a form display for the default form mode.
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'boolean_checkbox'))->save();
     // Create a display for the full view mode.
     entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name, array('type' => 'boolean'))->save();
     // Display creation form.
     $this->drupalGet('entity_test/add');
     $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
     $this->assertRaw($on);
     // Submit and ensure it is accepted.
     $edit = array("{$field_name}[value]" => 1);
     $this->drupalPostForm(NULL, $edit, t('Save'));
     preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
     $id = $match[1];
     $this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
     // Verify that boolean value is displayed.
     $entity = entity_load('entity_test', $id);
     $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
     $content = $display->build($entity);
     $this->drupalSetContent(drupal_render($content));
     $this->assertRaw('<div class="field-item">' . $on . '</div>');
     // Test the display_label option.
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'boolean_checkbox', 'settings' => array('display_label' => TRUE)))->save();
     $this->drupalGet('entity_test/add');
     $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
     $this->assertNoRaw($on);
     $this->assertText($this->field->label());
     // Go to the form display page and check if the default settings works as
     // expected.
     $fieldEditUrl = 'entity_test/structure/entity_test/form-display';
     $this->drupalGet($fieldEditUrl);
     // Click on the widget settings button to open the widget settings form.
     $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
     $this->assertText('Use field label instead of the "On label" as label', t('Display setting checkbox available.'));
     // Enable setting.
     $edit = array('fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1);
     $this->drupalPostAjaxForm(NULL, $edit, $field_name . "_plugin_settings_update");
     $this->drupalPostForm(NULL, NULL, 'Save');
     // Go again to the form display page and check if the setting
     // is stored and has the expected effect.
     $this->drupalGet($fieldEditUrl);
     $this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.');
     $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
     $this->assertText('Use field label instead of the "On label" as label', t('Display setting checkbox is available'));
     $this->assertFieldByXPath('*//input[@id="edit-fields-' . $field_name . '-settings-edit-form-settings-display-label" and @value="1"]', TRUE, t('Display label changes label of the checkbox'));
     // Test the boolean field settings.
     $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name . '/storage');
     $this->assertFieldById('edit-field-storage-settings-on-label', $on);
     $this->assertFieldById('edit-field-storage-settings-off-label', $off);
 }
Ejemplo n.º 12
0
 function setUp()
 {
     parent::setUp();
     // Create test user.
     $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'bypass node access'));
     $this->drupalLogin($admin_user);
     // Create content type, with underscores.
     $type_name = strtolower($this->randomMachineName(8)) . '_test';
     $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
     $this->type = $type->id();
     $display = entity_get_display('node', $type_name, 'default');
     // Create a node.
     $node_values = array('type' => $type_name);
     // Create test fields.
     $test_fields = array('field_test', 'field_test_2', 'field_no_access');
     foreach ($test_fields as $field_name) {
         $field_storage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'node', 'type' => 'test_field']);
         $field_storage->save();
         $instance = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $type_name, 'label' => $this->randomMachineName()]);
         $instance->save();
         // Assign a test value for the field.
         $node_values[$field_name][0]['value'] = mt_rand(1, 127);
         // Set the field visible on the display object.
         $display_options = array('label' => 'above', 'type' => 'field_test_default', 'settings' => array('test_formatter_setting' => $this->randomMachineName()));
         $display->setComponent($field_name, $display_options);
     }
     // Save display + create node.
     $display->save();
     $this->node = $this->drupalCreateNode($node_values);
 }
Ejemplo n.º 13
0
 function setUp()
 {
     parent::setUp();
     // Configure the theme system.
     $this->installConfig(array('system', 'field'));
     $this->installEntitySchema('entity_test');
     // @todo Add helper methods for all of the following.
     $this->entity_type = 'entity_test';
     if (!isset($this->bundle)) {
         $this->bundle = $this->entity_type;
     }
     $this->field_name = drupal_strtolower($this->randomName());
     $this->field_type = 'text_long';
     $this->field_settings = array();
     $this->instance_settings = array('text_processing' => FALSE);
     $this->formatter_type = 'string';
     $this->formatter_settings = array();
     $this->fieldStorage = entity_create('field_storage_config', array('name' => $this->field_name, 'entity_type' => $this->entity_type, 'type' => $this->field_type, 'settings' => $this->field_settings));
     $this->fieldStorage->save();
     $this->instance = entity_create('field_instance_config', array('field_storage' => $this->fieldStorage, 'bundle' => $this->bundle, 'label' => $this->randomName(), 'settings' => $this->instance_settings));
     $this->instance->save();
     $this->view_mode = 'default';
     $this->display = entity_get_display($this->entity_type, $this->bundle, $this->view_mode)->setComponent($this->field_name, array('type' => $this->formatter_type, 'settings' => $this->formatter_settings));
     $this->display->save();
     $this->langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
 }
Ejemplo n.º 14
0
 /**
  * Test the behavior of a field module after being disabled and re-enabled.
  */
 function testReEnabledField()
 {
     // Add a telephone field to the article content type.
     $field_storage = entity_create('field_storage_config', array('name' => 'field_telephone', 'entity_type' => 'node', 'type' => 'telephone'));
     $field_storage->save();
     entity_create('field_instance_config', array('field_storage' => $field_storage, 'bundle' => 'article', 'label' => 'Telephone Number'))->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 the article node form and verify the telephone widget is present.
     $this->drupalGet('node/add/article');
     $this->assertFieldByName("field_telephone[0][value]", '', 'Widget found.');
     // Submit an article node with a telephone field so data exist for the
     // field.
     $edit = array('title[0][value]' => $this->randomName(), 'field_telephone[0][value]' => "123456789");
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertRaw('<a href="tel:123456789">');
     // Test that the module can't be uninstalled from the UI while there is data
     // for it's fields.
     $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules'));
     $this->drupalLogin($admin_user);
     $this->drupalGet('admin/modules');
     $this->assertText('Fields type(s) in use');
     $field_storage->delete();
     $this->drupalGet('admin/modules');
     $this->assertText('Fields pending deletion');
     $this->cronRun();
     $this->assertNoText('Fields type(s) in use');
     $this->assertNoText('Fields pending deletion');
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array('node' => array('options' => array('promote' => FALSE), 'submitted' => FALSE))));
         $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     }
     $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'bypass node access', 'administer content types', 'administer xmlsitemap', 'administer taxonomy'));
     $this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'access content', 'view own unpublished content'));
     // allow anonymous user to view user profiles
     $user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
     $user_role->grantPermission('access content');
     $user_role->save();
     xmlsitemap_link_bundle_enable('node', 'article');
     xmlsitemap_link_bundle_enable('node', 'page');
     $this->config->set('xmlsitemap_entity_taxonomy_vocabulary', 1);
     $this->config->set('xmlsitemap_entity_taxonomy_term', 1);
     $this->config->save();
     xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.6, 'changefreq' => XMLSITEMAP_FREQUENCY_WEEKLY));
     // Add a vocabulary so we can test different view modes.
     $vocabulary = entity_create('taxonomy_vocabulary', array('name' => 'Tags', 'description' => $this->randomMachineName(), 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => ''));
     $vocabulary->save();
     xmlsitemap_link_bundle_enable('taxonomy_term', 'tags');
     // Set up a field and instance.
     $field_name = 'tags';
     entity_create('field_storage_config', array('name' => $field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->vid, 'parent' => '0'))), 'cardinality' => '-1'))->save();
     entity_create('field_instance_config', array('field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page'))->save();
     entity_get_form_display('node', 'page', 'default')->setComponent($field_name, array('type' => 'taxonomy_autocomplete'))->save();
     // Show on default display and teaser.
     entity_get_display('node', 'page', 'default')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link'))->save();
     entity_get_display('node', 'page', 'teaser')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link'))->save();
 }
Ejemplo n.º 16
0
 /**
  * Tests the node summary length functionality.
  */
 public function testSummaryLength()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     // Create a node to view.
     $settings = array('body' => array(array('value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero. Ut fermentum est vitae metus convallis scelerisque. Phasellus pellentesque rhoncus tellus, eu dignissim purus posuere id. Quisque eu fringilla ligula. Morbi ullamcorper, lorem et mattis egestas, tortor neque pretium velit, eget eleifend odio turpis eu purus. Donec vitae metus quis leo pretium tincidunt a pulvinar sem. Morbi adipiscing laoreet mauris vel placerat. Nullam elementum, nisl sit amet scelerisque malesuada, dolor nunc hendrerit quam, eu ultrices erat est in orci. Curabitur feugiat egestas nisl sed accumsan.')), 'promote' => 1);
     $node = $this->drupalCreateNode($settings);
     $this->assertTrue(Node::load($node->id()), 'Node created.');
     // Render the node as a teaser.
     $content = $this->drupalBuildEntityView($node, 'teaser');
     $this->assertTrue(strlen($content['body'][0]['#markup']) < 600, 'Teaser is less than 600 characters long.');
     $this->setRawContent($renderer->renderRoot($content));
     // The string 'What is a Drupalism?' is between the 200th and 600th
     // characters of the node body, so it should be included if the summary is
     // 600 characters long.
     $expected = 'What is a Drupalism?';
     $this->assertRaw($expected);
     // Change the teaser length for "Basic page" content type.
     $display = entity_get_display('node', $node->getType(), 'teaser');
     $display_options = $display->getComponent('body');
     $display_options['settings']['trim_length'] = 200;
     $display->setComponent('body', $display_options)->save();
     // Render the node as a teaser again and check that the summary is now only
     // 200 characters in length and so does not include 'What is a Drupalism?'.
     $content = $this->drupalBuildEntityView($node, 'teaser');
     $this->assertTrue(strlen($content['body'][0]['#markup']) < 200, 'Teaser is less than 200 characters long.');
     $this->setRawContent($renderer->renderRoot($content));
     $this->assertText($node->label());
     $this->assertNoRaw($expected);
 }
 /**
  * Adds term reference field for the article content type.
  */
 protected function setUpTermReferenceField()
 {
     entity_create('field_storage_config', array('field_name' => $this->termFieldName, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->vocabulary->id(), 'parent' => 0)))))->save();
     $field = entity_create('field_config', array('field_name' => $this->termFieldName, 'bundle' => 'article', 'entity_type' => 'node', 'translatable' => FALSE));
     $field->save();
     entity_get_form_display('node', 'article', 'default')->setComponent($this->termFieldName, array('type' => 'taxonomy_autocomplete'))->save();
     entity_get_display('node', 'article', 'default')->setComponent($this->termFieldName, array('type' => 'taxonomy_term_reference_link'))->save();
 }
 /**
  * Tests the Drupal 6 user picture to Drupal 8 entity display migration.
  */
 public function testUserPictureEntityDisplay()
 {
     $display = entity_get_display('user', 'user', 'default');
     $component = $display->getComponent('user_picture');
     $this->assertIdentical('image', $component['type']);
     $this->assertIdentical('content', $component['settings']['image_link']);
     $this->assertIdentical(array('user', 'user', 'default', 'user_picture'), entity_load('migration', 'd6_user_picture_entity_display')->getIdMap()->lookupDestinationID(array('')));
 }
 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyEntityDisplay()
 {
     // Test that the field exists.
     $component = entity_get_display('node', 'page', 'default')->getComponent('tags');
     $this->assertIdentical('entity_reference_label', $component['type']);
     $this->assertIdentical(20, $component['weight']);
     // Test the Id map.
     $this->assertIdentical(array('node', 'article', 'default', 'tags'), entity_load('migration', 'd6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
 }
Ejemplo n.º 20
0
 /**
  * Create a new image field.
  *
  * @param string $name
  *   The name of the new field (all lowercase), exclude the "field_" prefix.
  * @param string $type_name
  *   The node type that this field will be added to.
  * @param array $storage_settings
  *   A list of field storage settings that will be added to the defaults.
  * @param array $field_settings
  *   A list of instance settings that will be added to the instance defaults.
  * @param array $widget_settings
  *   A list of widget settings that will be added to the widget defaults.
  */
 function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array())
 {
     entity_create('field_storage_config', array('field_name' => $name, 'entity_type' => 'node', 'type' => 'image', 'settings' => $storage_settings, 'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1))->save();
     $field_config = entity_create('field_config', array('field_name' => $name, 'label' => $name, 'entity_type' => 'node', 'bundle' => $type_name, 'required' => !empty($field_settings['required']), 'settings' => $field_settings));
     $field_config->save();
     entity_get_form_display('node', $type_name, 'default')->setComponent($name, array('type' => 'image_image', 'settings' => $widget_settings))->save();
     entity_get_display('node', $type_name, 'default')->setComponent($name)->save();
     return $field_config;
 }
Ejemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->createImageField($this->fieldName, $this->contentType, ['uri_scheme' => 'public'], ['alt_field_required' => 0]);
     entity_get_display('node', $this->contentType, 'default')->setComponent($this->fieldName, ['type' => 'colorbox', 'settings' => []])->save();
     $this->drupalGet('node/add/article');
     $test_image = current($this->drupalGetTestFiles('image'));
     $this->testNid = $this->uploadNodeImage($test_image, $this->fieldName, 'article', '');
 }
 /**
  * Tests comment variables migrated into an entity display.
  */
 public function testCommentEntityDisplay()
 {
     foreach ($this->types as $type) {
         $component = entity_get_display('node', $type, 'default')->getComponent('comment');
         $this->assertIdentical('hidden', $component['label']);
         $this->assertIdentical('comment_default', $component['type']);
         $this->assertIdentical(20, $component['weight']);
     }
 }
Ejemplo n.º 23
0
 /**
  * Returns the in-place editor that Quick Edit selects.
  */
 protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default')
 {
     $storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
     $storage->resetCache([$entity_id]);
     $entity = $storage->load($entity_id);
     $items = $entity->get($field_name);
     $options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name);
     return $this->editorSelector->getEditor($options['type'], $items);
 }
Ejemplo n.º 24
0
 /**
  * Create a new image field.
  *
  * @param string $name
  *   The name of the new field (all lowercase), exclude the "field_" prefix.
  * @param string $type_name
  *   The node type that this field will be added to.
  * @param array $storage_settings
  *   A list of field storage settings that will be added to the defaults.
  * @param array $field_settings
  *   A list of instance settings that will be added to the instance defaults.
  * @param array $widget_settings
  *   Widget settings to be added to the widget defaults.
  * @param array $formatter_settings
  *   Formatter settings to be added to the formatter defaults.
  * @param string $description
  *   A description for the field.
  */
 function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array(), $description = '')
 {
     FieldStorageConfig::create(array('field_name' => $name, 'entity_type' => 'node', 'type' => 'image', 'settings' => $storage_settings, 'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1))->save();
     $field_config = FieldConfig::create(['field_name' => $name, 'label' => $name, 'entity_type' => 'node', 'bundle' => $type_name, 'required' => !empty($field_settings['required']), 'settings' => $field_settings, 'description' => $description]);
     $field_config->save();
     entity_get_form_display('node', $type_name, 'default')->setComponent($name, array('type' => 'image_image', 'settings' => $widget_settings))->save();
     entity_get_display('node', $type_name, 'default')->setComponent($name, array('type' => 'image', 'settings' => $formatter_settings))->save();
     return $field_config;
 }
 /**
  * Create taxonomy term reference field for testing categories.
  *
  * @param object $vocabulary
  *   Taxonomy vocabulary.
  *
  * @return string
  *   Created field name.
  */
 protected function createTaxonomyTermReferenceField($vocabulary)
 {
     $field_tags_name = Unicode::strtolower($this->randomMachineName());
     $field_storage = entity_create('field_storage_config', array('field_name' => $field_tags_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id(), 'parent' => '0')))));
     $field_storage->save();
     entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => 'article'))->save();
     entity_get_form_display('node', 'article', 'default')->setComponent($field_tags_name, array('type' => 'taxonomy_autocomplete'))->save();
     entity_get_display('node', 'article', 'full')->setComponent($field_tags_name, array('type' => 'taxonomy_term_reference_link'))->save();
     return $field_tags_name;
 }
 /**
  * Adds term reference field for the article content type.
  *
  * @param bool $translatable
  *   (optional) If TRUE, create a translatable term reference field. Defaults
  *   to FALSE.
  */
 protected function setUpTermReferenceField()
 {
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     $field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
     $field_storage->setTranslatable(FALSE);
     $field_storage->save();
     entity_get_form_display('node', 'article', 'default')->setComponent($this->termFieldName, array('type' => 'entity_reference_autocomplete_tags'))->save();
     entity_get_display('node', 'article', 'default')->setComponent($this->termFieldName, array('type' => 'entity_reference_label'))->save();
 }
Ejemplo n.º 27
0
 /**
  * Creates a field.
  *
  * @param string $field_name
  *   The field name.
  * @param string $type
  *   The field type.
  * @param int $cardinality
  *   The field's cardinality.
  * @param string $label
  *   The field's label (used everywhere: widget label, formatter label).
  * @param array $field_settings
  * @param string $widget_type
  *   The widget type.
  * @param array $widget_settings
  *   The widget settings.
  * @param string $formatter_type
  *   The formatter type.
  * @param array $formatter_settings
  *   The formatter settings.
  */
 protected function createFieldWithStorage($field_name, $type, $cardinality, $label, $field_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings)
 {
     $field_storage = $field_name . '_field_storage';
     $this->fields->{$field_storage} = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => $type, 'cardinality' => $cardinality));
     $this->fields->{$field_storage}->save();
     $field = $field_name . '_field';
     $this->fields->{$field} = entity_create('field_config', array('field_storage' => $this->fields->{$field_storage}, 'bundle' => 'entity_test', 'label' => $label, 'description' => $label, 'weight' => mt_rand(0, 127), 'settings' => $field_settings));
     $this->fields->{$field}->save();
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => $widget_type, 'settings' => $widget_settings))->save();
     entity_get_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('label' => 'above', 'type' => $formatter_type, 'settings' => $formatter_settings))->save();
 }
 /**
  * Setup the entity displays with required fields.
  */
 protected function setupEntityDisplays()
 {
     $this->fieldName = 'field_test_video_field';
     $this->contentTypeName = 'test_content_type_name';
     $this->createContentType(['type' => $this->contentTypeName]);
     $field_storage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'video_embed_field', 'settings' => ['allowed_providers' => []]]);
     $field_storage->save();
     FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->contentTypeName, 'settings' => []])->save();
     $this->entityDisplay = entity_get_display('node', $this->contentTypeName, 'default');
     $this->entityFormDisplay = entity_get_form_display('node', $this->contentTypeName, 'default');
 }
Ejemplo n.º 29
0
 protected function setUp()
 {
     parent::setUp();
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
     $this->vocabulary = $this->createVocabulary();
     $this->fieldName = 'taxonomy_' . $this->vocabulary->id();
     entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $this->vocabulary->id(), 'parent' => 0)))))->save();
     entity_create('field_config', array('field_name' => $this->fieldName, 'bundle' => 'article', 'entity_type' => 'node'))->save();
     entity_get_form_display('node', 'article', 'default')->setComponent($this->fieldName, array('type' => 'options_select'))->save();
     entity_get_display('node', 'article', 'default')->setComponent($this->fieldName, array('type' => 'taxonomy_term_reference_link'))->save();
 }
Ejemplo n.º 30
0
 protected function setUp()
 {
     parent::setUp();
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access', 'administer content types', 'administer node display']));
     $this->vocabulary = $this->createVocabulary();
     $this->fieldName = 'taxonomy_' . $this->vocabulary->id();
     $handler_settings = array('target_bundles' => array($this->vocabulary->id() => $this->vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     entity_get_form_display('node', 'article', 'default')->setComponent($this->fieldName, array('type' => 'options_select'))->save();
     entity_get_display('node', 'article', 'default')->setComponent($this->fieldName, array('type' => 'entity_reference_label'))->save();
 }