t('Load multiple nodes'), 'description' => t('Test the loading of multiple nodes.'), 'group' => t('Node'), ); } function setUp() { parent::setUp(); $web_user = $this->drupalCreateUser(array('create article content', 'create page content')); $this->drupalLogin($web_user); } /** * Create four nodes and ensure they're loaded correctly. */ function testNodeMultipleLoad() { $node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); $node2 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); $node3 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 0)); $node4 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0)); // Confirm that promoted nodes appear in the default node listing. $this->drupalGet('node'); $this->assertText($node1->title, t('Node title appears on the default listing.')); $this->assertText($node2->title, t('Node title appears on the default listing.')); $this->assertNoText($node3->title, t('Node title does not appear in the default listing.')); $this->assertNoText($node4->title, t('Node title does not appear in the default listing.')); // Load nodes with only a condition. Nodes 3 and 4 will be loaded. $nodes = node_load_multiple(NULL, array('promote' => 0)); $this->assertEqual($node3->title, $nodes[$node3->nid]->title, t('Node was loaded.')); $this->assertEqual($node4->title, $nodes[$node4->nid]->title, t('Node was loaded.')); $count = count($nodes); $this->assertTrue($count == 2, t('@count nodes loaded.', array('@count' => $count))); // Load nodes by nid. Nodes 1, 2 and 4 will be loaded. $nodes = node_load_multiple(array(1, 2, 4)); $count = count($nodes); $this->assertTrue(count($nodes) == 3, t('@count nodes loaded', array('@count' => $count))); $this->assertTrue(isset($nodes[$node1->nid]), t('Node is correctly keyed in the array')); $this->assertTrue(isset($nodes[$node2->nid]), t('Node is correctly keyed in the array')); $this->assertTrue(isset($nodes[$node4->nid]), t('Node is correctly keyed in the array')); foreach ($nodes as $node) { $this->assertTrue(is_object($node), t('Node is an object')); } // Load nodes by nid, where type = article. Nodes 1, 2 and 3 will be loaded. $nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article')); $count = count($nodes); $this->assertTrue($count == 3, t('@count nodes loaded', array('@count' => $count))); $this->assertEqual($nodes[$node1->nid]->title, $node1->title, t('Node successfully loaded.')); $this->assertEqual($nodes[$node2->nid]->title, $node2->title, t('Node successfully loaded.')); $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded.')); $this->assertFalse(isset($nodes[$node4->nid])); // Now that all nodes have been loaded into the static cache, ensure that // they are loaded correctly again when a condition is passed. $nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article')); $count = count($nodes); $this->assertTrue($count == 3, t('@count nodes loaded.', array('@count' => $count))); $this->assertEqual($nodes[$node1->nid]->title, $node1->title, t('Node successfully loaded')); $this->assertEqual($nodes[$node2->nid]->title, $node2->title, t('Node successfully loaded')); $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded')); $this->assertFalse(isset($nodes[$node4->nid]), t('Node was not loaded')); // Load nodes by nid, where type = article and promote = 0. $nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article', 'promote' => 0)); $count = count($nodes); $this->assertTrue($count == 1, t('@count node loaded', array('@count' => $count))); $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded.')); } } class NodeRevisionsTestCase extends DrupalWebTestCase { protected $nodes; protected $logs; public static function getInfo() { return array( 'name' => t('Node revisions'), 'description' => t('Create a node with revisions and test viewing, reverting, and deleting revisions.'), 'group' => t('Node'), ); } function setUp() { parent::setUp(); // Create and login user. $web_user = $this->drupalCreateUser(array('view revisions', 'revert revisions', 'edit any page content', 'delete revisions', 'delete any page content')); $this->drupalLogin($web_user); // Create initial node. $node = $this->drupalCreateNode(); $settings = get_object_vars($node); $settings['revision'] = 1; $nodes = array(); $logs = array(); // Get original node. $nodes[] = $node; // Create three revisions. $revision_count = 3; for ($i = 0; $i < $revision_count; $i++) { $logs[] = $settings['log'] = $this->randomName(32); // Create revision with random title and body and update variables. $this->drupalCreateNode($settings); $node = node_load($node->nid); // Make sure we get revision information. $settings = get_object_vars($node); $nodes[] = $node; } $this->nodes = $nodes; $this->logs = $logs; } /** * Check node revision related operations. */ function testRevisions() { $nodes = $this->nodes; $logs = $this->logs; // Get last node for simple checks. $node = $nodes[3]; // Confirm the correct revision text appears on "view revisions" page. $this->drupalGet("node/$node->nid/revisions/$node->vid/view"); $this->assertText($node->body[0]['value'], t('Correct text displays for version.')); // Confirm the correct log message appears on "revisions overview" page. $this->drupalGet("node/$node->nid/revisions"); foreach ($logs as $log) { $this->assertText($log, t('Log message found.')); } // Confirm that revisions revert properly. $this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/revert", array(), t('Revert')); $this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => 'Page', '%title' => $nodes[1]->title, '%revision-date' => format_date($nodes[1]->revision_timestamp))), t('Revision reverted.')); $reverted_node = node_load($node->nid); $this->assertTrue(($nodes[1]->body[0]['value'] == $reverted_node->body[0]['value']), t('Node reverted correctly.')); // Confirm revisions delete properly. $this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/delete", array(), t('Delete')); $this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($nodes[1]->revision_timestamp), '@type' => 'Page', '%title' => $nodes[1]->title)), t('Revision deleted.')); $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->nid, ':vid' => $nodes[1]->vid))->fetchField() == 0, t('Revision not found.')); } } class PageEditTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => t('Node edit'), 'description' => t('Create a node and test node edit functionality.'), 'group' => t('Node'), ); } function setUp() { parent::setUp(); $web_user = $this->drupalCreateUser(array('edit own page content', 'create page content')); $this->drupalLogin($web_user); } /** * Check node edit functionality. */ function testPageEdit() { $body_key = 'body[0][value]'; // Create node to edit. $edit = array(); $edit['title'] = $this->randomName(8); $edit[$body_key] = $this->randomName(16); $this->drupalPost('node/add/page', $edit, t('Save')); // Check that the node exists in the database. $node = $this->drupalGetNodeByTitle($edit['title']); $this->assertTrue($node, t('Node found in database.')); // Check that "edit" link points to correct page. $this->clickLink(t('Edit')); $edit_url = url("node/$node->nid/edit", array('absolute' => TRUE)); $actual_url = $this->getURL(); $this->assertEqual($edit_url, $actual_url, t('On edit page.')); // Check that the title and body fields are displayed with the correct values. $this->assertLink(t('Edit'), 0, t('Edit tab found.')); $this->assertFieldByName('title', $edit['title'], t('Title field displayed.')); $this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.')); // Edit the content of the node. $edit = array(); $edit['title'] = $this->randomName(8); $edit[$body_key] = $this->randomName(16); // Stay on the current page, without reloading. $this->drupalPost(NULL, $edit, t('Save')); // Check that the title and body fields are displayed with the updated values. $this->assertText($edit['title'], t('Title displayed.')); $this->assertText($edit[$body_key], t('Body displayed.')); } } class PagePreviewTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => t('Node preview'), 'description' => t('Test node preview functionality.'), 'group' => t('Node'), ); } function setUp() { parent::setUp(); $web_user = $this->drupalCreateUser(array('edit own page content', 'create page content')); $this->drupalLogin($web_user); } /** * Check the node preview functionality. */ function testPagePreview() { $body_key = 'body[0][value]'; // Fill in node creation form and preview node. $edit = array(); $edit['title'] = $this->randomName(8); $edit[$body_key] = $this->randomName(16); $this->drupalPost('node/add/page', $edit, t('Preview')); // Check that the preview is displaying the title and body. $this->assertTitle(t('Preview | Drupal'), t('Page title is preview.')); $this->assertText($edit['title'], t('Title displayed.')); $this->assertText($edit[$body_key], t('Body displayed.')); // Check that the title and body fields are displayed with the correct values. $this->assertFieldByName('title', $edit['title'], t('Title field displayed.')); $this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.')); } /** * Check the node preview functionality, when using revisions. */ function testPagePreviewWithRevisions() { $body_key = 'body[0][value]'; // Force revision on page content. variable_set('node_options_page', array('status', 'revision')); // Fill in node creation form and preview node. $edit = array(); $edit['title'] = $this->randomName(8); $edit[$body_key] = $this->randomName(16); $edit['log'] = $this->randomName(32); $this->drupalPost('node/add/page', $edit, t('Preview')); // Check that the preview is displaying the title and body. $this->assertTitle(t('Preview | Drupal'), t('Page title is preview.')); $this->assertText($edit['title'], t('Title displayed.')); $this->assertText($edit[$body_key], t('Body displayed.')); // Check that the title and body fields are displayed with the correct values. $this->assertFieldByName('title', $edit['title'], t('Title field displayed.')); $this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.')); // Check that the log field has the correct value. $this->assertFieldByName('log', $edit['log'], t('Log field displayed.')); } } class PageCreationTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => t('Node creation'), 'description' => t('Create a node and test saving it.'), 'group' => t('Node'), ); } function setUp() { parent::setUp(); $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content')); $this->drupalLogin($web_user); } /** * Create a page node and verify its consistency in the database. */ function testPageCreation() { // Create a node. $edit = array(); $edit['title'] = $this->randomName(8); $edit['body[0][value]'] = $this->randomName(16); $this->drupalPost('node/add/page', $edit, t('Save')); // Check that the page has been created. $this->assertRaw(t('!post %title has been created.', array('!post' => 'Page', '%title' => $edit['title'])), t('Page created.')); // Check that the node exists in the database. $node = $this->drupalGetNodeByTitle($edit['title']); $this->assertTrue($node, t('Node found in database.')); } } class PageViewTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => t('Node edit permissions'), 'description' => t('Create a node and test edit permissions.'), 'group' => t('Node'), ); } /** * Creates a node and then an anonymous and unpermissioned user attempt to edit the node. */ function testPageView() { // Create a node to view. $node = $this->drupalCreateNode(); $this->assertTrue(node_load($node->nid), t('Node created.')); // Try to edit with anonymous user. $html = $this->drupalGet("node/$node->nid/edit"); $this->assertResponse(403); // Create a user without permission to edit node. $web_user = $this->drupalCreateUser(array('access content')); $this->drupalLogin($web_user); // Attempt to access edit page. $this->drupalGet("node/$node->nid/edit"); $this->assertResponse(403); // Create user with permission to edit node. $web_user = $this->drupalCreateUser(array('bypass node access')); $this->drupalLogin($web_user); // Attempt to access edit page. $this->drupalGet("node/$node->nid/edit"); $this->assertResponse(200); } } 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( 'name' => t('Node title XSS filtering'), 'description' => t('Create a node with dangerous tags in its title and test that they are escaped.'), 'group' => t('Node'), ); } function testNodeTitleXSS() { // Prepare a user to do the stuff. $web_user = $this->drupalCreateUser(array('create page content', 'edit any page content')); $this->drupalLogin($web_user); $xss = ''; $edit = array( 'title' => $xss . $this->randomName(), ); $this->drupalPost('node/add/page', $edit, t('Preview')); $this->assertNoRaw($xss, t('Harmful tags are escaped when previewing a node.')); $node = $this->drupalCreateNode($edit); $this->drupalGet('node/' . $node->nid); // assertTitle() decodes HTML-entities inside the