You are here

public function AvatarKitGeneratorTest::testFileIsAvatarPreview in Avatar Kit 8

Tests whether a file is matched with an avatar preview.

Tests AvatarManagerInterface::getAvatarPreviewByFile()

File

tests/src/Functional/AvatarKitGeneratorTest.php, line 72

Class

AvatarKitGeneratorTest
Avatar Kit generator test.

Namespace

Drupal\Tests\avatars\Functional

Code

public function testFileIsAvatarPreview() {
  $generator_2 = AvatarGenerator::create([
    'label' => $this
      ->randomMachineName(),
    'id' => $this
      ->randomMachineName(),
    'plugin' => 'avatars_test_static',
  ]);
  $generator_2
    ->setStatus(TRUE)
    ->save();
  $user = $this
    ->createUser([
    'avatars avatar_generator user ' . $generator_2
      ->id(),
  ]);

  /** @var \Drupal\avatars\AvatarManagerInterface $am */
  $am = \Drupal::service('avatars.avatar_manager');
  $avatar_preview = $am
    ->findValidAvatar($user);
  $file = $avatar_preview
    ->getAvatar();
  $this
    ->assertEqual($avatar_preview
    ->id(), $am
    ->getAvatarPreviewByFile($file));
}