You are here

public function ContributorTest::testContributorName in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/tests/src/Kernel/ContributorTest.php \Drupal\Tests\bibcite_entity\Kernel\ContributorTest::testContributorName()

Test setting up of Contributor name.

File

modules/bibcite_entity/tests/src/Kernel/ContributorTest.php, line 47

Class

ContributorTest
Test contributor entity.

Namespace

Drupal\Tests\bibcite_entity\Kernel

Code

public function testContributorName() {
  $config = \Drupal::configFactory()
    ->getEditable('bibcite_entity.contributor.settings');
  $config
    ->set('full_name_pattern', '@prefix @first_name @middle_name @nick @last_name @suffix')
    ->save();
  $entity = Contributor::create($this->nameParts);
  $this
    ->assertEquals('Mr. Jüan Martinez Martin de Lorenzo y Gutierez Jr.', $entity->name->value);
  $config
    ->set('full_name_pattern', '@prefix @first_name @last_name @suffix')
    ->save();
  $this
    ->assertEquals('Mr. Jüan de Lorenzo y Gutierez Jr.', $entity->name->value);
  $entity = Contributor::create();
  $entity->name = $this->name;
  foreach ($this->nameParts as $part => $value) {
    $this
      ->assertEquals($value, $entity->{$part}->value);
  }
  $entity = Contributor::create();
  $entity->name = [
    $this->name,
  ];
  foreach ($this->nameParts as $part => $value) {
    $this
      ->assertEquals($value, $entity->{$part}->value);
  }
  $entity = Contributor::create();
  $entity->name = [
    'value' => $this->name,
  ];
  foreach ($this->nameParts as $part => $value) {
    $this
      ->assertEquals($value, $entity->{$part}->value);
  }
  $entity = Contributor::create();
  $entity->name = [
    [
      'value' => $this->name,
    ],
  ];
  foreach ($this->nameParts as $part => $value) {
    $this
      ->assertEquals($value, $entity->{$part}->value);
  }
}