From d14e66a4e1311e185cbc42ade033ca18572e6194 Mon Sep 17 00:00:00 2001
From: Shawn DeArmond <code@dearmond.net>
Date: Sun, 20 Mar 2011 22:56:29 -0700
Subject: [PATCH] Start adding tests.

---
 flag_friend.info |    1 +
 flag_friend.test |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100644 flag_friend.test

diff --git a/flag_friend.info b/flag_friend.info
index 520f690..a0e4a99 100644
--- a/flag_friend.info
+++ b/flag_friend.info
@@ -13,3 +13,4 @@ files[] = includes/flag_friend_handler_field_links.inc
 files[] = access/flag_friend_is_friend.inc
 files[] = content_types/flag_friend_count.inc
 files[] = content_types/flag_friend_links.inc
+files[] = flag_friend.test
diff --git a/flag_friend.test b/flag_friend.test
new file mode 100644
index 0000000..2f0365a
--- /dev/null
+++ b/flag_friend.test
@@ -0,0 +1,88 @@
+<?php
+
+class FlagFriendUserTestCase extends DrupalWebTestCase {
+  protected $admin_user;
+  protected $user_a;
+  protected $user_b;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Flag Friend User',
+      'description' => 'Test friending and un-friending of other users.',
+      'group' => 'Flag Friend',
+    );
+  }
+
+  public function setUp() {
+    // Load the flag and flag_friend modules.
+    parent::setUp('flag', 'flag_friend');
+
+    // Create Admin User.
+    $this->admin_user = $this->drupalCreateUser(array(
+      'administer flags', 'administer users'));
+    // Create User A.
+    $this->user_a = $this->drupalCreateUser(array(
+      'receive friend email notification', 'access user profiles'));
+    // Create User B.
+    $this->user_b = $this->drupalCreateUser(array(
+      'receive friend email notification', 'access user profiles'));
+  }
+  
+  public function adminConfig() {
+    $this->drupalLogin($this->admin_user);
+    $edit = array(
+      'roles[flag][2]' => TRUE,
+      'roles[unflag][2]' => TRUE,      
+    );
+    $this->drupalPost('admin/structure/flags/manage/friend', $edit, t('Submit'));
+    cache_clear_all();
+  }
+
+  public function testFriendAndUnfriend() {
+    $this->adminConfig();
+    $this->drupalGet('user/' . $this->user_b->uid);
+    // Allow User A to add User B as a friend.
+    $this->drupalLogin($this->user_a);
+    $this->drupalGet('user/' . $this->user_b->uid);
+    $this->assertText(t('Add friend'));
+    $edit = array(
+      'flag_friend_message' => t('Can I be your friend?'),
+    );
+    $this->drupalPost('flag/confirm/flag/friend/' . $this->user_b->uid, $edit, t('Send'));
+    $this->assertMailString('body', t('Can I be your friend?'), 1);
+    $this->assertMail('to', $this->user_b->mail);
+    $this->drupalGet('user/' . $this->user_b->uid);
+    $this->assertText(t('Friend Requested. Cancel?'));
+    $this->drupalGet('user/' . $this->user_a->uid . '/friends/flagged');
+    $this->assertText($this->user_b->name);
+    $this->assertText(t('Friend Requested. Cancel?'));
+    
+    // Log in as User B.
+    $this->drupalLogin($this->user_b);
+    $this->drupalGet('user/' . $this->user_a->uid);
+    $this->assertText(t('Approve'));
+    $this->drupalGet('user/' . $this->user_b->uid . '/friends/pending');
+    $this->assertText($this->user_b->name);
+    $this->assertText(t('Approve'));
+    $this->assertText(t('Deny'));
+    
+    // Approve friend request from User A.
+    $edit = array(
+      'flag_friend_message' => t('Hello, Friend!'),
+    );
+    $this->drupalPost('flag/confirm/flag/friend/' . $this->user_a->uid, $edit, t('Send'));
+    $this->assertMailString('body', t('Hello, Friend!'), 1);
+    
+    // Verify that User A is a friend of User B.
+    $this->drupalGet('user/' . $this->user_b->uid . '/friends');
+    $this->assertText($this->user_a->name);
+    // Log in as User A.
+    $this->drupalLogin($this->user_a);
+    // Verify that User B is a friend of User A.
+    $this->drupalGet('user/' . $this->user_b->uid . '/friends');
+    $this->assertText($this->user_b->name);
+    
+    // Remove friendship.
+    
+  }  
+}
-- 
1.7.0.3

