Commit 2e18878a authored by git's avatar git Committed by Florent Torregrosa
Browse files

Issue #2535490 by digitgopher, Grimreaper: Set page description per content type

parent eb3b264e
Loading
Loading
Loading
Loading
+3 −0
Changes for protected_node.fork.inc: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -97,7 +97,10 @@ function protected_node_enter_any_password() {
  }

  // Enter the detailed description of the protected node password.
  $description = variable_get('protected_node_description_' . $node->type, '');
  if (!$description) {
    $description = variable_get('protected_node_description', '');
  }
  if (!$description) {
    if ($node->protected_node_show_title) {
      // Embellish the title with double quotes.
+1 −0
Changes for protected_node.info: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ files[] = tests/protected_node.bulk.test
files[] = tests/protected_node.fork.test
files[] = tests/protected_node.global.test
files[] = tests/protected_node.mail_test.test
files[] = tests/protected_node.page_text.test
files[] = tests/protected_node.per_node.test
files[] = tests/protected_node.per_type.test
files[] = tests/protected_node.private_file.test
+3 −0
Changes for protected_node.redirect.inc: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -77,7 +77,10 @@ function protected_node_enterpassword() {
  }

  // Enter the detailed description of the protected node password.
  $description = variable_get('protected_node_description_' . $node->type, '');
  if (!$description) {
    $description = variable_get('protected_node_description', '');
  }
  if (!$description) {
    if ($node->protected_node_show_title) {
      // Embellish the title with double quotes.
+8 −1
Changes for protected_node.settings.inc: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -534,7 +534,7 @@ function protected_node_admin_settings() {
    '#type' => 'textarea',
    '#title' => t('Password page description (inside the field set with the password form)'),
    '#default_value' => variable_get('protected_node_description', ''),
    '#description' => t('Enter specific description for the protected node page. This description is displayed inside the fieldset with the password form. HTML is accepted. You can use node type tokens from the token module when installed.'),
    '#description' => t('Enter custom description for the protected node page. This description is displayed inside the fieldset with the password form. HTML is accepted. You can use node type tokens from the token module when installed.'),
  );

  $form['protected_node_form']['protected_node_password_label'] = array(
@@ -926,6 +926,13 @@ function protected_node_node_type_form_alter(&$form) {
    '#description' => t('Select whether the "Protected node" field set should be opened or closed when editing a node.'),
  );

  $form['protected_node']['protected_node_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Password page description (inside the field set with the password form)'),
    '#default_value' => variable_get('protected_node_description_' . $form['#node_type']->type, ''),
    '#description' => t('Enter custom description for the protected node page of this content type to override the global setting. This description is displayed inside the fieldset with the password form. HTML is accepted. You can use node type tokens from the token module when installed.'),
  );

  $form['#validate'][] = '_protected_node_node_type_validate';
  $form['#submit'][] = '_protected_node_node_type_submit';
}
+191 −0
Changes for tests/protected_node.page_text.test: 191 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Test protected node password page display options.
 */

/**
 * Configure protected_node to use per node password.
 */
class ProtectedNodePageDisplay extends ProtectedNodeBaseTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Protected node password page display options',
      'description' => "This tests what is displayed on the enter password page",
      'group' => 'Protected Node',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    // Log in an Admin.
    $this->drupalLogin($this->adminUser);
    // Submit the configuration form.
    $protected_node_settings = array(
      'protected_node_use_global_password' => PROTECTED_NODE_PER_NODE_PASSWORD,
    );
    $this->drupalPost('admin/config/content/protected_node', $protected_node_settings, t('Save configuration'));
  }

  /**
   * Test function.
   *
   * Test that default display text is displayed (not showing title).
   */
  public function testDefaultHideTitle() {
    // Create a protected node without showing its title.
    $node = $this->createProtectedNode(FALSE);

    // User sees the default text.
    $this->drupalLogin($this->normalAccessAllowedUser);
    $this->drupalGet('node/' . $node->nid);

    $text = t('The @node_type @node_title you are trying to view is password protected. Please enter the password below to proceed.',
      array('@node_type' => node_type_get_name($node), '@node_title' => ''));
    $this->assertText($text, "Default text displayed on the enter password page does not show the node title", $this->group);
  }

  /**
   * Test function.
   *
   * Test that default display text is displayed (showing title).
   */
  public function testDefaultShowTitle() {
    // Create a protected node that show its title.
    $node = $this->createProtectedNode(TRUE);

    // User sees the default text including node title.
    $this->drupalLogin($this->normalAccessAllowedUser);
    $this->drupalGet('node/' . $node->nid);

    $text = t('The @node_type @node_title you are trying to view is password protected. Please enter the password below to proceed.',
      array('@node_type' => node_type_get_name($node), '@node_title' => '"' . $node->title . '"'));

    $this->assertText($text, "Default text displayed on the enter password page contains the node title if asked", $this->group);
  }

  /**
   * Test function.
   *
   * Test that the password page description site config setting works.
   */
  public function testGlobalDescriptionOnly() {

    $global_description = $this->randomName(32);

    $this->drupalLogin($this->adminUser);
    $protected_node_settings = array(
      'protected_node_use_global_password' => PROTECTED_NODE_PER_NODE_PASSWORD,
      'protected_node_description' => $global_description,
    );
    $this->drupalPost('admin/config/content/protected_node', $protected_node_settings, t('Save configuration'));

    // $show_title parameter shouldn't matter.
    $node = $this->createProtectedNode(FALSE);

    // User sees the set global text.
    $this->drupalLogin($this->normalAccessAllowedUser);
    $this->drupalGet('node/' . $node->nid);
    $this->assertText($global_description, "Custom global text is displayed on the enter password page", $this->group);
  }

  /**
   * Test function.
   *
   * Test that the password page description content type setting is displayed.
   */
  public function testContentTypeDescriptionOnly() {

    $content_type_description = $this->randomName(16);

    // Set global text.
    $this->drupalLogin($this->adminUser);
    $settings = array(
      'protected_node_description' => $content_type_description,
    );
    $this->drupalPost('admin/structure/types/manage/page', $settings, t('Save content type'));

    // $show_title parameter shouldn't matter.
    $node = $this->createProtectedNode(TRUE);

    // User sees the set global text.
    $this->drupalLogin($this->normalAccessAllowedUser);
    $this->drupalGet('node/' . $node->nid);
    $this->assertText($content_type_description, "Custom per content type text displayed on the enter password page", $this->group);
  }

  /**
   * Test function.
   *
   * Test that the password page description per content type is displayed
   * instead instead of the global description.
   */
  public function testContentTypeWithGlobalDescriptionSet() {

    $global_description = $this->randomName(32);
    $content_type_description = $this->randomName(16);

    // Set global text.
    $this->drupalLogin($this->adminUser);
    $protected_node_settings = array(
      'protected_node_use_global_password' => PROTECTED_NODE_PER_NODE_PASSWORD,
      'protected_node_description' => $global_description,
    );
    $this->drupalPost('admin/config/content/protected_node', $protected_node_settings, t('Save configuration'));

    // Set content type text.
    $settings = array(
      'protected_node_description' => $content_type_description,
    );
    $this->drupalPost('admin/structure/types/manage/page', $settings, t('Save content type'));

    // $show_title parameter shouldn't matter.
    $node = $this->createProtectedNode(FALSE);

    // User sees the set content type text.
    $this->drupalLogin($this->normalAccessAllowedUser);
    $this->drupalGet('node/' . $node->nid);
    $this->assertText($content_type_description, "Custom content type description displayed instead of the global description on the enter password page", $this->group);
  }

  /**
   * Helper method to create a protected node.
   *
   * @param bool $show_title
   *   Whether show the node title or not.
   *
   * @return object.
   *   A node object.
   */
  public function createProtectedNode($show_title) {
    // Log in as Admin.
    $this->drupalLogin($this->adminUser);
    // Generate random password.
    $password = $this->randomName(10);

    $node_data = array(
      'title' => $this->randomName(8),
      'body[und][0][value]' => $this->randomName(32),
      'protected_node_is_protected' => TRUE,
      'protected_node_passwd[pass1]' => $password,
      'protected_node_passwd[pass2]' => $password,
      'protected_node_show_title' => $show_title,
    );
    $this->drupalPost('node/add/page', $node_data, t('Save'));

    // Once the node created logout the user.
    $this->drupalLogout();

    return $this->drupalGetNodeByTitle($node_data['title']);
  }

}