当前位置: 首页>>代码示例>>PHP>>正文


PHP Drupal::url方法代码示例

本文整理汇总了PHP中Drupal::url方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::url方法的具体用法?PHP Drupal::url怎么用?PHP Drupal::url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal的用法示例。


在下文中一共展示了Drupal::url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDeleteFeedItem

 /**
  * Tests running "delete items" from 'admin/config/services/aggregator' page.
  */
 public function testDeleteFeedItem()
 {
     // Create a bunch of test feeds.
     $feed_urls = array();
     // No last-modified, no etag.
     $feed_urls[] = \Drupal::url('aggregator_test.feed', array(), array('absolute' => TRUE));
     // Last-modified, but no etag.
     $feed_urls[] = \Drupal::url('aggregator_test.feed', array('use_last_modified' => 1), array('absolute' => TRUE));
     // No Last-modified, but etag.
     $feed_urls[] = \Drupal::url('aggregator_test.feed', array('use_last_modified' => 0, 'use_etag' => 1), array('absolute' => TRUE));
     // Last-modified and etag.
     $feed_urls[] = \Drupal::url('aggregator_test.feed', array('use_last_modified' => 1, 'use_etag' => 1), array('absolute' => TRUE));
     foreach ($feed_urls as $feed_url) {
         $feed = $this->createFeed($feed_url);
         // Update and delete items two times in a row to make sure that removal
         // resets all 'modified' information (modified, etag, hash) and allows for
         // immediate update. There's 8 items in the feed, but one has an empty
         // title and is skipped.
         $this->updateAndDelete($feed, 7);
         $this->updateAndDelete($feed, 7);
         $this->updateAndDelete($feed, 7);
         // Delete feed.
         $this->deleteFeed($feed);
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:28,代码来源:DeleteFeedItemTest.php

示例2: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
 {
     $settings = $editor->getSettings();
     $medium_editors = array();
     foreach (entity_load_multiple('medium_editor') as $medium_editor) {
         $medium_editors[$medium_editor->id()] = $medium_editor->label();
     }
     // Default editor
     $form['default_editor'] = array('#type' => 'select', '#title' => $this->t('Medium Editor'), '#options' => $medium_editors, '#default_value' => $settings['default_editor'], '#description' => $this->t('Select the default editor for the authorized roles. Editors can be configured at <a href="!url">Medium admin page</a>.', array('!url' => \Drupal::url('medium.admin'))), '#empty_option' => '- ' . $this->t('Select an editor') . ' -');
     // Roles editors
     $role_ids = array();
     if ($format_form = $form_state->getCompleteForm()) {
         if (isset($format_form['roles']['#value'])) {
             $role_ids = $format_form['roles']['#value'];
         } elseif (isset($format_form['roles']['#default_value'])) {
             $role_ids = $format_form['roles']['#default_value'];
         }
     } elseif ($format = $editor->getFilterFormat()) {
         $role_ids = array_keys(filter_get_roles_by_format($format));
     }
     if (count($role_ids) > 1) {
         $form['roles_editors'] = array('#type' => 'details', '#title' => t('Role specific editors'));
         $roles = user_roles();
         foreach ($role_ids as $role_id) {
             $form['roles_editors'][$role_id] = array('#type' => 'select', '#title' => $this->t('Editor for %role', array('%role' => $roles[$role_id]->label())), '#options' => $medium_editors, '#default_value' => isset($settings['roles_editors'][$role_id]) ? $settings['roles_editors'][$role_id] : '', '#empty_option' => '- ' . $this->t('Use the default') . ' -');
         }
     }
     return $form;
 }
开发者ID:digideskio,项目名称:medium-editor-d8,代码行数:32,代码来源:MediumEditor.php

示例3: testLanguageConfiguration

 /**
  * Functional tests for adding, editing and deleting languages.
  */
 public function testLanguageConfiguration()
 {
     // Create user with permissions to add and remove languages.
     $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
     $this->drupalLogin($admin_user);
     // Add custom language.
     $edit = array('predefined_langcode' => 'custom');
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
     // Test validation on missing values.
     $this->assertText(t('!name field is required.', array('!name' => t('Language code'))));
     $this->assertText(t('!name field is required.', array('!name' => t('Language name in English'))));
     $empty_language = new Language();
     $this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.');
     $this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
     // Test validation of invalid values.
     $edit = array('predefined_langcode' => 'custom', 'langcode' => 'white space', 'label' => '<strong>evil markup</strong>', 'direction' => LanguageInterface::DIRECTION_LTR);
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
     $this->assertRaw(t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => t('Language code'))));
     $this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name in English'))));
     $this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
     // Test validation of existing language values.
     $edit = array('predefined_langcode' => 'custom', 'langcode' => 'de', 'label' => 'German', 'direction' => LanguageInterface::DIRECTION_LTR);
     // Add the language the first time.
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
     $this->assertRaw(t('The language %language has been created and can now be used.', array('%language' => $edit['label'])));
     $this->assertUrl(\Drupal::url('language.admin_overview', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
     // Add the language a second time and confirm that this is not allowed.
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
     $this->assertRaw(t('The language %language (%langcode) already exists.', array('%language' => $edit['label'], '%langcode' => $edit['langcode'])));
     $this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:34,代码来源:LanguageCustomLanguageConfigurationTest.php

示例4: testUserLoginBlock

 /**
  * Test the user login block.
  */
 function testUserLoginBlock()
 {
     // Make sure the validation error is displayed when try to login with
     // invalid username/password.
     $edit['name'] = $this->randomMachineName();
     $edit['pass'] = $this->randomMachineName();
     $this->drupalPostForm('node', $edit, t('Log in'));
     $this->assertRaw('1 error has been found:');
     $this->assertRaw('<a href="#edit-name">Username</a>');
     $this->assertText(t('Sorry, unrecognized username or password.'));
     // Create a user with some permission that anonymous users lack.
     $user = $this->drupalCreateUser(array('administer permissions'));
     // Log in using the block.
     $edit = array();
     $edit['name'] = $user->getUsername();
     $edit['pass'] = $user->pass_raw;
     $this->drupalPostForm('admin/people/permissions', $edit, t('Log in'));
     $this->assertNoText(t('User login'), 'Logged in.');
     // Check that we are still on the same page.
     $this->assertUrl(\Drupal::url('user.admin_permissions', [], ['absolute' => TRUE]), [], 'Still on the same page after login for access denied page');
     // Now, log out and repeat with a non-403 page.
     $this->drupalLogout();
     $this->drupalPostForm('filter/tips', $edit, t('Log in'));
     $this->assertNoText(t('User login'), 'Logged in.');
     $this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', 'Still on the same page after login for allowed page');
     // Check that the user login block is not vulnerable to information
     // disclosure to third party sites.
     $this->drupalLogout();
     $this->drupalPostForm('http://example.com/', $edit, t('Log in'), array('external' => FALSE));
     // Check that we remain on the site after login.
     $this->assertUrl($user->url('canonical', ['absolute' => TRUE]), [], 'Redirected to user profile page after login from the frontpage');
 }
开发者ID:komejo,项目名称:article-test,代码行数:35,代码来源:UserBlocksTest.php

示例5: testMenuTokens

 function testMenuTokens()
 {
     // Add a menu.
     $menu = entity_create('menu', array('id' => 'main-menu', 'label' => 'Main menu', 'description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.'));
     $menu->save();
     // Add a root link.
     /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $root_link */
     $root_link = entity_create('menu_link_content', array('link' => ['uri' => 'internal:/admin'], 'title' => 'Administration', 'menu_name' => 'main-menu'));
     $root_link->save();
     // Add another link with the root link as the parent.
     /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $parent_link */
     $parent_link = entity_create('menu_link_content', array('link' => ['uri' => 'internal:/admin/config'], 'title' => 'Configuration', 'menu_name' => 'main-menu', 'parent' => $root_link->getPluginId()));
     $parent_link->save();
     // Test menu link tokens.
     $tokens = array('id' => $parent_link->getPluginId(), 'title' => 'Configuration', 'menu' => 'Main menu', 'menu:name' => 'Main menu', 'menu:machine-name' => $menu->id(), 'menu:description' => 'The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.', 'menu:menu-link-count' => '2', 'menu:edit-url' => \Drupal::url('entity.menu.edit_form', ['menu' => 'main-menu'], array('absolute' => TRUE)), 'url' => \Drupal::url('system.admin_config', [], array('absolute' => TRUE)), 'url:absolute' => \Drupal::url('system.admin_config', [], array('absolute' => TRUE)), 'url:relative' => \Drupal::url('system.admin_config', [], array('absolute' => FALSE)), 'url:path' => 'admin/config', 'url:alias' => 'admin/config', 'edit-url' => \Drupal::url('entity.menu_link_content.canonical', ['menu_link_content' => $parent_link->id()], array('absolute' => TRUE)), 'parent' => 'Administration', 'parent:id' => $root_link->getPluginId(), 'parent:title' => 'Administration', 'parent:menu' => 'Main menu', 'parent:parent' => NULL, 'parents' => 'Administration', 'parents:count' => 1, 'parents:keys' => $root_link->getPluginId(), 'root' => 'Administration', 'root:id' => $root_link->getPluginId(), 'root:parent' => NULL, 'root:root' => NULL);
     $this->assertTokens('menu-link', array('menu-link' => $parent_link), $tokens);
     // Add a node.
     $node = $this->drupalCreateNode();
     // Allow main menu for this node type.
     //$this->config('menu.entity.node.' . $node->getType())->set('available_menus', array('main-menu'))->save();
     // Add a node menu link.
     /** @var \Drupal\menu_link_content\Plugin\Menu\MenuLinkContent $node_link */
     $node_link = entity_create('menu_link_content', array('link' => ['uri' => 'entity:node/' . $node->id()], 'title' => 'Node link', 'parent' => $parent_link->getPluginId(), 'menu_name' => 'main-menu'));
     $node_link->save();
     // Test [node:menu] tokens.
     $tokens = array('menu-link' => 'Node link', 'menu-link:id' => $node_link->getPluginId(), 'menu-link:title' => 'Node link', 'menu-link:menu' => 'Main menu', 'menu-link:url' => $node->url('canonical', ['absolute' => TRUE]), 'menu-link:url:path' => 'node/' . $node->id(), 'menu-link:edit-url' => $node_link->url('edit-form', ['absolute' => TRUE]), 'menu-link:parent' => 'Configuration', 'menu-link:parent:id' => $parent_link->getPluginId(), 'menu-link:parents' => 'Administration, Configuration', 'menu-link:parents:count' => 2, 'menu-link:parents:keys' => $root_link->getPluginId() . ', ' . $parent_link->getPluginId(), 'menu-link:root' => 'Administration', 'menu-link:root:id' => $root_link->getPluginId());
     $this->assertTokens('node', array('node' => $node), $tokens);
     // Reload the node which will not have $node->menu defined and re-test.
     $loaded_node = Node::load($node->id());
     $this->assertTokens('node', array('node' => $loaded_node), $tokens);
     // Regression test for http://drupal.org/node/1317926 to ensure the
     // original node object is not changed when calling menu_node_prepare().
     $this->assertTrue(!isset($loaded_node->menu), t('The $node->menu property was not modified during token replacement.'), 'Regression');
 }
开发者ID:dev981,项目名称:gaptest,代码行数:34,代码来源:TokenMenuTest.php

示例6: buildRolesProfilesTable

 /**
  * Returns roles-profiles table.
  */
 public function buildRolesProfilesTable(array $roles_profiles)
 {
     $rp_table = array('#type' => 'table');
     // Prepare roles. Reverse the role order to prioritize the permissive ones.
     $roles = array_reverse(user_roles());
     $wrappers = \Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE);
     // Prepare profile options
     $options = array('' => '-' . $this->t('None') . '-');
     foreach (\Drupal::entityManager()->getStorage('imce_profile')->loadMultiple() as $pid => $profile) {
         $options[$pid] = $profile->label();
     }
     // Build header
     $imce_url = \Drupal::url('imce.page');
     $rp_table['#header'] = array($this->t('Role'));
     $default = file_default_scheme();
     foreach ($wrappers as $scheme => $name) {
         $url = $scheme === $default ? $imce_url : $imce_url . '/' . $scheme;
         $rp_table['#header'][]['data'] = array('#markup' => '<a href="' . $url . '">' . Html::escape($name) . '</a>');
     }
     // Build rows
     foreach ($roles as $rid => $role) {
         $rp_table[$rid]['role_name'] = array('#plain_text' => $role->label());
         foreach ($wrappers as $scheme => $name) {
             $rp_table[$rid][$scheme] = array('#type' => 'select', '#options' => $options, '#default_value' => isset($roles_profiles[$rid][$scheme]) ? $roles_profiles[$rid][$scheme] : '');
         }
     }
     // Add description
     $rp_table['#prefix'] = '<h3>' . $this->t('Role-profile assignments') . '</h3>';
     $rp_table['#suffix'] = '<div class="description">' . $this->t('Assign configuration profiles to user roles for available file systems. The default file system %name is accessible at :url path.', array('%name' => $wrappers[file_default_scheme()], ':url' => $imce_url)) . '</div>';
     return $rp_table;
 }
开发者ID:badelas,项目名称:afroweb,代码行数:34,代码来源:ImceSettingsForm.php

示例7: testSiteMaintenance

 /**
  * Verify site maintenance mode functionality.
  */
 protected function testSiteMaintenance()
 {
     $this->drupalGet(Url::fromRoute('user.page'));
     // JS should be aggregated, so drupal.js is not in the page source.
     $links = $this->xpath('//script[contains(@src, :href)]', array(':href' => '/core/misc/drupal.js'));
     $this->assertFalse(isset($links[0]), 'script /core/misc/drupal.js not in page');
     // Turn on maintenance mode.
     $edit = array('maintenance_mode' => 1);
     $this->drupalPostForm('admin/config/development/maintenance', $edit, t('Save configuration'));
     $admin_message = t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => \Drupal::url('system.site_maintenance_mode')));
     $user_message = t('Operating in maintenance mode.');
     $offline_message = t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => $this->config('system.site')->get('name')));
     $this->drupalGet(Url::fromRoute('user.page'));
     // JS should not be aggregated, so drupal.js is expected in the page source.
     $links = $this->xpath('//script[contains(@src, :href)]', array(':href' => '/core/misc/drupal.js'));
     $this->assertTrue(isset($links[0]), 'script /core/misc/drupal.js in page');
     $this->assertRaw($admin_message, 'Found the site maintenance mode message.');
     // Logout and verify that offline message is displayed.
     $this->drupalLogout();
     $this->drupalGet('');
     $this->assertText($offline_message);
     $this->drupalGet('node');
     $this->assertText($offline_message);
     $this->drupalGet('user/register');
     $this->assertText($offline_message);
     // Verify that user is able to log in.
     $this->drupalGet('user');
     $this->assertNoText($offline_message);
     $this->drupalGet('user/login');
     $this->assertNoText($offline_message);
     // Log in user and verify that maintenance mode message is displayed
     // directly after login.
     $edit = array('name' => $this->user->getUsername(), 'pass' => $this->user->pass_raw);
     $this->drupalPostForm(NULL, $edit, t('Log in'));
     $this->assertText($user_message);
     // Log in administrative user and configure a custom site offline message.
     $this->drupalLogout();
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('admin/config/development/maintenance');
     $this->assertNoRaw($admin_message, 'Site maintenance mode message not displayed.');
     $offline_message = 'Sorry, not online.';
     $edit = array('maintenance_mode_message' => $offline_message);
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     // Logout and verify that custom site offline message is displayed.
     $this->drupalLogout();
     $this->drupalGet('');
     $this->assertRaw($offline_message, 'Found the site offline message.');
     // Verify that custom site offline message is not displayed on user/password.
     $this->drupalGet('user/password');
     $this->assertText(t('Username or email address'), 'Anonymous users can access user/password');
     // Submit password reset form.
     $edit = array('name' => $this->user->getUsername());
     $this->drupalPostForm('user/password', $edit, t('Submit'));
     $mails = $this->drupalGetMails();
     $start = strpos($mails[0]['body'], 'user/reset/' . $this->user->id());
     $path = substr($mails[0]['body'], $start, 66 + strlen($this->user->id()));
     // Log in with temporary login link.
     $this->drupalPostForm($path, array(), t('Log in'));
     $this->assertText($user_message);
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:63,代码来源:SiteMaintenanceTest.php

示例8: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     module_load_include('inc', 'pathauto');
     $config = $this->config('pathauto.settings');
     $form = array();
     $form['verbose'] = array('#type' => 'checkbox', '#title' => t('Verbose'), '#default_value' => $config->get('verbose'), '#description' => t('Display alias changes (except during bulk updates).'));
     $form['separator'] = array('#type' => 'textfield', '#title' => t('Separator'), '#size' => 1, '#maxlength' => 1, '#default_value' => $config->get('separator'), '#description' => t('Character used to separate words in titles. This will replace any spaces and punctuation characters. Using a space or + character can cause unexpected results.'));
     $form['case'] = array('#type' => 'radios', '#title' => t('Character case'), '#default_value' => $config->get('case'), '#options' => array(self::CASE_LEAVE_ASIS => t('Leave case the same as source token values.'), self::CASE_LOWER => t('Change to lower case')));
     $max_length = \Drupal::service('pathauto.alias_storage_helper')->getAliasSchemaMaxlength();
     $form['max_length'] = array('#type' => 'number', '#title' => t('Maximum alias length'), '#size' => 3, '#maxlength' => 3, '#default_value' => $config->get('max_length'), '#min' => 1, '#max' => $max_length, '#description' => t('Maximum length of aliases to generate. 100 is the recommended length. @max is the maximum possible length. See <a href="@pathauto-help">Pathauto help</a> for details.', array('@pathauto-help' => $this->getUrlGenerator()->generateFromPath('admin/help/pathauto'), '@max' => $max_length)));
     $form['max_component_length'] = array('#type' => 'number', '#title' => t('Maximum component length'), '#size' => 3, '#maxlength' => 3, '#default_value' => $config->get('max_component_length'), '#min' => 1, '#max' => $max_length, '#description' => t('Maximum text length of any component in the alias (e.g., [title]). 100 is the recommended length. @max is the maximum possible length. See <a href="@pathauto-help">Pathauto help</a> for details.', array('@pathauto-help' => $this->getUrlGenerator()->generateFromPath('admin/help/pathauto'), '@max' => $max_length)));
     $description = t('What should Pathauto do when updating an existing content item which already has an alias?');
     if (\Drupal::moduleHandler()->moduleExists('redirect')) {
         $description .= ' ' . t('The <a href="!url">Redirect module settings</a> affect whether a redirect is created when an alias is deleted.', array('!url' => \Drupal::url('redirect.settings')));
     } else {
         $description .= ' ' . t('Considering installing the <a href="!url">Redirect module</a> to get redirects when your aliases change.', array('!url' => 'http://drupal.org/project/redirect'));
     }
     $form['update_action'] = array('#type' => 'radios', '#title' => t('Update action'), '#default_value' => $config->get('update_action'), '#options' => array(PathautoManagerInterface::UPDATE_ACTION_NO_NEW => t('Do nothing. Leave the old alias intact.'), PathautoManagerInterface::UPDATE_ACTION_LEAVE => t('Create a new alias. Leave the existing alias functioning.'), PathautoManagerInterface::UPDATE_ACTION_DELETE => t('Create a new alias. Delete the old alias.')), '#description' => $description);
     $form['transliterate'] = array('#type' => 'checkbox', '#title' => t('Transliterate prior to creating alias'), '#default_value' => $config->get('transliterate'), '#description' => t('When a pattern includes certain characters (such as those with accents) should Pathauto attempt to transliterate them into the US-ASCII alphabet? Transliteration is handled by the Transliteration module.'));
     $form['reduce_ascii'] = array('#type' => 'checkbox', '#title' => t('Reduce strings to letters and numbers'), '#default_value' => $config->get('reduce_ascii'), '#description' => t('Filters the new alias to only letters and numbers found in the ASCII-96 set.'));
     $form['ignore_words'] = array('#type' => 'textarea', '#title' => t('Strings to Remove'), '#default_value' => $config->get('ignore_words'), '#description' => t('Words to strip out of the URL alias, separated by commas. Do not use this to remove punctuation.'), '#wysiwyg' => FALSE);
     $form['punctuation'] = array('#type' => 'fieldset', '#title' => t('Punctuation'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#tree' => TRUE);
     $punctuation = \Drupal::service('pathauto.manager')->getPunctuationCharacters();
     foreach ($punctuation as $name => $details) {
         $details['default'] = PathautoManagerInterface::PUNCTUATION_REMOVE;
         if ($details['value'] == $config->get('separator')) {
             $details['default'] = PathautoManagerInterface::PUNCTUATION_REPLACE;
         }
         $form['punctuation']['punctuation' . $name] = array('#type' => 'select', '#title' => $details['name'] . ' (<code>' . SafeMarkup::checkPlain($details['value']) . '</code>)', '#default_value' => $details['default'], '#options' => array(PathautoManagerInterface::PUNCTUATION_REMOVE => t('Remove'), PathautoManagerInterface::PUNCTUATION_REPLACE => t('Replace by separator'), PathautoManagerInterface::PUNCTUATION_DO_NOTHING => t('No action (do not replace)')));
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:dev981,项目名称:gaptest,代码行数:35,代码来源:PathautoSettingsForm.php

示例9: testOverview

 public function testOverview()
 {
     $this->loginAsTranslator();
     $this->drupalGet('admin/tmgmt/sources/locale/default');
     $this->assertText('Hello World');
     $this->assertText('Example');
     $rows = $this->xpath('//tbody/tr');
     foreach ($rows as $row) {
         if ($row->td[1] == 'Hello World') {
             $this->assertEqual((string) $row->td[3]->img['title'], t('Translation up to date'));
             $this->assertEqual((string) $row->td[4]->img['title'], t('Not translated'));
         }
     }
     // Filter on the label.
     $edit = array('search[label]' => 'Hello');
     $this->drupalPostForm(NULL, $edit, t('Search'));
     $this->assertText('Hello World');
     $this->assertNoText('Example');
     $locale_object = db_query('SELECT * FROM {locales_source} WHERE source = :source LIMIT 1', array(':source' => 'Hello World'))->fetchObject();
     // First add source to the cart to test its functionality.
     $edit = array('items[' . $locale_object->lid . ']' => TRUE);
     $this->drupalPostForm(NULL, $edit, t('Add to cart'));
     $this->assertRaw(t('@count content source was added into the <a href=":url">cart</a>.', array('@count' => 1, ':url' => \Drupal::url('tmgmt.cart'))));
     $edit['target_language[]'] = array('gsw-berne');
     $this->drupalPostForm('admin/tmgmt/cart', $edit, t('Request translation'));
     // Assert that the job item is displayed.
     $this->assertText('Hello World');
     $this->assertText(t('Locale'));
     $this->assertText('2');
     $this->drupalPostForm(NULL, array('target_language' => 'gsw-berne'), t('Submit to provider'));
     // Test for the translation flag title.
     $this->drupalGet('admin/tmgmt/sources/locale/default');
     $this->assertRaw(t('Active job item: Needs review'));
     // Review and accept the job item.
     $job_items = tmgmt_job_item_load_latest('locale', 'default', $locale_object->lid, 'en');
     $this->drupalGet('admin/tmgmt/items/' . $job_items['gsw-berne']->id());
     $this->assertRaw('gsw-berne: Hello World');
     $this->drupalPostForm(NULL, array(), t('Save as completed'));
     $this->drupalGet('admin/tmgmt/sources/locale/default');
     $this->assertNoRaw(t('Active job item: Needs review'));
     $rows = $this->xpath('//tbody/tr');
     foreach ($rows as $row) {
         if ($row->td[1] == 'Hello World') {
             $this->assertEqual((string) $row->td[3]->img['title'], t('Translation up to date'));
             $this->assertEqual((string) $row->td[4]->img['title'], t('Translation up to date'));
         }
     }
     // Test the missing translation filter.
     $this->drupalGet('admin/tmgmt/sources/locale/default');
     // Check that the source language (en) has been removed from the target language
     // select box.
     $elements = $this->xpath('//select[@name=:name]//option[@value=:option]', array(':name' => 'search[target_language]', ':option' => 'en'));
     $this->assertTrue(empty($elements));
     // Filter on the "Not translated to".
     $edit = array('search[missing_target_language]' => 'gsw-berne');
     $this->drupalPostForm(NULL, $edit, t('Search'));
     // Hello world is translated to "gsw-berne" therefore it must not show up
     // in the list.
     $this->assertNoText('Hello World');
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:60,代码来源:LocaleSourceUiTest.php

示例10: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['#action'] = \Drupal::url('ajax_test.dialog');
     $form['description'] = array('#markup' => '<p>' . t("Ajax Form contents description.") . '</p>');
     $form['submit'] = array('#type' => 'submit', '#value' => t('Do it'));
     return $form;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:AjaxTestForm.php

示例11: testFieldFormatter

 /**
  * Test base logic for the Juicebox field formatter.
  */
 public function testFieldFormatter()
 {
     $node = $this->node;
     $xml_path = 'juicebox/xml/field/node/' . $node->id() . '/' . $this->instFieldName . '/full';
     $xml_url = \Drupal::url('juicebox.xml_field', array('entityType' => 'node', 'entityId' => $node->id(), 'fieldName' => $this->instFieldName, 'displayName' => 'full'));
     // Get the urls to the test image and thumb derivative used by default.
     $uri = \Drupal\file\Entity\File::load($node->{$this->instFieldName}[0]->target_id)->getFileUri();
     $test_image_url = entity_load('image_style', 'juicebox_medium')->buildUrl($uri);
     $test_thumb_url = entity_load('image_style', 'juicebox_square_thumb')->buildUrl($uri);
     // Check for correct embed markup.
     $this->drupalGet('node/' . $node->id());
     $this->assertRaw(trim(json_encode(array('configUrl' => $xml_url)), '{}"'), 'Gallery setting found in Drupal.settings.');
     $this->assertRaw('id="node--' . $node->id() . '--' . str_replace('_', '-', $this->instFieldName) . '--full"', 'Embed code wrapper found.');
     $this->assertRaw(Html::escape(file_url_transform_relative($test_image_url)), 'Test image found in embed code');
     // Check for correct XML.
     $this->drupalGet($xml_path);
     $this->assertRaw('<?xml version="1.0" encoding="UTF-8"?>', 'Valid XML detected.');
     $this->assertRaw('imageURL="' . Html::escape($test_image_url), 'Test image found in XML.');
     $this->assertRaw('thumbURL="' . Html::escape($test_thumb_url), 'Test thumbnail found in XML.');
     // Check for contextual links in embed code. It might we worth checking if
     // there is a more programmatic way to build the related id at some point.
     $this->drupalLogin($this->webUser);
     // Need access to contextual links.
     $this->drupalGet('node/' . $node->id());
     $id = 'juicebox_xml_field:entityType=node&entityId=' . $node->id() . '&fieldName=' . $this->instFieldName . '&displayName=full:langcode=en|juicebox_conf_field_node:view_mode_name=default&node_type=' . $this->instBundle . ':langcode=en|juicebox_conf_global::langcode=en';
     $this->assertRaw('<div data-contextual-id="' . Html::escape($id) . '"></div>', 'Correct contextual link placeholders found.');
     $json = Json::decode($this->renderContextualLinks(array($id), 'node/' . $node->id()));
     $this->assertResponse(200);
     $this->assertTrue(preg_match('|/juicebox/xml/field/node/' . $node->id() . '/' . $this->instFieldName . '/full.*/admin/structure/types/manage/' . $this->instBundle . '/display/default.*/admin/config/media/juicebox|', $json[$id]), 'Correct contextual links found.');
 }
开发者ID:pulibrary,项目名称:recap,代码行数:33,代码来源:JuiceboxFieldFormatterCase.php

示例12: testUserLoginBlock

 /**
  * Test the user login block.
  */
 function testUserLoginBlock()
 {
     // Create a user with some permission that anonymous users lack.
     $user = $this->drupalCreateUser(array('administer permissions'));
     // Log in using the block.
     $edit = array();
     $edit['name'] = $user->getUsername();
     $edit['pass'] = $user->pass_raw;
     $this->drupalPostForm('admin/people/permissions', $edit, t('Log in'));
     $this->assertNoText(t('User login'), 'Logged in.');
     // Check that we are still on the same page.
     $this->assertUrl(\Drupal::url('user.admin_permissions', [], ['absolute' => TRUE]), [], 'Still on the same page after login for access denied page');
     // Now, log out and repeat with a non-403 page.
     $this->drupalLogout();
     $this->drupalPostForm('filter/tips', $edit, t('Log in'));
     $this->assertNoText(t('User login'), 'Logged in.');
     $this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', 'Still on the same page after login for allowed page');
     // Check that the user login block is not vulnerable to information
     // disclosure to third party sites.
     $this->drupalLogout();
     $this->drupalPostForm('http://example.com/', $edit, t('Log in'), array('external' => FALSE));
     // Check that we remain on the site after login.
     $this->assertUrl($user->url('canonical', ['absolute' => TRUE]), [], 'Redirected to user profile page after login from the frontpage');
     // Verify that form validation errors are displayed immediately for forms
     // in blocks and not on subsequent page requests.
     $this->drupalLogout();
     $edit = array();
     $edit['name'] = 'foo';
     $edit['pass'] = 'invalid password';
     $this->drupalPostForm('filter/tips', $edit, t('Log in'));
     $this->assertText(t('Unrecognized username or password. Forgot your password?'));
     $this->drupalGet('filter/tips');
     $this->assertNoText(t('Unrecognized username or password. Forgot your password?'));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:37,代码来源:UserBlocksTest.php

示例13: testSystemSiteTokenReplacement

 /**
  * Tests the generation of all system site information tokens.
  */
 public function testSystemSiteTokenReplacement()
 {
     $url_options = array('absolute' => TRUE, 'language' => $this->interfaceLanguage);
     $slogan = '<blink>Slogan</blink>';
     $safe_slogan = Xss::filterAdmin($slogan);
     // Set a few site variables.
     $config = $this->config('system.site');
     $config->set('name', '<strong>Drupal<strong>')->set('slogan', $slogan)->set('mail', 'simpletest@example.com')->save();
     // Generate and test tokens.
     $tests = array();
     $tests['[site:name]'] = Html::escape($config->get('name'));
     $tests['[site:slogan]'] = $safe_slogan;
     $tests['[site:mail]'] = $config->get('mail');
     $tests['[site:url]'] = \Drupal::url('<front>', [], $url_options);
     $tests['[site:url-brief]'] = preg_replace(array('!^https?://!', '!/$!'), '', \Drupal::url('<front>', [], $url_options));
     $tests['[site:login-url]'] = \Drupal::url('user.page', [], $url_options);
     $base_bubbleable_metadata = new BubbleableMetadata();
     $metadata_tests = [];
     $metadata_tests['[site:name]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
     $metadata_tests['[site:slogan]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
     $metadata_tests['[site:mail]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
     $bubbleable_metadata = clone $base_bubbleable_metadata;
     $metadata_tests['[site:url]'] = $bubbleable_metadata->addCacheContexts(['url.site']);
     $metadata_tests['[site:url-brief]'] = $bubbleable_metadata;
     $metadata_tests['[site:login-url]'] = $bubbleable_metadata;
     // Test to make sure that we generated something for each token.
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
     foreach ($tests as $input => $expected) {
         $bubbleable_metadata = new BubbleableMetadata();
         $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId()), $bubbleable_metadata);
         $this->assertEqual($output, $expected, new FormattableMarkup('System site information token %token replaced.', ['%token' => $input]));
         $this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
     }
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:37,代码来源:TokenReplaceUnitTest.php

示例14: testNodeAttributes

 /**
  * Creates a node of type article and tests its RDFa markup.
  */
 function testNodeAttributes()
 {
     // Create node with single quotation mark title to ensure it does not get
     // escaped more than once.
     $node = $this->drupalCreateNode(array('type' => 'article', 'title' => $this->randomMachineName(8) . "'"));
     $node_uri = $node->url('canonical', ['absolute' => TRUE]);
     $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
     // Parses front page where the node is displayed in its teaser form.
     $parser = new \EasyRdf_Parser_Rdfa();
     $graph = new \EasyRdf_Graph();
     $parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
     // Inspects RDF graph output.
     // Node type.
     $expected_value = array('type' => 'uri', 'value' => 'http://rdfs.org/sioc/ns#Item');
     $this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (sioc:Item).');
     // Node type.
     $expected_value = array('type' => 'uri', 'value' => 'http://xmlns.com/foaf/0.1/Document');
     $this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (foaf:Document).');
     // Node title.
     $expected_value = array('type' => 'literal', 'value' => $node->getTitle(), 'lang' => 'en');
     $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).');
     // Node date (date format must be UTC).
     $expected_value = array('type' => 'literal', 'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'), 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime');
     $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Node date found in RDF output (dc:date).');
     // Node date (date format must be UTC).
     $expected_value = array('type' => 'literal', 'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'), 'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime');
     $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Node date found in RDF output (dc:created).');
 }
开发者ID:Wylbur,项目名称:gj,代码行数:31,代码来源:NodeAttributesTest.php

示例15: testSubRequestDependent

 /**
  * Test a gallery embedded in a view row that is dependent on the Juicebox
  * cache.
  */
 public function testSubRequestDependent()
 {
     $node = $this->node;
     $xml_path = 'juicebox/xml/field/node/' . $node->id() . '/' . $this->instFieldName . '/_custom';
     $xml_url = \Drupal::url('juicebox.xml_field', array('entityType' => 'node', 'entityId' => $node->id(), 'fieldName' => $this->instFieldName, 'displayName' => '_custom'));
     // Get the urls to the test image and thumb derivative used by default.
     $uri = \Drupal\file\Entity\File::load($node->{$this->instFieldName}[0]->target_id)->getFileUri();
     $test_image_url = entity_load('image_style', 'juicebox_medium')->buildUrl($uri);
     $test_thumb_url = entity_load('image_style', 'juicebox_square_thumb')->buildUrl($uri);
     // Check for correct embed markup. This will also prime the cache.
     $content = $this->drupalGet('juicebox_test_row_formatter');
     $this->assertRaw(trim(json_encode(array('configUrl' => $xml_url)), '{}"'), 'Gallery setting found in Drupal.settings.');
     $this->assertRaw('id="node--' . $node->id() . '--' . str_replace('_', '-', $this->instFieldName) . '---custom"', 'Embed code wrapper found.');
     $this->assertRaw(Html::escape($test_image_url), 'Test image found in embed code');
     // Extract the xml-source values from the XML.
     $matches = array();
     // In the pattern below we have to use four (yeah, FOUR) backslashes to
     // match a SINGLE literal backslash. Our source will contain an encoded
     // (JSON) "&" character as "\u0026", but we don't want the regex to confuse
     // that with an actaul "&" char in the pattern itself.
     preg_match('|xml-source-path=([a-z1-9_-]+)\\\\u0026xml-source-id=([a-z1-9-]+)|', $content, $matches);
     $this->assertNotNull($matches[1], 'xml-source-path value found in Drupal.settings.');
     $this->assertNotNull($matches[2], 'xml-source-id value found in Drupal.settings.');
     // Check for correct XML. This example is dependent on a sub-request XML
     // lookup, so everything below would fail without that feature.
     $this->drupalGet($xml_path, array('query' => array('xml-source-path' => $matches[1], 'xml-source-id' => $matches[2])));
     $this->assertRaw('<?xml version="1.0" encoding="UTF-8"?>', 'Valid XML detected.');
     $this->assertRaw('imageURL="' . Html::escape($test_image_url), 'Test image found in XML.' . $test_image_url);
     $this->assertRaw('thumbURL="' . Html::escape($test_thumb_url), 'Test thumbnail found in XML.' . $test_thumb_url);
     $this->assertRaw('backgroundcolor="green"', 'Custom background setting from pseudo field instance config found in XML.');
 }
开发者ID:angelamaunz,项目名称:pccdemo,代码行数:35,代码来源:JuiceboxSubRequestCase.php


注:本文中的Drupal::url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。