• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Utility\SafeMarkup类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Drupal\Component\Utility\SafeMarkup的典型用法代码示例。如果您正苦于以下问题:PHP SafeMarkup类的具体用法?PHP SafeMarkup怎么用?PHP SafeMarkup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: preRender

 /**
  * {@inheritdoc}
  */
 public function preRender(&$element, $rendering_object)
 {
     $element += array('#prefix' => '<div class=" ' . implode(' ', $this->getClasses()) . '">', '#suffix' => '</div>', '#tree' => TRUE, '#parents' => array($this->group->group_name), '#default_tab' => '');
     if ($this->getSetting('id')) {
         $element['#id'] = Html::getId($this->getSetting('id'));
     }
     // By default tabs don't have titles but you can override it in the theme.
     if ($this->getLabel()) {
         $element['#title'] = SafeMarkup::checkPlain($this->getLabel());
     }
     $form_state = new \Drupal\Core\Form\FormState();
     if ($this->getSetting('direction') == 'vertical') {
         $element += array('#type' => 'vertical_tabs', '#theme_wrappers' => array('vertical_tabs'));
         $complete_form = array();
         $element = \Drupal\Core\Render\Element\VerticalTabs::processVerticalTabs($element, $form_state, $complete_form);
     } else {
         $element += array('#type' => 'horizontal_tabs', '#theme_wrappers' => array('horizontal_tabs'));
         $on_form = $this->context == 'form';
         $element = \Drupal\field_group\Element\HorizontalTabs::processHorizontalTabs($element, $form_state, $on_form);
     }
     // Make sure the group has 1 child. This is needed to succeed at form_pre_render_vertical_tabs().
     // Skipping this would force us to move all child groups to this array, making it an un-nestable.
     $element['group']['#groups'][$this->group->group_name] = array(0 => array());
     $element['group']['#groups'][$this->group->group_name]['#group_exists'] = TRUE;
     // Search for a tab that was marked as open. First one wins.
     foreach (\Drupal\Core\Render\Element::children($element) as $tab_name) {
         if (!empty($element[$tab_name]['#open'])) {
             $element[$this->group->group_name . '__active_tab']['#default_value'] = $tab_name;
             break;
         }
     }
 }
开发者ID:penguinclub,项目名称:penguinweb_drupal8,代码行数:35,代码来源:Tabs.php


示例2: testRediscover

 /**
  * Tests the rediscovering.
  */
 public function testRediscover()
 {
     \Drupal::state()->set('menu_link_content_dynamic_route.routes', ['route_name_1' => new Route('/example-path')]);
     \Drupal::service('router.builder')->rebuild();
     // Set up a custom menu link pointing to a specific path.
     MenuLinkContent::create(['title' => '<script>alert("Welcome to the discovered jungle!")</script>', 'link' => [['uri' => 'internal:/example-path']], 'menu_name' => 'tools'])->save();
     $menu_tree = \Drupal::menuTree()->load('tools', new MenuTreeParameters());
     $this->assertEqual(1, count($menu_tree));
     /** @var \Drupal\Core\Menu\MenuLinkTreeElement $tree_element */
     $tree_element = reset($menu_tree);
     $this->assertEqual('route_name_1', $tree_element->link->getRouteName());
     // Change the underlying route and trigger the rediscovering.
     \Drupal::state()->set('menu_link_content_dynamic_route.routes', ['route_name_2' => new Route('/example-path')]);
     \Drupal::service('router.builder')->rebuild();
     // Ensure that the new route name / parameters are captured by the tree.
     $menu_tree = \Drupal::menuTree()->load('tools', new MenuTreeParameters());
     $this->assertEqual(1, count($menu_tree));
     /** @var \Drupal\Core\Menu\MenuLinkTreeElement $tree_element */
     $tree_element = reset($menu_tree);
     $this->assertEqual('route_name_2', $tree_element->link->getRouteName());
     $title = $tree_element->link->getTitle();
     $this->assertFalse($title instanceof TranslationWrapper);
     $this->assertIdentical('<script>alert("Welcome to the discovered jungle!")</script>', $title);
     $this->assertFalse(SafeMarkup::isSafe($title));
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:28,代码来源:MenuLinkContentDeriverTest.php


示例3: testSendPersonalContactMessage

 /**
  * Tests that mails for contact messages are correctly sent.
  */
 function testSendPersonalContactMessage()
 {
     // Ensure that the web user's email needs escaping.
     $mail = $this->webUser->getUsername() . '&[email protected]';
     $this->webUser->setEmail($mail)->save();
     $this->drupalLogin($this->webUser);
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertEscaped($mail);
     $message = $this->submitPersonalContact($this->contactUser);
     $mails = $this->drupalGetMails();
     $this->assertEqual(1, count($mails));
     $mail = $mails[0];
     $this->assertEqual($mail['to'], $this->contactUser->getEmail());
     $this->assertEqual($mail['from'], $this->config('system.site')->get('mail'));
     $this->assertEqual($mail['reply-to'], $this->webUser->getEmail());
     $this->assertEqual($mail['key'], 'user_mail');
     $variables = array('@site-name' => $this->config('system.site')->get('name'), '@subject' => $message['subject[0][value]'], '@recipient-name' => $this->contactUser->getDisplayName());
     $subject = PlainTextOutput::renderFromHtml(t('[@site-name] @subject', $variables));
     $this->assertEqual($mail['subject'], $subject, 'Subject is in sent message.');
     $this->assertTrue(strpos($mail['body'], 'Hello ' . $variables['@recipient-name']) !== FALSE, 'Recipient name is in sent message.');
     $this->assertTrue(strpos($mail['body'], $this->webUser->getDisplayName()) !== FALSE, 'Sender name is in sent message.');
     $this->assertTrue(strpos($mail['body'], $message['message[0][value]']) !== FALSE, 'Message body is in sent message.');
     // Check there was no problems raised during sending.
     $this->drupalLogout();
     $this->drupalLogin($this->adminUser);
     // Verify that the correct watchdog message has been logged.
     $this->drupalGet('/admin/reports/dblog');
     $placeholders = array('@sender_name' => $this->webUser->username, '@sender_email' => $this->webUser->getEmail(), '@recipient_name' => $this->contactUser->getUsername());
     $this->assertRaw(SafeMarkup::format('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders));
     // Ensure an unescaped version of the email does not exist anywhere.
     $this->assertNoRaw($this->webUser->getEmail());
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:35,代码来源:ContactPersonalTest.php


示例4: testCountryUI

 /**
  * Test enable/disable of countries.
  */
 public function testCountryUI()
 {
     $this->drupalLogin($this->drupalCreateUser(array('administer countries', 'administer store')));
     // Testing all countries is too much, so we just enable a random selection
     // of 8 countries. All countries will then be tested at some point.
     $countries = \Drupal::service('country_manager')->getAvailableList();
     $country_ids = array_rand($countries, 8);
     $last_country = array_pop($country_ids);
     // Loop over the first seven.
     foreach ($country_ids as $country_id) {
         // Verify this country isn't already enabled.
         $this->drupalGet('admin/store/config/country');
         $this->assertLinkByHref('admin/store/config/country/' . $country_id . '/enable', 0, SafeMarkup::format('%country is not enabled by default.', ['%country' => $countries[$country_id]]));
         // Enable this country.
         $this->drupalGet('admin/store/config/country/' . $country_id . '/enable');
         $this->assertText(t('The country @country has been enabled.', ['@country' => $countries[$country_id]]));
         $this->assertLinkByHref('admin/store/config/country/' . $country_id . '/disable', 0, SafeMarkup::format('%country is now enabled.', ['%country' => $countries[$country_id]]));
     }
     // Verify that last random country doesn't show up as available.
     $this->drupalGet('admin/store/config/store');
     $this->assertNoOption('edit-uc-store-country', $last_country, SafeMarkup::format('%country not listed in uc_address select country field.', ['%country' => $countries[$last_country]]));
     // Enable the last country.
     $this->drupalGet('admin/store/config/country/' . $last_country . '/enable');
     $this->assertText(t('The country @country has been enabled.', ['@country' => $countries[$last_country]]));
     $this->assertLinkByHref('admin/store/config/country/' . $last_country . '/disable', 0, SafeMarkup::format('%country is now enabled.', ['%country' => $countries[$last_country]]));
     // Verify that last random country now shows up as available.
     $this->drupalGet('admin/store/config/store');
     $this->assertOption('edit-uc-store-country', $last_country, SafeMarkup::format('%country is listed in uc_address select country field.', ['%country' => $countries[$last_country]]));
     // Disable the last country using the operations button.
     $this->drupalGet('admin/store/config/country');
     $this->clickLink('Disable', 7);
     // The 8th Disable link.
     $this->assertText(t('The country @country has been disabled.', ['@country' => $countries[$last_country]]));
     $this->assertLinkByHref('admin/store/config/country/' . $last_country . '/enable', 0, SafeMarkup::format('%country is now disabled.', ['%country' => $countries[$last_country]]));
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:38,代码来源:CountryTest.php


示例5: testDrupalFrontPage

 /**
  * Test front page functionality.
  */
 public function testDrupalFrontPage()
 {
     // Create a promoted node to test the <title> tag on the front page view.
     $settings = array('title' => $this->randomMachineName(8), 'promote' => 1);
     $this->drupalCreateNode($settings);
     $this->drupalGet('');
     $this->assertTitle('Home | Drupal');
     $this->assertText(t('On front page.'), 'Path is the front page.');
     $this->drupalGet('node');
     $this->assertText(t('On front page.'), 'Path is the front page.');
     $this->drupalGet($this->nodePath);
     $this->assertNoText(t('On front page.'), 'Path is not the front page.');
     // Change the front page to an invalid path.
     $edit = array('site_frontpage' => '/kittens');
     $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
     $this->assertText(t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $edit['site_frontpage'])));
     // Change the front page to a path without a starting slash.
     $edit = ['site_frontpage' => $this->nodePath];
     $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
     $this->assertRaw(SafeMarkup::format("The path '%path' has to start with a slash.", ['%path' => $edit['site_frontpage']]));
     // Change the front page to a valid path.
     $edit['site_frontpage'] = '/' . $this->nodePath;
     $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'), 'The front page path has been saved.');
     $this->drupalGet('');
     $this->assertText(t('On front page.'), 'Path is the front page.');
     $this->drupalGet('node');
     $this->assertNoText(t('On front page.'), 'Path is not the front page.');
     $this->drupalGet($this->nodePath);
     $this->assertText(t('On front page.'), 'Path is the front page.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:34,代码来源:FrontPageTest.php


示例6: testNodeTokenReplacement

 /**
  * Creates a node, then tests the tokens generated from it.
  */
 function testNodeTokenReplacement()
 {
     $url_options = array('absolute' => TRUE, 'language' => $this->interfaceLanguage);
     // Create a user and a node.
     $account = $this->createUser();
     /* @var $node \Drupal\node\NodeInterface */
     $node = entity_create('node', array('type' => 'article', 'tnid' => 0, 'uid' => $account->id(), 'title' => '<blink>Blinking Text</blink>', 'body' => array(array('value' => $this->randomMachineName(32), 'summary' => $this->randomMachineName(16), 'format' => 'plain_text'))));
     $node->save();
     // Generate and test sanitized tokens.
     $tests = array();
     $tests['[node:nid]'] = $node->id();
     $tests['[node:vid]'] = $node->getRevisionId();
     $tests['[node:type]'] = 'article';
     $tests['[node:type-name]'] = 'Article';
     $tests['[node:title]'] = SafeMarkup::checkPlain($node->getTitle());
     $tests['[node:body]'] = $node->body->processed;
     $tests['[node:summary]'] = $node->body->summary_processed;
     $tests['[node:langcode]'] = SafeMarkup::checkPlain($node->language()->getId());
     $tests['[node:url]'] = $node->url('canonical', $url_options);
     $tests['[node:edit-url]'] = $node->url('edit-form', $url_options);
     $tests['[node:author]'] = SafeMarkup::checkPlain($account->getUsername());
     $tests['[node:author:uid]'] = $node->getOwnerId();
     $tests['[node:author:name]'] = SafeMarkup::checkPlain($account->getUsername());
     $tests['[node:created:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($node->getCreatedTime(), array('langcode' => $this->interfaceLanguage->getId()));
     $tests['[node:changed:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($node->getChangedTime(), array('langcode' => $this->interfaceLanguage->getId()));
     // 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) {
         $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->getId()));
         $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input)));
     }
     // Generate and test unsanitized tokens.
     $tests['[node:title]'] = $node->getTitle();
     $tests['[node:body]'] = $node->body->value;
     $tests['[node:summary]'] = $node->body->summary;
     $tests['[node:langcode]'] = $node->language()->getId();
     $tests['[node:author:name]'] = $account->getUsername();
     foreach ($tests as $input => $expected) {
         $output = $this->tokenService->replace($input, array('node' => $node), array('langcode' => $this->interfaceLanguage->getId(), 'sanitize' => FALSE));
         $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced.', array('%token' => $input)));
     }
     // Repeat for a node without a summary.
     $node = entity_create('node', array('type' => 'article', 'uid' => $account->id(), 'title' => '<blink>Blinking Text</blink>', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => 'plain_text'))));
     $node->save();
     // Generate and test sanitized token - use full body as expected value.
     $tests = array();
     $tests['[node:summary]'] = $node->body->processed;
     // Test to make sure that we generated something for each token.
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.');
     foreach ($tests as $input => $expected) {
         $output = $this->tokenService->replace($input, array('node' => $node), array('language' => $this->interfaceLanguage));
         $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced for node without a summary.', array('%token' => $input)));
     }
     // Generate and test unsanitized tokens.
     $tests['[node:summary]'] = $node->body->value;
     foreach ($tests as $input => $expected) {
         $output = $this->tokenService->replace($input, array('node' => $node), array('language' => $this->interfaceLanguage, 'sanitize' => FALSE));
         $this->assertEqual($output, $expected, format_string('Unsanitized node token %token replaced for node without a summary.', array('%token' => $input)));
     }
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:63,代码来源:NodeTokenReplaceTest.php


