Example #1
0
 /**
  * Checks HTML double escaping of revision logs.
  */
 public function testNodeRevisionDoubleEscapeFix()
 {
     $this->drupalLogin($this->editor);
     $nodes = [];
     // Create the node.
     $node = $this->drupalCreateNode();
     $username = ['#theme' => 'username', '#account' => $this->editor];
     $editor = \Drupal::service('renderer')->renderPlain($username);
     // Get original node.
     $nodes[] = clone $node;
     // Create revision with a random title and body and update variables.
     $node->title = $this->randomMachineName();
     $node->body = ['value' => $this->randomMachineName(32), 'format' => filter_default_format()];
     $node->setNewRevision();
     $revision_log = 'Revision <em>message</em> with markup.';
     $node->revision_log->value = $revision_log;
     $node->save();
     // Make sure we get revision information.
     $node = Node::load($node->id());
     $nodes[] = clone $node;
     $this->drupalGet('node/' . $node->id() . '/revisions');
     // Assert the old revision message.
     $date = format_date($nodes[0]->revision_timestamp->value, 'short');
     $url = new Url('entity.node.revision', ['node' => $nodes[0]->id(), 'node_revision' => $nodes[0]->getRevisionId()]);
     $old_revision_message = t('!date by !username', ['!date' => \Drupal::l($date, $url), '!username' => $editor]);
     $this->assertRaw($old_revision_message);
     // Assert the current revision message.
     $date = format_date($nodes[1]->revision_timestamp->value, 'short');
     $current_revision_message = t('!date by !username', ['!date' => $nodes[1]->link($date), '!username' => $editor]);
     $current_revision_message .= '<p class="revision-log">' . $revision_log . '</p>';
     $this->assertRaw($current_revision_message);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     ConfigurableLanguage::createFromLangcode('it')->save();
     /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */
     $manager = \Drupal::service('content_translation.manager');
     $manager->setEnabled('node', 'article', TRUE);
     // Create and log in user.
     $web_user = $this->drupalCreateUser(array('view page revisions', 'revert page revisions', 'delete page revisions', 'edit any page content', 'delete any page content', 'translate any entity'));
     $this->drupalLogin($web_user);
     // Create initial node.
     $node = $this->drupalCreateNode();
     $settings = get_object_vars($node);
     $settings['revision'] = 1;
     $settings['isDefaultRevision'] = TRUE;
     $nodes = array();
     $logs = array();
     // Get original node.
     $nodes[] = clone $node;
     // Create three revisions.
     $revision_count = 3;
     for ($i = 0; $i < $revision_count; $i++) {
         $logs[] = $node->revision_log = $this->randomMachineName(32);
         // Create revision with a random title and body and update variables.
         $node->title = $this->randomMachineName();
         $node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format());
         $node->setNewRevision();
         $node->save();
         $node = Node::load($node->id());
         // Make sure we get revision information.
         $nodes[] = clone $node;
     }
     $this->nodes = $nodes;
     $this->revisionLogs = $logs;
 }
 function setUp()
 {
     parent::setUp();
     // Create and login user.
     $test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration'));
     $this->drupalLogin($test_user);
     // Add a new language.
     $language = new Language(array('id' => 'es', 'name' => 'Spanish'));
     language_save($language);
     // Make the body field translatable. The title is already translatable by
     // definition. The parent class has already created the article and page
     // content types.
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $field_storage->translatable = TRUE;
     $field_storage->save();
     // Create a few page nodes with multilingual body values.
     $default_format = filter_default_format();
     $nodes = array(array('title' => 'First node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'), array('title' => 'Second node this is the Spanish title', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'es'), array('title' => 'Third node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'));
     $this->searchable_nodes = array();
     foreach ($nodes as $setting) {
         $this->searchable_nodes[] = $this->drupalCreateNode($setting);
     }
     // Add English translation to the second node.
     $translation = $this->searchable_nodes[1]->addTranslation('en', array('title' => 'Second node en'));
     $translation->body->value = $this->randomMachineName(32);
     $this->searchable_nodes[1]->save();
     // Add Spanish translation to the third node.
     $translation = $this->searchable_nodes[2]->addTranslation('es', array('title' => 'Third node es'));
     $translation->body->value = $this->randomMachineName(32);
     $this->searchable_nodes[2]->save();
     // Update the index and then run the shutdown method.
     $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     $plugin->updateIndex();
     search_update_totals();
 }
 protected function setUp()
 {
     parent::setUp();
     // Create and log in user.
     $web_user = $this->drupalCreateUser(array('view page revisions', 'revert page revisions', 'delete page revisions', 'edit any page content', 'delete any page content'));
     $this->drupalLogin($web_user);
     // Create initial node.
     $node = $this->drupalCreateNode();
     $settings = get_object_vars($node);
     $settings['revision'] = 1;
     $settings['isDefaultRevision'] = TRUE;
     $nodes = array();
     $logs = array();
     // Get original node.
     $nodes[] = clone $node;
     // Create three revisions.
     $revision_count = 3;
     for ($i = 0; $i < $revision_count; $i++) {
         $logs[] = $node->revision_log = $this->randomMachineName(32);
         // Create revision with a random title and body and update variables.
         $node->title = $this->randomMachineName();
         $node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format());
         $node->setNewRevision();
         $node->save();
         $node = node_load($node->id());
         // Make sure we get revision information.
         $nodes[] = clone $node;
     }
     $this->nodes = $nodes;
     $this->revisionLogs = $logs;
 }
 protected function setUp()
 {
     parent::setUp();
     // Create and log in user.
     $test_user = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration']);
     $this->drupalLogin($test_user);
     // Add a new language.
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Set up times to be applied to the English and Spanish translations of the
     // node create time, so that they are filtered in/out in the
     // search_date_query_alter test module.
     $created_time_en = new \DateTime('February 10 2016 10PM');
     $created_time_es = new \DateTime('March 19 2016 10PM');
     $default_format = filter_default_format();
     $node = $this->drupalCreateNode(['title' => 'Node EN', 'type' => 'page', 'body' => ['value' => $this->randomMachineName(32), 'format' => $default_format], 'langcode' => 'en', 'created' => $created_time_en->format('U')]);
     // Add Spanish translation to the node.
     $translation = $node->addTranslation('es', ['title' => 'Node ES']);
     $translation->body->value = $this->randomMachineName(32);
     $translation->created->value = $created_time_es->format('U');
     $node->save();
     // Update the index.
     $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     $plugin->updateIndex();
     search_update_totals();
 }
