Issue #1479454 by Hugo Wetterberg, galooph, dawehner, andypost, marcingy, heyrocker...
[project/drupal.git] / core / modules / system / lib / Drupal / system / Tests / Upgrade / UserRoleUpgradePathTest.php
1 <?php
2
3 /**
4 * @file
5 * Definition of Drupal\system\Tests\Upgrade\UserRoleUpgradePathTest.
6 */
7
8 namespace Drupal\system\Tests\Upgrade;
9
10 /**
11 * Tests upgrading a bare database with user role data.
12 *
13 * Loads a bare installation of Drupal 7 with role data and runs the
14 * upgrade process on it. Tests for the conversion of serial role IDs to role
15 * machine names.
16 */
17 class UserRoleUpgradePathTest extends UpgradePathTestBase {
18 public static function getInfo() {
19 return array(
20 'name' => 'Role upgrade test',
21 'description' => 'Upgrade tests with role data.',
22 'group' => 'Upgrade path',
23 );
24 }
25
26 public function setUp() {
27 $this->databaseDumpFiles = array(
28 drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
29 drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.roles.database.php',
30 );
31 parent::setUp();
32 }
33
34 /**
35 * Tests expected role ID conversions after a successful upgrade.
36 */
37 public function testRoleUpgrade() {
38 $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
39
40 // Check that "gärtner" has been converted to "4" and that the role
41 // edit page for it exists.
42 $this->drupalGet('admin/people/roles/edit/4');
43 $this->assertResponse(200, 'Role edit page for "gärtner" was found.');
44
45 // Check that the anonymous user role ID has been converted from "1" to
46 // "anonymous".
47 $this->drupalGet('admin/people/permissions/' . DRUPAL_ANONYMOUS_RID);
48 $this->assertResponse(200, 'Permission edit page for "anonymous" was found.');
49
50 // Check that the authenticated user role ID has been converted from "2" to
51 // "authenticated".
52 $this->drupalGet('admin/people/permissions/' . DRUPAL_AUTHENTICATED_RID);
53 $this->assertResponse(200, 'Permission edit page for "authenticated" was found.');
54
55 // Check that the permission for "gärtner" still exists.
56 $this->drupalGet('admin/people/permissions/4');
57 $this->assertFieldChecked('edit-4-edit-own-comments', 'Edit own comments permission for "gärtner" is set correctly.');
58
59 // Check that the role visibility setting for the who's online block still
60 // exists.
61 $this->drupalGet('admin/structure/block/add/user_online_block/bartik');
62
63 // @todo Blocks are not being upgraded.
64 // $this->assertFieldChecked('edit-visibility-role-roles-5', "Who's online block visibility setting is correctly set for the long role name.");
65
66 // Check that the role name is still displayed as expected.
67 $this->assertText('gärtner', 'Role name is displayed on block visibility settings.');
68 $this->assertText('very long role name that has exactly sixty-four characters in it', 'Role name is displayed on block visibility settings.');
69 $this->assertText('very_long role name that has exactly sixty-four characters in it', 'Role name is displayed on block visibility settings.');
70
71 // The administrative user role must still be assigned to the
72 // "administrator" role (rid 3).
73 $this->drupalGet('admin/config/people/accounts');
74 $this->assertFieldByName('user_admin_role', 3);
75 }
76
77 /**
78 * Tests that roles were converted to config.
79 */
80 public function testRoleUpgradeToConfig() {
81 $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
82
83 // Check that the 'anonymous' role has been converted to config.
84 $anonymous = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
85 $this->assertNotEqual(FALSE, $anonymous, "The 'anonymous' role has been converted to config.");
86
87 // Check that the 'authenticated' role has been converted to config.
88 $authenticated = entity_load('user_role', DRUPAL_AUTHENTICATED_RID);
89 $this->assertNotEqual(FALSE, $authenticated, "The 'authenticated' role has been converted to config.");
90 }
91 }