You are here

public function IndividualUiTest::testIndividualTypeOperations in CRM Core 8.3

Tests the individual type operations.

User with permissions 'administer individual types' should be able to create/edit/delete individual types.

@covers \Drupal\crm_core_contact\Form\IndividualTypeForm::buildForm @covers \Drupal\crm_core_contact\Form\IndividualTypeForm::submitForm

File

modules/crm_core_contact/tests/src/Functional/IndividualUiTest.php, line 257

Class

IndividualUiTest
Tests the UI for Individual CRUD operations.

Namespace

Drupal\Tests\crm_core_contact\Functional

Code

public function testIndividualTypeOperations() : void {

  // Given I am logged in as a user with permission 'administer individual
  // types'.
  $user = $this
    ->drupalCreateUser([
    'administer individual types',
  ]);
  $this
    ->drupalLogin($user);

  // When I visit the individual type admin page.
  $this
    ->drupalGet('admin/structure/crm-core/individual-types');

  // Then I should see edit, and delete links for existing contacts.
  $this
    ->assertSession()
    ->linkByHrefExists('admin/structure/crm-core/individual-types/customer', 0);
  $this
    ->assertSession()
    ->linkByHrefExists('admin/structure/crm-core/individual-types/customer/delete', 0);

  // Given there is a individual of type 'customer.'.
  Individual::create([
    'type' => 'customer',
  ])
    ->save();

  // When I visit the individual type admin page.
  $this
    ->drupalGet('admin/structure/crm-core/individual-types');

  // Then I should not see a delete link.
  $this
    ->assertSession()
    ->linkByHrefNotExists('admin/structure/crm-core/individual-types/customer/delete');
  $this
    ->drupalGet('admin/structure/crm-core/individual-types/customer/delete');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // When I edit the individual type.
  $this
    ->drupalGet('admin/structure/crm-core/individual-types/customer');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Then I should see "Save individual type" button.
  $this
    ->assertSession()
    ->buttonExists('Save individual type');

  // Then I should not see a delete link.
  $this
    ->assertSession()
    ->linkByHrefNotExists('admin/structure/crm-core/individual-types/customer/delete');
}