Example #6
0
 /**
  * Creates a node based on default settings.
  *
  * @param array $settings
  *   (optional) An associative array of settings for the node, as used in
  *   entity_create(). Override the defaults by specifying the key and value
  *   in the array, for example:
  *   @code
  *     $this->drupalCreateNode(array(
  *       'title' => t('Hello, world!'),
  *       'type' => 'article',
  *     ));
  *   @endcode
  *   The following defaults are provided:
  *   - body: Random string using the default filter format:
  *     @code
  *       $settings['body'][0] = array(
  *         'value' => $this->randomMachineName(32),
  *         'format' => filter_default_format(),
  *       );
  *     @endcode
  *   - title: Random string.
  *   - type: 'page'.
  *   - uid: The currently logged in user, or anonymous.
  *
  * @return \Drupal\node\NodeInterface
  *   The created node entity.
  */
 protected function createNode(array $settings = array())
 {
     // Populate defaults array.
     $settings += array('body' => array(array('value' => $this->randomMachineName(32), 'format' => filter_default_format())), 'title' => $this->randomMachineName(8), 'type' => 'page', 'uid' => \Drupal::currentUser()->id());
     $node = Node::create($settings);
     $node->save();
     return $node;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function render($empty = FALSE)
 {
     $format = isset($this->options['format']) ? $this->options['format'] : filter_default_format();
     if (!$empty || !empty($this->options['empty'])) {
         return array('#type' => 'processed_text', '#text' => $this->tokenizeValue($this->options['content']), '#format' => $format);
     }
     return array();
 }
Example #8
0
/**
 * Implements hook_form_FORM_ID_alter() for system_theme_settings().
 */
function platon_form_system_theme_settings_alter(&$form, $form_state)
{
    $path = drupal_get_path('theme', 'platon');
    // If using a different Admin theme, we get a Fatal Error. Include the
    // template.php file.
    require_once DRUPAL_ROOT . "/{$path}/template.php";
    $form['#attached'] = array('js' => array('//cdnjs.cloudflare.com/ajax/libs/ace/1.1.01/ace.js' => array('type' => 'file', 'cache' => FALSE), "{$path}/js/platon.theme-settings.js" => array('type' => 'file', 'cache' => FALSE)));
    // Deactivate irrelevant settings.
    foreach (array('toggle_name', 'toggle_slogan', 'toggle_favicon', 'toggle_main_menu', 'toggle_secondary_menu') as $option) {
        $form['theme_settings'][$option]['#access'] = FALSE;
    }
    if (module_exists('color')) {
        // Add some descriptions to clarify what each color is used for.
        foreach (array('white' => t("e.g. main menu active menu link background"), 'very_light_gray' => t("e.g. body background color"), 'light_gray' => t('e.g content background color'), 'medium_gray' => t('e.g. title background color, table background color'), 'dark_gray' => t('e.g. forum tools background'), 'light_blue' => t('e.g. link hover color, tabs background, fieldset titles'), 'dark_blue' => t('e.g. link color, tabs active/hover background color'), 'deep_blue' => t('e.g. header background color, footer background color'), 'leaf_green' => t('e.g. form submit buttons, local actions'), 'blood_red' => t('e.g. form delete buttons')) as $color => $description) {
            $form['color']['palette'][$color]['#description'] = $description;
        }
        // Hide the base and link ones. They're just there to prevent Notices.
        $form['color']['palette']['base']['#type'] = 'hidden';
        $form['color']['palette']['link']['#type'] = 'hidden';
        // Make color section collapsible.
        $form['color']['#collapsible'] = TRUE;
        $form['color']['#collapsed'] = TRUE;
        if (isset($form['#submit']) && !in_array('platon_form_system_theme_settings_alter_color_submit', $form['#submit'])) {
            $form['#submit'][] = 'platon_form_system_theme_settings_alter_color_submit';
        }
    }
    // Header image settings.
    $form['platon_header_settings'] = array('#type' => 'fieldset', '#title' => t("Header background"));
    $form['platon_header_settings']['platon_use_header_background'] = array('#type' => 'checkbox', '#title' => t("Use another image for the header background"), '#description' => t("Check here if you want the theme to use a custom image for the header background."), '#default_value' => theme_get_setting('platon_use_header_background'));
    $form['platon_header_settings']['platon_header_image_path'] = array('#type' => 'textfield', '#title' => t("The path to the header background image."), '#description' => t("The path to the image file you would like to use as your custom header background (relative to sites/default/files). The suggested size for the header background is 3000x134."), '#default_value' => theme_get_setting('platon_header_image_path'), '#states' => array('invisible' => array('input[name="platon_use_header_background"]' => array('checked' => FALSE))));
    $form['platon_header_settings']['platon_header_image_upload'] = array('#type' => 'file', '#title' => t("Upload an image"), '#description' => t("If you don't have direct file access to the server, use this field to upload your header background image."), '#states' => array('invisible' => array('input[name="platon_use_header_background"]' => array('checked' => FALSE))));
    // Home page settings.
    $form['platon_home_page_settings'] = array('#type' => 'fieldset', '#title' => t("Homepage settings"));
    $form['platon_home_page_settings']['platon_use_home_page_markup'] = array('#type' => 'checkbox', '#title' => t("Use a different homepage for anonymous users."), '#description' => t("Check here if you want the theme to use a custom page for users that are not logged in."), '#default_value' => theme_get_setting('platon_use_home_page_markup'));
    $settings = theme_get_setting('platon_home_page_markup');
    $form['platon_home_page_settings']['platon_home_page_markup_wrapper'] = array('#type' => 'fieldset', '#states' => array('invisible' => array('input[name="platon_use_home_page_markup"]' => array('checked' => FALSE))), 'platon_home_page_markup' => array('#type' => 'text_format', '#base_type' => 'textarea', '#title' => t("Home page content"), '#description' => t("Set the content for the home page. This will be used for users that are not logged in."), '#format' => !empty($settings['format']) ? $settings['format'] : filter_default_format(), '#default_value' => !empty($settings['value']) ? $settings['value'] : ''));
    $form['platon_home_page_settings']['platon_use_home_page_background'] = array('#type' => 'checkbox', '#title' => t("Use an image for the home page background"), '#description' => t("Check here if you want the theme to use a custom image for the homepage background."), '#default_value' => theme_get_setting('platon_use_home_page_background'));
    $form['platon_home_page_settings']['platon_home_page_image_path'] = array('#type' => 'textfield', '#title' => t("The path to the home page background image."), '#description' => t("The path to the image file you would like to use as your custom home page background (relative to sites/default/files)."), '#default_value' => theme_get_setting('platon_home_page_image_path'), '#states' => array('invisible' => array('input[name="platon_use_home_page_background"]' => array('checked' => FALSE))));
    $form['platon_home_page_settings']['platon_home_page_image_upload'] = array('#type' => 'file', '#title' => t("Upload an image"), '#description' => t("If you don't have direct file access to the server, use this field to upload your background image."), '#states' => array('invisible' => array('input[name="platon_use_home_page_background"]' => array('checked' => FALSE))));
    // Main menu settings.
    if (module_exists('menu')) {
        $form['platon_menu_settings'] = array('#type' => 'fieldset', '#title' => t("Menu settings"));
        $form['platon_menu_settings']['platon_menu_source'] = array('#type' => 'select', '#title' => t("Main menu source"), '#options' => array(0 => t("None")) + menu_get_menus(), '#description' => t("The menu source to use for the tile navigation. If 'none', Platon will use a default list of tiles."), '#default_value' => theme_get_setting('platon_menu_source'));
        $form['platon_menu_settings']['platon_menu_show_for_anonymous'] = array('#type' => 'checkbox', '#title' => t("Show menu for anonymous users"), '#description' => t("Show the main menu for users that are not logged in. Only links that users have access to will show up."), '#default_value' => theme_get_setting('platon_menu_show_for_anonymous'));
    }
    // CSS overrides.
    $form['platon_css_settings'] = array('#type' => 'fieldset', '#title' => t("CSS overrides"), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $css_content = _platon_get_css_override_file_content();
    $form['platon_css_settings']['platon_css_override_content'] = array('#type' => 'textarea', '#title' => t("CSS overrides"), '#description' => t("You can write CSS rules here. They will be stored in a CSS file in your public files directory. Change it's content to alter the display of your site."), '#default_value' => $css_content);
    $form['platon_css_settings']['platon_css_override_fid'] = array('#type' => 'value', '#value' => _platon_get_css_override_file());
    if (isset($form['#validate']) && !in_array('platon_form_system_theme_settings_alter_validate', $form['#validate'])) {
        $form['#validate'][] = 'platon_form_system_theme_settings_alter_validate';
    }
    if (isset($form['#submit']) && !in_array('platon_form_system_theme_settings_alter_submit', $form['#submit'])) {
        array_unshift($form['#submit'], 'platon_form_system_theme_settings_alter_submit');
    }
    $form['platon_group_style'] = array('#type' => 'checkbox', '#title' => t("Platon group style"), '#description' => t("Check here if you want the new group style, left block with lessons"), '#default_value' => variable_get('platon_group_style', 1));
}
 /**
  * Creates a new revision for a given node.
  *
  * @param \Drupal\node\NodeInterface $node
  *   A node object.
  *
  * @return \Drupal\node\NodeInterface
  *   A node object with up to date revision information.
  */
 protected function createNodeRevision(NodeInterface $node)
 {
     // Create revision with a random title and body and update variables.
     $node->title = $this->randomMachineName();
     $node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format());
     $node->setNewRevision();
     $node->save();
     return $node;
 }
Example #10
0
 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create two nodes.
     for ($i = 0; $i < 2; $i++) {
         $this->nodes[] = $this->drupalCreateNode(array('type' => 'article', 'body' => array(array('value' => $this->randomMachineName(42), 'format' => filter_default_format(), 'summary' => $this->randomMachineName()))));
     }
 }
  /**
   * @see ctools_export_ui::edit_form()
   */
  function edit_form(&$form, &$form_state) {
    parent::edit_form($form, $form_state);
    $form['#attached']['js'] = array(
      drupal_get_path('module', 'uc_custom_payment') . '/plugins/export_ui/uc_custom_payment_ui.js',
    );
    $form['info']['admin_title']['#title'] = t('Name');
    $form['info']['admin_title']['#required'] = TRUE;
    $form['info']['admin_title']['#description'] = t('The name of this payment method as it will appear in administrative lists');
    $form['info']['name']['#machine_name']['exists'] = 'uc_custom_payment_name_exists';
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#default_value' => empty($form_state['item']->title) ? '' : $form_state['item']->title,
      '#description' => t('The title of this payment method as it will appear to the customer.'),
      '#required' => TRUE,
    );
    $form['instructions'] = array(
      '#type' => 'text_format',
      '#title' => t('Instructions'),
      '#default_value' => empty($form_state['item']->instructions) ? '' : $form_state['item']->instructions['value'],
      '#format' => empty($form_state['item']->instructions) ? filter_default_format() : $form_state['item']->instructions['format'],
      '#description' => t('The instructions for this payment method which will appear when the method is selected.'),
    );
    if (module_exists('token')) {
      $form['instructions']['#description'] .= ' ' . t('You may use any of the following replacement patterns.');
      $form['instructions']['#suffix'] = theme('token_tree', array('token_types' => array('uc_order')));
    }

    $default = '';
    if (!empty($form_state['item']->data['service_charge'])) {
      $default = $form_state['item']->data['service_charge'];
      if ($form_state['item']->data['service_charge_type'] === 'percentage') {
        $default .= '%';
      }
    }
    $form['service_charge'] = array(
      '#type' => 'textfield',
      '#title' => t('Service Charge'),
      '#field_prefix' => variable_get('uc_sign_after_amount', FALSE) ? '' : variable_get('uc_currency_sign', '$'),
      '#field_suffix' => variable_get('uc_sign_after_amount', FALSE) ? variable_get('uc_currency_sign', '$') : '',
      '#default_value' => $default,
      '#description' => t('The service charge to be applied to the order when this payment method is selected.
        May be an absolute price or percent of order total (e.g. enter "15%"). Leave blank for no service charge.'),
    );
    $form['service_charge_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Service Charge Title'),
      '#default_value' => empty($form_state['item']->data['service_charge_title']) ? t('Service charge') : $form_state['item']->data['service_charge_title'],
      '#description' => t('The line item title to use for the service charge.'),
      '#states' => array(
        'visible' => array(
          'input[name="service_charge"]' => array('filled' => TRUE),
        ),
      ),
    );
  }
