You are here

function Profile2CRUDTestCase::testEditAndDisplay in Profile 2 7.2

Same name and namespace in other branches
  1. 7 profile2.test \Profile2CRUDTestCase::testEditAndDisplay()

Test basic edit and display.

File

./profile2.test, line 112

Class

Profile2CRUDTestCase
Test basic CRUD functionality.

Code

function testEditAndDisplay() {
  user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, array(
    'edit own main profile',
    'view own main profile',
  ));
  $user1 = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user1);

  // Make sure access is denied to the profile.
  $this
    ->drupalGet('user/' . $user1->uid . '/edit/main');
  $this
    ->assertText(t('Access denied'), 'Access has been denied.');

  // Test creating a profile manually (e.g. by an admin) and ensure the user
  // may not see it.
  profile2_create(array(
    'type' => 'main',
    'uid' => $user1->uid,
  ))
    ->save();
  $this
    ->drupalGet('user/' . $user1->uid);
  $this
    ->assertNoText(t('Main profile'), 'Profile data is not visible to the owner.');
  $user2 = $this
    ->drupalCreateUser(array(
    'edit own main profile',
    'view own main profile',
  ));
  $this
    ->drupalLogin($user2);

  // Create profiles for the user2.
  $edit['profile_main[profile_fullname][und][0][value]'] = $this
    ->randomName();
  $this
    ->drupalPost('user/' . $user2->uid . '/edit/main', $edit, t('Save'));
  $this
    ->assertText(t('The changes have been saved.'), 'Profile saved.');
  $this
    ->assertEqual(profile2_load_by_user($user2, 'main')->profile_fullname[LANGUAGE_NONE][0]['value'], $edit['profile_main[profile_fullname][und][0][value]'], 'Profile edited.');
  $this
    ->drupalGet('user/' . $user2->uid);
  $this
    ->assertText(check_plain($edit['profile_main[profile_fullname][und][0][value]']), 'Profile displayed.');
}