diff --git a/src/Tests/ProfileCRUDTest.php b/src/Tests/ProfileCRUDTest.php index 7572e42..07f794e 100644 --- a/src/Tests/ProfileCRUDTest.php +++ b/src/Tests/ProfileCRUDTest.php @@ -248,9 +248,121 @@ class ProfileCRUDTest extends ProfileTestBase { $this->drupalGet('admin/config'); $this->clickLink('User profiles'); $this->assertResponse(200); - $this->assertUrl('admin/config/people/profiles'); + $this->assertUrl($profile1->toUrl('collection')->toString()); $this->assertLink($profile1->label()); $this->assertLinkByHref($profile2->toUrl('canonical')->toString()); } + + /** + * Tests mark as default action. + */ + public function testDefaultAction() { + $types_data = [ + 'profile_type_0' => [ + 'label' => $this->randomMachineName(), + 'multiple' => TRUE, + ], + 'profile_type_1' => [ + 'label' => $this->randomMachineName(), + 'multiple' => TRUE, + ], + ]; + + /** @var ProfileType[] $types */ + $types = []; + foreach ($types_data as $id => $values) { + $types[$id] = $this->createProfileType($id, $values['label']); + } + + $this->user1 = User::create([ + 'name' => $this->randomMachineName(), + 'mail' => $this->randomMachineName() . '@example.com', + ]); + $this->user1->save(); + $this->user2 = User::create([ + 'name' => $this->randomMachineName(), + 'mail' => $this->randomMachineName() . '@example.com', + ]); + $this->user2->save(); + + // Create new profiles. + $profile_profile_type_0_user1_1 = Profile::create($expected = [ + 'type' => $types['profile_type_0']->id(), + 'uid' => $this->user1->id(), + 'status' => PROFILE_ACTIVE, + ]); + $profile_profile_type_0_user1_1->save(); + $profile_profile_type_0_user1_2 = Profile::create($expected = [ + 'type' => $types['profile_type_0']->id(), + 'uid' => $this->user1->id(), + 'status' => PROFILE_ACTIVE, + ]); + $profile_profile_type_0_user1_2->save(); + $profile_profile_type_1_user1 = Profile::create($expected = [ + 'type' => $types['profile_type_1']->id(), + 'uid' => $this->user1->id(), + 'status' => PROFILE_ACTIVE, + ]); + $profile_profile_type_1_user1->save(); + $profile_profile_type_1_user2 = Profile::create($expected = [ + 'type' => $types['profile_type_1']->id(), + 'uid' => $this->user2->id(), + 'status' => PROFILE_ACTIVE, + ]); + $profile_profile_type_1_user2->save(); + $profile_profile_type_1_user1_inactive = Profile::create($expected = [ + 'type' => $types['profile_type_1']->id(), + 'uid' => $this->user1->id(), + 'status' => PROFILE_NOT_ACTIVE, + ]); + $profile_profile_type_1_user1_inactive->save(); + $profile_profile_type_1_user1_active = Profile::create($expected = [ + 'type' => $types['profile_type_1']->id(), + 'uid' => $this->user1->id(), + 'status' => PROFILE_ACTIVE, + ]); + $profile_profile_type_1_user1_active->save(); + + $this->drupalLogin($this->adminUser); + + $this->drupalGet('admin/config'); + $this->clickLink('User profiles'); + $this->assertResponse(200); + + // Check whether all have links "Mark as default". + $this->assertLinkByHref($profile_profile_type_0_user1_1->toUrl('set-default')->toString()); + $this->assertLinkByHref($profile_profile_type_0_user1_2->toUrl('set-default')->toString()); + $this->assertLinkByHref($profile_profile_type_1_user1->toUrl('set-default')->toString()); + $this->assertLinkByHref($profile_profile_type_1_user2->toUrl('set-default')->toString()); + $this->assertLinkByHref($profile_profile_type_1_user1_inactive->toUrl('set-default')->toString()); + $this->assertLinkByHref($profile_profile_type_1_user1_active->toUrl('set-default')->toString()); + + // @todo mark $profile_profile_type_0_user1_1 as default $profile_profile_type_0_user1_2 should stay not default + $this->drupalGet($profile_profile_type_0_user1_1->toUrl('set-default')->toString()); + $this->verbose($profile_profile_type_0_user1_1->isDefault() == 1 ? 'true' : 'false'); + $this->assertTrue($profile_profile_type_0_user1_1->isDefault()); + $this->assertFalse($profile_profile_type_0_user1_2->isDefault()); + // @todo mark $profile_profile_type_0_user1_2 as default $profile_profile_type_0_user1_1 should become not default + $this->drupalGet($profile_profile_type_0_user1_2->toUrl('set-default')->toString()); + $this->assertTrue($profile_profile_type_0_user1_2->isDefault()); + $this->assertFalse($profile_profile_type_0_user1_1->isDefault()); + // @todo mark $profile_profile_type_1_user1 as default $profile_profile_type_1_user2 should stay not default + $this->drupalGet($profile_profile_type_1_user1->toUrl('set-default')->toString()); + $this->assertTrue($profile_profile_type_1_user1->isDefault()); + $this->assertFalse($profile_profile_type_1_user2->isDefault()); + // @todo mark $profile_profile_type_1_user2 as default $profile_profile_type_1_user1 should stay default + $this->drupalGet($profile_profile_type_1_user2->toUrl('set-default')->toString()); + $this->assertTrue($profile_profile_type_1_user2->isDefault()); + $this->assertTrue($profile_profile_type_1_user1->isDefault()); + // @todo mark $profile_profile_type_1_user1_inactive as default $profile_profile_type_1_user1_active should stay not default + $this->drupalGet($profile_profile_type_1_user1_inactive->toUrl('set-default')->toString()); + $this->assertTrue($profile_profile_type_1_user1_inactive->isDefault()); + $this->assertFalse($profile_profile_type_1_user1_active->isDefault()); + // @todo mark $profile_profile_type_1_user1_active as default $profile_profile_type_1_user1_inactive should stay default + $this->drupalGet($profile_profile_type_1_user1_active->toUrl('set-default')->toString()); + $this->assertTrue($profile_profile_type_1_user1_active->isDefault()); + $this->assertTrue($profile_profile_type_1_user1_inactive->isDefault()); + } + } diff --git a/src/Tests/ProfileTabTest.php b/src/Tests/ProfileTabTest.php index 182eb3c..45af17b 100644 --- a/src/Tests/ProfileTabTest.php +++ b/src/Tests/ProfileTabTest.php @@ -95,7 +95,7 @@ class ProfileTabTest extends LocalTasksTest { $this->drupalGet('admin/config'); $this->clickLink('User profiles'); $this->assertResponse(200); - $this->assertUrl('admin/config/people/profiles'); + $this->assertUrl($profile1->toUrl('collection')->toString()); $this->assertLink($profile1->label()); $this->assertLinkByHref($profile2->toUrl('canonical')->toString());