Example #12
0
 /**
  * Tests the rendered output for fields display.
  */
 public function testFeedFieldOutput()
 {
     $this->drupalCreateContentType(['type' => 'page']);
     // Verify a title with HTML entities is properly escaped.
     $node_title = 'This "cool" & "neat" article\'s title';
     $this->drupalCreateNode(array('title' => $node_title, 'body' => [0 => ['value' => 'A paragraph', 'format' => filter_default_format()]]));
     $this->drupalGet('test-feed-display-fields.xml');
     $result = $this->xpath('//title/a');
     $this->assertEqual($result[0], $node_title, 'Node title with HTML entities displays correctly.');
     // Verify HTML is properly escaped in the description field.
     $this->assertRaw('&lt;p&gt;A paragraph&lt;/p&gt;');
 }
 function handleDocumentInfo($DocInfo)
 {
     $this->urls_processed[$DocInfo->http_status_code][] = $DocInfo->url;
     if (200 != $DocInfo->http_status_code) {
         return;
     }
     $nid = db_select('field_data_field_sitecrawler_url', 'fdfsu')->fields('fdfsu', array('entity_id'))->condition('fdfsu.field_sitecrawler_url_url', $DocInfo->url)->execute()->fetchField();
     if (!!$nid) {
         $node = node_load($nid);
         $this->nodes_updated++;
     } else {
         $node = new stdClass();
         $node->type = 'sitecrawler_page';
         node_object_prepare($node);
         $this->nodes_created++;
     }
     $node->title = preg_match('#<head.*?<title>(.*?)</title>.*?</head>#is', $DocInfo->source, $matches) ? $matches[1] : $DocInfo->url;
     $node->language = LANGUAGE_NONE;
     $node->field_sitecrawler_url[$node->language][0]['title'] = $node->title;
     $node->field_sitecrawler_url[$node->language][0]['url'] = $DocInfo->url;
     //     $node->field_sitecrawler_summary[$node->language][0]['value'] =
     // drupal_set_message('<pre style="border: 1px solid red;">body_xpaths: ' . print_r($this->body_xpaths,1) . '</pre>');
     $doc = new DOMDocument();
     $doc->loadHTML($DocInfo->source);
     foreach ($this->body_xpaths as $body_xpath) {
         $xpath = new DOMXpath($doc);
         // $body = $xpath->query('/html/body');
         // $body = $xpath->query('//div[@id="layout"]');
         $body = $xpath->query($body_xpath);
         if (!is_null($body)) {
             foreach ($body as $i => $element) {
                 $node_body = $element->nodeValue;
                 if (!empty($node_body)) {
                     break 2;
                 }
             }
         }
     }
     if (empty($node_body)) {
         $node_body = preg_match('#<body.*?>(.*?)</body>#is', $DocInfo->source, $matches) && !empty($matches[1]) ? $matches[1] : $DocInfo->source;
     }
     $node_body = mb_check_encoding($node_body, 'UTF-8') ? $node_body : utf8_encode($node_body);
     $node->body[$node->language][0]['value'] = $node_body;
     $node->body[$node->language][0]['summary'] = text_summary($node_body);
     $node->body[$node->language][0]['format'] = filter_default_format();
     // store the Drupal crawler ID from the opensanmateo_sitecrawler_sites table
     $node->field_sitecrawler_id[$node->language][0]['value'] = $this->crawler_id;
     // store the PHPCrawler ID for this pull of the site
     $node->field_sitecrawler_instance_id[$node->language][0]['value'] = $this->getCrawlerId();
     node_save($node);
     $this->{'nodes_' . (!!$nid ? 'updated' : 'created')}[$node->nid] = $node->title . ' :: ' . $DocInfo->url;
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Enable additional languages.
     ConfigurableLanguage::createFromLangcode('de')->save();
     ConfigurableLanguage::createFromLangcode('it')->save();
     $field_storage_definition = array('field_name' => 'untranslatable_string_field', 'entity_type' => 'node', 'type' => 'string', 'cardinality' => 1, 'translatable' => FALSE);
     $field_storage = FieldStorageConfig::create($field_storage_definition);
     $field_storage->save();
     $field_definition = array('field_storage' => $field_storage, 'bundle' => 'page');
     $field = FieldConfig::create($field_definition);
     $field->save();
     // Create and log in user.
     $web_user = $this->drupalCreateUser(array('view page revisions', 'revert page revisions', 'delete page revisions', 'edit any page content', 'delete any page content', 'access contextual links', 'translate any entity', 'administer content types'));
     $this->drupalLogin($web_user);
     // Create initial node.
     $node = $this->drupalCreateNode();
     $settings = get_object_vars($node);
     $settings['revision'] = 1;
     $settings['isDefaultRevision'] = TRUE;
     $nodes = array();
     $logs = array();
     // Get original node.
     $nodes[] = clone $node;
     // Create three revisions.
     $revision_count = 3;
     for ($i = 0; $i < $revision_count; $i++) {
         $logs[] = $node->revision_log = $this->randomMachineName(32);
         // Create revision with a random title and body and update variables.
         $node->title = $this->randomMachineName();
         $node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format());
         $node->untranslatable_string_field->value = $this->randomString();
         $node->setNewRevision();
         // Edit the 2nd revision with a different user.
         if ($i == 1) {
             $editor = $this->drupalCreateUser();
             $node->setRevisionUserId($editor->id());
         } else {
             $node->setRevisionUserId($web_user->id());
         }
         $node->save();
         $node = Node::load($node->id());
         // Make sure we get revision information.
         $nodes[] = clone $node;
     }
     $this->nodes = $nodes;
     $this->revisionLogs = $logs;
 }
 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create comment field on article.
     $this->container->get('comment.manager')->addDefaultField('node', 'article');
     // Create two nodes, with 5 comments on all of them.
     for ($i = 0; $i < 2; $i++) {
         $this->nodes[] = $this->drupalCreateNode(array('type' => 'article', 'body' => array(array('value' => $this->randomMachineName(42), 'format' => filter_default_format(), 'summary' => $this->randomMachineName()))));
     }
     foreach ($this->nodes as $node) {
         for ($i = 0; $i < 5; $i++) {
             $this->comments[$node->id()][] = $this->drupalCreateComment(array('entity_id' => $node->id()));
         }
     }
 }
 protected function setUp()
 {
     parent::setUp();
     // Create a user who can administer search, do searches, see the status
     // report, and administer cron. Log in.
     $user = $this->drupalCreateUser(array('administer search', 'search content', 'use advanced search', 'access content', 'access site reports', 'administer site configuration'));
     $this->drupalLogin($user);
     // Make sure that auto-cron is disabled.
     $this->config('system.cron')->set('threshold.autorun', 0)->save();
     // Set up the search plugin.
     $this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     // Check indexing counts before adding any nodes.
     $this->assertIndexCounts(0, 0, 'before adding nodes');
     $this->assertDatabaseCounts(0, 0, 'before adding nodes');
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('hu')->save();
     ConfigurableLanguage::createFromLangcode('sv')->save();
     // Make the body field translatable. The title is already translatable by
     // definition. The parent class has already created the article and page
     // content types.
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $field_storage->setTranslatable(TRUE);
     $field_storage->save();
     // Create a few page nodes with multilingual body values.
     $default_format = filter_default_format();
     $nodes = array(array('title' => 'First node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'), array('title' => 'Second node this is the English title', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'), array('title' => 'Third node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'), array(), array(), array(), array(), array());
     $this->searchableNodes = array();
     foreach ($nodes as $setting) {
         $this->searchableNodes[] = $this->drupalCreateNode($setting);
     }
     // Add a single translation to the second node.
     $translation = $this->searchableNodes[1]->addTranslation('hu', array('title' => 'Second node hu'));
     $translation->body->value = $this->randomMachineName(32);
     $this->searchableNodes[1]->save();
     // Add two translations to the third node.
     $translation = $this->searchableNodes[2]->addTranslation('hu', array('title' => 'Third node this is the Hungarian title'));
     $translation->body->value = $this->randomMachineName(32);
     $translation = $this->searchableNodes[2]->addTranslation('sv', array('title' => 'Third node sv'));
     $translation->body->value = $this->randomMachineName(32);
     $this->searchableNodes[2]->save();
     // Verify that we have 8 nodes left to do.
     $this->assertIndexCounts(8, 8, 'before updating the search index');
     $this->assertDatabaseCounts(0, 0, 'before updating the search index');
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $language = \Drupal::languageManager()->getCurrentLanguage();
     $ln = $language->getId();
     $popup_settings = eu_cookie_compliance_get_settings();
     $domainSetting = \Drupal::config('eu_cookie_compliance.settings')->get('domain');
     $form['eu_cookie_compliance_domain'] = array('#type' => 'textfield', '#title' => t('Domain'), '#default_value' => $domainSetting['setting'], '#description' => t('Sets the domain of the cookie to a specific url.  Used when you need consistency across domains.  This is language independent.'));
     $form['eu_cookie_compliance_' . $ln] = array('#type' => 'item', '#tree' => TRUE);
     if (\Drupal::moduleHandler()->moduleExists('locale')) {
         $form['eu_cookie_compliance_' . $ln]['#title'] = t('You are editing settings for the %language language.', array('%language' => $language->name));
     }
     $form['eu_cookie_compliance_' . $ln]['popup_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable popup'), '#default_value' => isset($popup_settings['popup_enabled']) ? $popup_settings['popup_enabled'] : 0);
     $form['eu_cookie_compliance_' . $ln]['popup_clicking_confirmation'] = array('#type' => 'checkbox', '#title' => t('Consent by clicking'), '#default_value' => isset($popup_settings['popup_clicking_confirmation']) ? $popup_settings['popup_clicking_confirmation'] : 1, '#description' => t('By default by clicking any link on the website the visitor accepts the cookie policy. Uncheck this box if you do not require this functionality. You may want to edit the pop-up message below accordingly.'));
     if (\Drupal::moduleHandler()->moduleExists('geoip') || \Drupal::moduleHandler()->moduleExists('smart_ip') || function_exists('geoip_country_code_by_name')) {
         $form['eu_cookie_compliance_' . $ln]['eu_only'] = array('#type' => 'checkbox', '#title' => t('Only display popup in EU countries (using the <a href="http://drupal.org/project/geoip">geoip</a> module or the <a href="http://drupal.org/project/smart_ip">smart_ip</a> module or the <a href="http://www.php.net/manual/fr/function.geoip-country-code-by-name.php">geoip_country_code_by_name()</a> PHP function)'), '#default_value' => isset($popup_settings['eu_only']) ? $popup_settings['eu_only'] : 0);
     }
     $form['eu_cookie_compliance_' . $ln]['popup_position'] = array('#type' => 'checkbox', '#title' => t('Place the pop-up at the top of the website'), '#default_value' => isset($popup_settings['popup_position']) ? $popup_settings['popup_position'] : 0, '#description' => t('By default the pop-up appears at the bottom of the website. Tick this box if you want it to appear at the top'));
     $form['eu_cookie_compliance_' . $ln]['popup_agree_button_message'] = array('#type' => 'textfield', '#title' => t('Agree button message'), '#default_value' => isset($popup_settings['popup_agree_button_message']) ? $popup_settings['popup_agree_button_message'] : t('OK, I agree'), '#size' => 30, '#required' => TRUE);
     $form['eu_cookie_compliance_' . $ln]['popup_disagree_button_message'] = array('#type' => 'textfield', '#title' => t('Disagree button message'), '#default_value' => isset($popup_settings['popup_disagree_button_message']) ? $popup_settings['popup_disagree_button_message'] : t('No, give me more info'), '#size' => 30, '#required' => TRUE);
     $form['eu_cookie_compliance_' . $ln]['popup_info'] = array('#type' => 'text_format', '#title' => t('Popup message - requests consent'), '#default_value' => isset($popup_settings['popup_info']['value']) ? $popup_settings['popup_info']['value'] : '', '#required' => TRUE, '#format' => isset($popup_settings['popup_info']['format']) ? $popup_settings['popup_info']['format'] : filter_default_format());
     $form['eu_cookie_compliance_' . $ln]['popup_agreed_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable thank you message'), '#default_value' => isset($popup_settings['popup_agreed_enabled']) ? $popup_settings['popup_agreed_enabled'] : 1);
     $form['eu_cookie_compliance_' . $ln]['popup_hide_agreed'] = array('#type' => 'checkbox', '#title' => t('Clicking hides thank you message'), '#default_value' => isset($popup_settings['popup_hide_agreed']) ? $popup_settings['popup_hide_agreed'] : 0, '#description' => t('Clicking a link hides the thank you message automatically.'));
     $form['eu_cookie_compliance_' . $ln]['popup_find_more_button_message'] = array('#type' => 'textfield', '#title' => t('Find more button message'), '#default_value' => isset($popup_settings['popup_find_more_button_message']) ? $popup_settings['popup_find_more_button_message'] : t('More info'), '#size' => 30, '#required' => TRUE);
     $form['eu_cookie_compliance_' . $ln]['popup_hide_button_message'] = array('#type' => 'textfield', '#title' => t('Hide button message'), '#default_value' => isset($popup_settings['popup_hide_button_message']) ? $popup_settings['popup_hide_button_message'] : t('Hide'), '#size' => 30, '#required' => TRUE);
     $form['eu_cookie_compliance_' . $ln]['popup_agreed'] = array('#type' => 'text_format', '#title' => t('Popup message - thanks for giving consent'), '#default_value' => isset($popup_settings['popup_agreed']['value']) ? $popup_settings['popup_agreed']['value'] : '', '#required' => TRUE, '#format' => isset($popup_settings['popup_agreed']['format']) ? $popup_settings['popup_agreed']['format'] : filter_default_format());
     $form['eu_cookie_compliance_' . $ln]['popup_link'] = array('#type' => 'textfield', '#title' => t('Privacy policy link'), '#default_value' => isset($popup_settings['popup_link']) ? $popup_settings['popup_link'] : '', '#size' => 60, '#maxlength' => 220, '#required' => TRUE, '#description' => t('Enter link to your privacy policy or other page that will explain cookies to your users. For external links prepend http://'));
     $form['eu_cookie_compliance_' . $ln]['popup_link_new_window'] = array('#type' => 'checkbox', '#title' => t('Open privacy policy link in a new window'), '#default_value' => isset($popup_settings['popup_link_new_window']) ? $popup_settings['popup_link_new_window'] : 1);
     $form['eu_cookie_compliance_' . $ln]['popup_height'] = array('#type' => 'textfield', '#title' => t('Popup height in pixels'), '#default_value' => isset($popup_settings['popup_height']) ? $popup_settings['popup_height'] : '', '#size' => 5, '#maxlength' => 5, '#required' => FALSE, '#description' => t('Enter an integer value for a desired height in pixels or leave empty for automatically adjusted height'));
     $form['eu_cookie_compliance_' . $ln]['popup_width'] = array('#type' => 'textfield', '#title' => t('Popup width in pixels or a percentage value'), '#default_value' => isset($popup_settings['popup_width']) ? $popup_settings['popup_width'] : '100%', '#size' => 5, '#maxlength' => 5, '#required' => TRUE, '#description' => t('Set the width of the popup. This can be either an integer value or percentage of the screen width. For example: 200 or 50%'));
     $form['eu_cookie_compliance_' . $ln]['popup_delay'] = array('#type' => 'textfield', '#title' => t('Popup time delay in seconds'), '#default_value' => isset($popup_settings['popup_delay']) ? $popup_settings['popup_delay'] : 1, '#size' => 5, '#maxlength' => 5, '#required' => TRUE);
     $form_color_picker_type = 'textfield';
     if (\Drupal::moduleHandler()->moduleExists('jquery_colorpicker')) {
         $form_color_picker_type = 'jquery_colorpicker';
     }
     $form['eu_cookie_compliance_' . $ln]['popup_bg_hex'] = array('#type' => $form_color_picker_type, '#title' => t('Background Color'), '#default_value' => isset($popup_settings['popup_bg_hex']) ? $popup_settings['popup_bg_hex'] : '0779BF', '#description' => t('Change the background color of the popup. Provide HEX value without the #'), '#element_validate' => array('eu_cookie_compliance_validate_hex'));
     $form['eu_cookie_compliance_' . $ln]['popup_text_hex'] = array('#type' => $form_color_picker_type, '#title' => t('Text Color'), '#default_value' => isset($popup_settings['popup_text_hex']) ? $popup_settings['popup_text_hex'] : 'ffffff', '#description' => t('Change the text color of the popup. Provide HEX value without the #'), '#element_validate' => array('eu_cookie_compliance_validate_hex'));
     // Adding option to add/remove popup on specified domains
     $exclude_domains_option_active = array(0 => t('Add'), 1 => t('Remove'));
     $form['eu_cookie_compliance_' . $ln]['domains_option'] = array('#type' => 'radios', '#title' => t('Add/Remove popup on specified domains'), '#default_value' => isset($popup_settings['domains_option']) ? $popup_settings['domains_option'] : 1, '#options' => $exclude_domains_option_active, '#description' => t("Specify if you want to add or remove popup on the listed below domains."));
     $form['eu_cookie_compliance_' . $ln]['domains_list'] = array('#type' => 'textarea', '#title' => t('Domains list'), '#default_value' => isset($popup_settings['domains_list']) ? $popup_settings['domains_list'] : '', '#description' => t("Specify domains with protocol (e.g. http or https). Enter one domain per line."));
     $form['eu_cookie_compliance_' . $ln]['exclude_paths'] = array('#type' => 'textarea', '#title' => t('Exclude paths'), '#default_value' => isset($popup_settings['exclude_paths']) ? $popup_settings['exclude_paths'] : '', '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')));
     return parent::buildForm($form, $form_state);
 }
