1 node.test SummaryLengthTestCase::testSummaryLength()

Tests the node summary length functionality.

File

core/modules/node/tests/node.test, line 1236
Tests for node.module.

Class

SummaryLengthTestCase
Tests the summary length functionality.

Code

function testSummaryLength() {
  // Create a node to view.
  $settings = array(
    'body' => array(LANGUAGE_NONE => 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 foobar? 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->backdropCreateNode($settings);
  $this->assertTrue(node_load($node->nid), t('Node created.'));

  // Create user with permission to view the node.
  $web_user = $this->backdropCreateUser(array('access content', 'administer content types'));
  $this->backdropLogin($web_user);

  // Attempt to access the front page.
  $this->backdropGet("node");
  // The node teaser when it has 600 characters in length
  $expected = 'What is a foobar?';
  $this->assertRaw($expected, 'Check that the summary is 600 characters in length', 'Node');

  // Change the teaser length for "Page" content type.
  $instance = field_info_instance('node', 'body', $node->type);
  $instance['display']['teaser']['settings']['trim_length'] = 200;
  field_update_instance($instance);

  // Attempt to access the front page again and check if the summary is now only 200 characters in length.
  $this->backdropGet("node");
  $this->assertNoRaw($expected, 'Check that the summary is not longer than 200 characters', 'Node');
}