/**
  * 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);
     }
 }
 /**
  * {@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;
 }
 /**
  * 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.');
 }
Example #4
0
 /**
  * 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');
 }
Example #5
0
 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');
 }
Example #6
0
 /**
  * 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;
 }
 /**
  * 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);
 }
Example #8
0
 /**
  * {@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);
 }
 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');
 }
 /**
  * {@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;
 }
 /**
  * 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.');
 }
Example #12
0
 /**
  * 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'] = '******';
     $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?'));
 }
 /**
  * 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', '*****@*****.**')->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]);
     }
 }
Example #14
0
 /**
  * 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).');
 }
 /**
  * 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.');
 }
 /**
  * Process handler for the language_configuration form element.
  */
 public static function processLanguageConfiguration(&$element, FormStateInterface $form_state, &$form)
 {
     $options = isset($element['#options']) ? $element['#options'] : array();
     // Avoid validation failure since we are moving the '#options' key in the
     // nested 'language' select element.
     unset($element['#options']);
     /** @var ContentLanguageSettings $default_config */
     $default_config = $element['#default_value'];
     $element['langcode'] = array('#type' => 'select', '#title' => t('Default language'), '#options' => $options + static::getDefaultOptions(), '#description' => t('Explanation of the language options is found on the <a href="@languages_list_page">languages list page</a>.', array('@languages_list_page' => \Drupal::url('entity.configurable_language.collection'))), '#default_value' => $default_config != NULL ? $default_config->getDefaultLangcode() : LanguageInterface::LANGCODE_SITE_DEFAULT);
     $element['language_alterable'] = array('#type' => 'checkbox', '#title' => t('Show language selector on create and edit pages'), '#default_value' => $default_config != NULL ? $default_config->isLanguageAlterable() : FALSE);
     // Add the entity type and bundle information to the form if they are set.
     // They will be used, in the submit handler, to generate the names of the
     // configuration entities that will store the settings and are a way to uniquely
     // identify the entity.
     $language = $form_state->get('language') ?: [];
     $language += array($element['#name'] => array('entity_type' => $element['#entity_information']['entity_type'], 'bundle' => $element['#entity_information']['bundle']));
     $form_state->set('language', $language);
     // Do not add the submit callback for the language content settings page,
     // which is handled separately.
     if ($form['#form_id'] != 'language_content_settings_form') {
         // Determine where to attach the language_configuration element submit
         // handler.
         // @todo Form API: Allow form widgets/sections to declare #submit
         //   handlers.
         $submit_name = isset($form['actions']['save_continue']) ? 'save_continue' : 'submit';
         if (isset($form['actions'][$submit_name]['#submit']) && array_search('language_configuration_element_submit', $form['actions'][$submit_name]['#submit']) === FALSE) {
             $form['actions'][$submit_name]['#submit'][] = 'language_configuration_element_submit';
         } elseif (array_search('language_configuration_element_submit', $form['#submit']) === FALSE) {
             $form['#submit'][] = 'language_configuration_element_submit';
         }
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public static function settingsForm(FieldDefinitionInterface $field_definition)
 {
     $selection_handler_settings = $field_definition->getSetting('handler_settings') ?: array();
     $view_settings = !empty($selection_handler_settings['view']) ? $selection_handler_settings['view'] : array();
     $displays = Views::getApplicableViews('entity_reference_display');
     // Filter views that list the entity type we want, and group the separate
     // displays by view.
     $entity_type = \Drupal::entityManager()->getDefinition($field_definition->getSetting('target_type'));
     $options = array();
     foreach ($displays as $data) {
         list($view, $display_id) = $data;
         if ($view->storage->get('base_table') == $entity_type->getBaseTable()) {
             $name = $view->storage->get('id');
             $display = $view->storage->get('display');
             $options[$name . ':' . $display_id] = $name . ' - ' . $display[$display_id]['display_title'];
         }
     }
     // The value of the 'view_and_display' select below will need to be split
     // into 'view_name' and 'view_display' in the final submitted values, so
     // we massage the data at validate time on the wrapping element (not
     // ideal).
     $plugin = new static($field_definition);
     $form['view']['#element_validate'] = array(array($plugin, 'settingsFormValidate'));
     if ($options) {
         $default = !empty($view_settings['view_name']) ? $view_settings['view_name'] . ':' . $view_settings['display_name'] : NULL;
         $form['view']['view_and_display'] = array('#type' => 'select', '#title' => t('View used to select the entities'), '#required' => TRUE, '#options' => $options, '#default_value' => $default, '#description' => '<p>' . t('Choose the view and display that select the entities that can be referenced.<br />Only views with a display of type "Entity Reference" are eligible.') . '</p>');
         $default = !empty($view_settings['arguments']) ? implode(', ', $view_settings['arguments']) : '';
         $form['view']['arguments'] = array('#type' => 'textfield', '#title' => t('View arguments'), '#default_value' => $default, '#required' => FALSE, '#description' => t('Provide a comma separated list of arguments to pass to the view.'));
     } else {
         $form['view']['no_view_help'] = array('#markup' => '<p>' . t('No eligible views were found. <a href="@create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href="@existing">existing view</a>.', array('@create' => \Drupal::url('views_ui.add'), '@existing' => \Drupal::url('views_ui.list'))) . '</p>');
     }
     return $form;
 }
Example #18
0
 /**
  * Tests adding, editing, and deleting languages.
  */
 function testLanguageLocaleList()
 {
     // User to add and remove language.
     $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
     $this->drupalLogin($admin_user);
     // Add predefined language.
     $edit = array('predefined_langcode' => 'fr');
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
     $this->assertText('The language French has been created and can now be used');
     $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]));
     $this->rebuildContainer();
     // Translate Spanish language to French (Espagnol).
     $source = $this->storage->createString(array('source' => 'Spanish', 'context' => ''))->save();
     $this->storage->createTranslation(array('lid' => $source->lid, 'language' => 'fr', 'translation' => 'Espagnol'))->save();
     // Get language list displayed in select list.
     $this->drupalGet('fr/admin/config/regional/language/add');
     $select = $this->xpath('//select[@id="edit-predefined-langcode"]');
     $select_element = (array) end($select);
     $options = $select_element['option'];
     // Remove the 'Custom language...' option form the end.
     array_pop($options);
     // Order language list.
     $options_ordered = $options;
     natcasesort($options_ordered);
     // Check the language list displayed is ordered.
     $this->assertTrue($options === $options_ordered, 'Language list is ordered.');
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $entities = $this->load();
     $build = parent::render();
     $build['table']['#empty'] = t('No keys are available. <a href="@link">Add a key</a>.', array('@link' => \Drupal::url('entity.key.add_form')));
     return $build;
 }
 public function providers(Request $request)
 {
     $methods = array('' => sprintf('-- %s --', t('Disabled')));
     foreach ($this->methodManager->getDefinitions() as $definition) {
         $methods[$definition['id']] = $definition['name'];
     }
     $providers = array();
     $defaultConfig = array('method' => null, 'settings' => array());
     $headers = array('providers', 'methods', 'settings');
     $rows = array();
     foreach ($this->providerManager->getDefinitions() as $id => $definition) {
         $row = array(array('data' => $definition['name']), array('data' => array('#theme' => 'select', '#value' => $definition['method'], '#options' => $methods, '#name' => sprintf('providers[%s][method]', $id))), array('data' => ''));
         $rows[] = $row;
     }
     $tableData = array('#theme' => 'table', '#header' => array_map(function ($header) {
         return array('data' => t($header));
     }, $headers), '#rows' => $rows);
     $build = array();
     $build['providers_settings_form'] = array('#type' => 'html_tag', '#tag' => 'form', '#attributes' => array('method' => 'POST', 'action' => \Drupal::url('purl.admin.save_providers_config')));
     $submitData = array('#type' => 'html_tag', '#tag' => 'input', '#attributes' => array('class' => array('button button--primary form-submit'), 'type' => 'submit', 'value' => 'Save'));
     $formContents = array('table' => $tableData, 'submit' => $submitData);
     $form = drupal_render($formContents);
     $build['providers_settings_form']['#value'] = $form;
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     foreach ($this->getEntitiesToView($items) as $delta => $entity) {
         $entity->rss_elements[] = array('key' => 'category', 'value' => $entity->label(), 'attributes' => array('domain' => $entity->id() ? \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $entity->id()], array('absolute' => TRUE)) : ''));
     }
     return $elements;
 }