Example #18
0
  /**
   * {@inheritdoc}
   */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $settings = $this->getSettings();

    $element['markup'] = [
      '#type'          => 'text_format',
      '#title'         => $this->t('Markup'),
      '#default_value' => isset($settings['markup']['value']) ? $settings['markup']['value'] : '',
      '#format'        => isset($settings['markup']['format']) ? $settings['markup']['format'] : filter_default_format(),
      '#required'      => TRUE,
      '#rows'          => 15,
      '#description'   => $this->t('The markup to be displayed. Any HTML is legal here, so be careful not to break your page layout.'),
    ];

    $element['instructions'] = [
      '#markup' => htmlentities($this->t('This is a special field. It will output the markup below, on the node/edit form for this content type. Consider wrapping any visible output in <div class="form-item"></div> to follow form standards.')),
      '#weight' => -1,
    ];

    return $element;
  }
 /**
  * Tests if the default text format is accessible to users.
  */
 function testDefaultTextFormats()
 {
     // Create two text formats, and two users. The first user has access to
     // both formats, but the second user only has access to the second one.
     $admin_user = $this->drupalCreateUser(array('administer filters'));
     $this->drupalLogin($admin_user);
     $formats = array();
     for ($i = 0; $i < 2; $i++) {
         $edit = array('format' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomMachineName());
         $this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
         $this->resetFilterCaches();
         $formats[] = entity_load('filter_format', $edit['format']);
     }
     list($first_format, $second_format) = $formats;
     $second_format_permission = $second_format->getPermissionName();
     $first_user = $this->drupalCreateUser(array($first_format->getPermissionName(), $second_format_permission));
     $second_user = $this->drupalCreateUser(array($second_format_permission));
     // Adjust the weights so that the first and second formats (in that order)
     // are the two lowest weighted formats available to any user.
     $edit = array();
     $edit['formats[' . $first_format->id() . '][weight]'] = -2;
     $edit['formats[' . $second_format->id() . '][weight]'] = -1;
     $this->drupalPostForm('admin/config/content/formats', $edit, t('Save changes'));
     $this->resetFilterCaches();
     // Check that each user's default format is the lowest weighted format that
     // the user has access to.
     $actual = filter_default_format($first_user);
     $expected = $first_format->id();
     $this->assertEqual($actual, $expected, "First user's default format {$actual} is the expected lowest weighted format {$expected} that the user has access to.");
     $actual = filter_default_format($second_user);
     $expected = $second_format->id();
     $this->assertEqual($actual, $expected, "Second user's default format {$actual} is the expected lowest weighted format {$expected} that the user has access to, and different to the first user's.");
     // Reorder the two formats, and check that both users now have the same
     // default.
     $edit = array();
     $edit['formats[' . $second_format->id() . '][weight]'] = -3;
     $this->drupalPostForm('admin/config/content/formats', $edit, t('Save changes'));
     $this->resetFilterCaches();
     $this->assertEqual(filter_default_format($first_user), filter_default_format($second_user), 'After the formats are reordered, both users have the same default format.');
 }
