diff --git a/src/Tests/ProfileCRUDTest.php b/src/Tests/ProfileCRUDTest.php index 07f794e..84084c1 100644 --- a/src/Tests/ProfileCRUDTest.php +++ b/src/Tests/ProfileCRUDTest.php @@ -248,121 +248,10 @@ class ProfileCRUDTest extends ProfileTestBase { $this->drupalGet('admin/config'); $this->clickLink('User profiles'); $this->assertResponse(200); - $this->assertUrl($profile1->toUrl('collection')->toString()); + $this->assertUrl('admin/config/people/profiles'); $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/ProfileDefaultTest.php b/src/Tests/ProfileDefaultTest.php index 140cacb..64b9ab1 100644 --- a/src/Tests/ProfileDefaultTest.php +++ b/src/Tests/ProfileDefaultTest.php @@ -123,4 +123,129 @@ class ProfileDefaultTest extends ProfileTestBase { $default_profile = $storage->loadDefaultByUser($this->user1, $profile_type->id()); $this->assertEqual($profile2->id(), $default_profile->id()); } + + /** + * 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(), + ]); + $profile_profile_type_0_user1_1->setActive(TRUE); + $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(), + ]); + $profile_profile_type_0_user1_2->setActive(TRUE); + $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(), + ]); + $profile_profile_type_1_user1->setActive(TRUE); + $profile_profile_type_1_user1->save(); + $profile_profile_type_1_user2 = Profile::create($expected = [ + 'type' => $types['profile_type_1']->id(), + 'uid' => $this->user2->id(), + ]); + $profile_profile_type_1_user2->setActive(TRUE); + $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(), + ]); + $profile_profile_type_1_user1_inactive->setActive(FALSE); + $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(), + ]); + $profile_profile_type_1_user1_active->isActive(TRUE); + $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()); + + // 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->assertTrue(Profile::load($profile_profile_type_0_user1_1->id())->isDefault()); + $this->assertFalse($profile_profile_type_0_user1_2->isDefault()); + + // Mark $profile_profile_type_0_user1_2 as default + // $profile_profile_type_0_user1_1 should become not default. + $profile_profile_type_0_user1_2->setDefault(TRUE); + $profile_profile_type_0_user1_2->save(); + $this->assertTrue($profile_profile_type_0_user1_2->isDefault()); + $this->assertFalse($profile_profile_type_0_user1_1->isDefault()); + + // 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::load($profile_profile_type_1_user1->id())->isDefault()); + $this->assertFalse($profile_profile_type_1_user2->isDefault()); + + // Mark $profile_profile_type_1_user2 as default + // $profile_profile_type_1_user1 should stay default. + $profile_profile_type_1_user2->setDefault(TRUE); + $profile_profile_type_1_user2->save(); + $this->assertTrue($profile_profile_type_1_user2->isDefault()); + $this->assertTrue(Profile::load($profile_profile_type_1_user1->id())->isDefault()); + + // 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::load($profile_profile_type_1_user1_inactive->id())->isDefault()); + $this->assertFalse($profile_profile_type_1_user1_active->isDefault()); + + // Mark $profile_profile_type_1_user1_active as default + // $profile_profile_type_1_user1_inactive should stay default. + $profile_profile_type_1_user1_active->setDefault(TRUE); + $profile_profile_type_1_user1_active->save(); + $this->assertTrue($profile_profile_type_1_user1_active->isDefault()); + $this->assertTrue(Profile::load($profile_profile_type_1_user1_inactive->id())->isDefault()); + } + } diff --git a/src/Tests/ProfileTabTest.php b/src/Tests/ProfileTabTest.php index 45af17b..182eb3c 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($profile1->toUrl('collection')->toString()); + $this->assertUrl('admin/config/people/profiles'); $this->assertLink($profile1->label()); $this->assertLinkByHref($profile2->toUrl('canonical')->toString());