diff --git a/lib/Drupal/profile2/Tests/ProfileCRUDTest.php b/lib/Drupal/profile2/Tests/ProfileCRUDTest.php index da652c8..ab399a2 100644 --- a/lib/Drupal/profile2/Tests/ProfileCRUDTest.php +++ b/lib/Drupal/profile2/Tests/ProfileCRUDTest.php @@ -7,14 +7,14 @@ namespace Drupal\profile2\Tests; -use Drupal\simpletest\WebTestBase; +use Drupal\simpletest\DrupalUnitTestBase; /** * Tests basic CRUD functionality of profiles. */ -class ProfileCRUDTest extends WebTestBase { +class ProfileCRUDTest extends DrupalUnitTestBase { - public static $modules = array('profile2'); + public static $modules = array('system', 'field', 'field_sql_storage', 'user', 'profile2'); public static function getInfo() { return array( @@ -24,6 +24,13 @@ class ProfileCRUDTest extends WebTestBase { ); } + function setUp() { + parent::setUp(); + $this->installSchema('system', 'url_alias'); + $this->installSchema('system', 'sequences'); + $this->enableModules(array('field', 'user', 'profile2')); + } + /** * Tests CRUD operations. */ @@ -36,8 +43,16 @@ class ProfileCRUDTest extends WebTestBase { $types[$id] = entity_create('profile2_type', array('id' => $id) + $values); $types[$id]->save(); } - $this->user1 = $this->drupalCreateUser(); - $this->user2 = $this->drupalCreateUser(); + $this->user1 = entity_create('user', array( + 'name' => $this->randomName(), + 'mail' => $this->randomName() . '@example.com', + )); + $this->user1->save(); + $this->user2 = entity_create('user', array( + 'name' => $this->randomName(), + 'mail' => $this->randomName() . '@example.com', + )); + $this->user2->save(); // Create a new profile. $profile = entity_create('profile2', $expected = array( diff --git a/lib/Drupal/profile2/Tests/ProfileEditTest.php b/lib/Drupal/profile2/Tests/ProfileEditTest.php index ab5dc3f..e04c54c 100644 --- a/lib/Drupal/profile2/Tests/ProfileEditTest.php +++ b/lib/Drupal/profile2/Tests/ProfileEditTest.php @@ -30,18 +30,17 @@ class ProfileEditTest extends WebTestBase { $type = entity_create('profile2_type', array( 'id' => 'test', 'label' => 'label', - 'weight' => 0 + 'weight' => 0, + 'registration' => TRUE, )); $type->save(); $type = entity_create('profile2_type', array( 'id' => 'test2', 'label' => 'label2', - 'weight' => 2 + 'weight' => 2, )); $type->save(); - entity_load_multiple('profile2', array(), TRUE); - // Add a field to main type, which is created during module installation. $field = array( 'field_name' => 'profile_fullname', 'type' => 'text', @@ -52,7 +51,7 @@ class ProfileEditTest extends WebTestBase { $instance = array( 'entity_type' => 'profile2', 'field_name' => 'profile_fullname', - 'bundle' => 'main', + 'bundle' => 'test', 'label' => 'Full name', 'description' => 'Specify your first and last name.', 'widget' => array( @@ -61,6 +60,8 @@ class ProfileEditTest extends WebTestBase { ), ); field_create_instance($instance); + + $this->checkPermissions(array(), TRUE); } /** @@ -106,41 +107,41 @@ class ProfileEditTest extends WebTestBase { $edit = array(); $edit['name'] = $name = $this->randomName(); $edit['mail'] = $mail = $edit['name'] . '@example.com'; - $edit['profile_main[profile_fullname][und][0][value]'] = $this->randomName(); + $edit['profile_test[profile_fullname][und][0][value]'] = $this->randomName(); $this->drupalPost('user/register', $edit, t('Create new account')); $this->assertText(t('A welcome message with further instructions has been sent to your e-mail address.'), t('User registered successfully.')); $new_user = user_load_by_name($name); $this->assertTrue((bool) $new_user->status, t('New account is active after registration.')); - $profile = profile2_load_by_user($new_user, 'main'); - $this->assertEqual($profile->profile_fullname[LANGUAGE_NOT_SPECIFIED][0]['value'], $edit['profile_main[profile_fullname][und][0][value]'], 'Profile created.'); + $profile = profile2_load_by_user($new_user, 'test'); + $this->assertEqual($profile->profile_fullname[LANGUAGE_NOT_SPECIFIED][0]['value'], $edit['profile_test[profile_fullname][und][0][value]'], 'Profile created.'); } /** * Test basic edit and display. */ function testEditAndDisplay() { - user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, array('edit own main profile', 'view own main profile')); + user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, array('edit own test profile', 'view own test profile')); $user1 = $this->drupalCreateUser(); $this->drupalLogin($user1); // Make sure access is denied to the profile. - $this->drupalGet('user/' . $user1->uid . '/edit/main'); + $this->drupalGet('user/' . $user1->uid . '/edit/test'); $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. - entity_create('profile2', array('type' => 'main', 'uid' => $user1->uid))->save(); + entity_create('profile2', array('type' => 'test', 'uid' => $user1->uid))->save(); $this->drupalGet('user/' . $user1->uid); - $this->assertNoText(t('Main profile'), 'Profile data is not visible to the owner.'); + $this->assertNoText('label', 'Profile data is not visible to the owner.'); - $user2 = $this->drupalCreateUser(array('edit own main profile', 'view own main profile')); + $user2 = $this->drupalCreateUser(array('edit own test profile', 'view own test profile')); $this->drupalLogin($user2); // Create profiles for the user2. $edit['profile_fullname[und][0][value]'] = $this->randomName(); - $this->drupalPost('user/' . $user2->uid . '/edit/main', $edit, t('Save')); + $this->drupalPost('user/' . $user2->uid . '/edit/test', $edit, t('Save')); $this->assertText(t('Your profile has been saved.'), 'Profile saved.'); - $profile = profile2_load_by_user($user2, 'main'); + $profile = profile2_load_by_user($user2, 'test'); $this->assertEqual($profile->profile_fullname[LANGUAGE_NOT_SPECIFIED][0]['value'], $edit['profile_fullname[und][0][value]'], 'Profile edited.'); $this->drupalGet('user/' . $user2->uid); diff --git a/lib/Drupal/profile2/Tests/ProfileTypeCRUDTest.php b/lib/Drupal/profile2/Tests/ProfileTypeCRUDTest.php index 4263e61..5abb07a 100644 --- a/lib/Drupal/profile2/Tests/ProfileTypeCRUDTest.php +++ b/lib/Drupal/profile2/Tests/ProfileTypeCRUDTest.php @@ -90,8 +90,9 @@ class ProfileTypeCRUDTest extends WebTestBase { $this->drupalGet("admin/people/profiles/manage/$id/fields"); // @todo D8 core: This assertion fails for an unknown reason. Database // contains the right values, so field_attach_rename_bundle() works - // correctly. Not even flushing all caches helps. Can be reproduced - // manually. + // correctly. The pre-existing field does not appear on the Manage + // fields page of the renamed bundle. Not even flushing all caches + // helps. Can be reproduced manually. //$this->assertText(check_plain($field_label)); } diff --git a/profile2.install b/profile2.install index 32dc1fb..1fbb5ae 100644 --- a/profile2.install +++ b/profile2.install @@ -6,26 +6,6 @@ */ /** - * Implements hook_install(). - */ -function profile2_install() { - // Add an initial profile type, but only if installed manually. In case the - // module is installed via an installation profile, skip that. - if (!drupal_installation_attempted()) { - entity_info_cache_clear(); - $type = entity_create('profile2_type', array( - 'id' => 'main', - 'label' => t('Main profile'), - 'weight' => 0, - 'registration' => TRUE, - )); - $type->save(); - user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('edit own main profile', 'view own main profile')); - drupal_set_message(t('A main profile type has been created and assigned to all users. Go to the Profile types page to add some fields or to configure further profile types.', array('!url' => url('admin/people/profiles')))); - } -} - -/** * Implements hook_schema(). */ function profile2_schema() { @@ -77,6 +57,7 @@ function profile2_schema() { ), 'indexes' => array( 'uid' => array('uid'), + 'type' => array('type'), ), 'foreign keys' => array( 'uid' => array(