Example #20
0
/**
 * Hook_builder_content_configure($delta = '', $content = array())
 */
function HOOK_builder_content_configure($delta = '', $content = array())
{
    $form = array();
    switch ($delta) {
        case 'node':
            $form['nid'] = array('#type' => 'textfield', '#title' => t('Enter node ID or title'), '#default_value' => !empty($content['settings']['nid']) ? $content['settings']['nid'] : '', '#autocomplete_path' => 'builder/autocomplete/node', '#required' => TRUE);
            $view_modes_options = array();
            $view_modes = builder_get_entity_view_modes('node');
            if (!empty($view_modes)) {
                foreach ($view_modes as $key => $vm) {
                    $view_modes_options[$key] = $vm['label'];
                }
            }
            $form['view_mode'] = array('#type' => 'select', '#title' => t('View mode'), '#options' => $view_modes_options, '#default_value' => isset($content['settings']['view_mode']) ? $content['settings']['view_mode'] : 'full');
            $form['hide_node_title'] = array('#type' => 'checkbox', '#title' => t('Hide node title'), '#default_value' => isset($content['settings']['hide_node_title']) ? $content['settings']['hide_node_title'] : FALSE);
            break;
        case 'custom_text':
            $form['custom_text'] = array('#type' => 'text_format', '#title' => t('Custom text'), '#default_value' => isset($content['settings']['custom_text']['value']) ? $content['settings']['custom_text']['value'] : '', '#format' => isset($content['settings']['custom_text']['format']) ? $content['settings']['custom_text']['format'] : filter_default_format());
            break;
    }
    return $form;
}
 public function testAreaText()
 {
     $view = Views::getView('test_view');
     $view->setDisplay();
     // add a text header
     $string = $this->randomMachineName();
     $view->displayHandlers->get('default')->overrideOption('header', array('area' => array('id' => 'area', 'table' => 'views', 'field' => 'area', 'content' => $string)));
     // Execute the view.
     $this->executeView($view);
     $view->display_handler->handlers['header']['area']->options['format'] = $this->randomString();
     $build = $view->display_handler->handlers['header']['area']->render();
     $this->assertEqual('', drupal_render($build), 'Nonexistent format should return empty markup.');
     $view->display_handler->handlers['header']['area']->options['format'] = filter_default_format();
     $build = $view->display_handler->handlers['header']['area']->render();
     $this->assertEqual(check_markup($string), drupal_render($build), 'Existent format should return something');
     // Empty results, and it shouldn't be displayed .
     $this->assertEqual(array(), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header');
     // Empty results, and it should be displayed.
     $view->display_handler->handlers['header']['area']->options['empty'] = TRUE;
     $build = $view->display_handler->handlers['header']['area']->render(TRUE);
     $this->assertEqual(check_markup($string), drupal_render($build), 'No result, but empty enabled lead to a full header');
 }
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Create a flag.
    $this->flag = $this->createFlag('node', ['article'], 'reload');

    // Create a user who may flag and log them in. This ensures we don't have
    // to worry about flag access.
    $this->adminUser = $this->drupalCreateUser([
      'administer flags',
      // This permission is needed to change the view mode settings to show and
      // hide the flag link field.
      'administer node display',
    ]);
    $this->grantFlagPermissions($this->flag);

    $this->drupalLogin($this->adminUser);

    // Create a node to flag.
    $this->node = Node::create([
      'body' => [
        [
          'value' => $this->randomMachineName(32),
          'format' => filter_default_format(),
        ],
      ],
      'type' => 'article',
      'title' => $this->randomMachineName(8),
      'uid' => $this->adminUser->id(),
      'status' => 1,
      // Promoted to front page to test teaser view mode.
      'promote' => 1,
      'sticky' => 0,
    ]);
    $this->node->save();
  }
