summaryrefslogtreecommitdiff
path: root/modules/node/node.test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/node/node.test')
-rw-r--r--modules/node/node.test108
1 files changed, 107 insertions, 1 deletions
diff --git a/modules/node/node.test b/modules/node/node.test
index df0b29bc1..4cd0a4859 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -378,7 +378,7 @@ class NodeCreationTestCase extends DrupalWebTestCase {
// Check that the failed rollback was logged.
$records = db_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Explicit rollback failed%'")->fetchAll();
- $this->assertTrue(count($records) > 0, t('Transactions not supported, and rollback error logged to watchdog.'));
+ $this->assertTrue(count($records) > 0, t('Transactions not supported, and rollback error logged to watchdog.'));
}
// Check that the rollback error was logged.
@@ -1170,3 +1170,109 @@ class NodeFeedTestCase extends DrupalWebTestCase {
$this->assertTrue(strpos($output, '<copyright>Drupal is a registered trademark of Dries Buytaert.</copyright>') !== FALSE);
}
}
+
+/**
+ * Functional tests for the node module blocks.
+ */
+class NodeBlockFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Node blocks',
+ 'description' => 'Test node block functionality.',
+ 'group' => 'Node',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('node');
+
+ // Create users and test node.
+ $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'administer blocks'));
+ $this->web_user = $this->drupalCreateUser(array('access content', 'create article content'));
+ }
+
+ /**
+ * Test the recent comments block.
+ */
+ function testRecentNodeBlock() {
+ $this->drupalLogin($this->admin_user);
+
+ // Disallow anonymous users to view content.
+ user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
+ 'access content' => FALSE,
+ ));
+
+ // Set the block to a region to confirm block is available.
+ $edit = array(
+ 'node_recent[region]' => 'sidebar_first',
+ );
+ $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
+ $this->assertText(t('The block settings have been updated.'), t('Block saved to first sidebar region.'));
+
+ // Set block title and variables.
+ $block = array(
+ 'title' => $this->randomName(),
+ 'node_recent_block_count' => 2,
+ );
+ $this->drupalPost('admin/structure/block/manage/node/recent/configure', $block, t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block saved.'));
+
+ // Test that block is not visible without nodes
+ $this->drupalGet('');
+ $this->assertText(t('No content available.'), t('Block with "No content available." found.'));
+
+ // Add some test nodes.
+ $default_settings = array('uid' => $this->web_user->uid, 'type' => 'article');
+ $node1 = $this->drupalCreateNode($default_settings);
+ $node2 = $this->drupalCreateNode($default_settings);
+ $node3 = $this->drupalCreateNode($default_settings);
+
+ // Change the changed time for node so that we can test ordering.
+ db_update('node')
+ ->fields(array(
+ 'changed' => $node1->changed + 100,
+ ))
+ ->condition('nid', $node2->nid)
+ ->execute();
+ db_update('node')
+ ->fields(array(
+ 'changed' => $node1->changed + 200,
+ ))
+ ->condition('nid', $node3->nid)
+ ->execute();
+
+ // Test that a user without the 'access content' permission cannot
+ // see the block.
+ $this->drupalLogout();
+ $this->drupalGet('');
+ $this->assertNoText($block['title'], t('Block was not found.'));
+
+ // Test that only the 2 latest nodes are shown.
+ $this->drupalLogin($this->web_user);
+ $this->assertNoText($node1->title, t('Node not found in block.'));
+ $this->assertText($node2->title, t('Node found in block.'));
+ $this->assertText($node3->title, t('Node found in block.'));
+
+ // Check to make sure nodes are in the right order.
+ $this->assertTrue($this->xpath('//div[@id="block-node-recent"]/div/table/tbody/tr[position() = 1]/td/div/a[text() = "' . $node3->title . '"]'), t('Nodes were ordered correctly in block.'));
+
+ // Set the number of recent nodes to show to 10.
+ $this->drupalLogout();
+ $this->drupalLogin($this->admin_user);
+ $block = array(
+ 'node_recent_block_count' => 10,
+ );
+ $this->drupalPost('admin/structure/block/manage/node/recent/configure', $block, t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block saved.'));
+
+ // Post an additional node.
+ $node4 = $this->drupalCreateNode($default_settings);
+
+ // Test that all four nodes are shown.
+ $this->drupalGet('');
+ $this->assertText($node1->title, t('Node found in block.'));
+ $this->assertText($node2->title, t('Node found in block.'));
+ $this->assertText($node3->title, t('Node found in block.'));
+ $this->assertText($node4->title, t('Node found in block.'));
+ }
+}