示例7: import

 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $file = $row->getSourceProperty($this->configuration['source_path_property']);
     $destination = $row->getDestinationProperty($this->configuration['destination_path_property']);
     $source = $this->configuration['source_base_path'] . $file;
     // Ensure the source file exists, if it's a local URI or path.
     if ($this->isLocalUri($source) && !file_exists($source)) {
         throw new MigrateException(SafeMarkup::format('File @source does not exist.', ['@source' => $source]));
     }
     // If the start and end file is exactly the same, there is nothing to do.
     if ($this->isLocationUnchanged($source, $destination)) {
         return parent::import($row, $old_destination_id_values);
     }
     $replace = $this->getOverwriteMode($row);
     $success = $this->writeFile($source, $destination, $replace);
     if (!$success) {
         $dir = $this->getDirectory($destination);
         if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
             $success = $this->writeFile($source, $destination, $replace);
         } else {
             throw new MigrateException(SafeMarkup::format('Could not create directory @dir', ['@dir' => $dir]));
         }
     }
     if ($success) {
         return parent::import($row, $old_destination_id_values);
     } else {
         throw new MigrateException(SafeMarkup::format('File %source could not be copied to %destination.', ['%source' => $source, '%destination' => $destination]));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:32,代码来源:EntityFile.php


示例8: testDatabaseLoaded

 /**
  * Tests that the database was properly loaded.
  */
 public function testDatabaseLoaded()
 {
     foreach (['user', 'node', 'system', 'update_test_schema'] as $module) {
         $this->assertEqual(drupal_get_installed_schema_version($module), 8000, SafeMarkup::format('Module @module schema is 8000', ['@module' => $module]));
     }
     // Ensure that all {router} entries can be unserialized. If they cannot be
     // unserialized a notice will be thrown by PHP.
     $result = \Drupal::database()->query("SELECT name, route from {router}")->fetchAllKeyed(0, 1);
     // For the purpose of fetching the notices and displaying more helpful error
     // messages, let's override the error handler temporarily.
     set_error_handler(function ($severity, $message, $filename, $lineno) {
         throw new \ErrorException($message, 0, $severity, $filename, $lineno);
     });
     foreach ($result as $route_name => $route) {
         try {
             unserialize($route);
         } catch (\Exception $e) {
             $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name)));
         }
     }
     restore_error_handler();
     // Before accessing the site we need to run updates first or the site might
     // be broken.
     $this->runUpdates();
     $this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
     $this->drupalGet('<front>');
     $this->assertText('Site-Install');
     // Ensure that the database tasks have been run during set up. Neither MySQL
     // nor SQLite make changes that are testable.
     $database = $this->container->get('database');
     if ($database->driver() == 'pgsql') {
         $this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
         $this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
     }
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:38,代码来源:UpdatePathTestBaseTest.php


