You are here

public function ProfileTest::testCompare in Profile 8

Tests comparing profiles.

File

tests/src/Kernel/ProfileTest.php, line 158

Class

ProfileTest
Tests basic functionality of profiles.

Namespace

Drupal\Tests\profile\Kernel

Code

public function testCompare() {
  $field_storage = FieldStorageConfig::create([
    'field_name' => 'field_fullname',
    'entity_type' => 'profile',
    'type' => 'text',
  ]);
  $field_storage
    ->save();
  foreach ([
    'customer_billing',
    'customer_shipping',
  ] as $profile_type_id) {
    $profile_type = ProfileType::create([
      'id' => $profile_type_id,
      'label' => $profile_type_id,
    ]);
    $profile_type
      ->save();
    $field = FieldConfig::create([
      'field_storage' => $field_storage,
      'bundle' => $profile_type_id,
      'label' => 'Full name',
    ]);
    $field
      ->save();
  }
  $first_profile = Profile::create([
    'type' => 'customer_billing',
    'uid' => 1,
    'field_fullname' => 'John Smith',
  ]);
  $second_profile = Profile::create([
    'type' => 'customer_billing',
    'uid' => 1,
    'field_fullname' => '',
  ]);
  $third_profile = Profile::create([
    'type' => 'customer_shipping',
    'uid' => 2,
    'field_fullname' => 'John Smith',
  ]);
  $this
    ->assertTrue($first_profile
    ->equalToProfile($third_profile));
  $this
    ->assertFalse($first_profile
    ->equalToProfile($third_profile, [
    'type',
    'field_fullname',
  ]));
  $this
    ->assertFalse($first_profile
    ->equalToProfile($second_profile));
  $this
    ->assertTrue($first_profile
    ->equalToProfile($second_profile, [
    'type',
  ]));
}