Example #22
0
 function testCurrentPageTokens()
 {
     $tokens = array('[current-page:title]' => t('Log in'), '[current-page:url]' => \Drupal::url('user.login', [], array('absolute' => TRUE)), '[current-page:url:absolute]' => \Drupal::url('user.login', [], array('absolute' => TRUE)), '[current-page:url:relative]' => \Drupal::url('user.login'), '[current-page:url:path]' => '/user/login', '[current-page:url:args:value:0]' => 'user', '[current-page:url:args:value:1]' => 'login', '[current-page:url:args:value:2]' => NULL, '[current-page:url:unaliased]' => \Drupal::url('user.login', [], array('absolute' => TRUE, 'alias' => TRUE)), '[current-page:page-number]' => 1, '[current-page:query:foo]' => NULL, '[current-page:query:bar]' => NULL, '[current-page:arg:0]' => 'user', '[current-page:arg:1]' => 'login', '[current-page:arg:2]' => NULL);
     $this->assertPageTokens('user/login', $tokens);
     $this->drupalCreateContentType(array('type' => 'page'));
     $node = $this->drupalCreateNode(array('title' => 'Node title', 'path' => array('alias' => '/node-alias')));
     $tokens = array('[current-page:title]' => 'Node title', '[current-page:url]' => $node->url('canonical', array('absolute' => TRUE)), '[current-page:url:absolute]' => $node->url('canonical', array('absolute' => TRUE)), '[current-page:url:relative]' => $node->url(), '[current-page:url:alias]' => '/node-alias', '[current-page:url:args:value:0]' => 'node-alias', '[current-page:url:args:value:1]' => NULL, '[current-page:url:unaliased]' => $node->url('canonical', array('absolute' => TRUE, 'alias' => TRUE)), '[current-page:url:unaliased:args:value:0]' => 'node', '[current-page:url:unaliased:args:value:1]' => $node->id(), '[current-page:url:unaliased:args:value:2]' => NULL, '[current-page:page-number]' => 1, '[current-page:query:foo]' => 'bar', '[current-page:query:bar]' => NULL, '[current-page:arg:0]' => 'node', '[current-page:arg:1]' => 1, '[current-page:arg:2]' => NULL);
     $this->assertPageTokens("/node/{$node->id()}", $tokens, array(), array('url_options' => array('query' => array('foo' => 'bar'))));
 }
