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


PHP Utility\SafeMarkup类代码示例

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


在下文中一共展示了SafeMarkup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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() . '&escaped@example.com';
     $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


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