public static function isPaymentValid($oplataSettings, $response) { list($orderId, ) = explode(self::ORDER_SEPARATOR, $response['order_id']); $order = uc_order_load($orderId); if ($order === FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') { return t('An error has occurred during payment. Please contact us to ensure your order has submitted.'); } if ($oplataSettings->merchant_id != $response['merchant_id']) { return t('An error has occurred during payment. Merchant data is incorrect.'); } $originalResponse = $response; foreach ($response as $k => $v) { if (!in_array($k, self::$responseFields)) { unset($response[$k]); } } if (self::getSignature($response, $oplataSettings->secret_key) != $originalResponse['signature']) { return t('An error has occurred during payment. Signature is not valid.'); } if (drupal_strtolower($originalResponse['sender_email']) !== drupal_strtolower($order->primary_email)) { uc_order_comment_save($order->order_id, 0, t('Customer used a different e-mail address during payment: !email', array('!email' => check_plain($originalResponse['sender_email']))), 'admin'); } uc_order_comment_save($order->order_id, 0, "Order status: {$response['order_status']}", 'admin'); return true; }
protected function setUp() { parent::setUp(); $this->installEntitySchema('taxonomy_term'); // We want a taxonomy term reference field. It needs a vocabulary, terms, // a field storage and a field. First, create the vocabulary. $vocabulary = entity_create('taxonomy_vocabulary', array('vid' => drupal_strtolower($this->randomMachineName()))); $vocabulary->save(); // Second, create the field. $this->fieldName = strtolower($this->randomMachineName()); entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'settings' => array('allowed_values' => array('vocabulary' => $vocabulary->id()))))->save(); entity_test_create_bundle('test_bundle'); // Third, create the instance. entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'test_bundle'))->save(); // Create two terms and also two accounts. for ($i = 0; $i <= 1; $i++) { $term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocabulary->id())); $term->save(); $this->terms[] = $term; $this->accounts[] = $this->createUser(); } // Create three entity_test entities, the 0th entity will point to the // 0th account and 0th term, the 1st and 2nd entity will point to the // 1st account and 1st term. for ($i = 0; $i <= 2; $i++) { $entity = entity_create('entity_test', array('type' => 'test_bundle')); $entity->name->value = $this->randomMachineName(); $index = $i ? 1 : 0; $entity->user_id->target_id = $this->accounts[$index]->id(); $entity->{$this->fieldName}->target_id = $this->terms[$index]->id(); $entity->save(); $this->entities[] = $entity; } $this->factory = \Drupal::service('entity.query'); }
/** * Tests email field. */ function testEmailField() { // Create a field with settings to validate. $field_name = drupal_strtolower($this->randomMachineName()); $this->fieldStorage = entity_create('field_storage_config', array('name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'email')); $this->fieldStorage->save(); $this->instance = entity_create('field_instance_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test')); $this->instance->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('user_id' => 1, 'name' => $this->randomMachineName(), "{$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 = entity_load('entity_test', $id); $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full'); $content = $display->build($entity); $this->drupalSetContent(drupal_render($content)); $this->assertLinkByHref('mailto:test@example.com'); }
/** * Tests that default values are correctly translated to UUIDs in config. */ function testEntityReferenceDefaultValue() { // Create a node to be referenced. $referenced_node = $this->drupalCreateNode(array('type' => 'referenced_content')); $field_name = drupal_strtolower($this->randomMachineName()); $field_storage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'node', 'type' => 'entity_reference', 'settings' => array('target_type' => 'node'))); $field_storage->save(); $field = entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => 'reference_content', 'settings' => array('handler' => 'default', 'handler_settings' => array('target_bundles' => array('referenced_content'), 'sort' => array('field' => '_none'))))); $field->save(); // Set created node as default_value. $field_edit = array('default_value_input[' . $field_name . '][0][target_id]' => $referenced_node->getTitle() . ' (' . $referenced_node->id() . ')'); $this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name, $field_edit, t('Save settings')); // Check that default value is selected in default value form. $this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name); $this->assertRaw('name="default_value_input[' . $field_name . '][0][target_id]" value="' . $referenced_node->getTitle() . ' (' . $referenced_node->id() . ')', 'The default value is selected in instance settings page'); // Check if the ID has been converted to UUID in config entity. $config_entity = $this->container->get('config.factory')->get('field.field.node.reference_content.' . $field_name)->get(); $this->assertTrue(isset($config_entity['default_value'][0]['target_uuid']), 'Default value contains target_uuid property'); $this->assertEqual($config_entity['default_value'][0]['target_uuid'], $referenced_node->uuid(), 'Content uuid and config entity uuid are the same'); // Ensure the configuration has the expected dependency on the entity that // is being used a default value. $this->assertEqual(array($referenced_node->getConfigDependencyName()), $config_entity['dependencies']['content']); // Clear field definitions cache in order to avoid stale cache values. \Drupal::entityManager()->clearCachedFieldDefinitions(); // Create a new node to check that UUID has been converted to numeric ID. $new_node = entity_create('node', array('type' => 'reference_content')); $this->assertEqual($new_node->get($field_name)->offsetGet(0)->target_id, $referenced_node->id()); }
/** * Returns a new vocabulary with random properties. */ function createVocabulary() { // Create a vocabulary. $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => drupal_strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10))); $vocabulary->save(); return $vocabulary; }
/** * Verifies that strings of CJK characters are tokenized. * * The search_simplify() function does special things with numbers, symbols, * and punctuation. So we only test that CJK characters that are not in these * character classes are tokenized properly. See PREG_CLASS_CKJ for more * information. */ function testTokenizer() { // Set the minimum word size to 1 (to split all CJK characters) and make // sure CJK tokenizing is turned on. \Drupal::config('search.settings')->set('index.minimum_word_size', 1)->set('index.overlap_cjk', TRUE)->save(); $this->refreshVariables(); // Create a string of CJK characters from various character ranges in // the Unicode tables. // Beginnings of the character ranges. $starts = array('CJK unified' => 0x4e00, 'CJK Ext A' => 0x3400, 'CJK Compat' => 0xf900, 'Hangul Jamo' => 0x1100, 'Hangul Ext A' => 0xa960, 'Hangul Ext B' => 0xd7b0, 'Hangul Compat' => 0x3131, 'Half non-punct 1' => 0xff21, 'Half non-punct 2' => 0xff41, 'Half non-punct 3' => 0xff66, 'Hangul Syllables' => 0xac00, 'Hiragana' => 0x3040, 'Katakana' => 0x30a1, 'Katakana Ext' => 0x31f0, 'CJK Reserve 1' => 0x20000, 'CJK Reserve 2' => 0x30000, 'Bomofo' => 0x3100, 'Bomofo Ext' => 0x31a0, 'Lisu' => 0xa4d0, 'Yi' => 0xa000); // Ends of the character ranges. $ends = array('CJK unified' => 0x9fcf, 'CJK Ext A' => 0x4dbf, 'CJK Compat' => 0xfaff, 'Hangul Jamo' => 0x11ff, 'Hangul Ext A' => 0xa97f, 'Hangul Ext B' => 0xd7ff, 'Hangul Compat' => 0x318e, 'Half non-punct 1' => 0xff3a, 'Half non-punct 2' => 0xff5a, 'Half non-punct 3' => 0xffdc, 'Hangul Syllables' => 0xd7af, 'Hiragana' => 0x309f, 'Katakana' => 0x30ff, 'Katakana Ext' => 0x31ff, 'CJK Reserve 1' => 0x2fffd, 'CJK Reserve 2' => 0x3fffd, 'Bomofo' => 0x312f, 'Bomofo Ext' => 0x31b7, 'Lisu' => 0xa4fd, 'Yi' => 0xa48f); // Generate characters consisting of starts, midpoints, and ends. $chars = array(); $charcodes = array(); foreach ($starts as $key => $value) { $charcodes[] = $starts[$key]; $chars[] = $this->code2utf($starts[$key]); $mid = round(0.5 * ($starts[$key] + $ends[$key])); $charcodes[] = $mid; $chars[] = $this->code2utf($mid); $charcodes[] = $ends[$key]; $chars[] = $this->code2utf($ends[$key]); } // Merge into a string and tokenize. $string = implode('', $chars); $out = trim(search_simplify($string)); $expected = drupal_strtolower(implode(' ', $chars)); // Verify that the output matches what we expect. $this->assertEqual($out, $expected, 'CJK tokenizer worked on all supplied CJK characters'); }
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; }
/** * Tests configuration options and the site-wide contact form. */ public function testContactStorage() { // Create and login administrative user. $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer users', 'administer account settings', 'administer contact_message fields')); $this->drupalLogin($admin_user); // Create first valid category. $mail = '*****@*****.**'; $this->addCategory($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($mail)), '', TRUE); $this->assertRaw(t('Category %label has been added.', array('%label' => $label))); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('Your email address')); $this->assertNoText(t('Category')); $this->submitContact($name = $this->randomName(16), $mail, $subject = $this->randomName(16), $id, $message = $this->randomName(64)); $this->assertText(t('Your message has been sent.')); $messages = Message::loadMultiple(); /** @var \Drupal\contact\Entity\Message $message */ $message = reset($messages); $this->assertEqual($message->getCategory()->id(), $id); $this->assertEqual($message->getSenderName(), $name); $this->assertEqual($message->getSubject(), $subject); $this->assertEqual($message->getSenderMail(), $mail); }
/** * 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); }
/** * Tests configuration options and the site-wide contact form. */ public function testContactStorage() { // Create and login administrative user. $admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer users', 'administer account settings', 'administer contact_message fields')); $this->drupalLogin($admin_user); // Create first valid contact form. $mail = '*****@*****.**'; $this->addContactForm($id = drupal_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', array($mail)), '', TRUE, ['send_a_pony' => 1]); $this->assertRaw(t('Contact form %label has been added.', array('%label' => $label))); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); $this->drupalLogout(); $this->drupalGet('contact'); $this->assertText(t('Your email address')); $this->assertNoText(t('Form')); $this->submitContact($name = $this->randomMachineName(16), $mail, $subject = $this->randomMachineName(16), $id, $message = $this->randomMachineName(64)); $this->assertText(t('Your message has been sent.')); $messages = Message::loadMultiple(); /** @var \Drupal\contact\Entity\Message $message */ $message = reset($messages); $this->assertEqual($message->getContactForm()->id(), $id); $this->assertTrue($message->getContactForm()->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE)); $this->assertEqual($message->getSenderName(), $name); $this->assertEqual($message->getSubject(), $subject); $this->assertEqual($message->getSenderMail(), $mail); $config = \Drupal::config("contact.form.{$id}"); $this->assertEqual($config->get('id'), $id); $this->assertConfigSchema(\Drupal::service('config.typed'), $config->getName(), $config->get()); }
/** * Tests that link field UI functionality does not generate warnings. */ function testFieldUI() { // Add a content type. $type = $this->drupalCreateContentType(); $type_path = 'admin/structure/types/manage/' . $type->type; // Add a link field to the newly-created type. $label = $this->randomName(); $field_name = drupal_strtolower($label); $edit = array( 'fields[_add_new_field][label]' => $label, 'fields[_add_new_field][field_name]' => $field_name, 'fields[_add_new_field][type]' => 'link', 'fields[_add_new_field][widget_type]' => 'link_default', ); $this->drupalPost("$type_path/fields", $edit, t('Save')); // Proceed to the Edit (field instance settings) page. $this->drupalPost(NULL, array(), t('Save field settings')); // Proceed to the Manage fields overview page. $this->drupalPost(NULL, array(), t('Save settings')); // Load the formatter page to check that the settings summary does not // generate warnings. // @todo Mess with the formatter settings a bit here. $this->drupalGet("$type_path/display"); $this->assertText(t('Link text trimmed to @limit characters', array('@limit' => 80))); }
/** * Override or insert PHPTemplate variables into the templates. */ function boldy_preprocess_page(&$vars) { $vars['tabs2'] = menu_secondary_local_tasks(); // Hook into color.module if (module_exists('color')) { _color_page_alter($vars); } // Classes for body element. Allows advanced theming based on context // (home page, node of certain type, etc.) $classes = explode(' ', $vars['body_classes']); // Remove the mostly useless page-ARG0 class. if ($index = array_search(preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-' . drupal_strtolower(arg(0))), $classes)) { unset($classes[$index]); } if (!$vars['is_front']) { // Add unique class for each page. $path = drupal_get_path_alias($_GET['q']); $classes[] = boldy_id_safe('page-' . $path); // Add unique class for each website section. list($section, ) = explode('/', $path, 2); if (arg(0) == 'node') { if (arg(1) == 'add') { $section = 'node-add'; } elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) { $section = 'node-' . arg(2); } } $classes[] = boldy_id_safe('section-' . $section); } $vars['body_classes_array'] = $classes; $vars['body_classes'] = implode(' ', $classes); // Concatenate with spaces. }
function flickr_context_tags_settings() { $form = array(); $mt_ns = variable_get('flickr_context_tags_mech_namespace', ''); //Make a qualified guess if (empty($mt_ns)) { $matches = array(); $site_name = variable_get('site_name', ''); if (preg_match('/^\\s*([^\\s\\.]+)/', $site_name, $matches)) { $mt_ns = drupal_strtolower($matches[1]); } } $form['flickr_context_tags_mech_namespace'] = array('#type' => 'textfield', '#title' => t('Machine-tag namespace'), '#default_value' => $mt_ns); $form['flickr_context_tags_userid'] = array('#type' => 'textfield', '#title' => t('Flickr id'), '#description' => t('Can be used to get photos from a specified flickr user'), '#default_value' => variable_get('flickr_context_tags_userid', '')); $form['flickr_context_tags_default_place_id'] = array('#type' => 'textfield', '#title' => t('Default place id'), '#description' => t('The default place id can be used to keep the flickr pictures relevant'), '#default_value' => variable_get('flickr_context_tags_default_place_id', '')); $form['flickr_context_tags_force_default_place_id'] = array('#type' => 'checkbox', '#title' => t('Always use the default place id'), '#default_value' => variable_get('flickr_context_tags_force_default_place_id', FALSE)); $sizes = array('s' => t('Square'), 't' => t('Thumbnail'), 'm' => t('Small'), '-' => t('Medium'), 'b' => t('Large'), 'o' => t('Orginal')); $form['flickr_context_tags_size'] = array('#type' => 'select', '#title' => t('Select the size you want your photos in'), '#default_value' => variable_get('flickr_context_tags_size', 'm'), '#options' => $sizes); // Tag configuration textarea $paths = variable_get('flickr_context_tags_contexts', array()); $form['flickr_context_tags_contexts'] = array('#type' => 'textarea', '#title' => t('Context tags for paths'), '#default_value' => flickr_context_tags_pack_contexts($paths), '#description' => t('Enter the path expression followed by a list of comma-separated tags')); // Piggyback on the system settings form for buttons and so on $form = system_settings_form($form); // ...but replace the #submit function $form['#submit'] = array('flickr_context_tags_settings_submit'); return $form; }
/** * Tests term language settings for vocabulary terms are saved and updated. */ function testVocabularyDefaultLanguageForTerms() { // Add a new vocabulary and check that the default language settings are for // the terms are saved. $edit = array('name' => $this->randomMachineName(), 'vid' => drupal_strtolower($this->randomMachineName()), 'default_language[langcode]' => 'bb', 'default_language[language_show]' => TRUE); $vid = $edit['vid']; $this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save')); // Check that the vocabulary was actually created. $this->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']); $this->assertResponse(200, 'The vocabulary has been created.'); // Check that the language settings were saved. $language_settings = language_get_default_configuration('taxonomy_term', $edit['vid']); $this->assertEqual($language_settings['langcode'], 'bb', 'The langcode was saved.'); $this->assertTrue($language_settings['language_show'], 'The visibility setting was saved.'); // Check that the correct options are selected in the interface. $this->assertOptionSelected('edit-default-language-langcode', 'bb', 'The correct default language for the terms of this vocabulary is selected.'); $this->assertFieldChecked('edit-default-language-language-show', 'Show language selection option is checked.'); // Edit the vocabulary and check that the new settings are updated. $edit = array('default_language[langcode]' => 'aa', 'default_language[language_show]' => FALSE); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save')); // And check again the settings and also the interface. $language_settings = language_get_default_configuration('taxonomy_term', $vid); $this->assertEqual($language_settings['langcode'], 'aa', 'The langcode was saved.'); $this->assertFalse($language_settings['language_show'], 'The visibility setting was saved.'); $this->drupalGet('admin/structure/taxonomy/manage/' . $vid); $this->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.'); $this->assertNoFieldChecked('edit-default-language-language-show', 'Show language selection option is not checked.'); // Check that language settings are changed after editing vocabulary. $edit = array('name' => $this->randomMachineName(), 'default_language[langcode]' => 'authors_default', 'default_language[language_show]' => FALSE); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save')); // Check that we have the new settings. $new_settings = language_get_default_configuration('taxonomy_term', $vid); $this->assertEqual($new_settings['langcode'], 'authors_default', 'The langcode was saved.'); $this->assertFalse($new_settings['language_show'], 'The new visibility setting was saved.'); }
protected function setUp() { parent::setUp(); $this->languageManager = $this->container->get('language_manager'); $this->installEntitySchema('entity_test_rev'); $this->installEntitySchema('entity_test_mul'); $this->installEntitySchema('entity_test_mulrev'); $this->installConfig(array('language')); // Create the test field. entity_test_install(); // Enable translations for the test entity type. $this->state->set('entity_test.translation', TRUE); // Create a translatable test field. $this->field_name = drupal_strtolower($this->randomMachineName() . '_field_name'); // Create an untranslatable test field. $this->untranslatable_field_name = drupal_strtolower($this->randomMachineName() . '_field_name'); // Create field fields in all entity variations. foreach (entity_test_entity_types() as $entity_type) { entity_create('field_storage_config', array('field_name' => $this->field_name, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save(); entity_create('field_config', array('field_name' => $this->field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => TRUE))->save(); $this->field[$entity_type] = entity_load('field_config', $entity_type . '.' . $entity_type . '.' . $this->field_name); entity_create('field_storage_config', array('field_name' => $this->untranslatable_field_name, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save(); entity_create('field_config', array('field_name' => $this->untranslatable_field_name, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => FALSE))->save(); } // Create the default languages. $this->installConfig(array('language')); // Create test languages. $this->langcodes = array(); for ($i = 0; $i < 3; ++$i) { $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString(), 'weight' => $i)); $this->langcodes[$i] = $language->getId(); $language->save(); } }
protected function setUp() { parent::setUp(); // Create Basic page node type. $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); $this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => drupal_strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('page' => 'page'), 'weight' => mt_rand(0, 10))); $this->vocabulary->save(); // Setup a field and instance. $this->field_name = drupal_strtolower($this->randomMachineName()); entity_create('field_storage_config', array('name' => $this->field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'settings' => array('allowed_values' => array(array('vocabulary' => $this->vocabulary->id(), 'parent' => '0')))))->save(); entity_create('field_instance_config', array('field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => 'page'))->save(); // Create a time in the past for the archive. $time = REQUEST_TIME - 3600; $this->container->get('comment.manager')->addDefaultField('node', 'page'); $this->container->get('views.views_data')->clear(); for ($i = 0; $i <= 10; $i++) { $user = $this->drupalCreateUser(); $term = $this->createTerm($this->vocabulary); $values = array('created' => $time, 'type' => 'page'); $values[$this->field_name][]['target_id'] = $term->id(); // Make every other node promoted. if ($i % 2) { $values['promote'] = TRUE; } $values['body'][]['value'] = l('Node ' . 1, 'node/' . 1); $node = $this->drupalCreateNode($values); $comment = array('uid' => $user->id(), 'status' => CommentInterface::PUBLISHED, 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment'); entity_create('comment', $comment)->save(); } // Some views, such as the "Who's Online" view, only return results if at // least one user is logged in. $account = $this->drupalCreateUser(array()); $this->drupalLogin($account); }
/** * 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'); }
function setUp() { parent::setUp(); $this->fieldStorageDefinition = array('name' => drupal_strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'test_field'); $this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition); $this->fieldStorage->save(); $this->instanceDefinition = array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test'); }
/** * Allow to override default machine name generation. * * @param string $machine_name * Machine name. * @param string $name * Basic name. * @param bool $force * Force new machine name. */ function hook_taxonomy_machine_name_clean_name(&$machine_name, $name, $force) { if ($force) { $machine_name = drupal_strtolower(str_replace('_', '-', $name)); $machine_name = preg_replace('/[^a-z0-9\_]/i', '_', $machine_name); $machine_name = trim($machine_name, '_'); } }
/** * Overrides \Drupal\simpletest\WebTestBase::setUp(). */ public function setUp() { $this->entityTypeId = 'block_content'; $this->bundle = 'basic'; $this->name = drupal_strtolower($this->randomName()); $this->testLanguageSelector = FALSE; parent::setUp(); }
/** * Implementation of hook_page_alter() */ function andromeda_page_alter(&$page) { //match pages and unset sidebar on matched pages $pages = drupal_strtolower(theme_get_setting('andromeda_sidebar_visibility')); $path = drupal_strtolower(drupal_get_path_alias($_GET['q'])); if (drupal_match_path($path, $pages)) { unset($page['sidebar']); } }
protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_mulrev'); $this->installConfig(array('language')); $figures = drupal_strtolower($this->randomMachineName()); $greetings = drupal_strtolower($this->randomMachineName()); foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) { $field_storage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'entity_test_mulrev', 'type' => $field_type, 'cardinality' => 2, 'translatable' => TRUE)); $field_storage->save(); $field_storages[] = $field_storage; } $bundles = array(); for ($i = 0; $i < 2; $i++) { // For the sake of tablesort, make sure the second bundle is higher than // the first one. Beware: MySQL is not case sensitive. do { $bundle = $this->randomMachineName(); } while ($bundles && strtolower($bundles[0]) >= strtolower($bundle)); entity_test_create_bundle($bundle); foreach ($field_storages as $field_storage) { entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $bundle))->save(); } $bundles[] = $bundle; } // Each unit is a list of field name, langcode and a column-value array. $units[] = array($figures, 'en', array('color' => 'red', 'shape' => 'triangle')); $units[] = array($figures, 'en', array('color' => 'blue', 'shape' => 'circle')); // To make it easier to test sorting, the greetings get formats according // to their langcode. $units[] = array($greetings, 'tr', array('value' => 'merhaba', 'format' => 'format-tr')); $units[] = array($greetings, 'pl', array('value' => 'siema', 'format' => 'format-pl')); // Make these languages available to the greetings field. ConfigurableLanguage::createFromLangcode('tr')->save(); ConfigurableLanguage::createFromLangcode('pl')->save(); // Calculate the cartesian product of the unit array by looking at the // bits of $i and add the unit at the bits that are 1. For example, // decimal 13 is binary 1101 so unit 3,2 and 0 will be added to the // entity. for ($i = 1; $i <= 15; $i++) { $entity = entity_create('entity_test_mulrev', array('type' => $bundles[$i & 1], 'name' => $this->randomMachineName(), 'langcode' => 'en')); // Make sure the name is set for every language that we might create. foreach (array('tr', 'pl') as $langcode) { $entity->getTranslation($langcode)->name = $this->randomMachineName(); } foreach (array_reverse(str_split(decbin($i))) as $key => $bit) { if ($bit) { list($field_name, $langcode, $values) = $units[$key]; $entity->getTranslation($langcode)->{$field_name}[] = $values; } } $entity->save(); } $this->figures = $figures; $this->greetings = $greetings; $this->factory = \Drupal::service('entity.query'); }
public function setUp() { parent::setUp(); $this->installEntitySchema('taxonomy_term'); $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomName(), 'vid' => drupal_strtolower($this->randomName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $vocabulary->save(); entity_create('field_storage_config', array('name' => 'field_test_taxonomy', 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id(), 'parent' => 0)))))->save(); entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_taxonomy', 'bundle' => 'entity_test'))->save(); $this->term = entity_create('taxonomy_term', array('name' => $this->randomName(), 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $this->term->save(); }
function scholar_base_id_safe($string) { // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores. $string = strtr(drupal_strtolower($string), array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); $string = strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string)); // If the first character is not a-z, add 'id' in front. if (!ctype_lower($string[0])) { // Don't use ctype_alpha since it is locale aware. $string = 'id' . $string; } return $string; }
public function refreshConsumerIDs() { $this->drupalRolesByName = array(); foreach (array_flip(user_roles()) as $role_name => $rid) { $this->drupalRolesByName[drupal_strtolower($role_name)] = $rid; } $this->_availableConsumerIDs = array(); // array_values(user_roles(TRUE)); foreach (array_values(user_roles(TRUE)) as $role_name) { $this->_availableConsumerIDs[] = drupal_strtolower($role_name); } }
/** * Helper function for testing drupal_html_to_text(). * * @param $html * The source HTML string to be converted. * @param $text * The expected result of converting $html to text. * @param $message * A text message to display in the assertion message. * @param $allowed_tags * (optional) An array of allowed tags, or NULL to default to the full * set of tags supported by drupal_html_to_text(). */ protected function assertHtmlToText($html, $text, $message, $allowed_tags = NULL) { preg_match_all('/<([a-z0-6]+)/', drupal_strtolower($html), $matches); $tested_tags = implode(', ', array_unique($matches[1])); $message .= ' (' . $tested_tags . ')'; $result = drupal_html_to_text($html, $allowed_tags); $pass = $this->assertEqual($result, $text, String::checkPlain($message)); $verbose = 'html = <pre>' . $this->stringToHtml($html) . '</pre><br />' . 'result = <pre>' . $this->stringToHtml($result) . '</pre><br />' . 'expected = <pre>' . $this->stringToHtml($text) . '</pre>'; $this->verbose($verbose); if (!$pass) { $this->pass("Previous test verbose info:<br />{$verbose}"); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Create an administrative user. $this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'bypass node access')); $this->drupalLogin($this->admin_user); // Create a vocabulary and add two term reference fields to article nodes. $this->field_name_1 = drupal_strtolower($this->randomMachineName()); entity_create('field_storage_config', array('field_name' => $this->field_name_1, '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->field_name_1, 'bundle' => 'article', 'entity_type' => 'node'))->save(); entity_get_form_display('node', 'article', 'default')->setComponent($this->field_name_1, array('type' => 'options_select'))->save(); entity_get_display('node', 'article', 'default')->setComponent($this->field_name_1, array('type' => 'taxonomy_term_reference_link'))->save(); }
function generateVocabs($records, $maxlength = 12) { $vocs = array(); // Insert new data: for ($i = 1; $i <= $records; $i++) { $name = $this->generateWord(mt_rand(2, $maxlength)); $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $name, 'vid' => drupal_strtolower($name), 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'description' => "description of {$name}", 'hierarchy' => 1, 'weight' => mt_rand(0, 10), 'multiple' => 1, 'required' => 0, 'relations' => 1)); $vocabulary->save(); $vocs[] = $vocabulary->name; unset($vocabulary); } return $vocs; }
/** * Tests a simple site export import case. */ public function testExportImport() { $this->originalSlogan = \Drupal::config('system.site')->get('slogan'); $this->newSlogan = $this->randomString(16); $this->assertNotEqual($this->newSlogan, $this->originalSlogan); \Drupal::config('system.site')->set('slogan', $this->newSlogan)->save(); $this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->newSlogan); // Create a content type. $this->content_type = $this->drupalCreateContentType(); // Create a field. $this->fieldName = drupal_strtolower($this->randomMachineName()); $this->fieldStorage = entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text')); $this->fieldStorage->save(); entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => $this->content_type->type))->save(); entity_get_form_display('node', $this->content_type->type, 'default')->setComponent($this->fieldName, array('type' => 'text_textfield'))->save(); entity_get_display('node', $this->content_type->type, 'full')->setComponent($this->fieldName)->save(); $this->drupalGet('node/add/' . $this->content_type->type); $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed'); // Export the configuration. $this->drupalPostForm('admin/config/development/configuration/full/export', array(), 'Export'); $this->tarball = $this->drupalGetContent(); \Drupal::config('system.site')->set('slogan', $this->originalSlogan)->save(); $this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->originalSlogan); // Delete the custom field. $fields = entity_load_multiple('field_config'); foreach ($fields as $field) { if ($field->field_name == $this->fieldName) { $field->delete(); } } $field_storages = entity_load_multiple('field_storage_config'); foreach ($field_storages as $field_storage) { if ($field_storage->field_name == $this->fieldName) { $field_storage->delete(); } } $this->drupalGet('node/add/' . $this->content_type->type); $this->assertNoFieldByName("{$this->fieldName}[0][value]", '', 'Widget is not displayed'); // Import the configuration. $filename = 'temporary://' . $this->randomMachineName(); file_put_contents($filename, $this->tarball); $this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload'); $this->drupalPostForm(NULL, array(), 'Import all'); $this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->newSlogan); $this->drupalGet('node/add'); $this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed'); \Drupal::config('system.site')->set('slogan', $this->originalSlogan)->save(); $this->drupalGet('admin/config/development/configuration'); $this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site'); }
protected function setUp() { parent::setUp(); node_access_rebuild(); // Create some users. $this->admin_user = $this->drupalCreateUser(array('access content', 'bypass node access')); $this->content_admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields')); // Add a custom field to the page content type. $this->field_name = drupal_strtolower($this->randomMachineName() . '_field_name'); entity_create('field_storage_config', array('field_name' => $this->field_name, 'entity_type' => 'node', 'type' => 'text'))->save(); entity_create('field_config', array('field_name' => $this->field_name, 'entity_type' => 'node', 'bundle' => 'page'))->save(); entity_get_display('node', 'page', 'default')->setComponent($this->field_name)->save(); entity_get_form_display('node', 'page', 'default')->setComponent($this->field_name)->save(); }