You are here

public function ProfileTypeTest::testDelete in Profile 8

Tests deleting a product type.

File

tests/src/Functional/ProfileTypeTest.php, line 122

Class

ProfileTypeTest
Tests the profile type UI.

Namespace

Drupal\Tests\profile\Functional

Code

public function testDelete() {
  $profile_type = ProfileType::create([
    'id' => 'customer',
    'label' => 'Customer',
  ]);
  $profile_type
    ->save();
  $profile = Profile::create([
    'type' => 'customer',
    'uid' => $this->adminUser
      ->id(),
  ]);
  $profile
    ->save();

  // Confirm that the type can't be deleted while there's a profile.
  $this
    ->drupalGet($profile_type
    ->toUrl('delete-form'));
  $this
    ->assertSession()
    ->pageTextContains(t('@type is used by 1 profile on your site. You cannot remove this profile type until you have removed all of the @type profiles.', [
    '@type' => $profile_type
      ->label(),
  ]));
  $this
    ->assertSession()
    ->pageTextNotContains('This action cannot be undone.');

  // Delete the profile, confirm that deletion works.
  $profile
    ->delete();
  $profile_type
    ->save();
  $this
    ->drupalGet($profile_type
    ->toUrl('delete-form'));
  $this
    ->assertSession()
    ->pageTextContains(t('Are you sure you want to delete the profile type @type?', [
    '@type' => $profile_type
      ->label(),
  ]));
  $this
    ->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $this
    ->submitForm([], 'Delete');
  $profile_type_exists = (bool) ProfileType::load($profile_type
    ->id());
  $this
    ->assertEmpty($profile_type_exists);
}