? .DS_Store
? sites/.DS_Store
? sites/all/.DS_Store
? sites/all/modules/devel
? sites/all/themes/.DS_Store
? sites/default/files
? sites/default/private
? sites/default/settings.php
? themes/.DS_Store
? themes/goofy/.DS_Store
? themes/goofy/images/.DS_Store
Index: modules/profile/profile.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.test,v
retrieving revision 1.24
diff -u -p -r1.24 profile.test
--- modules/profile/profile.test	8 Mar 2010 15:46:58 -0000	1.24
+++ modules/profile/profile.test	19 Apr 2010 21:52:11 -0000
@@ -2,9 +2,13 @@
 // $Id: profile.test,v 1.24 2010/03/08 15:46:58 webchick Exp $
 
 /**
+ * @file
+ * SimpleTest for profile.module
+ */
+/**
  * A class for common methods for testing profile fields.
  */
-class ProfileTestCase extends DrupalWebTestCase {
+class ProfileTestCase extends DrupalWebTestCase{
   protected $admin_user;
   protected $normal_user;
 
@@ -16,6 +20,9 @@ class ProfileTestCase extends DrupalWebT
 
     // This is the user whose profile will be edited.
     $this->normal_user = $this->drupalCreateUser();
+    
+    // This is another normal user-- for checking visibility of fields between non-privileged users 
+    $this->normal_user2 = $this->drupalCreateUser();
   }
 
   /**
@@ -40,6 +47,16 @@ class ProfileTestCase extends DrupalWebT
     $fid = db_query("SELECT fid FROM {profile_field} WHERE title = :title", array(':title' => $title))->fetchField();
     $this->assertTrue($fid, t('New Profile field has been entered in the database'));
 
+    // change the title, name and explanation to test Update capability
+    $edit['title'] = $title = $this->randomName(8);
+    $edit['name'] = $form_name = 'profile_' . $title;
+    $edit['category'] = $category;
+    $edit['explanation'] = $this->randomName(50);
+
+    $this->drupalPost('admin/config/people/profile/edit/' . $fid, $edit, t('Save field'));
+    $fid = db_query("SELECT fid FROM {profile_field} WHERE title = :title", array(':title' => $title))->fetchField();
+    $this->assertTrue($fid, t('Profile field %title been updated in the database', array('%title' => $edit['title'])));
+    
     // Check that the new field is appearing on the user edit form.
     $this->drupalGet('user/' . $this->admin_user->uid . '/edit/' . $category);
 
@@ -113,6 +130,155 @@ class ProfileTestCase extends DrupalWebT
       'category' => $category,
     );
   }
+  
+  /**
+   * Set the profile field visibility and test for correct behavior
+   *
+   * @param $field
+   *   The field that should have visibility set.
+   * @param $value
+   *   The default value for the field-- needed in order to check field presence on Member listing page-- e.g /profile
+   * @param $visibility
+   *   The value for the visibility field, defaults to 2, public.
+   * @return
+   *   The visibility that has been assigned to the field.
+   */
+  function setProfileFieldVisibility($field, $value = '', $visibility = PROFILE_PUBLIC) {
+    // ensure we are logged in as admin
+    $this->drupalLogin($this->admin_user);
+    
+    //Create field
+    $edit = array(
+      'visibility' => $visibility,
+    );
+    $this->drupalPost('admin/config/people/profile/edit/' . $field['fid'], $edit, t('Save field'));
+    
+    // Check profile page as admin
+    
+    $vis_to_admin = $this->assertText($field['title'], t('Found visible profile field with title %title', array('%title' => $field['title'])));
+    // Check profile page as self
+    
+    // Check profile page as other non-priv user
+    
+    
+    switch ($visibility) {
+      case PROFILE_PUBLIC:
+        $this->drupalGet('user/' . $this->normal_user->uid);
+        $this->assertText($field['title'], t('Profile Public: Found visible profile field with title %title', array('%title' => $field['title'])));
+
+        // Check that field is correctly not appearing on member listing page 
+        $this->drupalGet('profile');
+        $this->assertNoText($value, t('Profile Public: Profile field %profile correctly NOT displayed on member listing page', array('%profile' => $field['title'])));
+        break;
+      case PROFILE_PRIVATE:
+        // ensure admin can see it
+        $this->drupalGet('user/' . $this->normal_user->uid);
+        $this->assertText($field['title'], t('Profile Private: Admin: Found visible profile field with title %title', array('%title' => $field['title'])));
+        
+        // ensure normal user cannot see it
+        $this->drupalLogin($this->normal_user);
+        $this->drupalGet('user/' . $this->normal_user->uid);
+        $this->assertText($field['title'], t('Profile Private: User: Self: Found visible profile field with title %title', array('%title' => $field['title'])));
+        
+        // ensure other normal user can see it
+        $this->drupalLogin($this->normal_user2);
+        $this->drupalGet('user/' . $this->normal_user->uid);
+        $this->assertNoText($field['title'], t('Profile Private: User: Other: Profile field %title not visibile to non-privileged other user', array('%title' => $field['title'])));
+        break;
+      case PROFILE_PUBLIC_LISTINGS:
+        $this->drupalGet('user/' . $this->normal_user->uid);
+        $this->assertText($field['title'], t('Profile Public Listings: Found visible profile field with title %title', array('%title' => $field['title'])));
+        
+        //Check that field appears on public listing page
+        $this->drupalGet('profile');
+        $this->assertText($value, t('Profile Public Listings: Profile field %profile correctly displayed on member listing page', array('%profile' => $field['title'])));
+        break;
+      case PROFILE_HIDDEN:
+        $this->drupalGet('user/' . $this->normal_user->uid);
+        $this->assertText($field['title'], t('Profile Hidden: Admin: Found visible profile field with title %title', array('%title' => $field['title'])));
+        
+        // ensure normal user cannot see it
+        $this->drupalLogin($this->normal_user);
+        $this->drupalGet('user/' . $this->normal_user->uid);
+        $this->assertNoText($field['title'], t('Profile Hidden: User: Self: Profile field %title not visible to non-privileged user', array('%title' => $field['title'])));
+        
+        // ensure other normal user cannot see it
+        $this->drupalLogin($this->normal_user2);
+        $this->drupalGet('user/' . $this->normal_user->uid);
+        $this->assertNoText($field['title'], t('Profile Hidden: User: Other: Profile field %title not visible to non-privileged other user', array('%title' => $field['title'])));
+        break;
+    }
+
+    //restore to admin user to not break the rest of the test
+    $this->drupalLogin($this->admin_user);
+    return $visibility;
+  } // setProfileFieldVisibility
+  
+  /**
+   * Set the profile field requirement
+   *
+   * @param $field
+   *   The field that should have requirement set.
+   * @param $required
+   *   Boolean value indicating whether or not field should be required.
+   * @return
+   *   The requirement that has been assigned to the field.
+   */
+  function setProfileFieldRequired($field, $required = TRUE) {
+  
+    $edit = array(
+      'required' => $required,
+    );
+    $this->drupalPost('admin/config/people/profile/edit/' . $field['fid'], $edit, t('Save field'));
+
+    // Check profile page.
+    $profile_edit = $this->drupalGet('user/' . $this->normal_user->uid . '/edit/' . $field['category']);
+
+    if ($required) {
+      $this->assertRaw($field['title'] . ' <span class="form-required" title="This field is required.">*</span>', t('Found requirement for profile field with title %title', array('%title' => $field['title'])));
+    } // if
+    else {
+      $this->assertNoRaw($field['title'] . ' <span class="form-required" title="This field is required.">*</span>', t('Did not find requirement for profile field with title %title', array('%title' => $field['title'])));
+    } // else
+
+    return $required;
+  
+  } // setProfileFieldRequired
+
+  /**
+   * Set the profile field registration form visibility
+   *
+   * @param $field
+   *   The field that should have visibility set.
+   * @param $required
+   *   Boolean value indicating whether or not field should show on the registration form.
+   * @return
+   *   The registration form visibility that has been assigned to the field.
+   */
+  function setProfileFieldRegistrationVisibility($field, $visible = TRUE) {
+  
+    $edit = array(
+      'register' => $visible,
+    );
+    $this->drupalPost('admin/config/people/profile/edit/' . $field['fid'], $edit, t('Save field'));
+
+    $this->drupalLogout();
+
+    // Check profile page.
+    $registration_form = $this->drupalGet('user/register');
+
+    if ($visible) {
+      $this->assertField($field['form_name'], t('Found field with title %title on registration form.', array('%title' => $field['title'])));
+    } // if
+    else {
+      $this->assertNoField($field['form_name'], t('Did not find field with title %title on registration form.', array('%title' => $field['title'])));
+    } // else
+
+    $this->drupalLogin($this->admin_user);
+
+    return $visible;
+  
+  } // setProfileFieldRegistrationVisibility
 
   /**
    * Set the profile field to a random value
@@ -192,6 +358,13 @@ class ProfileTestFields extends ProfileT
     foreach ($field_types as $type => $value) {
       $field = $this->createProfileField($type);
       $this->setProfileField($field, $value);
+      foreach (array(PROFILE_PUBLIC_LISTINGS, PROFILE_PRIVATE, PROFILE_HIDDEN, PROFILE_PUBLIC) as $visibility_setting) {
+        $this->setProfileFieldVisibility($field, $value, $visibility_setting);
+      }
+      $this->setProfileFieldRequired($field, TRUE);
+      $this->setProfileFieldRequired($field, FALSE);
+      $this->setProfileFieldRegistrationVisibility($field, TRUE);
+      $this->setProfileFieldRegistrationVisibility($field, FALSE);
       $edit = array(
         'name' => $field['form_name'],
         'title' => $this->randomName(),
@@ -420,12 +593,4 @@ class ProfileTestBrowsing extends Profil
     $this->drupalGet("profile/{$field['form_name']}/$value");
     $this->assertText($this->normal_user->name);
   }
-}
-
-  /**
-   * TODO:
-   * - Test field visibility
-   * - Test required fields
-   * - Test fields on registration form
-   * - Test updating fields
-   */
+}
\ No newline at end of file