示例9:

 /**
  * Form element #after_build callback: output the old form build-id.
  */
 function form_test_storage_page_cache_old_build_id($form)
 {
     if (isset($form['#build_id_old'])) {
         $form['test_build_id_old']['#markup'] = SafeMarkup::checkPlain($form['#build_id_old']);
     }
     return $form;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:10,代码来源:FormTestStoragePageCacheForm.php


示例10: getOutput

 /**
  * {@inheritdoc}
  */
 public function getOutput()
 {
     $image = array('#theme' => 'image', '#uri' => $this->get('url'), '#alt' => $this->get('alt'));
     $output = '<h2 class="tour-tip-label" id="tour-tip-' . $this->get('ariaId') . '-label">' . SafeMarkup::checkPlain($this->get('label')) . '</h2>';
     $output .= '<p class="tour-tip-image" id="tour-tip-' . $this->get('ariaId') . '-contents">' . drupal_render($image) . '</p>';
     return array('#markup' => $output);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:10,代码来源:TipPluginImage.php


示例11: getToolkitOperationPluginId

 /**
  * Returns the plugin ID for a given toolkit and operation.
  *
  * @param \Drupal\Core\ImageToolkit\ImageToolkitInterface $toolkit
  *   The toolkit instance.
  * @param string $operation
  *   The operation (e.g. "crop").
  *
  * @return string
  *   The plugin ID.
  *
  * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
  *   When no plugin is available.
  */
 protected function getToolkitOperationPluginId(ImageToolkitInterface $toolkit, $operation)
 {
     $toolkit_id = $toolkit->getPluginId();
     $definitions = $this->getDefinitions();
     $definitions = array_filter($definitions, function ($definition) use($toolkit_id, $operation) {
         return $definition['toolkit'] == $toolkit_id && $definition['operation'] == $operation;
     });
     if (!$definitions) {
         // If this image toolkit plugin is a derivative and returns no operation,
         // try once again with its base plugin.
         $base_toolkit_id = $toolkit->getBaseId();
         if ($toolkit_id != $base_toolkit_id && !empty($base_toolkit_id)) {
             $base_toolkit = $this->toolkitManager->createInstance($base_toolkit_id);
             return $this->getToolkitOperationPluginId($base_toolkit, $operation);
         }
         $message = SafeMarkup::format("No image operation plugin for '@toolkit' toolkit and '@operation' operation.", array('@toolkit' => $toolkit_id, '@operation' => $operation));
         throw new PluginNotFoundException($toolkit_id . '.' . $operation, $message);
     } else {
         // Pickup the first plugin found.
         // @todo In https://www.drupal.org/node/2110591 we'll return here the UI
         //   selected plugin or the first found if missed.
         $definition = reset($definitions);
         return $definition['id'];
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:39,代码来源:ImageToolkitOperationManager.php


示例12: filter

 /**
  * {@inheritdoc}
  */
 public function filter(RouteCollection $collection, Request $request)
 {
     // Generates a list of Symfony formats matching the acceptable MIME types.
     // @todo replace by proper content negotiation library.
     $acceptable_mime_types = $request->getAcceptableContentTypes();
     $acceptable_formats = array_filter(array_map(array($request, 'getFormat'), $acceptable_mime_types));
     $primary_format = $request->getRequestFormat();
     foreach ($collection as $name => $route) {
         // _format could be a |-delimited list of supported formats.
         $supported_formats = array_filter(explode('|', $route->getRequirement('_format')));
         if (empty($supported_formats)) {
             // No format restriction on the route, so it always matches. Move it to
             // the end of the collection by re-adding it.
             $collection->add($name, $route);
         } elseif (in_array($primary_format, $supported_formats)) {
             // Perfect match, which will get a higher priority by leaving the route
             // on top of the list.
         } elseif (in_array('*/*', $acceptable_mime_types) || array_intersect($acceptable_formats, $supported_formats)) {
             // Move it to the end of the list.
             $collection->add($name, $route);
         } else {
             // Remove the route if it does not match at all.
             $collection->remove($name);
         }
     }
     if (count($collection)) {
         return $collection;
     }
     // We do not throw a
     // \Symfony\Component\Routing\Exception\ResourceNotFoundException here
     // because we don't want to return a 404 status code, but rather a 406.
     throw new NotAcceptableHttpException(SafeMarkup::format('No route found for the specified formats @formats.', array('@formats' => implode(' ', $acceptable_mime_types))));
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:36,代码来源:AcceptHeaderMatcher.php


示例13: testMatchPath

 /**
  * Test that standard paths works with multiple patterns.
  *
  * @dataProvider getMatchPathData
  */
 public function testMatchPath($patterns, $paths)
 {
     foreach ($paths as $path => $expected_result) {
         $actual_result = $this->pathMatcher->matchPath($path, $patterns);
         $this->assertEquals($actual_result, $expected_result, SafeMarkup::format('Tried matching the path <code>@path</code> to the pattern <pre>@patterns</pre> - expected @expected, got @actual.', array('@path' => $path, '@patterns' => $patterns, '@expected' => var_export($expected_result, TRUE), '@actual' => var_export($actual_result, TRUE))));
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:12,代码来源:PathMatcherTest.php


示例14: testBooleanFormatterSettings

 /**
  * Tests the formatter settings page for the Boolean formatter.
  */
 function testBooleanFormatterSettings()
 {
     // List the options we expect to see on the settings form. Omit the one
     // with the Unicode check/x characters, which does not appear to work
     // well in WebTestBase.
     $options = array('Yes / No', 'True / False', 'On / Off', 'Enabled / Disabled', '1 / 0', 'Custom');
     // Define what the "default" option should look like, depending on the
     // field settings.
     $default = 'Field settings (@on / @off)';
     // For several different values of the field settings, test that the
     // options, including default, are shown correctly.
     $settings = array(array('Yes', 'No'), array('On', 'Off'), array('TRUE', 'FALSE'));
     foreach ($settings as $values) {
         // Set up the field settings.
         $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
         $this->drupalPostForm(NULL, array('settings[on_label]' => $values[0], 'settings[off_label]' => $values[1]), 'Save settings');
         // Open the Manage Display page and trigger the field settings form.
         $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
         $this->drupalPostAjaxForm(NULL, array(), $this->fieldName . '_settings_edit');
         // Test that the settings options are present in the correct format.
         foreach ($options as $string) {
             $this->assertText($string);
         }
         $this->assertText(SafeMarkup::format($default, array('@on' => $values[0], '@off' => $values[1])));
     }
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:29,代码来源:BooleanFormatterSettingsTest.php


示例15: testIntegration

 /**
  * Tests the integration.
  */
 public function testIntegration()
 {
     // Remove the watchdog entries added by the potential batch process.
     $this->container->get('database')->truncate('watchdog')->execute();
     $entries = array();
     // Setup a watchdog entry without tokens.
     $entries[] = array('message' => $this->randomMachineName(), 'variables' => array('link' => \Drupal::l('Link', new Url('<front>'))));
     // Setup a watchdog entry with one token.
     $entries[] = array('message' => '@token1', 'variables' => array('@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', new Url('<front>'))));
     // Setup a watchdog entry with two tokens.
     $entries[] = array('message' => '@token1 !token2', 'variables' => array('@token1' => $this->randomMachineName(), '!token2' => $this->randomMachineName(), 'link' => \Drupal::l(SafeMarkup::set('<object>Link</object>'), new Url('<front>'))));
     $logger_factory = $this->container->get('logger.factory');
     foreach ($entries as $entry) {
         $entry += array('type' => 'test-views', 'severity' => RfcLogLevel::NOTICE);
         $logger_factory->get($entry['type'])->log($entry['severity'], $entry['message'], $entry['variables']);
     }
     $view = Views::getView('test_dblog');
     $this->executeView($view);
     $view->initStyle();
     foreach ($entries as $index => $entry) {
         $this->assertEqual($view->style_plugin->getField($index, 'message'), SafeMarkup::format($entry['message'], $entry['variables']));
         $this->assertEqual($view->style_plugin->getField($index, 'link'), Xss::filterAdmin($entry['variables']['link']));
     }
     // Disable replacing variables and check that the tokens aren't replaced.
     $view->destroy();
     $view->storage->invalidateCaches();
     $view->initHandlers();
     $this->executeView($view);
     $view->initStyle();
     $view->field['message']->options['replace_variables'] = FALSE;
     foreach ($entries as $index => $entry) {
         $this->assertEqual($view->style_plugin->getField($index, 'message'), $entry['message']);
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:37,代码来源:ViewsIntegrationTest.php


示例16: testInlineTemplate

 /**
  * Tests inline templates.
  */
 public function testInlineTemplate()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     /** @var \Drupal\Core\Template\TwigEnvironment $environment */
     $environment = \Drupal::service('twig');
     $this->assertEqual($environment->renderInline('test-no-context'), 'test-no-context');
     $this->assertEqual($environment->renderInline('test-with-context {{ llama }}', array('llama' => 'muuh')), 'test-with-context muuh');
     $element = array();
     $unsafe_string = '<script>alert(\'Danger! High voltage!\');</script>';
     $element['test'] = array('#type' => 'inline_template', '#template' => 'test-with-context <label>{{ unsafe_content }}</label>', '#context' => array('unsafe_content' => $unsafe_string));
     $this->assertEqual($renderer->renderRoot($element), 'test-with-context <label>' . SafeMarkup::checkPlain($unsafe_string) . '</label>');
     // Enable twig_auto_reload and twig_debug.
     $settings = Settings::getAll();
     $settings['twig_debug'] = TRUE;
     $settings['twig_auto_reload'] = TRUE;
     new Settings($settings);
     $this->container = $this->kernel->rebuildContainer();
     \Drupal::setContainer($this->container);
     $element = array();
     $element['test'] = array('#type' => 'inline_template', '#template' => 'test-with-context {{ llama }}', '#context' => array('llama' => 'muuh'));
     $element_copy = $element;
     // Render it twice so that twig caching is triggered.
     $this->assertEqual($renderer->renderRoot($element), 'test-with-context muuh');
     $this->assertEqual($renderer->renderRoot($element_copy), 'test-with-context muuh');
 }
开发者ID:scratch,项目名称:gai,代码行数:29,代码来源:TwigEnvironmentTest.php


示例17: submitGetForm

 /**
  * Simulates submission of a form using GET instead of POST.
  *
  * Forms that use the GET method cannot be submitted with
  * WebTestBase::drupalPostForm(), which explicitly uses POST to submit the
  * form. So this method finds the form, verifies that it has input fields and
  * a submit button matching the inputs to this method, and then calls
  * WebTestBase::drupalGet() to simulate the form submission to the 'action'
  * URL of the form (if set, or the current URL if not).
  *
  * See WebTestBase::drupalPostForm() for more detailed documentation of the
  * function parameters.
  *
  * @param string $path
  *   Location of the form to be submitted: either a Drupal path, absolute
  *   path, or NULL to use the current page.
  * @param array $edit
  *   Form field data to submit. Unlike drupalPostForm(), this does not support
  *   file uploads.
  * @param string $submit
  *   Value of the submit button to submit clicking. Unlike drupalPostForm(),
  *   this does not support AJAX.
  * @param string $form_html_id
  *   (optional) HTML ID of the form, to disambiguate.
  */
 protected function submitGetForm($path, $edit, $submit, $form_html_id = NULL)
 {
     if (isset($path)) {
         $this->drupalGet($path);
     }
     if ($this->parse()) {
         // Iterate over forms to find one that matches $edit and $submit.
         $edit_save = $edit;
         $xpath = '//form';
         if (!empty($form_html_id)) {
             $xpath .= "[@id='" . $form_html_id . "']";
         }
         $forms = $this->xpath($xpath);
         foreach ($forms as $form) {
             // Try to set the fields of this form as specified in $edit.
             $edit = $edit_save;
             $post = array();
             $upload = array();
             $submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form);
             if (!$edit && $submit_matches) {
                 // Everything matched, so "submit" the form.
                 $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : NULL;
                 $this->drupalGet($action, array('query' => $post));
                 return;
             }
         }
         // We have not found a form which contained all fields of $edit and
         // the submit button.
         foreach ($edit as $name => $value) {
             $this->fail(SafeMarkup::format('Failed to set field @name to @value', array('@name' => $name, '@value' => $value)));
         }
         $this->assertTrue($submit_matches, format_string('Found the @submit button', array('@submit' => $submit)));
         $this->fail(format_string('Found the requested form fields at @path', array('@path' => $path)));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:60,代码来源:SearchTestBase.php


示例18: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form['help'] = array('#markup' => t('By default, only the "Free order" payment method is listed here. To see additional payment methods you must <a href="@install">install additional modules</a>. The "Payment Method Pack" module that comes with Ubercart provides "Check" and "COD" payment methods. The "Credit Card" module that comes with Ubercart provides a credit card payment method, although you will need an additional module to provide a payment gateway for your credit card. For more information about payment methods and settings please read the <a href="@doc">Ubercart Documentation</a>.', ['@install' => Url::fromRoute('system.modules_list')->toString(), '@doc' => Url::fromUri('http://www.drupal.org/documentation/modules/ubercart')->toString()]));
     $form['methods'] = array('#type' => 'table', '#header' => array(t('Payment method'), t('List position'), t('Operations')), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'uc-payment-method-weight')));
     foreach ($this->paymentMethodManager->getDefinitions() as $id => $method) {
         $form['methods'][$id]['#attributes']['class'][] = 'draggable';
         $form['methods'][$id]['status'] = array('#type' => 'checkbox', '#title' => SafeMarkup::checkPlain($method['name']), '#default_value' => $method['checkout']);
         $form['methods'][$id]['weight'] = array('#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $method['name'])), '#title_display' => 'invisible', '#default_value' => $method['weight'], '#attributes' => array('class' => array('uc-payment-method-weight')));
         if (empty($method['no_gateway'])) {
             $gateways = _uc_payment_gateway_list($id, TRUE);
             $options = array();
             foreach ($gateways as $gateway_id => $gateway) {
                 $options[$gateway_id] = $gateway['title'];
             }
             if ($options) {
                 $form['methods'][$id]['status']['#title'] .= ' (' . t('includes %gateways', array('%gateways' => implode(', ', $options))) . ')';
             }
         }
         $links = array();
         if (!empty($method['settings_form'])) {
             $links['settings'] = array('title' => t('Settings'), 'url' => Url::fromRoute('uc_payment.method_settings', ['method' => $id]));
         }
         // $links['conditions'] = array(
         //   'title' => t('Conditions'),
         //   'url' => Url::fromRoute('admin/store/config/payment/manage/uc_payment_method_', ['method' => $id]),
         // );
         $form['methods'][$id]['settings'] = array('#type' => 'operations', '#links' => $links);
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:33,代码来源:PaymentMethodsForm.php


示例19: assertBreadcrumbParts

 /**
  * Assert that a trail exists in the internal browser.
  *
  * @param array $trail
  *   An associative array whose keys are expected breadcrumb link paths and
  *   whose values are expected breadcrumb link texts (not sanitized).
  */
 protected function assertBreadcrumbParts($trail)
 {
     // Compare paths with actual breadcrumb.
     $parts = $this->getBreadcrumbParts();
     $pass = TRUE;
     // There may be more than one breadcrumb on the page. If $trail is empty
     // this test would go into an infinite loop, so we need to check that too.
     while ($trail && !empty($parts)) {
         foreach ($trail as $path => $title) {
             // If the path is empty, generate the path from the <front> route.  If
             // the path does not start with a leading slash, then run it through
             // Url::fromUri('base:')->toString() to get the correct base
             // prepended.
             if ($path == '') {
                 $url = Url::fromRoute('<front>')->toString();
             } elseif ($path[0] != '/') {
                 $url = Url::fromUri('base:' . $path)->toString();
             } else {
                 $url = $path;
             }
             $part = array_shift($parts);
             $pass = $pass && $part['hr 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Utility\String类代码示例发布时间:2022-05-23
下一篇:
PHP Utility\Random类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap