You are here

protected function UserUnauthorizedTest::setUp in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/Plugin/freelinking/UserUnauthorizedTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\UserUnauthorizedTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/Plugin/freelinking/UserUnauthorizedTest.php, line 35

Class

UserUnauthorizedTest
Tests the user plugin when the current user does not have access.

Namespace

Drupal\Tests\freelinking\Unit\Plugin\freelinking

Code

protected function setUp() {

  // Mock string translation interface.
  $tProphet = $this
    ->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
  $tProphet
    ->translateString(Argument::any())
    ->willReturn('Unauthorized to view user profile.');
  $this->translationInterfaceMock = $tProphet
    ->reveal();

  // Mock current user interface.
  $currentUserProphet = $this
    ->prophesize('\\Drupal\\Core\\Session\\AccountProxyInterface');
  $currentUserProphet
    ->hasPermission('access user profiles')
    ->willReturn(FALSE);

  // Mock entity type manager;
  $entityManagerProphet = $this
    ->prophesize('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
  $container = new ContainerBuilder();
  $container
    ->set('entity_type.manager', $entityManagerProphet
    ->reveal());
  $container
    ->set('string_translation', $this->translationInterfaceMock);
  $container
    ->set('current_user', $currentUserProphet
    ->reveal());
  \Drupal::setContainer($container);
  $this->container = $container;
  $plugin_definition = [
    'id' => 'user',
    'title' => 'User',
    'weight' => 0,
    'hidden' => FALSE,
    'settings' => [],
  ];
  $this->plugin = User::create($container, [], 'user', $plugin_definition);
}