Example #23
0
 /**
  * Processes a dropzone upload element, make use of #multiple if present.
  */
 public static function processDropzoneJs(&$element, FormStateInterface $form_state, &$complete_form)
 {
     $element['uploaded_files'] = ['#type' => 'hidden', '#default_value' => '', '#attributes' => ['data-upload-path' => \Drupal::url('dropzonejs.upload')]];
     if (!\Drupal::currentUser()->hasPermission('dropzone upload files')) {
         $element['#access'] = FALSE;
         drupal_set_message("You don't have sufficent permissions to use the DropzoneJS uploader. Contact your system administrator", 'warning');
     }
     return $element;
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['#action'] = \Drupal::url('ajax_test.dialog');
     $form['description'] = array('#markup' => '<p>' . $this->t("Ajax Form contents description.") . '</p>');
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Do it'));
     $form['actions']['preview'] = array('#type' => 'submit', '#value' => $this->t('Preview'), '#submit' => array(), '#ajax' => array('callback' => '::preview', 'event' => 'click'));
     return $form;
 }
 /**
  * Test that the search form block can be placed and works.
  */
 public function testSearchFormBlock()
 {
     // Test availability of the search block in the admin "Place blocks" list.
     $this->drupalGet('admin/structure/block');
     $this->clickLinkPartialName('Place block');
     $this->assertLinkByHref('/admin/structure/block/add/search_form_block/classy', 0, 'Did not find the search block in block candidate list.');
     $block = $this->drupalPlaceBlock('search_form_block');
     $this->drupalGet('');
     $this->assertText($block->label(), 'Block title was found.');
     // Check that name attribute is not empty.
     $pattern = "//input[@type='submit' and @name='']";
     $elements = $this->xpath($pattern);
     $this->assertTrue(empty($elements), 'The search input field does not have empty name attribute.');
     // Test a normal search via the block form, from the front page.
     $terms = array('keys' => 'test');
     $this->submitGetForm('', $terms, t('Search'));
     $this->assertResponse(200);
     $this->assertText('Your search yielded no results');
     // Test a search from the block on a 404 page.
     $this->drupalGet('foo');
     $this->assertResponse(404);
     $this->submitGetForm(NULL, $terms, t('Search'));
     $this->assertResponse(200);
     $this->assertText('Your search yielded no results');
     $visibility = $block->getVisibility();
     $visibility['request_path']['pages'] = 'search';
     $block->setVisibilityConfig('request_path', $visibility['request_path']);
     $this->submitGetForm('', $terms, t('Search'));
     $this->assertResponse(200);
     $this->assertText('Your search yielded no results');
     // Confirm that the form submits to the default search page.
     /** @var $search_page_repository \Drupal\search\SearchPageRepositoryInterface */
     $search_page_repository = \Drupal::service('search.search_page_repository');
     $entity_id = $search_page_repository->getDefaultSearchPage();
     $this->assertEqual($this->getUrl(), \Drupal::url('search.view_' . $entity_id, array(), array('query' => array('keys' => $terms['keys']), 'absolute' => TRUE)), 'Submitted to correct URL.');
     // Test an empty search via the block form, from the front page.
     $terms = array('keys' => '');
     $this->submitGetForm('', $terms, t('Search'));
     $this->assertResponse(200);
     $this->assertText('Please enter some keywords');
     // Confirm that the user is redirected to the search page, when form is
     // submitted empty.
     $this->assertEqual($this->getUrl(), \Drupal::url('search.view_' . $entity_id, array(), array('query' => array('keys' => ''), 'absolute' => TRUE)), 'Redirected to correct URL.');
     // Test that after entering a too-short keyword in the form, you can then
     // search again with a longer keyword. First test using the block form.
     $this->submitGetForm('node', array('keys' => $this->randomMachineName(1)), t('Search'));
     $this->assertText('You must include at least one keyword to match in the content', 'Keyword message is displayed when searching for short word');
     $this->assertNoText(t('Please enter some keywords'), 'With short word entered, no keywords message is not displayed');
     $this->submitGetForm(NULL, array('keys' => $this->randomMachineName()), t('Search'), 'search-block-form');
     $this->assertNoText('You must include at least one keyword to match in the content', 'Keyword message is not displayed when searching for long word after short word search');
     // Same test again, using the search page form for the second search this
     // time.
     $this->submitGetForm('node', array('keys' => $this->randomMachineName(1)), t('Search'));
     $this->drupalPostForm(NULL, array('keys' => $this->randomMachineName()), t('Search'), array(), array(), 'search-form');
     $this->assertNoText('You must include at least one keyword to match in the content', 'Keyword message is not displayed when searching for long word after short word search');
 }
