RelationEntityTest.php 1.56 KB
Newer Older
RoSk0's avatar
RoSk0 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<?php

namespace Drupal\Tests\crm_core_user_sync\Kernel;

use Drupal\crm_core_user_sync\Entity\Relation;
use Drupal\KernelTests\KernelTestBase;

/**
 * Tests the relation entity class.
 *
 * @group crm_core_user_sync
 */
class RelationEntityTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'system',
    'user',
    'name',
    'crm_core_contact',
    'crm_core_user_sync',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->installEntitySchema('crm_core_user_sync_relation');
  }

  /**
   * Tests some of the methods.
   *
   * @see \Drupal\crm_core_user_sync\Entity\Relation::setUserId()
   * @see \Drupal\crm_core_user_sync\Entity\Relation::setIndividualId()
   * @see \Drupal\crm_core_user_sync\Entity\Relation::getUserId()
   * @see \Drupal\crm_core_user_sync\Entity\Relation::getIndividualId()
   */
  public function testRelationMethods() {
    $user_id_1 = 1;
    $individual_id_1 = 1;
    $user_id_2 = 2;
    $individual_id_2 = 2;

    $relation = Relation::create([
      'user_id' => $user_id_1,
      'individual_id' => $individual_id_1,
    ]);
    $this->assertEquals($user_id_1, $relation->getUserId(), 'User ID match');
    $this->assertEquals($individual_id_1, $relation->getIndividualId(), 'Individual ID match');

    $relation->setUserId($user_id_2);
    $this->assertEquals($user_id_2, $relation->getUserId(), 'User ID match');

    $relation->setIndividualId($individual_id_2);
    $this->assertEquals($individual_id_2, $relation->getIndividualId(), 'Individual ID match');
  }

}