From 199dc7cc9d18378d4a3ca19551984381b6094744 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 1 Jul 2009 12:10:32 +0000 Subject: [PATCH] - Patch #504564 by tic2000: fixed teaser length setting and added tests. --- modules/field/modules/text/text.module | 3 +- modules/node/content_types.inc | 4 +-- modules/node/node.admin.inc | 4 +-- modules/node/node.test | 42 ++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/modules/field/modules/text/text.module b/modules/field/modules/text/text.module index fe6e1da8098..bd241342b94 100644 --- a/modules/field/modules/text/text.module +++ b/modules/field/modules/text/text.module @@ -317,7 +317,8 @@ function theme_field_formatter_text_summary_or_trimmed($element) { return $element['#item']['safe_summary']; } else { - return text_summary($element['#item']['safe'], $instance['settings']['text_processing'] ? $element['#item']['format'] : NULL); + $size = variable_get('teaser_length_' . $element['#bundle'], 600); + return text_summary($element['#item']['safe'], $instance['settings']['text_processing'] ? $element['#item']['format'] : NULL, $size); } } diff --git a/modules/node/content_types.inc b/modules/node/content_types.inc index f7e73a42a94..441a8b5177c 100644 --- a/modules/node/content_types.inc +++ b/modules/node/content_types.inc @@ -185,9 +185,9 @@ function node_type_form(&$form_state, $type = NULL) { $form['display']['teaser_length'] = array( '#type' => 'select', '#title' => t('Length of trimmed posts'), - '#default_value' => 600, + '#default_value' => variable_get('teaser_length_' . $type->type, 600), '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_node_characters'), - '#description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited' . Note that this setting will only affect new or updated content and will not affect existing teasers.") + '#description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'.") ); $form['old_type'] = array( '#type' => 'value', diff --git a/modules/node/node.admin.inc b/modules/node/node.admin.inc index 62f49382b7b..9a8d8126187 100644 --- a/modules/node/node.admin.inc +++ b/modules/node/node.admin.inc @@ -31,9 +31,9 @@ function node_configure() { ); $form['teaser_length'] = array( '#type' => 'select', '#title' => t('Length of trimmed posts'), - '#default_value' => 600, + '#default_value' => variable_get('teaser_length', 600), '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_node_characters'), - '#description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited' . Note that this setting will only affect new or updated content and will not affect existing teasers.") + '#description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'.") ); $form['node_preview'] = array( diff --git a/modules/node/node.test b/modules/node/node.test index 246f9b2c428..1d2abd69e6f 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -362,6 +362,48 @@ class PageViewTestCase extends DrupalWebTestCase { } } +class SummaryLengthTestCase extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => t('Summary length'), + 'description' => t('Test summary length.'), + 'group' => t('Node'), + ); + } + + /** + * Creates a node and then an anonymous and unpermissioned user attempt to edit the node. + */ + function testSummaryLength() { + // Create a node to view. + $settings = array( + 'body' => array(array('value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero. Ut fermentum est vitae metus convallis scelerisque. Phasellus pellentesque rhoncus tellus, eu dignissim purus posuere id. Quisque eu fringilla ligula. Morbi ullamcorper, lorem et mattis egestas, tortor neque pretium velit, eget eleifend odio turpis eu purus. Donec vitae metus quis leo pretium tincidunt a pulvinar sem. Morbi adipiscing laoreet mauris vel placerat. Nullam elementum, nisl sit amet scelerisque malesuada, dolor nunc hendrerit quam, eu ultrices erat est in orci. Curabitur feugiat egestas nisl sed accumsan.')), + 'promote' => 1, + ); + $node = $this->drupalCreateNode($settings); + $this->assertTrue(node_load($node->nid), t('Node created.')); + + // Create user with permission to view the node. + $web_user = $this->drupalCreateUser(array('access content', 'administer content types')); + $this->drupalLogin($web_user); + + // Attempt to access the front page. + $this->drupalGet("node"); + // The node teaser when it has 600 characters in length + $expected = 'What is a Drupalism?'; + $this->assertRaw($expected, t('Check that the summary is 600 characters in length'), 'Node'); + + // Edit the teaser lenght for 'page' content type + $edit = array ( + 'teaser_length' => 200, + ); + $this->drupalPost('admin/build/node-type/page', $edit, t('Save content type')); + // Attempt to access the front page again and check if the summary is now only 200 characters in length. + $this->drupalGet("node"); + $this->assertNoRaw($expected, t('Check that the summary is not longer than 200 characters'), 'Node'); + } +} + class NodeTitleXSSTestCase extends DrupalWebTestCase { public static function getInfo() { return array(