? .cvsignore
? author_links_with_tests.patch
? author_links_with_tests6.patch
? author_links_with_tests7.patch
Index: privatemsg.test
===================================================================
RCS file: /cvs/drupal/contributions/modules/privatemsg/privatemsg.test,v
retrieving revision 1.14
diff -u -p -r1.14 privatemsg.test
--- privatemsg.test	6 Jun 2010 15:13:47 -0000	1.14
+++ privatemsg.test	20 Jun 2010 17:28:36 -0000
@@ -670,4 +670,152 @@ class PrivatemsgTestCase extends DrupalW
     $this->assertText($message['subject'], t('Message is displayed again.'));
     $this->assertNoText(t('No messages available.'), t('Messages are available.'));
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Tests for node, blocks and profile integration.
+ */
+class PrivatemsgLinksTestCase extends DrupalWebTestCase {
+
+  /**
+   * Implements of getInfo().
+   */
+  public function getInfo() {
+    return array
+    (
+      'name' => t('Privatemsg links'),
+      'description' => t('Tests links displayed in nodes, profiles and blocks.'),
+      'group' => t('Privatemsg'),
+    );
+  }
+
+  /**
+   * Implements setUp().
+   */
+  function setUp() {
+    parent::setUp('privatemsg');
+  }
+
+  /**
+   * Tests author links displayed on nodes and comments.
+   */
+  function testAuthorLinks() {
+    $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'create story content', 'create page content'));
+    $user = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg'));
+
+    $this->drupalLogin($admin);
+
+    $settings = array(
+      'privatemsg_display_link_self' => FALSE,
+      'privatemsg_link_node_types[story]' => TRUE,
+      'privatemsg_display_on_teaser' => FALSE,
+      'privatemsg_display_on_comments' => TRUE,
+    );
+    $this->drupalPost('admin/settings/messages', $settings, t('Save configuration'));
+
+    $node1 = array(
+      'title' => $this->randomName(10),
+      'body' => $this->randomString(50),
+    );
+    $this->drupalPost('node/add/story', $node1, t('Save'));
+    $this->clickLink(t('Add new comment'));
+
+    $comment = array(
+      'comment' => $this->randomName(20),
+    );
+    // First preview, then save.
+    $this->drupalPost(NULL, $comment, t('Preview'));
+    $this->drupalPost(NULL, $comment, t('Save'));
+
+    $node2 = array(
+      'title' => $this->randomName(),
+      'body' => $this->randomString(50),
+    );
+    $this->drupalPost('node/add/page', $node2, t('Save'));
+
+    $this->drupalGet('node');
+    $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
+    $this->clickLink($node1['title']);
+    $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
+
+    $this->drupalLogin($user);
+    $this->drupalGet('node');
+    $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
+    $this->clickLink($node1['title']);
+    $this->assertText(t('Send author a message'), t('Send author a message link displayed.'));
+    $this->assertText(t('Send private message'), t('Send private message link on comment displayed.'));
+
+    // @todo: Do not guess nid.
+    $this->drupalGet('node/2');
+    $this->assertNoText(t('Send author a message'), t('Send author a message link not displayed.'));
+  }
+
+  /**
+   * Tests menu block.
+   */
+  function testMenuBlock() {
+    $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'administer blocks', 'administer menu'));
+    $user = $this->drupalCreateUser(array('read privatemsg'));
+
+    // Enable block.
+    $this->drupalLogin($admin);
+    $blocks = array(
+      'privatemsg_privatemsg-menu[region]' => 'right',
+    );
+    $this->drupalPost('admin/build/block', $blocks, t('Save blocks'));
+
+    // Disable secondary menu.
+    /* @todo: Not yet possible because simpletest needs a log out link to verify that the user is logged in.
+    $menu_settings = array(
+      'menu_secondary_links_source' => '',
+    );
+    $this->drupalPost('admin/structure/menu/settings', $menu_settings, t('Save configuration'));
+     *
+     */
+
+    $this->drupalGet('');
+    $this->assertRaw('<h2>Private messages</h2>', t('Privatemsg menu block title displayed.'));
+    $this->assertText('Write new message', t('Write new message link displayed.'));
+
+    $message = array(
+      'recipient' => $user->name,
+      'subject' => $this->randomName(),
+      'body' => $this->randomName(50),
+    );
+    $this->drupalPost('messages/new', $message, t('Send message'));
+
+    $this->drupalLogin($user);
+    $this->assertNoText(t('Write new message'), t('Write new message link not displayed.'));
+    $this->assertNoUniqueText(t('Messages (1 new)'), t('Messages link including new message information displayed'));
+  }
+
+  /**
+   * Tests menu block.
+   */
+  function testNewBlock() {
+    $admin = $this->drupalCreateUser(array('read privatemsg', 'write privatemsg', 'administer privatemsg settings', 'administer blocks', 'administer menu'));
+    $user = $this->drupalCreateUser(array('read privatemsg'));
+
+    // Enable block.
+    $this->drupalLogin($admin);
+    $blocks = array(
+      'privatemsg_privatemsg-new[region]' => 'right',
+    );
+    $this->drupalPost('admin/build/block', $blocks, t('Save blocks'));
+
+    $this->drupalGet('');
+    $this->assertNoRaw('<h2>New message</h2>', t('Privatemsg new block title not displayed.'));
+
+    $message = array(
+      'recipient' => $user->name,
+      'subject' => $this->randomName(),
+      'body' => $this->randomName(50),
+    );
+    $this->drupalPost('messages/new', $message, t('Send message'));
+
+    $this->drupalLogin($user);
+    $this->assertRaw('<h2>New message</h2>', t('Privatemsg new block title displayed.'));
+
+    $this->assertText(t('You have a new message, click here to read it'), t('New message indication displayed.'));
+  }
+}