Example #23
0
 /**
  * Tests the field row style using fieldapi fields.
  */
 public function testFieldapiField()
 {
     $this->drupalCreateContentType(array('type' => 'page'));
     $node = $this->drupalCreateNode();
     $result = $this->drupalGetJSON('test/serialize/node-field');
     $this->assertEqual($result[0]['nid'], $node->id());
     $this->assertEqual($result[0]['body'], $node->body->processed);
     // Make sure that serialized fields are not exposed to XSS.
     $node = $this->drupalCreateNode();
     $node->body = ['value' => '<script type="text/javascript">alert("node-body");</script>' . $this->randomMachineName(32), 'format' => filter_default_format()];
     $node->save();
     $result = $this->drupalGetJSON('test/serialize/node-field');
     $this->assertEqual($result[1]['nid'], $node->id());
     $this->assertTrue(strpos($this->getRawContent(), "<script") === FALSE, "No script tag is present in the raw page contents.");
     $this->drupalLogin($this->adminUser);
     // Add an alias and make the output raw.
     $row_options = 'admin/structure/views/nojs/display/test_serializer_node_display_field/rest_export_1/row_options';
     // Test an empty string for an alias, this should not be used. This also
     // tests that the form can be submitted with no aliases.
     $this->drupalPostForm($row_options, ['row_options[field_options][title][raw_output]' => '1'], t('Apply'));
     $this->drupalPostForm(NULL, [], t('Save'));
     $view = Views::getView('test_serializer_node_display_field');
     $view->setDisplay('rest_export_1');
     $this->executeView($view);
     // Test the raw 'created' value against each row.
     foreach ($this->drupalGetJSON('test/serialize/node-field') as $index => $values) {
         $this->assertIdentical($values['title'], $view->result[$index]->_entity->title->value, 'Expected raw title value found.');
     }
     // Test that multiple raw body fields are shown.
     // Make the body field unlimited cardinatlity.
     $storage_definition = $node->getFieldDefinition('body')->getFieldStorageDefinition();
     $storage_definition->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     $storage_definition->save();
     $this->drupalPostForm($row_options, ['row_options[field_options][body][raw_output]' => '1'], t('Apply'));
     $this->drupalPostForm(NULL, [], t('Save'));
     $node = $this->drupalCreateNode();
     $body = ['value' => '<script type="text/javascript">alert("node-body");</script>' . $this->randomMachineName(32), 'format' => filter_default_format()];
     // Add two body items.
     $node->body = [$body, $body];
     $node->save();
     $view = Views::getView('test_serializer_node_display_field');
     $view->setDisplay('rest_export_1');
     $this->executeView($view);
     $result = $this->drupalGetJSON('test/serialize/node-field');
     $this->assertEqual(count($result[2]['body']), $node->body->count(), 'Expected count of values');
     $this->assertEqual($result[2]['body'], array_map(function ($item) {
         return $item['value'];
     }, $node->body->getValue()), 'Expected raw body values found.');
 }
 /**
  * Creates a node based on default settings.
  *
  * @param $settings
  *   An associative array of settings to change from the defaults, keys are
  *   node properties, for example 'title' => 'Hello, world!'.
  * @return
  *   Created node entity.
  */
 protected function backdropCreateNode($settings = array())
 {
     // Populate defaults array.
     $settings += array('body' => array(LANGUAGE_NONE => array(array())), 'title' => $this->randomName(8), 'comment' => 2, 'changed' => REQUEST_TIME, 'moderate' => 0, 'promote' => 0, 'revision' => 1, 'log' => '', 'status' => 1, 'sticky' => 0, 'type' => 'page', 'revisions' => NULL, 'langcode' => LANGUAGE_NONE);
     // Use the original node's created time for existing nodes.
     if (isset($settings['created']) && !isset($settings['date'])) {
         $settings['date'] = format_date($settings['created'], 'custom', 'Y-m-d H:i:s O');
     }
     // If the node's user uid is not specified manually, use the currently
     // logged in user if available, or else the user running the test.
     if (!isset($settings['uid'])) {
         if ($this->loggedInUser) {
             $settings['uid'] = $this->loggedInUser->uid;
         } else {
             global $user;
             $settings['uid'] = $user->uid;
         }
     }
     // Merge body field value and format separately.
     $body = array('value' => $this->randomName(32), 'format' => filter_default_format());
     $settings['body'][$settings['langcode']][0] += $body;
     $node = entity_create('node', $settings);
     $node->save();
     // Small hack to link revisions to our test user.
     db_update('node_revision')->fields(array('uid' => $node->uid))->condition('vid', $node->vid)->execute();
     return $node;
 }
 /**
  * Executes the computed properties tests for the given entity type.
  *
  * @param string $entity_type
  *   The entity type to run the tests with.
  */
 protected function assertComputedProperties($entity_type)
 {
     $entity = $this->createTestEntity($entity_type);
     $entity->field_test_text->value = "The <strong>text</strong> text to filter.";
     $entity->field_test_text->format = filter_default_format();
     $target = "<p>The &lt;strong&gt;text&lt;/strong&gt; text to filter.</p>\n";
     $this->assertEqual($entity->field_test_text->processed, $target, format_string('%entity_type: Text is processed with the default filter.', array('%entity_type' => $entity_type)));
     // Save and load entity and make sure it still works.
     $entity->save();
     $entity = entity_load($entity_type, $entity->id());
     $this->assertEqual($entity->field_test_text->processed, $target, format_string('%entity_type: Text is processed with the default filter.', array('%entity_type' => $entity_type)));
 }
