You are here

public function ProfileDefaultTest::testSetDefaultRoute in Profile 8

Tests the entity.profile.set_default route.

File

tests/src/Functional/ProfileDefaultTest.php, line 39

Class

ProfileDefaultTest
Tests "default" functionality via the UI.

Namespace

Drupal\Tests\profile\Functional

Code

public function testSetDefaultRoute() {
  $this->type
    ->setMultiple(TRUE)
    ->save();
  $id = $this->type
    ->id();
  $test_user = $this
    ->drupalCreateUser([
    "view own {$id} profile",
    "create {$id} profile",
    "update own {$id} profile",
    "delete own {$id} profile",
  ]);
  $profile1 = Profile::create([
    'type' => $id,
    'uid' => $test_user
      ->id(),
    'profile_fullname' => 'Frederick Pabst',
  ]);
  $profile1
    ->save();
  $profile2 = Profile::create([
    'type' => $id,
    'uid' => $test_user
      ->id(),
    'profile_fullname' => 'Frederick Miller',
  ]);
  $profile2
    ->save();
  $this
    ->drupalLogin($test_user);
  $this
    ->drupalGet(Url::fromRoute('profile.user_page.multiple', [
    'user' => $test_user
      ->id(),
    'profile_type' => $id,
  ]));
  $this
    ->assertSession()
    ->pageTextContains('Frederick Pabst');
  $this
    ->assertSession()
    ->pageTextContains('Frederick Miller');
  $this
    ->assertSession()
    ->linkExists('Mark as default');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Mark as default');
  $this
    ->assertSession()
    ->responseContains((string) t('The %label profile has been marked as default.', [
    '%label' => $profile2
      ->label(),
  ]));
}