You are here

public function UserDataCdfAttributeTest::testMailAttributePopulation in Acquia Content Hub 8.2

Tests mail attribute population.

@dataProvider populateMailAttributeProvider

Parameters

string $user_name: User name.

string $email: User email.

File

tests/src/Unit/EventSubscriber/CdfAttributes/UserDataCdfAttributeTest.php, line 131

Class

UserDataCdfAttributeTest
Tests the user data cdf attribute.

Namespace

Drupal\Tests\acquia_contenthub\Unit\EventSubscriber\CdfAttributes

Code

public function testMailAttributePopulation($user_name, $email) {

  /** @var \Drupal\user\UserInterface $entity */
  $entity = $this
    ->getMockBuilder(UserInterface::class)
    ->disableOriginalConstructor()
    ->setMethods([])
    ->getMockForAbstractClass();
  $entity
    ->method('label')
    ->willReturn($user_name);
  $entity
    ->method('getEntityTypeId')
    ->willReturn('user');
  $entity
    ->method('isAnonymous')
    ->willReturn(FALSE);
  $entity
    ->method('getEmail')
    ->willReturn($email);
  $entity
    ->method('uuid')
    ->willReturn('3f0b403c-4093-4caa-ba78-37df21125f09');
  $wrapper = new DependentEntityWrapper($entity);
  $event = new CdfAttributesEvent($this->cdf, $entity, $wrapper);
  $this->dispatcher
    ->dispatch(AcquiaContentHubEvents::POPULATE_CDF_ATTRIBUTES, $event);
  $attribute = $event
    ->getCdf()
    ->getAttribute('mail');
  $this
    ->assertEquals(CDFAttribute::TYPE_STRING, $attribute
    ->getType());
  $this
    ->assertNull($event
    ->getCdf()
    ->getAttribute('is_anonymous'));
  $this
    ->assertArrayEquals($attribute
    ->getValue(), [
    CDFObject::LANGUAGE_UNDETERMINED => $email,
  ]);
}