Example #26
0
 /**
  * Test the "on demand text" for the input required exposed form type.
  */
 public function testTextInputRequired()
 {
     $view = Views::getView('test_exposed_form_buttons');
     $display =& $view->storage->getDisplay('default');
     $display['display_options']['exposed_form']['type'] = 'input_required';
     // Set up the "on demand text".
     // @see https://www.drupal.org/node/535868
     $on_demand_text = 'Select any filter and click Apply to see results.';
     $display['display_options']['exposed_form']['options']['text_input_required'] = $on_demand_text;
     $display['display_options']['exposed_form']['options']['text_input_required_format'] = filter_default_format();
     $view->save();
     // Ensure that the "on demand text" is displayed when no exposed filters are
     // applied.
     $this->drupalGet('test_exposed_form_buttons');
     $this->assertText('Select any filter and click Apply to see results.');
     // Ensure that the "on demand text" is not displayed when an exposed filter
     // is applied.
     $this->drupalGet('test_exposed_form_buttons', array('query' => array('type' => 'article')));
     $this->assertNoText($on_demand_text);
 }
Example #27
0
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $form['text_input_required'] = array('#type' => 'text_format', '#title' => $this->t('Text on demand'), '#description' => $this->t('Text to display instead of results until the user selects and applies an exposed filter.'), '#default_value' => $this->options['text_input_required'], '#format' => isset($this->options['text_input_required_format']) ? $this->options['text_input_required_format'] : filter_default_format(), '#editor' => FALSE);
 }
 protected function nodeStub()
 {
     $settings = array('type' => 'webform', 'language' => \Drupal\Core\Language\Language::LANGCODE_NOT_SPECIFIED, 'uid' => '1', 'status' => '1', 'promote' => '1', 'moderate' => '0', 'sticky' => '0', 'tnid' => '0', 'translate' => '0', 'title' => 'FormState class unit test', 'body' => array(\Drupal\Core\Language\Language::LANGCODE_NOT_SPECIFIED => array(array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo. Sed tempor. Sed vitae tellus. Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non lacus vitae ipsum viverra pretium. Phasellus massa. Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce consectetuer luctus ipsum. Vestibulum nunc. Suspendisse dignissim adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum nibh, ullamcorper eget, pulvinar sed, posuere vitae, nulla. Sed varius nibh ut lacus. Curabitur fringilla. Nunc est ipsum, pretium quis, dapibus sed, varius non, lectus. Proin a quam. Praesent lacinia, eros quis aliquam porttitor, urna lacus volutpat urna, ut fermentum neque mi egestas dolor.'))), 'teaser' => array(\Drupal\Core\Language\Language::LANGCODE_NOT_SPECIFIED => array(array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo. Sed tempor. Sed vitae tellus. Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non lacus vitae ipsum viverra pretium. Phasellus massa. Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce consectetuer luctus ipsum. Vestibulum nunc. Suspendisse dignissim adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum nibh, ullamcorper eget, pulvinar sed, posuere vitae, nulla. Sed varius nibh ut lacus. Curabitur fringilla.'))), 'log' => '', 'format' => '1', 'webform' => array('confirmation' => 'Thanks!', 'confirmation_format' => filter_default_format(), 'redirect_url' => '<confirmation>', 'teaser' => '0', 'allow_draft' => '1', 'submit_text' => '', 'submit_limit' => '-1', 'submit_interval' => '-1', 'submit_notice' => '1', 'roles' => array('1', '2'), 'components' => array(), 'emails' => array(), 'preview' => FALSE));
     $this->nodeStubAddWebform($settings['webform']['components']);
     $this->webformNode = $this->drupalCreateNode($settings);
 }
 /**
  * Tests the cache tags on the front page.
  *
  * @param bool $do_assert_views_caches
  *   Whether to check Views' result & output caches.
  */
 protected function doTestFrontPageViewCacheTags($do_assert_views_caches)
 {
     $view = Views::getView('frontpage');
     $view->setDisplay('page_1');
     $cache_contexts = ['user.node_grants:view', 'languages:' . LanguageInterface::TYPE_INTERFACE, 'user.permissions', 'theme', 'url.query_args', 'url.site'];
     $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)->getCacheTags();
     // Test before there are any nodes.
     $empty_node_listing_cache_tags = ['config:views.view.frontpage', 'node_list'];
     $render_cache_tags = Cache::mergeTags($empty_node_listing_cache_tags, $cache_context_tags);
     $render_cache_tags = Cache::mergeTags($render_cache_tags, ['config:system.site']);
     $this->assertViewsCacheTags($view, $empty_node_listing_cache_tags, $do_assert_views_caches, $render_cache_tags);
     $expected_tags = Cache::mergeTags($empty_node_listing_cache_tags, $cache_context_tags);
     $expected_tags = Cache::mergeTags($expected_tags, ['rendered', 'config:user.role.anonymous', 'config:system.site']);
     $this->assertPageCacheContextsAndTags(Url::fromRoute('view.frontpage.page_1'), $cache_contexts, $expected_tags);
     // Create some nodes on the frontpage view. Add more than 10 nodes in order
     // to enable paging.
     $this->drupalCreateContentType(['type' => 'article']);
     for ($i = 0; $i < 15; $i++) {
         $node = Node::create(['body' => [['value' => $this->randomMachineName(32), 'format' => filter_default_format()]], 'type' => 'article', 'created' => $i, 'title' => $this->randomMachineName(8), 'nid' => $i + 1]);
         $node->enforceIsNew(TRUE);
         $node->save();
     }
     $cache_contexts = Cache::mergeContexts($cache_contexts, ['timezone']);
     $this->pass('First page');
     // First page.
     $first_page_result_cache_tags = ['config:views.view.frontpage', 'node_list', 'node:6', 'node:7', 'node:8', 'node:9', 'node:10', 'node:11', 'node:12', 'node:13', 'node:14', 'node:15'];
     $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)->getCacheTags();
     $first_page_output_cache_tags = Cache::mergeTags($first_page_result_cache_tags, $cache_context_tags);
     $first_page_output_cache_tags = Cache::mergeTags($first_page_output_cache_tags, ['config:filter.format.plain_text', 'node_view', 'user_view', 'user:0']);
     $view->setDisplay('page_1');
     $view->setCurrentPage(0);
     $this->assertViewsCacheTags($view, $first_page_result_cache_tags, $do_assert_views_caches, $first_page_output_cache_tags);
     $this->assertPageCacheContextsAndTags(Url::fromRoute('view.frontpage.page_1'), $cache_contexts, Cache::mergeTags($first_page_output_cache_tags, ['rendered', 'config:user.role.anonymous']));
     // Second page.
     $this->pass('Second page');
     $this->assertPageCacheContextsAndTags(Url::fromRoute('view.frontpage.page_1', [], ['query' => ['page' => 1]]), $cache_contexts, ['node:1', 'node:2', 'node:3', 'node:4', 'node:5', 'config:filter.format.plain_text', 'config:views.view.frontpage', 'node_list', 'node_view', 'user_view', 'user:0', 'rendered', 'config:user.role.anonymous']);
     // Let's update a node title on the first page and ensure that the page
     // cache entry invalidates.
     $node = Node::load(10);
     $title = $node->getTitle() . 'a';
     $node->setTitle($title);
     $node->save();
     $this->drupalGet(Url::fromRoute('view.frontpage.page_1'));
     $this->assertText($title);
 }
 /**
  * Tests the field row style using fieldapi fields.
  */
 public function testFieldapiField()
 {
     $this->drupalCreateContentType(array('type' => 'page'));
     $node = $this->drupalCreateNode();
     $result = $this->drupalGetJSON('test/serialize/node-field');
     $this->assertEqual($result[0]['nid'], $node->id());
     $this->assertEqual($result[0]['body'], $node->body->processed);
     // Make sure that serialized fields are not exposed to XSS.
     $node = $this->drupalCreateNode();
     $node->body = ['value' => '<script type="text/javascript">alert("node-body");</script>' . $this->randomMachineName(32), 'format' => filter_default_format()];
     $node->save();
     $result = $this->drupalGetJSON('test/serialize/node-field');
     $this->assertEqual($result[1]['nid'], $node->id());
     $this->assertTrue(strpos($this->getRawContent(), "<script") === FALSE, "No script tag is present in the raw page contents.");
 }