You are here

public function OrganizationUiTest::testOrganizationTypeOperations in CRM Core 8.2

Same name and namespace in other branches
  1. 8 modules/crm_core_contact/src/Tests/OrganizationUiTest.php \Drupal\crm_core_contact\Tests\OrganizationUiTest::testOrganizationTypeOperations()

Tests the organization type operations.

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

File

modules/crm_core_contact/src/Tests/OrganizationUiTest.php, line 194

Class

OrganizationUiTest
Tests the UI for Organization CRUD operations.

Namespace

Drupal\crm_core_contact\Tests

Code

public function testOrganizationTypeOperations() {

  // Create user with permission 'administer organization types'.
  $user = $this
    ->drupalCreateUser(array(
    'administer organization types',
  ));
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('admin/structure/crm-core/organization-types');

  // Test that there are edit, delete links for existing organizations.
  $this
    ->assertOrganizationTypeLink('supplier', 'Edit link for supplier.');
  $this
    ->assertOrganizationTypeLink('supplier/delete', 'Delete link for supplier.');
  $this
    ->assertOrganizationTypeLink('household', 'Edit link for household.');
  $this
    ->assertOrganizationTypeLink('household/delete', 'Delete link for household.');

  // Add another organization type.
  $second_organization_type = OrganizationType::create([
    'id' => 'new_organization_type',
    'label' => 'New organization type',
    'primary_fields' => [],
  ]);
  $second_organization_type
    ->save();
  $this
    ->drupalGet('admin/structure/crm-core/organization-types');

  // Create organization of type 'supplier.'.
  Organization::create(array(
    'type' => 'supplier',
  ))
    ->save();
  $this
    ->drupalGet('admin/structure/crm-core/organization-types');

  // Test that there is no a delete link.
  $this
    ->assertNoOrganizationTypeLink('supplier/delete', 'No delete link for supplier.');
  $this
    ->drupalGet('admin/structure/crm-core/organization-types/supplier/delete');
  $this
    ->assertResponse(403);
  $this
    ->drupalGet('admin/structure/crm-core/organization-types/supplier');

  // Test that there is no a delete link on supplier type form.
  $this
    ->assertNoOrganizationTypeLink('supplier/delete', 'No delete link on supplier type form.');
}