Example #26
0
 /**
  * Processes widget form.
  */
 public static function processWidget($element, FormStateInterface $form_state, $form)
 {
     // Path input
     $element['imce_paths'] = array('#type' => 'hidden', '#attributes' => array('class' => array('imce-filefield-paths'), 'data-imce-url' => \Drupal::url('imce.page', array('scheme' => $element['#scheme']))), '#value' => '');
     // Library
     $element['#attached']['library'][] = 'imce/drupal.imce.filefield';
     // Set the pre-renderer to conditionally disable the elements.
     $element['#pre_render'][] = array(get_called_class(), 'preRenderWidget');
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('ckeditor_media_embed.settings');
     $form['embed_provider'] = array('#type' => 'textfield', '#title' => $this->t('Provider URL'), '#default_value' => $config->get('embed_provider'), '#description' => $this->t('
     A template for the URL of the provider endpoint. This URL will be queried for each resource to be embedded. By default CKEditor uses the Iframely service.<br />
     Check out the <a href=":help">help</a> page for more information.<br />
     <strong>Example</strong> <code>//example.com/api/oembed-proxy?resource-url={url}&callback={callback}</code><br />
     <strong>Default</strong> <code>//ckeditor.iframe.ly/api/oembed?url={url}&callback={callback}</code><br />', array(':help' => \Drupal::url('help.page', array('name' => 'ckeditor_media_embed')))));
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('acquia_connector.settings');
     $form['#prefix'] = $this->t('Enter your <a href="@net">identifier and key</a> from your subscriptions overview or <a href="@url">log in</a> to connect your site to the Acquia Subscription.', array('@net' => Url::fromUri('https://insight.acquia.com/subscriptions')->getUri(), '@url' => \Drupal::url('acquia_connector.setup')));
     $form['acquia_identifier'] = array('#type' => 'textfield', '#title' => $this->t('Identifier'), '#default_value' => $config->get('identifier'), '#required' => TRUE);
     $form['acquia_key'] = array('#type' => 'textfield', '#title' => $this->t('Network key'), '#default_value' => $config->get('key'), '#required' => TRUE);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Connect'));
     $form['actions']['signup'] = array('#markup' => $this->t('Need a subscription? <a href="@url">Get one</a>.', array('@url' => Url::fromUri('https://www.acquia.com/acquia-cloud-free')->getUri())));
     return $form;
 }
 public function view($preset)
 {
     if (!empty($preset)) {
         $_SESSION['innovation_default_preset'] = $preset - 1;
         $config = \Drupal::service('config.factory')->getEditable('innovation.settings');
         $config->set('updated', true);
         $config->save();
     }
     $destination = isset($_GET['destination']) ? $_GET['destination'] : '<front>';
     return new RedirectResponse(\Drupal::url($destination));
 }
Example #30
0
 function testNodeTokens()
 {
     $page = Node::create(['type' => 'page', 'revision_log' => $this->randomMachineName(), 'path' => array('alias' => 'content/source-node')]);
     $page->save();
     $tokens = array('log' => $page->revision_log->value, 'url:path' => 'content/source-node', 'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $page->id()], array('absolute' => TRUE)), 'url:relative' => \Drupal::url('entity.node.canonical', ['node' => $page->id()], array('absolute' => FALSE)), 'url:unaliased:path' => "node/{$page->id()}", 'content-type' => 'Basic page', 'content-type:name' => 'Basic page', 'content-type:machine-name' => 'page', 'content-type:description' => "Use <em>basic pages</em> for your static content, such as an 'About us' page.", 'content-type:node-count' => 1, 'content-type:edit-url' => \Drupal::url('entity.node_type.edit_form', ['node_type' => 'page'], array('absolute' => TRUE)), 'type' => 'page', 'type-name' => 'Basic page', 'url:alias' => 'content/source-node');
     $this->assertTokens('node', array('node' => $page), $tokens);
     $article = Node::create(['type' => 'article']);
     $article->save();
     $tokens = array('log' => '', 'url:path' => "node/{$article->id()}", 'url:absolute' => \Drupal::url('entity.node.canonical', ['node' => $article->id()], array('absolute' => TRUE)), 'url:relative' => \Drupal::url('entity.node.canonical', ['node' => $article->id()], array('absolute' => FALSE)), 'url:unaliased:path' => "node/{$article->id()}", 'content-type' => 'Article', 'content-type:name' => 'Article', 'content-type:machine-name' => 'article', 'content-type:description' => "Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.", 'content-type:node-count' => 1, 'content-type:edit-url' => \Drupal::url('entity.node_type.edit_form', ['node_type' => 'article'], array('absolute' => TRUE)), 'type' => 'article', 'type-name' => 'Article', 'url:alias' => "node/{$article->id()}");
     $this->assertTokens('node', array('node' => $article), $tokens);
 }