summaryrefslogtreecommitdiff
path: root/modules/node/node.test
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-12-05 22:18:46 +0000
committerDries Buytaert <dries@buytaert.net>2008-12-05 22:18:46 +0000
commit58b0235a72859aa433d743a9f284504f24664857 (patch)
tree524132d2e7ca157baa1059117244a5b27b1f51fb /modules/node/node.test
parent0b06c68b988410c49c9f4ffbf8c3160d4e9da2c7 (diff)
downloadbrdo-58b0235a72859aa433d743a9f284504f24664857.tar.gz
brdo-58b0235a72859aa433d743a9f284504f24664857.tar.bz2
- Patch #324313 by catch et al: load multiple nodes and terms at once.
Diffstat (limited to 'modules/node/node.test')
-rw-r--r--modules/node/node.test84
1 files changed, 82 insertions, 2 deletions
diff --git a/modules/node/node.test b/modules/node/node.test
index f45225922..7f5e5c303 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -1,6 +1,86 @@
<?php
// $Id$
+/**
+ * Test the node_load_multiple() function.
+ */
+class NodeLoadMultipleUnitTest extends DrupalWebTestCase {
+
+ function getInfo() {
+ return array(
+ 'name' => 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;
@@ -258,7 +338,7 @@ class PageEditTestCase extends DrupalWebTestCase {
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the node exists in the database.
- $node = node_load(array('title' => $edit['title']));
+ $node = $this->drupalGetNodeByTitle($edit['title']);
$this->assertTrue($node, t('Node found in database.'));
// Check that "edit" link points to correct page.
@@ -352,7 +432,7 @@ class PageCreationTestCase extends DrupalWebTestCase {
$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 = node_load(array('title' => $edit['title']));
+ $node = $this->drupalGetNodeByTitle($edit['title']);
$this->assertTrue($node, t('Node found in database.'));
}
}