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; 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 opperations. */ 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, 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 == $reverted_node->body), 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_result(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = %d and vid = %d', $node->nid, $nodes[1]->vid)) == 0, t('Revision not found.')); } } class NodeTeaserTestCase extends DrupalWebTestCase { function getInfo() { return array( 'name' => t('Node teaser'), 'description' => t('Test node_teaser() with different strings and lengths.'), 'group' => t('Node'), ); } /** * Tests an edge case where if the first sentence is a question and * subsequent sentences are not. This is edge case is documented at * http://drupal.org/node/180425. */ function testFirstSentenceQuestion() { $body = 'A question? A sentence. Another sentence.'; $expected = 'A question? A sentence.'; $this->callNodeTeaser($body, $expected, NULL, 30); } /** * Test teaser with long example. */ function testLongSentence() { $body = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' . // 125 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' . // 108 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' . // 103 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; // 110 $expected = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' . 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' . 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'; // First three sentences add up to: 336, so add one for space and then 3 to get half-way into next word. $this->callNodeTeaser($body, $expected, NULL, 340); } /** * Test various teaser length edge cases. */ function testLength() { // This body string tests a number of edge cases. $body = "
\nHi\n
\n\nfolks\n
\n!\n
\nHi\n
\n\nfolks\n
\n!\n
", "
\n", "
\nH", "
\nHi", "
\nHi\n", "
\nHi\n<", "
\nHi\n", "
\nHi\n
\nHi\n", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
\n\nfolks\n
\n!\n
\nHi\n
\n\nfolks\n
\n!\n
\nHi\n
\n\nfolks\n
\n!\n
\nHi\n
\n\nfolks\n
\n!\n
", "
", "
", "
", "
\nHi", "
\nHi", "
\nHi", "
\nHi", "
\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
", "\nHi\n
\n\nfolks\n
\n!\n
\nHi\n
\n\nfolks\n
\n!\n
\nHi\n
\n\nfolks\n
\n!\n