Commit 199dc7cc authored by Dries's avatar Dries
Browse files

- Patch #504564 by tic2000: fixed teaser length setting and added tests.

parent 75d449d1
......@@ -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);
}
}
......
......@@ -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',
......
......@@ -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(
......
......@@ -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(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment